MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / symbolise

Function symbolise

scripts/memwaste-report.py:136–161  ·  view source on GitHub ↗
(binary: str | None, base: str, addrs: list[str])

Source from the content-addressed store, hash-verified

134
135
136def symbolise(binary: str | None, base: str, addrs: list[str]) -> dict[str, str]:
137 if not binary or not addrs:
138 return {}
139 if not os.path.exists(binary) and os.path.exists(binary + ".exe"):
140 binary = binary + ".exe"
141 out: dict[str, str] = {}
142 uniq = sorted(set(addrs))
143 if platform.system() == "Darwin" and shutil.which("atos"):
144 for i in range(0, len(uniq), 2000):
145 chunk = uniq[i:i + 2000]
146 res = subprocess.run(["atos", "-o", binary, "-l", base] + chunk,
147 capture_output=True, text=True, check=False)
148 for addr, name in zip(chunk, res.stdout.splitlines()):
149 out[addr] = name.strip()
150 elif shutil.which("addr2line") or shutil.which("llvm-addr2line"):
151 tool = shutil.which("llvm-addr2line") or shutil.which("addr2line")
152 b = int(base, 16)
153 preferred = pe_image_base(binary) or 0
154 for i in range(0, len(uniq), 2000):
155 chunk = uniq[i:i + 2000]
156 rel = [hex(int(a, 16) - b + preferred) if b else a for a in chunk]
157 res = subprocess.run([tool, "-f", "-C", "-p", "-e", binary] + rel,
158 capture_output=True, text=True, check=False)
159 for addr, name in zip(chunk, res.stdout.splitlines()):
160 out[addr] = name.strip()
161 return out
162
163
164def pct(part: float, whole: float) -> float:

Callers 1

mainFunction · 0.85

Calls 6

setFunction · 0.85
rangeFunction · 0.85
zipFunction · 0.85
pe_image_baseFunction · 0.85
hexFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected