Skip to content

Commit

Permalink
fix #29: do not include unnecessary sections
Browse files Browse the repository at this point in the history
  • Loading branch information
DennyDai committed Apr 24, 2024
1 parent 6bc4e58 commit 4658a03
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/patcherex2/components/compilers/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 4658a03

Please sign in to comment.