feat(ghidra): make the startup deadline configurable (#974)

* feat(ghidra): make the startup deadline configurable

Large binaries (an 8 MB PE with about 20,000 functions) need more than the
fixed 330 s for import and full auto-analysis, so every first request timed
out. REA_GHIDRA_STARTUP_TIMEOUT_MS overrides the deadline in milliseconds;
absent, empty or invalid values keep the 330 s default.

* docs(ghidra): document REA_GHIDRA_STARTUP_TIMEOUT_MS

* fix(ghidra): parse startup deadlines through runtime configuration

---------

Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
Selim
2026-10-09 07:21:36 +08:00
committed by GitHub
co-authored by morluto
parent 65a809a0da
commit d84bc8f11a
11 changed files with 145 additions and 17 deletions
+2
View File
@@ -4,6 +4,7 @@ import { isAbsolute } from "node:path";
import { ConfigurationError } from "../domain/configurationErrors.js";
import { err, ok, type Result } from "../domain/result.js";
import { analysisProviderSelectorSchema } from "../contracts/providerSelection.js";
import { ghidraStartupTimeoutSchema } from "./ghidraStartupTimeout.js";
import { mcpResponseBudgetSchema } from "./mcpResponseBudget.js";
const environmentSchema = z.object({
@@ -29,6 +30,7 @@ const environmentSchema = z.object({
.min(1)
.refine(isAbsolute, "REA_GHIDRA_NATIVEAOT_JAR must be absolute")
.optional(),
REA_GHIDRA_STARTUP_TIMEOUT_MS: ghidraStartupTimeoutSchema,
REA_ILSPY_CMD_PATH: z
.string()
.min(1)
+20
View File
@@ -0,0 +1,20 @@
import { z } from "zod";
/** Default absolute deadline for Ghidra import, analysis, bridge, and readiness. */
export const DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS = 330_000;
// Node schedules delays above this signed 32-bit boundary as a 1 ms timer.
const MAX_TIMER_DELAY_MS = 2_147_483_647;
/** Parse the optional setting without reading the ambient process environment. */
export const ghidraStartupTimeoutSchema = z
.string()
.optional()
.transform((raw) => {
const value = Number(raw);
return Number.isSafeInteger(value) &&
value > 0 &&
value <= MAX_TIMER_DELAY_MS
? value
: DEFAULT_GHIDRA_STARTUP_TIMEOUT_MS;
});
+1
View File
@@ -53,6 +53,7 @@ export const parseConfig = (
: { idaMcpConfigPath: env.REA_IDA_MCP_CONFIG }),
ghidraInstallDir: env.GHIDRA_INSTALL_DIR,
ghidraJavaHome: env.JAVA_HOME,
ghidraStartupTimeoutMs: env.REA_GHIDRA_STARTUP_TIMEOUT_MS,
...(env.REA_GHIDRA_NATIVEAOT_JAR === undefined
? {}
: { ghidraNativeAotJar: env.REA_GHIDRA_NATIVEAOT_JAR }),
+1
View File
@@ -7,6 +7,7 @@ export interface AppConfig {
readonly idaMcpConfigPath?: string;
readonly ghidraInstallDir: string | undefined;
readonly ghidraJavaHome: string | undefined;
readonly ghidraStartupTimeoutMs: number;
readonly ghidraNativeAotJar?: string;
readonly ilspyCmdPath: string | undefined;
readonly hopperLauncherPath: string;