Skip to content

Commit

Permalink
Correctly parse offset from info proc mappings output (#1096) (#1098)
Browse files Browse the repository at this point in the history
## Description
Fix the Offset column in the `vmmap` command by getting the offset from
the correct column in `parse_gdb_info_proc_maps`.

Before:
```
gef➤  vmmap
[ Legend:  Code | Heap | Stack ]
Start              End                Offset             Perm Path
0x0000555555554000 0x0000555555558000 0x0000000000004000 r-- /usr/bin/ls
0x0000555555558000 0x000055555556e000 0x0000000000016000 r-x /usr/bin/ls
0x000055555556e000 0x0000555555577000 0x0000000000009000 r-- /usr/bin/ls
0x0000555555577000 0x0000555555579000 0x0000000000002000 r-- /usr/bin/ls
0x0000555555579000 0x000055555557a000 0x0000000000001000 rw- /usr/bin/ls
0x000055555557a000 0x000055555557b000 0x0000000000001000 rw- [heap]
```

After:
```
gef➤  vmmap
[ Legend:  Code | Heap | Stack ]
Start              End                Offset             Perm Path
0x0000555555554000 0x0000555555558000 0x0000000000000000 r-- /usr/bin/ls
0x0000555555558000 0x000055555556e000 0x0000000000004000 r-x /usr/bin/ls
0x000055555556e000 0x0000555555577000 0x000000000001a000 r-- /usr/bin/ls
0x0000555555577000 0x0000555555579000 0x0000000000023000 r-- /usr/bin/ls
0x0000555555579000 0x000055555557a000 0x0000000000025000 rw- /usr/bin/ls
0x000055555557a000 0x000055555557b000 0x0000000000000000 rw- [heap]
```

info proc mappings:
```
gef➤  info proc mappings
process 18800
Mapped address spaces:

          Start Addr           End Addr       Size     Offset  Perms  objfile
      0x555555554000     0x555555558000     0x4000        0x0  r--p   /usr/bin/ls
      0x555555558000     0x55555556e000    0x16000     0x4000  r-xp   /usr/bin/ls
      0x55555556e000     0x555555577000     0x9000    0x1a000  r--p   /usr/bin/ls
      0x555555577000     0x555555579000     0x2000    0x23000  r--p   /usr/bin/ls
      0x555555579000     0x55555557a000     0x1000    0x25000  rw-p   /usr/bin/ls
      0x55555557a000     0x55555557b000     0x1000        0x0  rw-p   [heap]
```
  • Loading branch information
mjklbhvg committed May 19, 2024
1 parent 18c1f7c commit 13d1de2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -10709,7 +10709,7 @@ def parse_gdb_info_proc_maps(cls) -> Generator[Section, None, None]:
break

parts = [x.strip() for x in line.split()]
addr_start, addr_end, offset = [int(x, 16) for x in parts[0:3]]
addr_start, addr_end, _, offset = [int(x, 16) for x in parts[0:4]]
if mock_permission:
perm = Permission(7)
path = " ".join(parts[4:]) if len(parts) >= 4 else ""
Expand Down
7 changes: 5 additions & 2 deletions tests/api/gef_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ def test_api_gef_memory_parse_info_proc_maps(self):
next(root.eval("gef.memory.parse_gdb_info_proc_maps()") )

else:
for section in root.eval("gef.memory.parse_gdb_info_proc_maps()"):
assert isinstance(section, Section)
sections = list(root.eval("gef.memory.parse_gdb_info_proc_maps()"))
with open(f"/proc/{gef.session.pid}/maps") as f:
for section, line in zip(sections, f.read().splitlines()):
assert isinstance(section, Section)
assert section.offset == int(line.split()[2], 16)

def test_func_parse_permissions(self):
root = self._conn.root
Expand Down

0 comments on commit 13d1de2

Please sign in to comment.