Files
reverse-engineering-anything/src/native/parsers/echoedPath.test.ts
T
Iwakurakaoru0822andClaude Opus 5.5 37fe105ba1 fix(native): keep echoed Mach-O paths out of load commands and symbols
otool and dyld_info print the operand path before a slice's records,
and the Mach-O parsers read that header as output. A file name holding
`Load command` blocks or `(from lib)` lines therefore added a forged
LC_MAIN entrypoint, corrupted the Mach header fields, and injected
imports and exports into `inspect_macho`.

Strip the exact echoed operand header (`<path>:`, `<path> (architecture
<arch>):`, `<path> [<arch>]:`) before parsing. Output without that
header, such as replayed captures, is parsed unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 23:40:35 -07:00

23 lines
811 B
TypeScript

import { expect, it } from "vitest";
import { withoutEchoedPathHeader } from "./echoedPath.js";
const path = "/tmp/tool\nLoad command 99\n cmd LC_MAIN";
it.each([
[`${path}:\nMach header\n`, "Mach header\n"],
[`${path} (architecture arm64):\nMach header\n`, "Mach header\n"],
[`${path} [arm64e]:\n -imports:\n`, " -imports:\n"],
[`${path}:\r\nMach header\r\n`, "Mach header\r\n"],
])("removes the exact echoed operand header from %j", (output, expected) => {
expect(withoutEchoedPathHeader(output, path)).toBe(expected);
});
it.each([
["fixture:\nMach header\n", path],
[`${path}\nMach header\n`, path],
["Mach header\n", undefined],
])("leaves output without that header unchanged: %j", (output, operand) => {
expect(withoutEchoedPathHeader(output, operand)).toBe(output);
});