Skip to content

Commit 18c1f7c

Browse files
Supporting changes for the "got-audit" command. (#1097)
## Description This change moves the setup of the line describing a GOT entry into a method in order to support the "got-audit" command, which is a subclass of the GotCommand. It also uses a full-width output from readelf, and gets the path for `nm`, both of which also support the got-audit command as a subclass.
1 parent 29fb74e commit 18c1f7c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

docs/install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Therefore it requires the following binaries to be present:
77

88
* `file`
99
* `readelf`
10+
* `nm`
1011
* `ps`
1112
* `python3`
1213

gef.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9263,6 +9263,11 @@ def __init__(self):
92639263
"Line color of the got command output for unresolved function")
92649264
return
92659265

9266+
def build_line(self, name: str, color: str, address_val: int, got_address: int) -> str:
9267+
line = f"[{hex(address_val)}] "
9268+
line += Color.colorify(f"{name} {RIGHT_ARROW} {hex(got_address)}", color)
9269+
return line
9270+
92669271
@only_if_gdb_running
92679272
def do_invoke(self, argv: List[str]) -> None:
92689273
readelf = gef.session.constants["readelf"]
@@ -9289,7 +9294,7 @@ def do_invoke(self, argv: List[str]) -> None:
92899294
relro_status = "No RelRO"
92909295

92919296
# retrieve jump slots using readelf
9292-
lines = gef_execute_external([readelf, "--relocs", elf_file], as_list=True)
9297+
lines = gef_execute_external([readelf, "--wide", "--relocs", elf_file], as_list=True)
92939298
jmpslots = [line for line in lines if "JUMP" in line]
92949299

92959300
gef_print(f"\nGOT protection: {relro_status} | GOT functions: {len(jmpslots)}\n ")
@@ -9317,8 +9322,7 @@ def do_invoke(self, argv: List[str]) -> None:
93179322
else:
93189323
color = self["function_resolved"]
93199324

9320-
line = f"[{hex(address_val)}] "
9321-
line += Color.colorify(f"{name} {RIGHT_ARROW} {hex(got_address)}", color)
9325+
line = self.build_line(name, color, address_val, got_address)
93229326
gef_print(line)
93239327
return
93249328

@@ -11072,7 +11076,7 @@ def __init__(self) -> None:
1107211076
self.aliases: List[GefAlias] = []
1107311077
self.modules: List[FileFormat] = []
1107411078
self.constants = {} # a dict for runtime constants (like 3rd party file paths)
11075-
for constant in ("python3", "readelf", "file", "ps"):
11079+
for constant in ("python3", "readelf", "nm", "file", "ps"):
1107611080
self.constants[constant] = which(constant)
1107711081
return
1107811082

0 commit comments

Comments
 (0)