* fix(domain): admit Qualcomm Hexagon (EM_HEXAGON, 164) ELF binaries Resolve missing ELF admission case for Qualcomm Hexagon DSP targets (e_machine = 164, EM_HEXAGON). - Add 'hexagon' to BINARY_ARCHITECTURES and HeaderArchitecture - Map EM_HEXAGON (164) in elfArchitecture() to 'hexagon' - Include 'hexagon' in GhidraProvider's SUPPORTED_ARCHITECTURES - Gracefully decline 'hexagon' with Ghidra-directed diagnostic in Hopper and IDA - Add unit tests for Hexagon ELF parsing and adapter admission checks Fixes #4781 * fix(hopper,ghidra): add Ghidra guidance to Hopper Hexagon refusal and add Ghidra admission regression test
57 lines
1.8 KiB
TypeScript
57 lines
1.8 KiB
TypeScript
import type { HeaderArchitecture } from "./binaryTargetTypes.js";
|
|
|
|
export type PeArchitecture = Exclude<HeaderArchitecture, "hexagon">;
|
|
|
|
/** A decoded COFF machine and whether it carried a ReadyToRun OS override. */
|
|
export interface PeMachine {
|
|
readonly architecture: PeArchitecture;
|
|
readonly nativeOsOverride: boolean;
|
|
}
|
|
|
|
const architectureForMachine = (
|
|
machine: number,
|
|
): PeArchitecture | undefined => {
|
|
switch (machine) {
|
|
case 0x014c:
|
|
return "x86";
|
|
case 0x8664:
|
|
return "x86_64";
|
|
case 0x01c0:
|
|
case 0x01c2:
|
|
case 0x01c4:
|
|
return "arm";
|
|
case 0xaa64:
|
|
return "arm64";
|
|
}
|
|
return undefined;
|
|
};
|
|
|
|
/** The optional-header magic a machine's architecture requires: PE32+ for 64-bit, PE32 otherwise. */
|
|
export const peOptionalHeaderMagic = (
|
|
architecture: PeArchitecture,
|
|
): 0x10b | 0x20b =>
|
|
architecture === "x86_64" || architecture === "arm64" ? 0x20b : 0x10b;
|
|
|
|
/**
|
|
* ReadyToRun images compiled for a non-Windows OS store the COFF machine XORed
|
|
* with IMAGE_FILE_MACHINE_NATIVE_OS_OVERRIDE (dotnet/runtime
|
|
* src/coreclr/inc/pedecoder.h): Apple, FreeBSD, OpenBSD, Linux, NetBSD, SunOS.
|
|
*/
|
|
const NATIVE_OS_OVERRIDES = [0x4644, 0xadc4, 0xadc5, 0x7b79, 0x1993, 0x1992];
|
|
|
|
/**
|
|
* Decode a COFF machine. Only managed images carry an OS override, so callers
|
|
* must reject `nativeOsOverride` when the image has no CLI header.
|
|
*/
|
|
export const decodePeMachine = (machine: number): PeMachine | undefined => {
|
|
const direct = architectureForMachine(machine);
|
|
if (direct !== undefined)
|
|
return { architecture: direct, nativeOsOverride: false };
|
|
for (const override of NATIVE_OS_OVERRIDES) {
|
|
const architecture = architectureForMachine(machine ^ override);
|
|
if (architecture !== undefined)
|
|
return { architecture, nativeOsOverride: true };
|
|
}
|
|
return undefined;
|
|
};
|