From 0386676f904570310e2e5fc56fd1fd7896facf59 Mon Sep 17 00:00:00 2001 From: Dobin Date: Sun, 2 Jun 2024 17:38:52 +0100 Subject: [PATCH] add: relokator --- relokator.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 relokator.py diff --git a/relokator.py b/relokator.py new file mode 100644 index 0000000..113fc19 --- /dev/null +++ b/relokator.py @@ -0,0 +1,44 @@ +import sys + +from model.defs import * +from pe.superpe import SuperPe + + +def main(filename: str, current_base: int): + print("Handling: {}".format(filename)) + superpe = SuperPe(filename) + + r = {} + relocation: PeRelocEntry + for relocation in superpe.get_base_relocs(): + if relocation.base_rva in r: + r[relocation.base_rva] += 1 + else: + r[relocation.base_rva] = 1 + + #print("Base: 0x{:X} RVA: 0x{:X} Offset: {} Type: {}".format( + # relocation.base_rva, + # relocation.rva, + # relocation.offset, + # relocation.type, + #)) + + sum = 0 + for base, count in r.items(): + print("0x{:X}: {}".format(base, count)) + sum += count + print("Sum: {}".format(sum)) + + print("Image Base : 0x{:X}".format(superpe.get_image_base())) + print("Current Base: 0x{:X}".format(current_base)) + + +if __name__ == "__main__": + if len(sys.argv) != 3: + print("./relokator ") + exit(1) + + filename = sys.argv[1] + current_base = int(sys.argv[2], 16) + main(filename, current_base) +