Skip to content

Commit

Permalink
[error] Separate unsupported instruction logging #7
Browse files Browse the repository at this point in the history
  • Loading branch information
SanWieb committed Dec 22, 2023
1 parent 52ceb6b commit b8bcbe4
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
15 changes: 14 additions & 1 deletion analyzer/scanner/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,23 @@ def run(self, proj: angr.Project, start_address, config) -> list[TransmissionExp
except SplitException as e:
l.error(str(e))
continue
except (angr.errors.SimIRSBNoDecodeError, angr.errors.UnsupportedIROpError) as e:
l.error("=============== UNSUPPORTED INSTRUCTION ===============")
l.error(str(e))
report_unsupported(e, hex(self.cur_state.addr), hex(start_address), error_type="SCANNER")
continue
except angr.errors.UnsupportedDirtyError as e:
if "IRET" in str(e):
continue
l.error("=============== UNSUPPORTED INSTRUCTION ===============")
l.error(str(e))
report_unsupported(e, hex(self.cur_state.addr), hex(start_address), error_type="SCANNER")
continue
except Exception as e:
l.error("=============== ERROR ===============")
l.error(str(e))
l.error(traceback.format_exc())
if not l.disabled:
traceback.format_exc()
report_error(e, hex(self.cur_state.addr), hex(start_address), error_type="SCANNER")
continue

Expand Down
16 changes: 15 additions & 1 deletion analyzer/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,28 @@ def get_x86_registers():


def report_error(error: Exception, where="dunno", start_addr="dunno", error_type="GENERIC"):
ins_addr = None
if hasattr(error, 'ins_addr') and isinstance(error.ins_addr, int):
ins_addr = hex(error.ins_addr)

o = open("fail.txt", "a+")
o.write(f"---------------- [ {error_type} ERROR ] ----------------\n")
o.write(f"in basic block: {where} started at:{start_addr}\n")
o.write(f"where: {where} started at: {start_addr} {f'instruction addr: {ins_addr}' if ins_addr else ''}\n")
o.write(str(error) + "\n")
o.write(traceback.format_exc())
o.write("\n")
o.close()

def report_unsupported(error: Exception, where="dunno", start_addr="dunno", error_type="GENERIC"):
if hasattr(error, 'ins_addr') and isinstance(error.ins_addr, int):
where = hex(error.ins_addr)

o = open("unsupported.txt", "a+")
o.write(f"---------------- [ {error_type} UNSUPPORTED INSTRUCTION ] ----------------\n")
o.write(f"instruction addr: {where} started at: {start_addr}\n")
o.write(str(error) + "\n")
o.write("\n")
o.close()

def branch_outcomes(history):
outcomes = []
Expand Down
1 change: 1 addition & 0 deletions tests/test-cases/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*/gadget
output/*
fail.txt
unsupported.txt

0 comments on commit b8bcbe4

Please sign in to comment.