Skip to content

Commit

Permalink
refactor: print to logging, and other small stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dobin committed Jun 19, 2023
1 parent c881df9 commit 3c2d802
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ stuff/
app/upload/**
app/examples/**
doc/todo.txt
doc/notes/**
4 changes: 2 additions & 2 deletions app/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def examples_list():

outcome, fileInfo, errStr = getFileData(filepath)
if errStr is not None:
print("Err: {} {}".format(example, errStr))
logging.error("Err: {} {}".format(example, errStr))
continue

outcomes.append(outcome)
Expand Down Expand Up @@ -154,7 +154,7 @@ def getFileData(filepath):

# Main file (exe, docx etc.)
if not os.path.isfile(filepath):
print("File does not exist: " + filepath)
logging.error("File does not exist: " + filepath)
return None, None, 'File not found: ' + filepath

# log file
Expand Down
1 change: 0 additions & 1 deletion config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ def load(self):
with open(CONFIG_FILE) as jsonfile:
try:
self.data = yaml.safe_load(jsonfile)
print(str(self.data))
except ValueError as e:
print('Decoding {} as failed with: {}'.format(CONFIG_FILE, e))
quit()
Expand Down
2 changes: 1 addition & 1 deletion pcodedmp/disasm.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def dumpLine(moduleData, modulename, lineStart, lineLength, endian, vbaVer, is64
translatedOpcode = translateOpcode(opcode, vbaVer, is64bit)
if not translatedOpcode in opcodes:
disasmEntry += myPrint('Unrecognized opcode 0x{:04X} at offset 0x{:08X}.'.format(opcode, offset), file=output_file)
print(disasmEntry)
# print(disasmEntry)
return
instruction = opcodes[translatedOpcode]
mnemonic = instruction['mnem']
Expand Down
4 changes: 2 additions & 2 deletions plugins/outflank_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def outflankPe(
ret = []
data: Data = filePe.DataCopy()
for patch in results:
print("Match {} offset {}: {} <-> {} ({})".format(
patch.matchIdx, hex(patch.offset), patch.asmOne.disasm, patch.asmTwo.disasm, patch.info))
#print("Match {} offset {}: {} <-> {} ({})".format(
# patch.matchIdx, hex(patch.offset), patch.asmOne.disasm, patch.asmTwo.disasm, patch.info))
data.patchData(patch.offset, patch.replaceBytes)
ret.append(patch)
if not scanner.scannerDetectsBytes(data.getBytes(), filePe.filename):
Expand Down
4 changes: 2 additions & 2 deletions scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def scannerDetectsBytes(self, data: bytes, filename: str):
jsonRes = res.json()

if res.status_code != 200:
print("Err: " + str(res.status_code))
print("Err: " + str(res.text))
logging.error("Err: " + str(res.status_code))
logging.error("Err: " + str(res.text))

ret_value = jsonRes['detected']
return ret_value
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pe.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_pe4(self):

matches, _ = analyzeFileExe(filePe, scanner)
# A: [Interval(29808, 29864), Interval(30816, 30844), Interval(31824, 31880), Interval(33140, 33168)]
self.assertTrue(len(matches) == 4)
self.assertEqual(len(matches), 4)


def test_disasm(self):
Expand Down
9 changes: 7 additions & 2 deletions tools/patchfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@

fname = sys.argv[1]
pos = int(sys.argv[2], 0)
data = str.encode(sys.argv[3])

print( f"Writing {data} to file {fname} at position {pos} ")
#data = str.encode(sys.argv[3])
data = bytes.fromhex(sys.argv[3])
#len = int(sys.argv[3])

#data = b"A" * len

print( f"Writing {len} bytes to file {fname} at position {pos} ")

fp = open(fname, "r+b")

Expand Down

0 comments on commit 3c2d802

Please sign in to comment.