feat(ghidra): apply validated analyzer overrides before analysis
Apply caller-selected analyzer opt-outs before Ghidra analysis, reject unknown or ineffective names, and commit raw/header imports to the same analyzer profile. Use supported x86 raw compiler specs and cover the real analyzer/readback and raw workflows. Adopts the original implementation from #1800 with validated corrections. Refs #1783, #1836. Co-authored-by: akushonkamen <74654766+akushonkamen@users.noreply.github.com> Co-authored-by: N0zoM1z0 <161784452+N0zoM1z0@users.noreply.github.com> Co-authored-by: Kaoru0822 <208281322+kaoru0822-kitauji@users.noreply.github.com>
This commit is contained in:
co-authored by
akushonkamen
Kaoru0822
parent
12ee785e5e
commit
9878bb7296
@@ -8,6 +8,7 @@ import {
|
||||
ghidraCompilerSpecIdSchema,
|
||||
ghidraLanguageIdSchema,
|
||||
} from "./ghidraLanguageOverride.js";
|
||||
import { ghidraDisabledAnalyzersSchema } from "./ghidraDisabledAnalyzers.js";
|
||||
import {
|
||||
DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS,
|
||||
DEFAULT_HOPPER_STARTUP_TIMEOUT_MS,
|
||||
@@ -48,6 +49,7 @@ const environmentSchema = z.object({
|
||||
),
|
||||
REA_GHIDRA_LANGUAGE_ID: ghidraLanguageIdSchema.optional(),
|
||||
REA_GHIDRA_COMPILER_SPEC_ID: ghidraCompilerSpecIdSchema.optional(),
|
||||
REA_GHIDRA_DISABLED_ANALYZERS: ghidraDisabledAnalyzersSchema.optional(),
|
||||
REA_GHIDRA_SEED_FILE: z
|
||||
.string()
|
||||
.min(1)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { z } from "zod";
|
||||
|
||||
export const MAX_GHIDRA_DISABLED_ANALYZER_NAMES = 32;
|
||||
export const MAX_GHIDRA_DISABLED_ANALYZER_NAME_LENGTH = 120;
|
||||
|
||||
// Ghidra's headless parser consumes `-`-prefixed arguments after a script path
|
||||
// as its own options, and REA joins the names with commas into one pre-script
|
||||
// argument, so a name can neither start with `-` nor contain a comma. The
|
||||
// remaining admitted characters keep the argument a single quotable token on
|
||||
// every supported launcher, including the Windows batch invocation.
|
||||
const ghidraAnalyzerNamePattern = /^[A-Za-z0-9][A-Za-z0-9 ._-]*$/u;
|
||||
|
||||
/**
|
||||
* Parse `REA_GHIDRA_DISABLED_ANALYZERS` into the Ghidra auto-analyzer names to
|
||||
* disable before default auto-analysis, such as
|
||||
* `Objective-C Message Analyzer`. Empty and blank entries are dropped; a list
|
||||
* without names selects no override.
|
||||
*/
|
||||
export const ghidraDisabledAnalyzersSchema = z
|
||||
.string()
|
||||
.transform((value) =>
|
||||
value
|
||||
.split(",")
|
||||
.map((name) => name.trim())
|
||||
.filter((name) => name.length > 0),
|
||||
)
|
||||
.refine(
|
||||
(names) => names.length <= MAX_GHIDRA_DISABLED_ANALYZER_NAMES,
|
||||
`must list at most ${MAX_GHIDRA_DISABLED_ANALYZER_NAMES} analyzer names`,
|
||||
)
|
||||
.refine(
|
||||
(names) =>
|
||||
names.every(
|
||||
(name) => name.length <= MAX_GHIDRA_DISABLED_ANALYZER_NAME_LENGTH,
|
||||
),
|
||||
`must keep every analyzer name at most ${MAX_GHIDRA_DISABLED_ANALYZER_NAME_LENGTH} characters`,
|
||||
)
|
||||
.refine(
|
||||
(names) => names.every((name) => ghidraAnalyzerNamePattern.test(name)),
|
||||
"must be Ghidra analyzer names starting with a letter or digit and containing only letters, digits, spaces, periods, underscores, and hyphens",
|
||||
)
|
||||
.transform((names) => (names.length === 0 ? undefined : names));
|
||||
@@ -88,6 +88,9 @@ export const parseConfig = (
|
||||
...(env.REA_GHIDRA_SEED_FILE === undefined
|
||||
? {}
|
||||
: { ghidraSeedFile: env.REA_GHIDRA_SEED_FILE }),
|
||||
...(env.REA_GHIDRA_DISABLED_ANALYZERS === undefined
|
||||
? {}
|
||||
: { ghidraDisabledAnalyzers: env.REA_GHIDRA_DISABLED_ANALYZERS }),
|
||||
...(env.REA_GHIDRA_NATIVEAOT_JAR === undefined
|
||||
? {}
|
||||
: { ghidraNativeAotJar: env.REA_GHIDRA_NATIVEAOT_JAR }),
|
||||
|
||||
@@ -14,6 +14,7 @@ export interface AppConfig {
|
||||
readonly ghidraJavaHome: string | undefined;
|
||||
readonly ghidraStartupTimeoutMs: number;
|
||||
readonly ghidraLanguageOverride?: GhidraLanguageOverride;
|
||||
readonly ghidraDisabledAnalyzers?: readonly string[];
|
||||
readonly ghidraSeedFile?: string;
|
||||
readonly ghidraNativeAotJar?: string;
|
||||
readonly ilspyCmdPath: string | undefined;
|
||||
|
||||
Reference in New Issue
Block a user