from miasm2.core.locationdb import LocationDB # Basic tests (LocationDB description) loc_db = LocationDB() loc_key1 = loc_db.add_location() loc_key2 = loc_db.add_location(offset=0x1234) loc_key3 = loc_db.add_location(name="first_name") loc_db.add_location_name(loc_key3, "second_name") loc_db.set_location_offset(loc_key3, 0x5678) loc_db.remove_location_name(loc_key3, "second_name") assert loc_db.get_location_offset(loc_key1) is None assert loc_db.get_location_offset(loc_key2) == 0x1234 assert loc_db.pretty_str(loc_key1) == str(loc_key1) assert loc_db.pretty_str(loc_key2) == "loc_1234" assert loc_db.pretty_str(loc_key3) == "first_name" loc_db.consistency_check() # Offset manipulation loc_key4 = loc_db.add_location() assert loc_db.get_location_offset(loc_key4) is None loc_db.set_location_offset(loc_key4, 0x1122) assert loc_db.get_location_offset(loc_key4) == 0x1122 loc_db.unset_location_offset(loc_key4) assert loc_db.get_location_offset(loc_key4) is None try: loc_db.set_location_offset(loc_key4, 0x1234) has_raised = False except KeyError: has_raised = True
from miasm2.core.locationdb import LocationDB # Basic tests (LocationDB description) loc_db = LocationDB() loc_key1 = loc_db.add_location() loc_key2 = loc_db.add_location(offset=0x1234) loc_key3 = loc_db.add_location(name="first_name") loc_db.add_location_name(loc_key3, "second_name") loc_db.set_location_offset(loc_key3, 0x5678) loc_db.remove_location_name(loc_key3, "second_name") assert loc_db.get_location_offset(loc_key1) is None assert loc_db.get_location_offset(loc_key2) == 0x1234 assert loc_db.pretty_str(loc_key1) == str(loc_key1) assert loc_db.pretty_str(loc_key2) == "loc_1234" assert loc_db.pretty_str(loc_key3) == "first_name" loc_db.consistency_check() # Offset manipulation loc_key4 = loc_db.add_location() assert loc_db.get_location_offset(loc_key4) is None loc_db.set_location_offset(loc_key4, 0x1122) assert loc_db.get_location_offset(loc_key4) == 0x1122 loc_db.unset_location_offset(loc_key4) assert loc_db.get_location_offset(loc_key4) is None try: loc_db.set_location_offset(loc_key4, 0x1234) has_raised = False except KeyError:
addr_main = 0 virt = st output = st # Get and parse the source code with open(args.source) as fstream: source = fstream.read() loc_db = LocationDB() asmcfg, loc_db = parse_asm.parse_txt(machine.mn, attrib, source, loc_db) # Fix shellcode addrs loc_db.set_location_offset(loc_db.get_name_location("main"), addr_main) if args.PE: loc_db.set_location_offset(loc_db.get_or_create_name_location("MessageBoxA"), pe.DirImport.get_funcvirt('USER32.dll', 'MessageBoxA')) # Print and graph firsts blocks before patching it for block in asmcfg.blocks: print block open("graph.dot", "w").write(asmcfg.dot()) # Apply patches patches = asmblock.asm_resolve_final(machine.mn, asmcfg, loc_db,