Skip to content

Commit

Permalink
add some symbols automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
DennyDai committed May 20, 2024
1 parent af1e952 commit 5854fa9
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/patcherex2/components/compilers/llvm_recomp.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,29 @@ def compile(
_symbols.update(symbols)

with open(os.path.join(td, "obj.o"), "rb") as f:
elf = ELFFile(f)
linker_script_rodata_sections = " ".join(
[
f". = ALIGN({section['sh_addralign']}); *({section.name})"
for section in ELFFile(f).iter_sections()
for section in elf.iter_sections()
if section.name.startswith(".rodata")
]
)

# automatically add symbols like off_deadbeef, dword_deadbeef, etc.
for sym in elf.get_section_by_name(".symtab").iter_symbols():
if (
sym.entry.st_shndx == "SHN_UNDEF"
and sym.name
and "_" in sym.name
):
try:
_, addr = sym.name.split("_", 1)
addr = int(addr, 16)
if sym.name not in _symbols:
_symbols[sym.name] = addr
except ValueError:
pass
linker_script_symbols = "".join(
f"{name} = {hex(addr)};" for name, addr in _symbols.items()
)
Expand Down

0 comments on commit 5854fa9

Please sign in to comment.