Skip to content

Commit 35f9406

Browse files
committed
Add get_mapinfo method
1 parent dc156bb commit 35f9406

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

qiling/os/memory.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,32 @@ def del_mapinfo(self, mem_s: int, mem_e: int):
149149

150150
self.map_info = tmp_map_info
151151

152+
def get_mapinfo(self) -> Sequence[Tuple[int, int, str, str, Optional[str]]]:
153+
"""Get memory map info.
154+
155+
Returns: A sequence of 5-tuples representing the memory map entries. Each
156+
tuple contains range start, range end, permissions, range label and path of
157+
containing image (or None if not contained by any image)
158+
"""
159+
160+
def __perms_mapping(ps: int) -> str:
161+
perms_d = {
162+
UC_PROT_READ : 'r',
163+
UC_PROT_WRITE : 'w',
164+
UC_PROT_EXEC : 'x'
165+
}
166+
167+
return ''.join(val if idx & ps else '-' for idx, val in perms_d.items())
168+
169+
def __process(lbound: int, ubound: int, perms: int, label: str) -> Tuple[int, int, str, str, Optional[str]]:
170+
perms_str = __perms_mapping(perms)
171+
172+
image = self.ql.os.find_containing_image(lbound)
173+
container = image.path if image else None
174+
175+
return (lbound, ubound, perms_str, label, container)
176+
177+
return tuple(__process(*entry) for entry in self.map_info)
152178

153179
def show_mapinfo(self):
154180
"""Emit memory map info in a nicely formatted table.

0 commit comments

Comments
 (0)