Skip to content

Commit a187ad6

Browse files
authored
Fix dump memory (#2771)
* analyzer/linux: improve memory map parse and fix error * lib/cuckoo: fix unknown memory protection flags This is a temporary fix because when processing the Linux memory dumps it fails with an undefined value. Current it is incorrectly parsing the dump, but this is useful to visualize the dumps.
1 parent b965620 commit a187ad6

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

analyzer/linux/analyzer.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,15 @@ 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+
if not m:
111+
log.error("Could not parse memory map line for pid %s: %s", pid, line)
112+
continue
113+
perms = m.group(3)
114+
pathname = m.group(7)
115+
if "r" in perms:
110116
# Testing: Uncomment to skip memory regions associated with dynamic libraries
111-
# pathname = m.group(5)
112117
# if pathname and (pathname.endswith('.so') or 'lib' in pathname or '[' in pathname):
113118
# continue
114119
start = int(m.group(1), 16)
@@ -118,7 +123,7 @@ def dump_memory(pid):
118123
chunk = mem_file.read(end - start)
119124
output_file.write(chunk)
120125
except (OSError, ValueError) as e:
121-
log.error("Could not read memory range %s: {e}", f"{start:x}-{end:x}", str(e))
126+
log.error("Could not read memory range %x-%x (%s) (%s): %s", start, end, perms, pathname, e)
122127
maps_file.close()
123128
mem_file.close()
124129
output_file.close()

lib/cuckoo/common/objects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -796,7 +796,7 @@ def _prot_to_str(self, prot):
796796
if prot & PAGE_GUARD:
797797
return "G"
798798
prot &= 0xFF
799-
return self.protmap[prot]
799+
return self.protmap.get(prot, "UNKNOWN")
800800

801801
def pretty_print(self):
802802
new_addr_space = copy.deepcopy(self.address_space)

0 commit comments

Comments
 (0)