From b72049ce41766e113775793e3d37062985671f52 Mon Sep 17 00:00:00 2001 From: mjklbhvg <83467290+mjklbhvg@users.noreply.github.com> Date: Wed, 1 May 2024 18:28:07 +0200 Subject: [PATCH 1/2] Correctly parse offset from `info proc mappings` output (#1096) Fix the Offset column in the `vmmap` command by getting the offset from the correct column in `parse_gdb_info_proc_maps`. --- gef.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gef.py b/gef.py index d05f918ef..a744a9881 100644 --- a/gef.py +++ b/gef.py @@ -10705,7 +10705,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 "" From c7a19f88d9f3a12bb8c9bfc7b903d7ccfb2b6ccb Mon Sep 17 00:00:00 2001 From: mjklbhvg <83467290+mjklbhvg@users.noreply.github.com> Date: Thu, 2 May 2024 00:52:57 +0200 Subject: [PATCH 2/2] Extend the test for `gef.memory.parse_gdb_info_proc_maps()` The offsets parsed are now checked against the offsets in `/proc/PID/maps`. --- tests/api/gef_memory.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/api/gef_memory.py b/tests/api/gef_memory.py index d771b1038..19d2d350b 100644 --- a/tests/api/gef_memory.py +++ b/tests/api/gef_memory.py @@ -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