From 4658a0325694d6c660492c393e0bfc54f35bc440 Mon Sep 17 00:00:00 2001 From: Han Dai Date: Wed, 24 Apr 2024 14:54:34 -0400 Subject: [PATCH] fix #29: do not include unnecessary sections --- src/patcherex2/components/compilers/compiler.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/patcherex2/components/compilers/compiler.py b/src/patcherex2/components/compilers/compiler.py index 6f2ce72..970fb1e 100644 --- a/src/patcherex2/components/compilers/compiler.py +++ b/src/patcherex2/components/compilers/compiler.py @@ -94,17 +94,14 @@ def compile( ld = cle.Loader( os.path.join(td, "obj_linked.o"), main_opts={"base_addr": 0x0} ) - # TODO: cle will stop at the beginning of the first unallocated region - # found, or when `ld.memory.max_addr` bytes have been read. - # So if there is no gap between .text and the next section, cle will - # include the next section in the compiled code as well. - # text_section = next( - # (s for s in ld.main_object.sections if s.name == ".text"), None - # ) + text_section = next( + (s for s in ld.main_object.sections if s.name == ".text"), None + ) + compiled_start = ld.all_objects[0].entry + base + compiled = ld.memory.load( - ld.all_objects[0].entry + base, - ld.memory.max_addr, - # (text_section.vaddr + text_section.memsize), + compiled_start, + text_section.memsize - compiled_start, ) return compiled