* fix: select caller paths through symlinks and .. as the filesystem does CLI adapters, binary target resolution, the reverse-engineering service and the objdump and Rizin command builders made caller-selected paths absolute with path.resolve, which collapses `link/..` lexically. On POSIX the filesystem follows `link` first, so these commands inspected, hashed or launched a different file and returned internally consistent Evidence for it. absoluteCallerPath now owns that step: on POSIX it prefixes a relative path with the working directory and keeps an absolute path as spelled; on Windows, where `..` resolves lexically, it keeps win32.resolve. Fixes #3864 Fixes #3911 Fixes #3912 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep firmware, WASM list and output-root paths on the selected file Review follow-up. The CLI already passed firmware and WASM paths through absoluteCallerPath, but snapshotFirmware and SafeOutputTree.create re-resolved them lexically, and the WASM glue and candidate lists still used resolve, so those inputs could still select a sibling file or create output beside the intended directory. absoluteCallerPath now also drops `.` segments and repeated or trailing separators on POSIX, which never change the named file, so selected paths such as `./module.wasm` keep matching their glue references exactly. Every `..` is still left for the filesystem. SafeOutputTree keeps host path syntax; its platform argument selects only the Windows name policy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep directory requirements and relative cwd in caller paths Review follow-up. absoluteCallerPath stripped a trailing `/` or `/.`, so `file/` selected the regular file instead of failing with ENOTDIR; it now keeps one trailing separator. A relative cwd option was appended to the root; it is now made absolute without collapsing `..`. WASM glue matching resolved local literals lexically, so a module selected through `link/..` matched only by basename; the adapter now compares both sides through absoluteCallerPath and still reports each candidate as given. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
103 lines
3.7 KiB
TypeScript
103 lines
3.7 KiB
TypeScript
import { z } from "incur";
|
|
import {
|
|
createRecordedCrashService,
|
|
createBinaryLayoutService,
|
|
createPeResourcesService,
|
|
} from "../composition/binaryDiagnostics.js";
|
|
import { CLI_COMMANDS } from "../cliCommandNames.js";
|
|
import { logCliCommand } from "../cliLogging.js";
|
|
import type { Logger } from "pino";
|
|
import type { CliInstance } from "./types.js";
|
|
import { withCommandCancellation } from "./commandCancellation.js";
|
|
import { inspectPeResourcesInputSchema } from "../domain/native/peResources.js";
|
|
import { projectAnalysisError } from "../domain/analysisErrorProjection.js";
|
|
import { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
import { absoluteCallerPath } from "../filesystem/callerPath.js";
|
|
|
|
/** Inspect operator-selected files through the same shared workflow as MCP. */
|
|
export const registerBinaryDiagnosticsCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.inspectPeResources, {
|
|
description:
|
|
"Inspect PE resource identities, payload ranges, hashes and icon-group relationships",
|
|
args: z.object({ path: z.string().describe("Local PE32/PE32+ image") }),
|
|
options: z.object({
|
|
maxFileBytes: inspectPeResourcesInputSchema.shape.max_file_bytes,
|
|
maxEntries: inspectPeResourcesInputSchema.shape.max_entries,
|
|
}),
|
|
run: ({ args, options }) =>
|
|
withCommandCancellation(async (signal) => {
|
|
const pe = createPeResourcesService();
|
|
return await logCliCommand(
|
|
logger,
|
|
CLI_COMMANDS.inspectPeResources,
|
|
async () =>
|
|
finishAnalysisCommand(
|
|
() =>
|
|
pe.inspect(
|
|
{
|
|
path: absoluteCallerPath(args.path),
|
|
max_file_bytes: options.maxFileBytes,
|
|
max_entries: options.maxEntries,
|
|
},
|
|
{ signal },
|
|
),
|
|
pe,
|
|
"rea-pe-resources",
|
|
"inspect_pe_resources",
|
|
),
|
|
);
|
|
}),
|
|
});
|
|
const service = createBinaryLayoutService(environment);
|
|
cli.command(CLI_COMMANDS.inspectBinaryLayout, {
|
|
description:
|
|
"Inspect binary file/linked layout without executing the selected object",
|
|
args: z.object({
|
|
path: z.string().describe("Local ELF binary or relocatable object"),
|
|
}),
|
|
run: ({ args }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectBinaryLayout, async () => {
|
|
const result = await service.inspectAndClose(
|
|
{ path: absoluteCallerPath(args.path) },
|
|
{ signal },
|
|
);
|
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
|
}),
|
|
),
|
|
});
|
|
const recorded = createRecordedCrashService(environment);
|
|
cli.command(CLI_COMMANDS.inspectRecordedCrash, {
|
|
description:
|
|
"Inspect supplied core registers/signals and optional debugger mapping evidence",
|
|
args: z.object({
|
|
path: z
|
|
.string()
|
|
.describe("Local Linux ELF64 amd64 or AArch64 little-endian core"),
|
|
}),
|
|
options: z.object({
|
|
debuggerContext: z
|
|
.boolean()
|
|
.default(false)
|
|
.describe("Add BYO core-only GDB/pwndbg mapping candidates"),
|
|
}),
|
|
run: ({ args, options }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectRecordedCrash, async () => {
|
|
const result = await recorded.inspectAndClose(
|
|
{
|
|
path: absoluteCallerPath(args.path),
|
|
include_debugger_context: options.debuggerContext,
|
|
},
|
|
{ signal },
|
|
);
|
|
return result.ok ? result.value : projectAnalysisError(result.error);
|
|
}),
|
|
),
|
|
});
|
|
};
|