Skip to content

Commit

Permalink
Supporting changes for the "got-audit" command. (#1097)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
gordonmessmer committed May 5, 2024
1 parent 29fb74e commit 18c1f7c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/install.md
Expand Up @@ -7,6 +7,7 @@ Therefore it requires the following binaries to be present:

* `file`
* `readelf`
* `nm`
* `ps`
* `python3`

Expand Down
12 changes: 8 additions & 4 deletions gef.py
Expand Up @@ -9263,6 +9263,11 @@ def __init__(self):
"Line color of the got command output for unresolved function")
return

def build_line(self, name: str, color: str, address_val: int, got_address: int) -> str:
line = f"[{hex(address_val)}] "
line += Color.colorify(f"{name} {RIGHT_ARROW} {hex(got_address)}", color)
return line

@only_if_gdb_running
def do_invoke(self, argv: List[str]) -> None:
readelf = gef.session.constants["readelf"]
Expand All @@ -9289,7 +9294,7 @@ def do_invoke(self, argv: List[str]) -> None:
relro_status = "No RelRO"

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

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

line = f"[{hex(address_val)}] "
line += Color.colorify(f"{name} {RIGHT_ARROW} {hex(got_address)}", color)
line = self.build_line(name, color, address_val, got_address)
gef_print(line)
return

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

Expand Down

0 comments on commit 18c1f7c

Please sign in to comment.