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>
19 lines
687 B
TypeScript
19 lines
687 B
TypeScript
/**
|
|
* Remove the header line otool and dyld_info print before a slice's output:
|
|
* `<path>:`, `<path> (architecture <arch>):`, or `<path> [<arch>]:`. File
|
|
* names may contain line breaks and tool keywords, so only the exact operand
|
|
* path is stripped; output without that header is returned unchanged.
|
|
*/
|
|
export const withoutEchoedPathHeader = (
|
|
output: string,
|
|
path: string | undefined,
|
|
): string => {
|
|
if (path === undefined || !output.startsWith(path)) return output;
|
|
const header = /^(?: \(architecture [^)\n]*\)| \[[^\]\n]*\])?:\r?\n/u.exec(
|
|
output.slice(path.length),
|
|
);
|
|
return header === null
|
|
? output
|
|
: output.slice(path.length + header[0].length);
|
|
};
|