Skip to content

Commit

Permalink
Add (real) info mem parser and rename old one
Browse files Browse the repository at this point in the history
  • Loading branch information
Grazfather committed Sep 1, 2023
1 parent e1b62ba commit a615d6b
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions gef.py
Original file line number Diff line number Diff line change
Expand Up @@ -2824,7 +2824,7 @@ class X86(Architecture):
def x():
yield from itertools.chain(GefMemoryManager.parse_procfs_maps(),
# GefMemoryManager.parse_gdb_info_sections(),
GefMemoryManager.parse_info_mem())
GefMemoryManager.parse_monitor_info_mem())
maps: GefMemoryMapProvider = x

def flag_register_to_human(self, val: Optional[int] = None) -> str:
Expand Down Expand Up @@ -10371,7 +10371,7 @@ def __parse_maps(self) -> List[Section]:
maps = list(gef.arch.maps())
return maps

return list(itertools.chain(self.parse_info_mem(),
return list(itertools.chain(self.parse_monitor_info_mem(),
self.parse_procfs_maps(),
self.parse_gdb_info_sections()))

Expand Down Expand Up @@ -10428,7 +10428,6 @@ def parse_gdb_info_sections() -> Generator[Section, None, None]:
page_end=addr_end,
offset=off,
permission=perm,
inode="",
path=path)

except IndexError:
Expand All @@ -10438,7 +10437,7 @@ def parse_gdb_info_sections() -> Generator[Section, None, None]:
return

@staticmethod
def parse_info_mem() -> Generator[Section, None, None]:
def parse_monitor_info_mem() -> Generator[Section, None, None]:
"""Get the memory mapping from GDB's command `monitor info mem`"""
try:
stream = StringIO(gdb.execute("monitor info mem", to_string=True))
Expand All @@ -10459,8 +10458,28 @@ def parse_info_mem() -> Generator[Section, None, None]:
yield Section(page_start=start,
page_end=end,
offset=off,
permission=perm,
inode="")
permission=perm)

@staticmethod
def parse_info_mem():
"""Get the memory mapping from GDB's command `monitor info mem`.
This can be provided by certain gdbserver implementations."""
for line in StringIO(gdb.execute("info mem", to_string=True)):
# Using memory regions provided by the target.
# Num Enb Low Addr High Addr Attrs
# 0 y 0x10000000 0x10200000 flash blocksize 0x1000 nocache
# 1 y 0x20000000 0x20042000 rw nocache
_, en, start, end, *attrs = line.split()
if en != "y":
continue

if "flash" in attrs:
perm = Permission.from_info_mem("r")
else:
perm = Permission.from_info_mem("rw")
yield Section(page_start=int(start, 0),
page_end=int(end, 0),
permission=perm)


class GefHeapManager(GefManager):
Expand Down

0 comments on commit a615d6b

Please sign in to comment.