refactor(cli): share analysis snapshot option contract

This commit is contained in:
morluto
2026-10-22 10:33:38 +08:00
parent 527ade245a
commit d77bc0e8a0
3 changed files with 20 additions and 45 deletions
+8 -35
View File
@@ -9,6 +9,7 @@ import type { Logger } from "pino";
import {
directAnalysisOptionsFromCli,
nativeOpenOptionFields,
snapshotSelectionOption,
} from "./options.js";
import type { CliInstance } from "./types.js";
import { runCliJavaScriptApplicationAnalysis } from "./javascriptApplicationAnalysis.js";
@@ -38,11 +39,7 @@ const registerOverviewCommands = (
runDirectAnalysis: DirectAnalysis["runDirectAnalysis"],
): void => {
const overviewOptions = z.object({
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
});
// `analyze` declares the JavaScript integrity policy for its JavaScript
@@ -179,11 +176,7 @@ const registerDecompileCommand = (
.describe(
"Ghidra source-file byte offset; mapped internally to an analysis address",
),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
@@ -266,11 +259,7 @@ const registerXrefsCommand = (
.describe(
"Address or symbol name; use --address=<value> for leading dashes",
),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
@@ -315,11 +304,7 @@ const registerTraceCommand = (
.boolean()
.default(false)
.describe("Match the query with exact letter case"),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
@@ -365,11 +350,7 @@ const registerFunctionCommand = (
.describe(
"Procedure name or address; use --procedure=<value> for leading dashes",
),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
@@ -414,11 +395,7 @@ const registerInstructionsCommand = (
.describe(
"Procedure name or address; use --procedure=<value> for leading dashes",
),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
@@ -475,11 +452,7 @@ const registerSearchCommand = (
.boolean()
.default(false)
.describe("Match the pattern with exact letter case"),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
+5 -10
View File
@@ -7,6 +7,7 @@ import type { Logger } from "pino";
import {
directAnalysisOptionsFromCli,
nativeOpenOptionFields,
snapshotSelectionOption,
} from "./options.js";
import type { CliInstance } from "./types.js";
@@ -271,11 +272,9 @@ const registerNativeDispatchMetadataCommand = (
.max(20_000)
.default(5_000)
.describe("Maximum symbol records to inspect"),
snapshot: z
.string()
.min(1)
.optional()
.describe("Load or update the local analysis snapshot"),
snapshot: snapshotSelectionOption.describe(
"Load or update the local analysis snapshot",
),
...nativeOpenOptionFields,
}),
run: async ({ args, options }) =>
@@ -360,11 +359,7 @@ const registerNativeApiCommand = (
address: z.string().describe("Procedure name or address"),
}),
options: z.object({
snapshot: z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot"),
snapshot: snapshotSelectionOption,
...nativeOpenOptionFields,
}),
run: ({ args, options }) =>
+7
View File
@@ -26,6 +26,13 @@ export const providerSelectionOption = analysisProviderSelectorSchema
"Bind deep analysis to a provider ID or use deterministic auto selection",
);
/** Optional path to the local analysis snapshot loaded or updated by a command. */
export const snapshotSelectionOption = z
.string()
.min(1)
.optional()
.describe("Load and update a local analysis snapshot");
/** Explicit interpretation for headerless native executable formats. */
export const formatSelectionOption = executableFormatHintSchema
.optional()