diff --git a/src/patcherex2/components/compilers/compiler.py b/src/patcherex2/components/compilers/compiler.py index 27a5109..74c2086 100644 --- a/src/patcherex2/components/compilers/compiler.py +++ b/src/patcherex2/components/compilers/compiler.py @@ -95,13 +95,13 @@ def compile( os.path.join(td, "obj_linked.o"), main_opts={"base_addr": 0x0} ) - text_section = next( + patcherex2_section = next( (s for s in ld.main_object.sections if s.name == ".patcherex2"), None ) compiled_start = ld.all_objects[0].entry + base compiled = ld.memory.load( compiled_start, - text_section.memsize - compiled_start, + patcherex2_section.memsize - compiled_start, ) return compiled diff --git a/src/patcherex2/components/compilers/llvm_recomp.py b/src/patcherex2/components/compilers/llvm_recomp.py index 5fc9072..9b2669d 100644 --- a/src/patcherex2/components/compilers/llvm_recomp.py +++ b/src/patcherex2/components/compilers/llvm_recomp.py @@ -202,7 +202,14 @@ def compile( ld = cle.Loader( os.path.join(td, "obj_linked.o"), main_opts={"base_addr": 0x0} ) + + patcherex2_section = next( + (s for s in ld.main_object.sections if s.name == ".patcherex2"), None + ) + compiled_start = ld.all_objects[0].entry + base + compiled = ld.memory.load( - ld.all_objects[0].entry + base, ld.memory.max_addr + compiled_start, + patcherex2_section.memsize - compiled_start, ) return compiled