Skip to content

Commit

Permalink
Style changes and parsing unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Nov 17, 2022
1 parent d17ebc5 commit 360e3b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
9 changes: 2 additions & 7 deletions gef.py
Expand Up @@ -10264,16 +10264,11 @@ def __parse_gdb_info_sections(self) -> Generator[Section, None, None]:

def __parse_info_mem(self) -> Generator[Section, None, None]:
"""Get the memory mapping from GDB's command `monitor info mem`"""
stream = StringIO(gdb.execute("monitor info mem", to_string=True))
for line in stream:
for line in StringIO(gdb.execute("monitor info mem", to_string=True)):
if not line:
break
try:
# FORMAT
# ffffff2a65e0b000-ffffff2a65e0c000 0000000000001000 -r-
# ^--- start ^--- end ^--- offset ^^^-- perms
# `perms` are `urw`, for "usermode", "readable", "writable"
ranges, off, perms = line.split(" ")
ranges, off, perms = line.split()
off = int(off, 16)
start, end = [int(s, 16) for s in ranges.split("-")]
except ValueError as e:
Expand Down
12 changes: 12 additions & 0 deletions tests/api/misc.py
Expand Up @@ -41,6 +41,18 @@ def test_func_parse_address(self):
res = gdb_test_python_method(func)
self.assertException(res)

def test_func_parse_maps(self):
func = "Permission.from_info_sections(' [10] 0x555555574000->0x55555557401b at 0x00020000: .init ALLOC LOAD READONLY CODE HAS_CONTENTS')"
res = gdb_test_python_method(func)
self.assertNoException(res)

func = "Permission.from_process_maps('0x0000555555554000 0x0000555555574000 0x0000000000000000 r-- /usr/bin/bash')"
res = gdb_test_python_method(func)
self.assertNoException(res)

func = "Permission.from_info_mem('ffffff2a65e0b000-ffffff2a65e0c000 0000000000001000 -r-')"
res = gdb_test_python_method(func)
self.assertNoException(res)

@pytest.mark.slow
@pytest.mark.online
Expand Down

0 comments on commit 360e3b9

Please sign in to comment.