Skip to content

Commit 00578b8

Browse files
authored
Rebase addresses feature (#35)
1 parent 1563f74 commit 00578b8

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ Settings are stored in a file `.llef` located in your home directory formatted a
6969
| show_threads | Boolean | Enable/disable threads output |
7070
| show_trace | Boolean | Enable/disable trace output |
7171
| force_arch | String | Force register display architecture (experimental) |
72+
| rebase_addresses | Boolean | Enable/disable address rebase output |
73+
| rebase_offset | Int | Set the rebase offset (default 0x100000) |
7274

7375
#### Context
7476

@@ -106,6 +108,12 @@ aabacadaea
106108
### Breakpoint hook
107109
This is automatic and prints all the currently implemented information at a break point.
108110

111+
#### Address Rebasing
112+
Configurable with the `rebase_addresses` setting the address rebasing feature performs a lookup for each code address presented in the output to display the associated binary and relative address. This relative address is offset by the value defined in setting `rebase_offset` which defaults to the Ghidra base address of `0x100000`. The result is an address output that can be easily copied and pasted into an IDE "Go To Address" feature without having to do the maths to convert from the runtime address.
113+
114+
Rebased addresses are shown in brackets after the runtime address:
115+
![rebase address feature](assets/rebase-feature.png)
116+
109117
## 👷‍♂️ Troubleshooting LLDB Python support
110118
LLDB comes bundled with python modules that are required for LLEF to run. If on launching LLDB with LLEF you encounter `ModuleNotFoundError` messages it is likely you will need to manually add the LLDB python modules on your python path.
111119

assets/rebase-feature.png

67.1 KB
Loading

common/context_handler.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import os
2+
13
from typing import Dict, Type, Optional
24

35
from lldb import (
@@ -60,6 +62,16 @@ def output_line(self, line: str) -> None:
6062
for term_color in TERM_COLORS:
6163
line = line.replace(term_color.value, "")
6264
print(line)
65+
66+
def generate_rebased_address_string(self, address: SBAddress) -> str:
67+
module = address.GetModule()
68+
69+
if module is not None and self.settings.rebase_addresses is True:
70+
file_name = os.path.basename(str(module.file))
71+
rebased_address = address.GetFileAddress() + self.settings.rebase_offset
72+
return f" {TERM_COLORS.GREY.value}({file_name} {rebased_address:#x}){TERM_COLORS.ENDC.value}"
73+
74+
return ""
6375

6476
def generate_printable_line_from_pointer(
6577
self, pointer: SBValue, address_containing_pointer: Optional[int] = None
@@ -78,7 +90,7 @@ def generate_printable_line_from_pointer(
7890
pointer_value.offset - pointer_value.symbol.GetStartAddress().offset
7991
)
8092
line += (
81-
f" {GLYPHS.RIGHT_ARROW.value} {TERM_COLORS.GREY.value}"
93+
f"{self.generate_rebased_address_string(pointer_value)} {GLYPHS.RIGHT_ARROW.value} {TERM_COLORS.GREY.value}"
8294
+ f"<{pointer_value.symbol.name}+{offset}>{TERM_COLORS.ENDC.value}"
8395
)
8496

@@ -285,15 +297,16 @@ def display_trace(self) -> None:
285297
current_frame = self.thread.GetFrameAtIndex(i)
286298
pc_address = current_frame.GetPCAddress()
287299
func = current_frame.GetFunction()
300+
trace_address = pc_address.GetLoadAddress(self.target)
288301

289302
if func:
290303
line += (
291-
f"{pc_address.GetLoadAddress(self.target):#x} {GLYPHS.RIGHT_ARROW.value} "
304+
f"{trace_address:#x}{self.generate_rebased_address_string(pc_address)} {GLYPHS.RIGHT_ARROW.value} "
292305
+ f"{TERM_COLORS.GREEN.value}{func.GetName()}{TERM_COLORS.ENDC.value}"
293306
)
294307
else:
295308
line += (
296-
f"{pc_address.GetLoadAddress(self.target):#x} {GLYPHS.RIGHT_ARROW.value} "
309+
f"{trace_address:#x}{self.generate_rebased_address_string(pc_address)} {GLYPHS.RIGHT_ARROW.value} "
297310
+ f"{TERM_COLORS.GREEN.value}{current_frame.GetSymbol().GetName()}{TERM_COLORS.ENDC.value}"
298311
)
299312

common/settings.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ def force_arch(self):
5252
arch = self._RAW_CONFIG.get(GLOBAL_SECTION, "force_arch", fallback=None)
5353
return None if arch not in supported_arch else arch
5454

55+
@property
56+
def rebase_addresses(self):
57+
return self._RAW_CONFIG.getboolean(GLOBAL_SECTION, "rebase_addresses", fallback=True)
58+
59+
@property
60+
def rebase_offset(self):
61+
return self._RAW_CONFIG.getint(GLOBAL_SECTION, "rebase_offset", fallback=0x100000)
62+
5563
@classmethod
5664
def _get_setting_names(cls):
5765
return [name for name, value in vars(cls).items() if isinstance(value, property)]

0 commit comments

Comments
 (0)