| 134 | |
| 135 | |
| 136 | def 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 | |
| 164 | def pct(part: float, whole: float) -> float: |