Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support .L for local labels #53

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion ppcdis/disassembler.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def to_txt(self, sym: SymbolGetter, inline=False, hashable=False, referenced=Non
prefix.append(f".global {name}")
prefix.append(f"{name}:")
else:
# Use the inline version of the name for non-global addresses if inline asm
name = sym.get_name_inline(self.instr.address, hashable, True) if inline else name
prefix.append(f"{name}:")

# Add jumptable label if required
Expand Down Expand Up @@ -191,7 +193,7 @@ def _process_labelled_branch(self, instr: capstone.CsInsn, line: DisasmLine, inl
dest = instr.operands[-1].imm

# Get symbol name
name = self._sym.get_name(dest, hashable)
name = self._sym.get_name_inline(dest, hashable) if inline and not self._sym.is_global(dest) else self._sym.get_name(dest, hashable)

# Use hardcoded address if needed
# TODO: make shiftable somehow
Expand Down
18 changes: 18 additions & 0 deletions ppcdis/symbols.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ def get_name(self, addr: int, hash_mode=False, miss_ok=False) -> str:
return sym.name
else:
return None

def get_name_inline(self, addr: int, hash_mode=False, miss_ok=False) -> str:
"""Checks the name of the symbol at an address
for inline asm functions

Asserts the symbol exists unless miss_ok"""

assert miss_ok or addr in self._sym, f"Address {addr:x} missed in analysis"

sym = self._sym.get(addr)

if sym is not None:
if hash_mode:
return self.get_hash_name(addr)
else:
return f"lbl_{addr:x}"
else:
return None

def is_global(self, addr: int, miss_ok=False) -> bool:
"""Checks whether the symbol at an address is global
Expand Down