Skip to content

armgit / rea

Public Imported from GitHub
0

Reverse engineer anything with agents, from app behavior down to native binaries.

fix(domain): admit Qualcomm Hexagon (EM_HEXAGON, 164) ELF binaries (#4819)

Prasad Navale3c1cce78ee6c
diff --git a/src/domain/binaryTarget.test.ts b/src/domain/binaryTarget.test.ts
index 6164e8c22..33cce15f3 100644
--- a/src/domain/binaryTarget.test.ts
+++ b/src/domain/binaryTarget.test.ts
@@ -17,6 +17,7 @@ describe("executable header parsing", () => {
it.each([
[elf(1, 1, 62), "elf", "x86_64"],
[elf(2, 2, 183), "elf", "arm64"],
+ [elf(1, 1, 164), "elf", "hexagon"],
[thinMach(0xfeedfacf, 0x0100000c), "mach-o", "arm64"],
[thinMach(0xcefaedfe, 0x01000007), "mach-o", "x86_64"],
[pe(0x8664), "pe", "x86_64"],
diff --git a/src/domain/binaryTarget.ts b/src/domain/binaryTarget.ts
index dcbf8f397..08c14b421 100644
--- a/src/domain/binaryTarget.ts
+++ b/src/domain/binaryTarget.ts
@@ -41,6 +41,11 @@ export type ExecutableMetadata =
readonly availableArchitectures: readonly "powerpc"[];
readonly powerpc: PowerPcElfMetadata;
}
+ | {
+ readonly format: "elf";
+ readonly architecture: "hexagon";
+ readonly availableArchitectures: readonly "hexagon"[];
+ }
| {
readonly format: "mach-o" | "elf" | "dos-mz" | "dos-com";
readonly architecture: HeaderArchitecture;
@@ -247,6 +252,12 @@ const parseElf = (
riscv: metadata,
});
}
+ if (architecture === "hexagon")
+ return ok({
+ format: "elf",
+ architecture,
+ availableArchitectures: [architecture],
+ });
return ok({
format: "elf",
architecture,
diff --git a/src/domain/binaryTargetTypes.ts b/src/domain/binaryTargetTypes.ts
index 1bcf67e96..67600852a 100644
--- a/src/domain/binaryTargetTypes.ts
+++ b/src/domain/binaryTargetTypes.ts
@@ -11,6 +11,7 @@ export const BINARY_ARCHITECTURES = [
"riscv",
"powerpc",
"m68k",
+ "hexagon",
] as const;
export type BinaryArchitecture = (typeof BINARY_ARCHITECTURES)[number];
@@ -62,7 +63,7 @@ export const isElfMetadataArchitecture = (
/** Recognized family with no ELF metadata member; the header alone is the fact. */
export type HeaderArchitecture = Exclude<
BinaryArchitecture,
- ElfMetadataArchitecture | RawOnlyArchitecture
+ ElfMetadataArchitecture | RawOnlyArchitecture | "hexagon"
>;
/** Raw ELF facts; family recognition does not establish ISA or ABI support. */
@@ -175,6 +176,14 @@ export type BinaryTarget =
readonly executableRole?: never;
readonly managed?: never;
})
+ | (BinaryTargetIdentity & {
+ readonly kind: "executable";
+ readonly format: "elf";
+ readonly architecture: "hexagon";
+ readonly availableArchitectures: readonly "hexagon"[];
+ readonly executableRole?: never;
+ readonly managed?: never;
+ })
| (ExecutableTarget & {
readonly format: "mach-o" | "elf" | "dos-mz" | "dos-com";
readonly universalSlice?: never;
@@ -191,14 +200,11 @@ export type BinaryTarget =
| (BinaryTargetIdentity & {
readonly kind: "executable";
readonly format: "raw-binary";
- readonly architecture: Exclude<
- BinaryArchitecture,
- ElfMetadataArchitecture
- >;
- readonly availableArchitectures: readonly Exclude<
- BinaryArchitecture,
- ElfMetadataArchitecture
- >[];
+ readonly architecture: HeaderArchitecture | RawOnlyArchitecture;
+ readonly availableArchitectures: readonly (
+ | HeaderArchitecture
+ | RawOnlyArchitecture
+ )[];
readonly entryPoint: string;
readonly entryPointSource: string;
readonly executableRole?: never;
diff --git a/src/domain/elfFixedHeader.ts b/src/domain/elfFixedHeader.ts
index ea5943d69..c91eeb0ce 100644
--- a/src/domain/elfFixedHeader.ts
+++ b/src/domain/elfFixedHeader.ts
@@ -80,6 +80,8 @@ const elfArchitecture = (
return "powerpc";
case 40:
return "arm";
+ case 164: // EM_HEXAGON: Qualcomm Hexagon DSP (QDSP6).
+ return "hexagon";
case 183:
return "arm64";
case 243: // EM_RISCV: XLEN, byte order and e_flags remain separate ELF facts.
diff --git a/src/domain/peMachine.ts b/src/domain/peMachine.ts
index c7cc16a11..3ef52522d 100644
--- a/src/domain/peMachine.ts
+++ b/src/domain/peMachine.ts
@@ -1,6 +1,6 @@
import type { HeaderArchitecture } from "./binaryTargetTypes.js";
-export type PeArchitecture = HeaderArchitecture;
+export type PeArchitecture = Exclude<HeaderArchitecture, "hexagon">;
/** A decoded COFF machine and whether it carried a ReadyToRun OS override. */
export interface PeMachine {
diff --git a/src/ghidra/GhidraProvider.behavior.test.ts b/src/ghidra/GhidraProvider.behavior.test.ts
index 9ebde3523..d03b92477 100644
--- a/src/ghidra/GhidraProvider.behavior.test.ts
+++ b/src/ghidra/GhidraProvider.behavior.test.ts
@@ -35,6 +35,7 @@ import { jsonValueSchema, type JsonValue } from "../domain/jsonValue.js";
import { parseConfig } from "../config/parseConfig.js";
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
import { parseExecutableHeader } from "../domain/binaryTarget.js";
+import { elf } from "../domain/binaryTarget.fixture.js";
import { GhidraProvider } from "./GhidraProvider.js";
import type { GhidraTargetSnapshot } from "./GhidraClient.js";
import type { GhidraProviderClientFactory } from "./GhidraProviderClient.js";
@@ -282,6 +283,37 @@ describe("Ghidra provider", () => {
const windows = provider(installationHost("win32"));
expect(windows.inspectTargetSupport(target).status).toBe("unsupported");
});
+ it("admits parsed Hexagon ELF targets through Ghidra profile selection and declines them on Windows", async () => {
+ const parsed = parseExecutableHeader(elf(1, 1, 164), "x64");
+ if (!parsed.ok) throw new Error("Expected valid Hexagon ELF target");
+ const target: BinaryTarget = {
+ path: "/tmp/chre_pal.so",
+ sha256: "a".repeat(64),
+ kind: "executable",
+ ...parsed.value,
+ };
+ const ghidra = provider();
+ expect(ghidra.inspectTargetSupport(target)).toMatchObject({
+ status: "supported",
+ });
+ const resolved = await ghidra.resolveAnalysisProfile(target);
+ expect(resolved.ok && resolved.value).toMatchObject({
+ profile: {
+ parameters: {
+ target_format: "elf",
+ architecture: "hexagon",
+ loader: "auto-from-header",
+ language_id: "auto-from-header",
+ compiler_spec_id: "auto-default",
+ },
+ },
+ });
+ const windows = provider(installationHost("win32"));
+ expect(windows.inspectTargetSupport(target)).toMatchObject({
+ status: "unsupported",
+ code: "target_format_unsupported",
+ });
+ });
it("re-observes the exact installation for each fresh task without launching Ghidra", async () => {
let probeCount = 0;
const host: GhidraInstallationHost = {
diff --git a/src/ghidra/GhidraProvider.ts b/src/ghidra/GhidraProvider.ts
index b7489ecc7..d5a25b36d 100644
--- a/src/ghidra/GhidraProvider.ts
+++ b/src/ghidra/GhidraProvider.ts
@@ -90,6 +90,7 @@ const SUPPORTED_ARCHITECTURES = new Set([
"riscv",
"powerpc",
"m68k",
+ "hexagon",
]);
/** Ghidra candidate backed by an isolated ephemeral headless import. */
diff --git a/src/hopper/HopperAnalysisProfile.ts b/src/hopper/HopperAnalysisProfile.ts
index 85159ee31..26fb390f5 100644
--- a/src/hopper/HopperAnalysisProfile.ts
+++ b/src/hopper/HopperAnalysisProfile.ts
@@ -106,14 +106,20 @@ export const resolveHopperAnalysisProfile = async (
/** Ghidra owns these lanes; Hopper names the family it declines rather than guessing. */
const HOPPER_DECLINED_ARCHITECTURE_LABELS: Record<
- ElfMetadataArchitecture,
+ ElfMetadataArchitecture | "hexagon",
string
> = {
mips: "MIPS",
riscv: "RISC-V",
powerpc: "PowerPC",
+ hexagon: "Hexagon",
};
+export const hopperDeclinedArchitectureReason = (
+ architecture: ElfMetadataArchitecture | "hexagon",
+): string =>
+ `REA's Hopper adapter does not admit ${HOPPER_DECLINED_ARCHITECTURE_LABELS[architecture]} targets. Select a verified Ghidra ${HOPPER_DECLINED_ARCHITECTURE_LABELS[architecture]} profile instead.`;
+
/** Derive Hopper's complete non-interactive CLI loader selection. */
export const hopperLoaderArgsForTarget = (
target: BinaryTarget,
@@ -128,12 +134,12 @@ export const hopperLoaderArgsForTarget = (
if (target.format === "raw-binary")
return err(new ProviderAdapterError("hopper", "resolve_analysis_profile"));
const architecture = target.architecture;
- if (isElfMetadataArchitecture(architecture))
+ if (isElfMetadataArchitecture(architecture) || architecture === "hexagon")
return err(
new AnalysisCapabilityUnavailableError(
"hopper",
"resolve_analysis_profile",
- `REA's Hopper adapter does not admit ${HOPPER_DECLINED_ARCHITECTURE_LABELS[architecture]} targets. Select a verified Ghidra ${HOPPER_DECLINED_ARCHITECTURE_LABELS[architecture]} profile instead.`,
+ hopperDeclinedArchitectureReason(architecture),
),
);
const flag = hopperArchitectureFlag(architecture);
diff --git a/src/hopper/HopperProvider.test.ts b/src/hopper/HopperProvider.test.ts
index 94715034c..29a91d5a0 100644
--- a/src/hopper/HopperProvider.test.ts
+++ b/src/hopper/HopperProvider.test.ts
@@ -45,4 +45,25 @@ describe("Hopper provider capabilities", () => {
reason: expect.stringContaining("Ghidra"),
});
});
+ it("declines Hexagon targets with a Ghidra-directed reason", () => {
+ const config = parseConfig({});
+ if (!config.ok) throw new Error("expected valid configuration");
+ const provider = new HopperProvider(config.value, silentLogger, {});
+ const support = provider.inspectTargetSupport({
+ path: "/tmp/chre_pal.so",
+ sha256: "a".repeat(64),
+ kind: "executable",
+ format: "elf",
+ architecture: "hexagon",
+ availableArchitectures: ["hexagon"],
+ });
+ expect(support).toMatchObject({
+ status: "unsupported",
+ code: "architecture_unsupported",
+ reason: expect.stringContaining("Hexagon"),
+ });
+ if (support.status === "unsupported") {
+ expect(support.reason).toContain("Ghidra");
+ }
+ });
});
diff --git a/src/hopper/HopperProvider.ts b/src/hopper/HopperProvider.ts
index 684c8bb08..48d3432f6 100644
--- a/src/hopper/HopperProvider.ts
+++ b/src/hopper/HopperProvider.ts
@@ -26,6 +26,7 @@ import { AnalysisCapabilityUnavailableError } from "../domain/analysisErrorCore.
import { err, ok } from "../domain/result.js";
import { HopperApplicationLauncher } from "./BridgeLauncher.js";
import {
+ hopperDeclinedArchitectureReason,
hopperLoaderArgsForTarget,
resolveHopperAnalysisProfile,
} from "./HopperAnalysisProfile.js";
@@ -129,17 +130,14 @@ export class HopperProvider implements AnalysisProviderCandidate {
reason: null,
diagnostics,
};
- if (isElfMetadataArchitecture(target.architecture))
+ if (
+ isElfMetadataArchitecture(target.architecture) ||
+ target.architecture === "hexagon"
+ )
return {
status: "unsupported",
code: "architecture_unsupported",
- reason: `REA's Hopper adapter does not admit ${
- target.architecture === "mips"
- ? "MIPS"
- : target.architecture === "riscv"
- ? "RISC-V"
- : "PowerPC"
- } targets.`,
+ reason: hopperDeclinedArchitectureReason(target.architecture),
diagnostics,
};
if (target.format === "raw-binary")
diff --git a/src/ida/IdaProvider.test.ts b/src/ida/IdaProvider.test.ts
index ccf67c5b4..e0d5a2180 100644
--- a/src/ida/IdaProvider.test.ts
+++ b/src/ida/IdaProvider.test.ts
@@ -25,4 +25,23 @@ describe("IDA provider target support", () => {
reason: expect.stringContaining("Ghidra"),
});
});
+ it("declines Hexagon targets with a Ghidra-directed reason", () => {
+ const config = parseConfig({});
+ if (!config.ok) throw new Error("expected valid configuration");
+ const provider = new IdaProvider(config.value, {});
+ expect(
+ provider.inspectTargetSupport({
+ path: "/tmp/chre_pal.so",
+ sha256: "a".repeat(64),
+ kind: "executable",
+ format: "elf",
+ architecture: "hexagon",
+ availableArchitectures: ["hexagon"],
+ }),
+ ).toMatchObject({
+ status: "unsupported",
+ code: "architecture_unsupported",
+ reason: expect.stringContaining("Hexagon"),
+ });
+ });
});
diff --git a/src/ida/IdaProvider.ts b/src/ida/IdaProvider.ts
index 38476502d..1511b9b1a 100644
--- a/src/ida/IdaProvider.ts
+++ b/src/ida/IdaProvider.ts
@@ -111,7 +111,8 @@ export class IdaProvider implements AnalysisProviderCandidate {
};
if (
target.kind === "executable" &&
- isElfMetadataArchitecture(target.architecture)
+ (isElfMetadataArchitecture(target.architecture) ||
+ target.architecture === "hexagon")
)
return {
status: "unsupported",
@@ -121,7 +122,9 @@ export class IdaProvider implements AnalysisProviderCandidate {
? "MIPS"
: target.architecture === "riscv"
? "RISC-V"
- : "PowerPC"
+ : target.architecture === "powerpc"
+ ? "PowerPC"
+ : "Hexagon"
} lane. Select a supported Ghidra profile instead.`,
diagnostics,
};