MCPcopy Create free account
hub / github.com/HexHive/NASS / parse_proc_maps

Function parse_proc_maps

utils/utils.py:66–123  ·  view source on GitHub ↗
(proc_maps_str)

Source from the content-addressed store, hash-verified

64 return out
65
66def parse_proc_maps(proc_maps_str):
67 vma_list = []
68 prev_vma = None # Keep track of the previous VMA
69 for line in proc_maps_str.split("\n"):
70 fields = re.split(r"\s+", line.strip())
71 if len(fields) < 5:
72 break
73 address_range = fields[0]
74 permissions = fields[1]
75 offset = fields[2]
76 device = fields[3]
77 inode = fields[4] if len(fields) == 6 else None
78 pathname = fields[-1] if len(fields) > 5 else None
79
80 # Parse the address range into base and top addresses
81 base_address, top_address = map(
82 lambda x: int(x, 16), address_range.split("-")
83 )
84
85 # Check if the current VMA is consecutive to the previous one
86 if (
87 (
88 prev_vma
89 #and base_address == prev_vma["top_address"]
90 and pathname == prev_vma["pathname"]
91 )
92 #handle case for library padding..
93 or
94 (
95 prev_vma
96 and
97 permissions == '---p'
98 )
99 ):
100 # Merge the consecutive VMAs
101 prev_vma["top_address"] = top_address
102 else:
103 # Create a new entry for the non-consecutive VMA
104 vma_info = {
105 "base_address": base_address,
106 "top_address": top_address,
107 "permissions": permissions,
108 "offset": int(offset, 16),
109 "device": device,
110 "inode": int(inode) if inode else None,
111 "pathname": pathname,
112 }
113
114 vma_list.append(vma_info)
115 prev_vma = vma_info
116
117 out = []
118 for vma in vma_list:
119 out.append(
120 PocMap_VMA(vma["base_address"], vma["top_address"], vma["pathname"])
121 )
122
123 return ProcMap(out)

Callers

nothing calls this directly

Calls 2

PocMap_VMAClass · 0.85
ProcMapClass · 0.85

Tested by

no test coverage detected