Skip to content

Commit d5dd963

Browse files
committed
analyzer/linux: improve memory map parse and fix error
1 parent 5d54c5c commit d5dd963

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

analyzer/linux/analyzer.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,12 @@ def dump_memory(pid):
105105
output_file = open(f"{MEM_PATH}/{pid}.dmp", "wb")
106106

107107
for line in maps_file.readlines():
108-
m = re.match(r"([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])(\S+)\s+\d+\s+\S+\s+\d+\s*(.*)?", line)
109-
if m and m.group(3) == "r":
108+
# Reference: https://man7.org/linux/man-pages/man5/proc_pid_maps.5.html
109+
m = re.match(r"^([0-9a-f]+)-([0-9a-f]+) ([-rwxsp]{4}) ([0-9a-f]+) (\d\d:\d\d) (\d+) *(.*)$", line)
110+
perms = m.group(3)
111+
pathname = m.group(7)
112+
if m and "r" in perms:
110113
# Testing: Uncomment to skip memory regions associated with dynamic libraries
111-
# pathname = m.group(5)
112114
# if pathname and (pathname.endswith('.so') or 'lib' in pathname or '[' in pathname):
113115
# continue
114116
start = int(m.group(1), 16)
@@ -118,7 +120,7 @@ def dump_memory(pid):
118120
chunk = mem_file.read(end - start)
119121
output_file.write(chunk)
120122
except (OSError, ValueError) as e:
121-
log.error("Could not read memory range %s: {e}", f"{start:x}-{end:x}", str(e))
123+
log.error("Could not read memory range %x-%x (%s) (%s): %s", start, end, perms, pathname, e)
122124
maps_file.close()
123125
mem_file.close()
124126
output_file.close()

0 commit comments

Comments
 (0)