From 9570c5d3939bc18de6aed1365785e1d88afb04ab Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Sat, 20 Apr 2019 11:33:59 +0200 Subject: Tracked Xrefs in routines. --- python/check_links.py | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 python/check_links.py diff --git a/python/check_links.py b/python/check_links.py new file mode 100644 index 0000000..c0c2f17 --- /dev/null +++ b/python/check_links.py @@ -0,0 +1,65 @@ + +import sys +import pychrysalide +from pychrysalide.analysis.contents import FileContent +from pychrysalide.analysis import StudyProject +from pychrysalide.core import wait_for_all_global_works + + +if len(sys.argv) != 3: + print('Usage: %s ' % sys.argv[0]) + sys.exit(1) + + +# Load the provided binary + +cnt = FileContent(sys.argv[1]) + +prj = StudyProject() + +prj.discover(cnt) + +wait_for_all_global_works() + +if len(prj.contents) == 0: + print('Unable to load %s...' % sys.argv[1]) + sys.exit(1) + +binary = prj.contents[0] + +routine = binary.format.find_symbol_by_label(sys.argv[2]) + +if routine is None: + print('%s not found!' % sys.argv[2]) + sys.exit(1) + + +# Display links + +types = [ + 'ILT_EXEC_FLOW', + 'ILT_JUMP', + 'ILT_CASE_JUMP', + 'ILT_JUMP_IF_TRUE', + 'ILT_JUMP_IF_FALSE', + 'ILT_LOOP', + 'ILT_CALL', + 'ILT_CATCH_EXCEPTION', + 'ILT_REF' +] + +has_virt = binary.processor.virtual_space + +for ins in binary.processor.instrs.restrict(routine.range): + + if has_virt: + print('%x / %x - %s' % (ins.range.addr.phys, ins.range.addr.virt, ins.keyword)) + else: + print('%x - %s' % (ins.range.addr.phys, ins.keyword)) + + for dst, tp in ins.destinations: + + if has_virt: + print(' > %x / %x (%s)' % (dst.range.addr.phys, dst.range.addr.virt, types[tp])) + else: + print(' > %x (%s)' % (dst.range.addr.phys, types[tp])) -- cgit v0.11.2-87-g4458