diff --git a/linux-ramdump-parser-v2/gdbmi.py b/linux-ramdump-parser-v2/gdbmi.py old mode 100644 new mode 100755 index 981d14907c313e10f81fdb771d8774382add50af..7301bef2d47323d3564910733753911b8374f175 --- a/linux-ramdump-parser-v2/gdbmi.py +++ b/linux-ramdump-parser-v2/gdbmi.py @@ -56,9 +56,10 @@ class GdbMI(object): print('GDB Version: ' + g.version()) """ - def __init__(self, gdb_path, elf): + def __init__(self, gdb_path, elf, kaslr_offset=0): self.gdb_path = gdb_path self.elf = elf + self.kaslr_offset = kaslr_offset self._cache = {} self._gdbmi = None @@ -214,7 +215,7 @@ class GdbMI(object): '0xc0b0006a' """ result = self._run_for_one('print /x &{0}'.format(symbol)) - return int(result.split(' ')[-1], 16) + return int(result.split(' ')[-1], 16) + self.kaslr_offset def get_symbol_info(self, address): """Returns a GdbSymbol representing the nearest symbol found at diff --git a/linux-ramdump-parser-v2/ramdump.py b/linux-ramdump-parser-v2/ramdump.py old mode 100644 new mode 100755 index 357ba6dd16687c2bb2d53ff5f42aeaf6973ad6c5..91d1bc55c0d42681e1b37a29197169a238230056 --- a/linux-ramdump-parser-v2/ramdump.py +++ b/linux-ramdump-parser-v2/ramdump.py @@ -420,6 +420,7 @@ class RamDump(): def __init__(self, options, nm_path, gdb_path, objdump_path): self.ebi_files = [] self.phys_offset = None + self.kaslr_offset = options.kaslr_offset self.tz_start = 0 self.ebi_start = 0 self.cpu_type = None @@ -432,7 +433,8 @@ class RamDump(): self.objdump_path = objdump_path self.outdir = options.outdir self.imem_fname = None - self.gdbmi = gdbmi.GdbMI(self.gdb_path, self.vmlinux) + self.gdbmi = gdbmi.GdbMI(self.gdb_path, self.vmlinux, + self.kaslr_offset or 0) self.gdbmi.open() self.arm64 = options.arm64 self.page_offset = 0xc0000000 @@ -447,6 +449,7 @@ class RamDump(): self.ipc_log_help = options.ipc_help self.use_stdout = options.stdout self.kernel_version = (0, 0, 0) + if options.ram_addr is not None: # TODO sanity check to make sure the memory regions don't overlap for file_path, start, end in options.ram_addr: @@ -815,8 +818,12 @@ class RamDump(): 'PER.S.F C15:0x202 %L 0x80030000\n'.encode('ascii', 'ignore')) startup_script.write('mmu.on\n'.encode('ascii', 'ignore')) startup_script.write('mmu.scan\n'.encode('ascii', 'ignore')) - startup_script.write( - ('data.load.elf ' + os.path.abspath(self.vmlinux) + ' /nocode\n').encode('ascii', 'ignore')) + + where = os.path.abspath(self.vmlinux) + if self.kaslr_offset is not None: + where += ' 0x{0:x}'.format(self.kaslr_offset) + dloadelf = 'data.load.elf {} /nocode\n'.format(where) + startup_script.write(dloadelf.encode('ascii', 'ignore')) if t32_host_system != 'Linux': if self.arm64: @@ -990,10 +997,16 @@ class RamDump(): def setup_symbol_tables(self): stream = os.popen(self.nm_path + ' -n ' + self.vmlinux) symbols = stream.readlines() + kaslr = 0 + + if self.kaslr_offset is not None: + kaslr = int(self.kaslr_offset) + for line in symbols: s = line.split(' ') if len(s) == 3: - self.lookup_table.append((int(s[0], 16), s[2].rstrip())) + self.lookup_table.append((int(s[0], 16) + kaslr, + s[2].rstrip())) stream.close() def address_of(self, symbol): diff --git a/linux-ramdump-parser-v2/ramparse.py b/linux-ramdump-parser-v2/ramparse.py index 318f68b63844dd77bf7464b8b40725b95a67aa7c..4c3cc9866b4892db3c867e61c969400339c56600 100755 --- a/linux-ramdump-parser-v2/ramparse.py +++ b/linux-ramdump-parser-v2/ramparse.py @@ -110,6 +110,9 @@ if __name__ == '__main__': dest='stdout', help='Dump to stdout instead of the file') parser.add_option('', '--phys-offset', type='int', dest='phys_offset', help='use custom phys offset') + parser.add_option('', '--kaslr-offset', type='int', + dest='kaslr_offset', + help='Offset for address space layout randomization') parser.add_option('', '--page-offset', type='int', dest='page_offset', help='use custom page offset') parser.add_option('', '--force-hardware', type='int',