* 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>
120 lines
4.0 KiB
TypeScript
120 lines
4.0 KiB
TypeScript
import { inspectPacketFieldsInputSchema } from "../domain/captures/packetFields.js";
|
|
import { z } from "incur";
|
|
import type { PacketCaptureService } from "../application/captures/PacketCaptureService.js";
|
|
import { createPacketCaptureService } from "../composition/captures.js";
|
|
import {
|
|
packetCaptureOptionsSchema,
|
|
packetCaptureSelectorBudgetIssue,
|
|
withinPacketCaptureSelectorBudget,
|
|
} from "../domain/captures/packetCapture.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 { finishAnalysisCommand } from "./finishAnalysisCommand.js";
|
|
import { absoluteCallerPath } from "../filesystem/callerPath.js";
|
|
export const registerCaptureCommands = (
|
|
cli: CliInstance,
|
|
logger: Logger,
|
|
environment: Readonly<NodeJS.ProcessEnv>,
|
|
service: Pick<
|
|
PacketCaptureService,
|
|
"inspect" | "inspectFields" | "close"
|
|
> = createPacketCaptureService(environment),
|
|
): void => {
|
|
cli.command(CLI_COMMANDS.inspectPacketFields, {
|
|
description: "Search installed TShark protocol and field definitions",
|
|
options: z
|
|
.object({
|
|
...inspectPacketFieldsInputSchema.shape,
|
|
limit: z
|
|
.number()
|
|
.int()
|
|
.positive()
|
|
.max(Number.MAX_SAFE_INTEGER)
|
|
.optional()
|
|
.describe("Maximum matching records to return; defaults to 50"),
|
|
all: z
|
|
.boolean()
|
|
.default(false)
|
|
.describe("Return all remaining matches within resource limits"),
|
|
})
|
|
.superRefine((options, context) => {
|
|
if (options.all && options.limit !== undefined)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["all"],
|
|
message: "all and limit are mutually exclusive",
|
|
});
|
|
}),
|
|
run: ({ options: { all, ...options } }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectPacketFields, async () =>
|
|
finishAnalysisCommand(
|
|
() =>
|
|
service.inspectFields(
|
|
{ ...options, ...(all ? { limit: null } : {}) },
|
|
{ signal },
|
|
),
|
|
service,
|
|
"tshark-capture",
|
|
"inspect_packet_fields",
|
|
),
|
|
),
|
|
),
|
|
});
|
|
cli.command(CLI_COMMANDS.inspectPacketCapture, {
|
|
description:
|
|
"Inspect an existing packet capture with caller-supplied TShark",
|
|
args: z.object({ path: z.string().describe("Local packet capture") }),
|
|
options: z
|
|
.object({
|
|
...packetCaptureOptionsSchema.shape,
|
|
match_limit: z
|
|
.number()
|
|
.int()
|
|
.positive()
|
|
.optional()
|
|
.describe("Returned matching frames per page; default 50"),
|
|
all_matches: z
|
|
.boolean()
|
|
.default(false)
|
|
.describe(
|
|
"Return all remaining matching frames instead of a bounded page",
|
|
),
|
|
})
|
|
.superRefine((options, context) => {
|
|
if (options.all_matches && options.match_limit !== undefined)
|
|
context.addIssue({
|
|
code: "custom",
|
|
path: ["all_matches"],
|
|
message: "all_matches and match_limit are mutually exclusive",
|
|
});
|
|
})
|
|
.refine(
|
|
withinPacketCaptureSelectorBudget,
|
|
packetCaptureSelectorBudgetIssue,
|
|
),
|
|
run: ({ args, options: { all_matches, ...options } }) =>
|
|
withCommandCancellation((signal) =>
|
|
logCliCommand(logger, CLI_COMMANDS.inspectPacketCapture, async () => {
|
|
return finishAnalysisCommand(
|
|
() =>
|
|
service.inspect(
|
|
{
|
|
...options,
|
|
...(all_matches ? { match_limit: null } : {}),
|
|
path: absoluteCallerPath(args.path),
|
|
},
|
|
{ signal },
|
|
),
|
|
service,
|
|
"tshark-capture",
|
|
"inspect_packet_capture",
|
|
);
|
|
}),
|
|
),
|
|
});
|
|
};
|