From 37bed568baaeebf981fd8015482e1b70292c996d Mon Sep 17 00:00:00 2001 From: Cyrille Bagard Date: Thu, 31 Jan 2019 21:53:21 +0100 Subject: Handled flat binaries for loop detection. --- python/wmzc.py | 53 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 8 deletions(-) diff --git a/python/wmzc.py b/python/wmzc.py index 957e247..a928722 100644 --- a/python/wmzc.py +++ b/python/wmzc.py @@ -6,10 +6,15 @@ import argparse import sys # from pychrysalide.features import * -from pychrysalide.analysis.contents import FileContent +from pychrysalide.analysis import BinRoutine +from pychrysalide.analysis import LoadedBinary from pychrysalide.analysis import StudyProject +from pychrysalide.analysis.contents import FileContent from pychrysalide.arch import ArchInstruction +from pychrysalide.arch import vmpa from pychrysalide.core import wait_for_all_global_works +from pychrysalide.format import FlatFormat +from pychrysalide.glibext import BinPortion def link_type_to_str(t): @@ -192,7 +197,7 @@ if __name__ == '__main__': parser.add_argument('-h', '--help', action='store_true', help='Display the command line options understood by %s.' % sys.argv[0]) parser.add_argument('binfile', type=str, help='The object file to be examined') - parser.add_argument('fname', type=str, help='The analyzed function to process') + parser.add_argument('target', type=str, help='The analyzed function to process (name or address)') args = parser.parse_args() @@ -200,20 +205,52 @@ if __name__ == '__main__': parser.print_help() sys.exit(1) - prj = StudyProject() + target = args.target cnt = FileContent(args.binfile) - prj.discover(cnt) + if target.startswith('0x'): + + fmt = FlatFormat(cnt) + fmt.set_machine('armv7') + + base = vmpa(0, int(target, 16) & ~0x1) + + p = BinPortion(BinPortion.BPC_CODE, base, cnt.size) + p.rights = BinPortion.PAC_READ | BinPortion.PAC_EXEC + + print(p.range) + + fmt.register_user_portion(p) + + sym = BinRoutine() + sym.name = 'code' + sym.range = p.range + + fmt.add_symbol(sym) + + fmt.register_code_point(int(target, 16), True) + + binary = LoadedBinary(fmt) + binary.analyze_and_wait() + + target = sym.name + + else: + + prj = StudyProject() + + prj.discover(cnt) + + wait_for_all_global_works() - wait_for_all_global_works() + binary = prj.contents[0] - binary = prj.contents[0] - sym = binary.format.find_symbol_by_label(args.fname) + sym = binary.format.find_symbol_by_label(target) if not(sym): - print('Function "%s" not found!' % args.fname) + print('Function "%s" not found!' % target) sys.exit(1) maxlen = 0 -- cgit v0.11.2-87-g4458