fix(ghidra): admit the 12.1 line and the install's JDK range (#840)
* fix(ghidra): admit the 12.1 line and the install's JDK range The provider treated the verified Ghidra 12.1.4 build and JDK 21 as the only legal installation, so a working 12.1.x package or a newer JDK was rejected before analysis started. Admission now follows the 12.1 release line and application.java.min/max. A compatible build other than 12.1.4 keeps its observed version and records that the bridge was verified against 12.1.4. Fixes #821 * fix(ghidra): stop pinning the NativeAOT build to one version string The build script still rejected every Ghidra release except the literal 12.1.4 and every javac except major 21. It now accepts the 12.1 line and javac 21 or newer, compiles with --release 21, and records the observed Ghidra version. The JADX engine version uses the audited release constant. * fix(ghidra): report unverified builds on analysis results Session open uses health only as a startup gate and discards that execution, so the unverified-build limitation never reached CLI or MCP results. Attach it to every Ghidra execution for that install. --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com>
This commit is contained in:
@@ -79,7 +79,7 @@ export class JadxSession {
|
||||
);
|
||||
const engine = {
|
||||
name: "jadx-headless-mcp",
|
||||
version: "0.7.1",
|
||||
version: JADX_RELEASE.version,
|
||||
artifact_sha256: jarHash,
|
||||
source_revision:
|
||||
jarHash === JADX_RELEASE.sha256 ? JADX_RELEASE.revision : null,
|
||||
|
||||
@@ -60,7 +60,7 @@ describe("Ghidra installation inspection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts only the exact Linux x64 Ghidra and JDK commitment", () => {
|
||||
it("accepts the verified Linux x64 Ghidra release and JDK", () => {
|
||||
expect(
|
||||
inspectGhidraInstallation(
|
||||
{ installDir: INSTALL, platform: "linux", architecture: "x64" },
|
||||
@@ -74,6 +74,40 @@ describe("Ghidra installation inspection", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.each([
|
||||
["12.1.2", "27", 27],
|
||||
["12.1.2-2.1", "27", 27],
|
||||
["12.1.0", "21.0.2", 21],
|
||||
[SUPPORTED_GHIDRA_VERSION, "25.0.1", 25],
|
||||
])(
|
||||
"accepts Ghidra %s with JDK %s on the verified release line",
|
||||
(providerVersion, javaVersion, major) => {
|
||||
const result = inspectGhidraInstallation(
|
||||
{ installDir: INSTALL, platform: "linux", architecture: "x64" },
|
||||
host({
|
||||
readText: () =>
|
||||
`application.version=${providerVersion}\napplication.java.min=21\napplication.java.max=\n`,
|
||||
probeJava: () => ({
|
||||
...JAVA,
|
||||
version: javaVersion,
|
||||
major,
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(result.status).toBe("available");
|
||||
expect(result).toMatchObject({ providerVersion, javaVersion });
|
||||
expect(
|
||||
result.checks.find(({ name }) => name === "version"),
|
||||
).toMatchObject({
|
||||
status: "passed",
|
||||
detail:
|
||||
providerVersion === SUPPORTED_GHIDRA_VERSION
|
||||
? SUPPORTED_GHIDRA_VERSION
|
||||
: expect.stringContaining("verified build"),
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each(["x64", "arm64"] as const)(
|
||||
"accepts macOS %s with matching native tools",
|
||||
(architecture) => {
|
||||
@@ -247,3 +281,84 @@ describe("Ghidra installation rejection diagnostics", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ghidra release line and JDK bounds", () => {
|
||||
it.each([
|
||||
{
|
||||
name: "JDK above the installation maximum",
|
||||
readText: () =>
|
||||
"application.version=12.1.4\napplication.java.min=21\napplication.java.max=25\n",
|
||||
probeJava: () => ({ ...JAVA, major: 27, version: "27" }),
|
||||
failed: "java",
|
||||
code: "unsupported_version",
|
||||
},
|
||||
{
|
||||
name: "unreadable Java minimum",
|
||||
readText: () =>
|
||||
"application.version=12.1.4\napplication.java.min=latest\n",
|
||||
probeJava: () => JAVA,
|
||||
failed: "java",
|
||||
code: "version_unresolved",
|
||||
},
|
||||
{
|
||||
name: "unparseable Ghidra version",
|
||||
readText: () => "application.version=latest\n",
|
||||
probeJava: () => JAVA,
|
||||
failed: "version",
|
||||
code: "version_unresolved",
|
||||
},
|
||||
{
|
||||
name: "different Ghidra line",
|
||||
readText: () => "application.version=12.2.0\n",
|
||||
probeJava: () => JAVA,
|
||||
failed: "version",
|
||||
code: "unsupported_version",
|
||||
},
|
||||
])("distinguishes $name", ({ readText, probeJava, failed, code }) => {
|
||||
const result = inspectGhidraInstallation(
|
||||
{ installDir: INSTALL, platform: "linux", architecture: "x64" },
|
||||
host({ readText, probeJava }),
|
||||
);
|
||||
expect(result.status).toBe("unavailable");
|
||||
expect(
|
||||
result.checks.find(({ status }) => status === "failed"),
|
||||
).toMatchObject({ name: failed, code });
|
||||
});
|
||||
|
||||
it("names the accepted Ghidra line and JDK range in failure remediation", () => {
|
||||
const result = inspectGhidraInstallation(
|
||||
{
|
||||
installDir: INSTALL,
|
||||
javaHome: "/usr/lib/jvm/java-17-openjdk",
|
||||
platform: "linux",
|
||||
architecture: "x64",
|
||||
},
|
||||
host({
|
||||
readText: () =>
|
||||
"application.version=12.0.4\napplication.java.min=21\napplication.java.max=\n",
|
||||
probeJava: () => ({ ...JAVA, major: 17, version: "17.0.20.1" }),
|
||||
}),
|
||||
);
|
||||
expect(result.status).toBe("unavailable");
|
||||
if (result.status !== "unavailable") return;
|
||||
expect(result.rejection.reason).toContain("12.1.x");
|
||||
expect(result.rejection.reason).toContain(SUPPORTED_GHIDRA_VERSION);
|
||||
expect(result.checks.find(({ name }) => name === "java")).toMatchObject({
|
||||
status: "failed",
|
||||
remediation: expect.stringContaining("JDK 21 or newer"),
|
||||
});
|
||||
});
|
||||
|
||||
it("honors an installation that declares a lower Java minimum", () => {
|
||||
expect(
|
||||
inspectGhidraInstallation(
|
||||
{ installDir: INSTALL, platform: "linux", architecture: "x64" },
|
||||
host({
|
||||
readText: () =>
|
||||
`application.version=${SUPPORTED_GHIDRA_VERSION}\napplication.java.min=17\n`,
|
||||
probeJava: () => ({ ...JAVA, major: 17, version: "17.0.20.1" }),
|
||||
}),
|
||||
),
|
||||
).toMatchObject({ status: "available", javaVersion: "17.0.20.1" });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,11 +5,22 @@ import { posix, win32 } from "node:path";
|
||||
|
||||
import type { ProviderRejectionCode } from "../contracts/providerSelection.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
import {
|
||||
ghidraApplicationProperties,
|
||||
ghidraJavaMajorAccepted,
|
||||
ghidraJavaRangeLabel,
|
||||
ghidraJavaRequirement,
|
||||
ghidraReleaseAccepted,
|
||||
ghidraReleaseCompatibility,
|
||||
ghidraReleaseLine,
|
||||
ghidraVersionDetail,
|
||||
SUPPORTED_GHIDRA_JAVA_MAJOR,
|
||||
SUPPORTED_GHIDRA_VERSION,
|
||||
type GhidraApplicationProperties,
|
||||
type GhidraJavaRequirement,
|
||||
} from "./GhidraInstallationPolicy.js";
|
||||
|
||||
/** Exact Ghidra build whose Java bridge contract this REA release supports. */
|
||||
export const SUPPORTED_GHIDRA_VERSION = "12.1.4";
|
||||
/** Exact JDK major documented by the supported Ghidra release. */
|
||||
export const SUPPORTED_GHIDRA_JAVA_MAJOR = 21;
|
||||
export { SUPPORTED_GHIDRA_JAVA_MAJOR, SUPPORTED_GHIDRA_VERSION };
|
||||
|
||||
/** Caller-owned paths and host coordinates used for one installation probe. */
|
||||
export interface GhidraInstallationOptions {
|
||||
@@ -110,7 +121,7 @@ interface GhidraInstallationCoordinates {
|
||||
readonly applicationPropertiesPath: string | null;
|
||||
readonly analyzeHeadlessPath: string | null;
|
||||
readonly nativeDecompilerPath: string | null;
|
||||
readonly properties: Readonly<{ providerVersion: string | null }> | undefined;
|
||||
readonly properties: GhidraApplicationProperties | undefined;
|
||||
readonly javaCommand: string;
|
||||
readonly java: GhidraJavaObservation | undefined;
|
||||
}
|
||||
@@ -269,7 +280,7 @@ const installationCoordinates = (
|
||||
properties:
|
||||
properties === undefined
|
||||
? undefined
|
||||
: { providerVersion: propertyValue(properties, "application.version") },
|
||||
: ghidraApplicationProperties(properties),
|
||||
javaCommand,
|
||||
java: host.probeJava(
|
||||
javaCommand,
|
||||
@@ -290,8 +301,7 @@ const installationChecks = ({
|
||||
passed: coordinates.installDir !== null,
|
||||
code: "not_configured",
|
||||
detail: coordinates.installDir ?? "GHIDRA_INSTALL_DIR is not set",
|
||||
remediation:
|
||||
"Set GHIDRA_INSTALL_DIR to an extracted Ghidra 12.1.4 release directory.",
|
||||
remediation: `Set GHIDRA_INSTALL_DIR to an extracted Ghidra ${ghidraReleaseLine()} release directory.`,
|
||||
}),
|
||||
installationCheck({
|
||||
name: "platform",
|
||||
@@ -323,18 +333,7 @@ const installationChecks = ({
|
||||
remediation:
|
||||
"Point GHIDRA_INSTALL_DIR at the root of an extracted official Ghidra release.",
|
||||
}),
|
||||
installationCheck({
|
||||
name: "version",
|
||||
passed:
|
||||
coordinates.properties?.providerVersion === SUPPORTED_GHIDRA_VERSION,
|
||||
code:
|
||||
coordinates.properties?.providerVersion === null ||
|
||||
coordinates.properties?.providerVersion === undefined
|
||||
? "version_unresolved"
|
||||
: "unsupported_version",
|
||||
detail: coordinates.properties?.providerVersion ?? "unknown",
|
||||
remediation: `Install Ghidra ${SUPPORTED_GHIDRA_VERSION}, or update REA for a different Ghidra build.`,
|
||||
}),
|
||||
versionCheck(coordinates.properties),
|
||||
installationCheck({
|
||||
name: "headless",
|
||||
passed:
|
||||
@@ -357,7 +356,12 @@ const installationChecks = ({
|
||||
remediation:
|
||||
"REA does not build native tools. Build Ghidra's native components for this macOS architecture or provide an installation containing Ghidra/Features/Decompiler/os/<platform>/decompile.",
|
||||
}),
|
||||
javaCheck(coordinates.java, coordinates.javaCommand, javaHome),
|
||||
javaCheck(
|
||||
coordinates.java,
|
||||
coordinates.javaCommand,
|
||||
javaHome,
|
||||
coordinates.properties,
|
||||
),
|
||||
];
|
||||
|
||||
/** Project an installation probe into caller-visible, secret-free diagnostics. */
|
||||
@@ -428,40 +432,65 @@ const installationCheck = (options: {
|
||||
remediation: options.remediation,
|
||||
};
|
||||
|
||||
const versionCheck = (
|
||||
properties: GhidraApplicationProperties | undefined,
|
||||
): GhidraInstallationCheck => {
|
||||
const raw = properties?.providerVersion;
|
||||
return installationCheck({
|
||||
name: "version",
|
||||
passed: ghidraReleaseAccepted(raw),
|
||||
code:
|
||||
ghidraReleaseCompatibility(raw).status === "unsupported"
|
||||
? "unsupported_version"
|
||||
: "version_unresolved",
|
||||
detail: ghidraVersionDetail(raw),
|
||||
remediation: `Install a Ghidra ${ghidraReleaseLine()} release (verified with ${SUPPORTED_GHIDRA_VERSION}), or update REA for another Ghidra line.`,
|
||||
});
|
||||
};
|
||||
|
||||
const javaCheck = (
|
||||
observation: GhidraJavaObservation | undefined,
|
||||
command: string,
|
||||
configuredHome: string | undefined,
|
||||
properties: GhidraApplicationProperties | undefined,
|
||||
): GhidraInstallationCheck => {
|
||||
const requirement = ghidraJavaRequirement(properties);
|
||||
const range = ghidraJavaRangeLabel(requirement);
|
||||
const supported =
|
||||
observation !== undefined &&
|
||||
observation.major === SUPPORTED_GHIDRA_JAVA_MAJOR &&
|
||||
ghidraJavaMajorAccepted(observation.major, requirement) &&
|
||||
observation.bits === 64 &&
|
||||
observation.runtime === "jdk";
|
||||
const detail =
|
||||
observation === undefined
|
||||
? command
|
||||
: `${observation.version}; ${String(observation.bits)}-bit; ${observation.runtime === "jdk" ? "JDK" : "runtime only"}; ${observation.home}`;
|
||||
? requirement.unresolved === null
|
||||
? command
|
||||
: `${command}; ${requirement.unresolved}`
|
||||
: `${observation.version}; ${String(observation.bits)}-bit; ${observation.runtime === "jdk" ? "JDK" : "runtime only"}; ${observation.home}; accepted ${range}`;
|
||||
return installationCheck({
|
||||
name: "java",
|
||||
passed: supported,
|
||||
code: observation === undefined ? "runtime_missing" : "unsupported_version",
|
||||
code:
|
||||
requirement.unresolved !== null
|
||||
? "version_unresolved"
|
||||
: observation === undefined
|
||||
? "runtime_missing"
|
||||
: "unsupported_version",
|
||||
detail,
|
||||
remediation:
|
||||
configuredHome === undefined
|
||||
? "Install a 64-bit JDK 21 or set JAVA_HOME before starting REA."
|
||||
: "Update JAVA_HOME to the root of a 64-bit JDK 21 installation.",
|
||||
remediation: javaRemediation(requirement, configuredHome, range),
|
||||
});
|
||||
};
|
||||
|
||||
const propertyValue = (content: string, name: string): string | null => {
|
||||
for (const line of content.split(/\r?\n/u)) {
|
||||
const separator = line.indexOf("=");
|
||||
if (separator < 0 || line.slice(0, separator).trim() !== name) continue;
|
||||
const value = line.slice(separator + 1).trim();
|
||||
return value.length === 0 ? null : value;
|
||||
}
|
||||
return null;
|
||||
const javaRemediation = (
|
||||
requirement: GhidraJavaRequirement,
|
||||
configuredHome: string | undefined,
|
||||
range: string,
|
||||
): string => {
|
||||
if (requirement.unresolved !== null)
|
||||
return `The Ghidra installation's Java bounds could not be read (${requirement.unresolved}). Install a 64-bit full JDK inside the declared application.java.min and application.java.max.`;
|
||||
return configuredHome === undefined
|
||||
? `Install ${range}, or set JAVA_HOME before starting REA.`
|
||||
: `Update JAVA_HOME to the root of ${range} installation.`;
|
||||
};
|
||||
|
||||
const systemGhidraInstallationHost = (): GhidraInstallationHost => ({
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
/** Ghidra build whose bridge behavior this REA release verifies. */
|
||||
export const SUPPORTED_GHIDRA_VERSION = "12.1.4";
|
||||
/**
|
||||
* JDK major used when an installation omits `application.java.min`.
|
||||
* Admission uses that installation's `application.java.min` and
|
||||
* `application.java.max`. An empty maximum means the release sets no upper bound.
|
||||
*/
|
||||
export const SUPPORTED_GHIDRA_JAVA_MAJOR = 21;
|
||||
|
||||
/** Numeric Ghidra release read from `application.version`. */
|
||||
interface GhidraReleaseVersion {
|
||||
readonly major: number;
|
||||
readonly minor: number;
|
||||
readonly patch: number;
|
||||
}
|
||||
|
||||
/** How an observed Ghidra release relates to this adapter's bridge. */
|
||||
type GhidraReleaseCompatibility =
|
||||
| {
|
||||
readonly status: "verified";
|
||||
readonly version: GhidraReleaseVersion;
|
||||
readonly raw: string;
|
||||
}
|
||||
| {
|
||||
readonly status: "compatible";
|
||||
readonly version: GhidraReleaseVersion;
|
||||
readonly raw: string;
|
||||
}
|
||||
| {
|
||||
readonly status: "unsupported";
|
||||
readonly version: GhidraReleaseVersion;
|
||||
readonly raw: string;
|
||||
}
|
||||
| { readonly status: "unresolved"; readonly raw: string | null };
|
||||
|
||||
/** One Java major bound declared by `application.properties`. */
|
||||
type GhidraJavaBound =
|
||||
| { readonly status: "absent" }
|
||||
| { readonly status: "major"; readonly major: number }
|
||||
| { readonly status: "unresolved"; readonly raw: string };
|
||||
|
||||
/** JDK majors this installation admits, after reading its own properties. */
|
||||
export interface GhidraJavaRequirement {
|
||||
readonly minimumMajor: number;
|
||||
readonly maximumMajor: number | null;
|
||||
readonly unresolved: string | null;
|
||||
}
|
||||
|
||||
/** Version and Java bounds read from one `application.properties` file. */
|
||||
export interface GhidraApplicationProperties {
|
||||
readonly providerVersion: string | null;
|
||||
readonly javaMinimum: GhidraJavaBound;
|
||||
readonly javaMaximum: GhidraJavaBound;
|
||||
}
|
||||
|
||||
const GHIDRA_RELEASE_PATTERN = /^(\d+)\.(\d+)(?:\.(\d+))?([-+].*)?$/u;
|
||||
const JAVA_MAJOR_PATTERN = /^(\d+)(?:\.\d+)*$/u;
|
||||
|
||||
/** Read the version and Java bounds Ghidra publishes for one installation. */
|
||||
export const ghidraApplicationProperties = (
|
||||
content: string,
|
||||
): GhidraApplicationProperties => ({
|
||||
providerVersion: propertyValue(content, "application.version"),
|
||||
javaMinimum: parseJavaBound(propertyValue(content, "application.java.min")),
|
||||
javaMaximum: parseJavaBound(propertyValue(content, "application.java.max")),
|
||||
});
|
||||
|
||||
/** Classify `application.version` against the verified release line. */
|
||||
export const ghidraReleaseCompatibility = (
|
||||
raw: string | null | undefined,
|
||||
): GhidraReleaseCompatibility => {
|
||||
if (raw === null || raw === undefined)
|
||||
return { status: "unresolved", raw: null };
|
||||
const version = parseGhidraRelease(raw);
|
||||
if (version === undefined) return { status: "unresolved", raw };
|
||||
if (raw === SUPPORTED_GHIDRA_VERSION)
|
||||
return { status: "verified", version, raw };
|
||||
const verified = verifiedGhidraRelease();
|
||||
return version.major === verified.major && version.minor === verified.minor
|
||||
? { status: "compatible", version, raw }
|
||||
: { status: "unsupported", version, raw };
|
||||
};
|
||||
|
||||
/**
|
||||
* Limitation recorded when a session runs a compatible build other than the
|
||||
* verified release. The observed version stays on the provider identity.
|
||||
*/
|
||||
export const unverifiedGhidraBuildLimitation = (
|
||||
providerVersion: string,
|
||||
): string | undefined => {
|
||||
const compatibility = ghidraReleaseCompatibility(providerVersion);
|
||||
if (compatibility.status !== "compatible") return undefined;
|
||||
return `This session uses Ghidra ${providerVersion}. The bridge is verified against ${SUPPORTED_GHIDRA_VERSION}; other ${ghidraReleaseLine()} builds are accepted and the observed version is reported.`;
|
||||
};
|
||||
|
||||
/** Release line accepted by this bridge, such as `12.1.x`. */
|
||||
export const ghidraReleaseLine = (): string => {
|
||||
const verified = verifiedGhidraRelease();
|
||||
return `${String(verified.major)}.${String(verified.minor)}.x`;
|
||||
};
|
||||
|
||||
/** Detail for the installation version check, including the accepted line. */
|
||||
export const ghidraVersionDetail = (raw: string | null | undefined): string => {
|
||||
const compatibility = ghidraReleaseCompatibility(raw);
|
||||
switch (compatibility.status) {
|
||||
case "unresolved":
|
||||
return compatibility.raw ?? "unknown";
|
||||
case "verified":
|
||||
return compatibility.raw;
|
||||
case "compatible":
|
||||
return `${compatibility.raw}; compatible ${ghidraReleaseLine()} release (verified build ${SUPPORTED_GHIDRA_VERSION})`;
|
||||
case "unsupported":
|
||||
return `${compatibility.raw}; accepted releases are ${ghidraReleaseLine()} (verified build ${SUPPORTED_GHIDRA_VERSION})`;
|
||||
default: {
|
||||
const unreachable: never = compatibility;
|
||||
return unreachable;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/** Whether this release line can run the packaged bridge. */
|
||||
export const ghidraReleaseAccepted = (
|
||||
raw: string | null | undefined,
|
||||
): boolean => {
|
||||
const status = ghidraReleaseCompatibility(raw).status;
|
||||
return status === "verified" || status === "compatible";
|
||||
};
|
||||
|
||||
/** Resolve JDK majors from `application.java.min` and `application.java.max`. */
|
||||
export const ghidraJavaRequirement = (
|
||||
properties: GhidraApplicationProperties | undefined,
|
||||
): GhidraJavaRequirement => {
|
||||
const minimum = properties?.javaMinimum ?? { status: "absent" };
|
||||
const maximum = properties?.javaMaximum ?? { status: "absent" };
|
||||
if (minimum.status === "unresolved")
|
||||
return unresolvedJavaRequirement(`application.java.min=${minimum.raw}`);
|
||||
if (maximum.status === "unresolved")
|
||||
return unresolvedJavaRequirement(`application.java.max=${maximum.raw}`);
|
||||
const minimumMajor =
|
||||
minimum.status === "major" ? minimum.major : SUPPORTED_GHIDRA_JAVA_MAJOR;
|
||||
const maximumMajor = maximum.status === "major" ? maximum.major : null;
|
||||
if (maximumMajor !== null && maximumMajor < minimumMajor)
|
||||
return unresolvedJavaRequirement(
|
||||
`application.java.max=${String(maximumMajor)} is below application.java.min=${String(minimumMajor)}`,
|
||||
);
|
||||
return { minimumMajor, maximumMajor, unresolved: null };
|
||||
};
|
||||
|
||||
/** Caller-facing description of one resolved or unreadable JDK range. */
|
||||
export const ghidraJavaRangeLabel = (
|
||||
requirement: GhidraJavaRequirement,
|
||||
): string => {
|
||||
if (requirement.unresolved !== null)
|
||||
return "a 64-bit full JDK matching the installation's declared Java bounds";
|
||||
if (requirement.maximumMajor === null)
|
||||
return `a 64-bit full JDK ${String(requirement.minimumMajor)} or newer`;
|
||||
if (requirement.maximumMajor === requirement.minimumMajor)
|
||||
return `a 64-bit full JDK ${String(requirement.minimumMajor)}`;
|
||||
return `a 64-bit full JDK ${String(requirement.minimumMajor)} through ${String(requirement.maximumMajor)}`;
|
||||
};
|
||||
|
||||
/** Whether an observed JDK satisfies the installation's declared range. */
|
||||
export const ghidraJavaMajorAccepted = (
|
||||
major: number,
|
||||
requirement: GhidraJavaRequirement,
|
||||
): boolean =>
|
||||
requirement.unresolved === null &&
|
||||
major >= requirement.minimumMajor &&
|
||||
(requirement.maximumMajor === null || major <= requirement.maximumMajor);
|
||||
|
||||
const verifiedGhidraRelease = (): GhidraReleaseVersion => {
|
||||
const version = parseGhidraRelease(SUPPORTED_GHIDRA_VERSION);
|
||||
if (version === undefined)
|
||||
throw new TypeError(
|
||||
`SUPPORTED_GHIDRA_VERSION ${SUPPORTED_GHIDRA_VERSION} is not a Ghidra release`,
|
||||
);
|
||||
return version;
|
||||
};
|
||||
|
||||
const parseGhidraRelease = (raw: string): GhidraReleaseVersion | undefined => {
|
||||
const match = GHIDRA_RELEASE_PATTERN.exec(raw);
|
||||
const major = integerGroup(match?.[1]);
|
||||
const minor = integerGroup(match?.[2]);
|
||||
if (match === null || major === undefined || minor === undefined)
|
||||
return undefined;
|
||||
const patch = match[3] === undefined ? 0 : integerGroup(match[3]);
|
||||
return patch === undefined ? undefined : { major, minor, patch };
|
||||
};
|
||||
|
||||
const parseJavaBound = (raw: string | null): GhidraJavaBound => {
|
||||
if (raw === null) return { status: "absent" };
|
||||
const major = integerGroup(JAVA_MAJOR_PATTERN.exec(raw)?.[1]);
|
||||
return major === undefined
|
||||
? { status: "unresolved", raw }
|
||||
: { status: "major", major };
|
||||
};
|
||||
|
||||
const integerGroup = (value: string | undefined): number | undefined => {
|
||||
if (value === undefined) return undefined;
|
||||
const parsed = Number(value);
|
||||
return Number.isSafeInteger(parsed) ? parsed : undefined;
|
||||
};
|
||||
|
||||
const unresolvedJavaRequirement = (
|
||||
unresolved: string,
|
||||
): GhidraJavaRequirement => ({
|
||||
minimumMajor: SUPPORTED_GHIDRA_JAVA_MAJOR,
|
||||
maximumMajor: null,
|
||||
unresolved,
|
||||
});
|
||||
|
||||
const propertyValue = (content: string, name: string): string | null => {
|
||||
for (const line of content.split(/\r?\n/u)) {
|
||||
const separator = line.indexOf("=");
|
||||
if (separator < 0 || line.slice(0, separator).trim() !== name) continue;
|
||||
const value = line.slice(separator + 1).trim();
|
||||
return value.length === 0 ? null : value;
|
||||
}
|
||||
return null;
|
||||
};
|
||||
@@ -791,3 +791,70 @@ describe("Ghidra extension failures", () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe("compatible Ghidra builds", () => {
|
||||
it("accepts the build and reports that it is unverified", async () => {
|
||||
const ghidra = provider(
|
||||
{
|
||||
...installationHost(),
|
||||
readText: () =>
|
||||
"application.version=12.1.2\napplication.java.min=21\napplication.java.max=\n",
|
||||
probeJava: () => ({
|
||||
version: "27",
|
||||
major: 27,
|
||||
home: "/usr/lib/jvm/java-27-openjdk",
|
||||
bits: 64,
|
||||
runtime: "jdk",
|
||||
}),
|
||||
},
|
||||
() => ({
|
||||
start: () =>
|
||||
Promise.resolve(
|
||||
ok({
|
||||
...sessionInfo(),
|
||||
provider: { id: "ghidra", version: "12.1.2" },
|
||||
}),
|
||||
),
|
||||
callTool: () =>
|
||||
Promise.resolve(
|
||||
ok([
|
||||
{
|
||||
address: "0x1000",
|
||||
value: "fixture_main",
|
||||
procedure: {
|
||||
external: false,
|
||||
thunk: false,
|
||||
thunk_target: null,
|
||||
},
|
||||
},
|
||||
]),
|
||||
),
|
||||
close: () => Promise.resolve(),
|
||||
}),
|
||||
);
|
||||
const resolved = await ghidra.resolveAnalysisProfile(
|
||||
executableTarget("elf", "x86_64"),
|
||||
);
|
||||
if (!resolved.ok || resolved.value.profile === null)
|
||||
throw new Error("expected a compatible Ghidra profile");
|
||||
const client = ghidra.createClient(
|
||||
executableTarget("elf", "x86_64"),
|
||||
resolved.value.profile,
|
||||
);
|
||||
const health = await client.execute("health", {});
|
||||
const procedures = await client.execute("list_procedures", {});
|
||||
expect(ghidra.inspectAvailability()).toMatchObject({
|
||||
status: "available",
|
||||
diagnostics: { provider_version: "12.1.2", java_version: "27" },
|
||||
});
|
||||
expect(health.ok && health.value.provider.version).toBe("12.1.2");
|
||||
const unverified = expect.stringContaining("12.1.2");
|
||||
expect(health.ok && health.value.limitations).toEqual(
|
||||
expect.arrayContaining([unverified]),
|
||||
);
|
||||
expect(procedures.ok && procedures.value.limitations).toEqual(
|
||||
expect.arrayContaining([unverified]),
|
||||
);
|
||||
expect(procedures.ok && procedures.value.provider.version).toBe("12.1.2");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -59,6 +59,7 @@ import {
|
||||
type GhidraInstallationHost,
|
||||
type GhidraInstallationInspection,
|
||||
} from "./GhidraInstallation.js";
|
||||
import { unverifiedGhidraBuildLimitation } from "./GhidraInstallationPolicy.js";
|
||||
import { GhidraHeadlessLauncher } from "./GhidraLauncher.js";
|
||||
import { resolveGhidraAnalysisProfile } from "./GhidraAnalysisProfile.js";
|
||||
import type { GhidraSessionError } from "./GhidraSessionError.js";
|
||||
@@ -332,6 +333,15 @@ export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
await client.close();
|
||||
return extensionFailure;
|
||||
};
|
||||
const releaseLimitation = unverifiedGhidraBuildLimitation(
|
||||
prerequisites.value.providerVersion,
|
||||
);
|
||||
const sessionLimitations = [
|
||||
...providerLimitations,
|
||||
...targetLimitations,
|
||||
...ghidraExtensionLimitations(extensions),
|
||||
...(releaseLimitation === undefined ? [] : [releaseLimitation]),
|
||||
];
|
||||
return {
|
||||
execute: async (operation, parameters, options) => {
|
||||
if (extensionFailure !== undefined) return err(extensionFailure);
|
||||
@@ -356,12 +366,7 @@ export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
return ok(
|
||||
createAnalysisExecution(started.value, committedProfile.provider, {
|
||||
analysisProfile: committedProfile,
|
||||
limitations: [
|
||||
...healthLimitations,
|
||||
...providerLimitations,
|
||||
...targetLimitations,
|
||||
...ghidraExtensionLimitations(extensions),
|
||||
],
|
||||
limitations: [...healthLimitations, ...sessionLimitations],
|
||||
}),
|
||||
);
|
||||
}
|
||||
@@ -435,12 +440,7 @@ export class GhidraProvider implements AnalysisProviderCandidate {
|
||||
createAnalysisExecution(normalized, committedProfile.provider, {
|
||||
rawResult: called.value,
|
||||
analysisProfile: committedProfile,
|
||||
limitations: [
|
||||
...limitationsFor(operation),
|
||||
...providerLimitations,
|
||||
...targetLimitations,
|
||||
...ghidraExtensionLimitations(extensions),
|
||||
],
|
||||
limitations: [...limitationsFor(operation), ...sessionLimitations],
|
||||
}),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user