diff --git a/ScratchABit.py b/ScratchABit.py index 3a4c376..ac0b7bf 100755 --- a/ScratchABit.py +++ b/ScratchABit.py @@ -846,7 +846,15 @@ def parse_disasm_def(fname): if args[2][0] in string.digits: addr = str2int(args[2]) print("Loading %s @0x%x" % (args[1], addr)) - engine.ADDRESS_SPACE.load_content(open(args[1], "rb"), addr) + file_off = 0 + sz = None + if len(args) == 4: + try: + file_off = str2int(args[3]) + except: + file_off, end = parse_range(args[3]) + sz = end - file_off + 1 + engine.ADDRESS_SPACE.load_content(open(args[1], "rb"), addr, sz, file_off) else: print("Loading %s (%s plugin)" % (args[1], args[2])) loader = __import__(args[2]) diff --git a/example-x86_64.def b/example-x86_64.def index e17a0c8..c6af111 100644 --- a/example-x86_64.def +++ b/example-x86_64.def @@ -15,6 +15,11 @@ area .bin 0x600000(0x1000) rwx # Load binary code to disassemble to the defined memory area load example-x86_64.bin 0x600000 +# Load binary code to disassemble to the defined memory area +# optional argument takes offset in source file and lenght with same syntax as area +#load example-x86_64.bin 0x600000 0x8 #Load area size from example-x86_64.bin, skipping first 8 bytes of example-x86_64.bin +#load example-x86_64.bin 0x600000 0x8(0x9) #Load given size (0x9) from example-x86_64.bin, skipping first 0x8 bytes of example-x86_64.bin + # And/or load a structured executable (e.g. ELF) via a specific # loader plugin ("elf" below). #load example-x86_32.elf elf diff --git a/scratchabit/engine.py b/scratchabit/engine.py index f16dcc9..f9ac471 100644 --- a/scratchabit/engine.py +++ b/scratchabit/engine.py @@ -180,10 +180,13 @@ def is_exec(self, addr): # Binary Data API - def load_content(self, file, addr, sz=None): + def load_content(self, file, addr, sz=None, file_off=0): off, area = self.addr2area(addr) to = off + sz if sz else None - file.readinto(memoryview(area[BYTES])[off:to]) + if file_off != 0: + file.seek(file_off) + rbc = file.readinto(memoryview(area[BYTES])[off:to]) + log.info("read 0x%x bytes into area @0x%x from file %s with offset 0x%x" % (rbc, addr, file.name, file_off)) def is_valid_addr(self, addr): off, area = self.addr2area(addr)