fix(native): preserve universal Mach-O container identity
Keep FAT container format distinct from selected slice architecture through target admission, Evidence, snapshots, and CLI/MCP lifecycle results. Preserve native, Hopper, Ghidra, extraction, and dylib routing for the Mach-O family. Reject selected FAT ranges overlapping their table or too short for a Mach-O header. Replace empty-slice fixtures with in-bounds executable headers and cover thin, universal, single-slice, FAT64, and swapped containers. Validation: static and architecture checks, generated docs, targeted producer and public MCP tests. Provider routing uses controlled fixtures; no live Hopper, IDA, JADX, or Ghidra analysis was performed for this change.
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { hopperLoaderArgsForTarget } from "./HopperAnalysisProfile.js";
|
||||
|
||||
it("routes physical universal Mach-O containers through Hopper's FAT loader", () => {
|
||||
const result = hopperLoaderArgsForTarget(
|
||||
{
|
||||
path: "/tmp/universal",
|
||||
sha256: "a".repeat(64),
|
||||
kind: "executable",
|
||||
format: "mach-o-universal",
|
||||
architecture: "arm64",
|
||||
availableArchitectures: ["x86_64", "arm64"],
|
||||
},
|
||||
"fat64",
|
||||
);
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: true,
|
||||
value: ["-l", "FAT", "--aarch64", "-l", "Mach-O"],
|
||||
});
|
||||
});
|
||||
@@ -6,8 +6,11 @@ import type {
|
||||
ProviderIdentity,
|
||||
} from "../application/AnalysisProvider.js";
|
||||
import { createAnalysisProfile } from "../domain/analysisProfile.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import type { BinaryArchitecture } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
isMachOFormat,
|
||||
type BinaryTarget,
|
||||
type BinaryArchitecture,
|
||||
} from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisCapabilityUnavailableError,
|
||||
@@ -37,7 +40,7 @@ export const resolveHopperAnalysisProfile = async (
|
||||
if (target.kind !== "executable" && target.kind !== "database")
|
||||
return ok({ profile: null });
|
||||
let machoContainer: "thin" | "fat32" | "fat64" | undefined;
|
||||
if (target.kind === "executable" && target.format === "mach-o") {
|
||||
if (target.kind === "executable" && isMachOFormat(target.format)) {
|
||||
const header = await readMachoMagic(target.path, options.signal);
|
||||
if (!header.ok) return header;
|
||||
machoContainer = [0xcafebabf, 0xbfbafeca].includes(header.value)
|
||||
@@ -119,21 +122,22 @@ export const hopperLoaderArgsForTarget = (
|
||||
),
|
||||
);
|
||||
const flag = hopperArchitectureFlag(architecture);
|
||||
switch (target.format) {
|
||||
case "mach-o":
|
||||
if (machoContainer === undefined)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"hopper",
|
||||
"resolve_analysis_profile",
|
||||
"Mach-O container kind is unknown; resolve the Hopper analysis profile before starting its client.",
|
||||
),
|
||||
);
|
||||
return ok(
|
||||
machoContainer === "fat32" || machoContainer === "fat64"
|
||||
? ["-l", "FAT", flag, "-l", "Mach-O"]
|
||||
: ["-l", "Mach-O", flag],
|
||||
if (isMachOFormat(target.format)) {
|
||||
if (machoContainer === undefined)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"hopper",
|
||||
"resolve_analysis_profile",
|
||||
"Mach-O container kind is unknown; resolve the Hopper analysis profile before starting its client.",
|
||||
),
|
||||
);
|
||||
return ok(
|
||||
machoContainer === "fat32" || machoContainer === "fat64"
|
||||
? ["-l", "FAT", flag, "-l", "Mach-O"]
|
||||
: ["-l", "Mach-O", flag],
|
||||
);
|
||||
}
|
||||
switch (target.format) {
|
||||
case "elf":
|
||||
return ok(["-l", "ELF", flag]);
|
||||
case "pe":
|
||||
|
||||
@@ -2,7 +2,10 @@ import { createHash } from "node:crypto";
|
||||
import { open, type FileHandle } from "node:fs/promises";
|
||||
import { z } from "zod";
|
||||
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
isMachOFormat,
|
||||
type BinaryTarget,
|
||||
} from "../domain/binaryTargetTypes.js";
|
||||
import { BinaryTargetError } from "../domain/configurationErrors.js";
|
||||
import { AnalysisCancelledError } from "../domain/analysisErrorCore.js";
|
||||
import {
|
||||
@@ -44,7 +47,7 @@ export const resolveHopperMachOImage = async (
|
||||
),
|
||||
);
|
||||
if (signal?.aborted) return err(new AnalysisCancelledError("open_binary"));
|
||||
if (target.format !== "mach-o")
|
||||
if (!isMachOFormat(target.format) || target.architecture === "mips")
|
||||
return invalid("Hopper FAT64 image preparation requires a Mach-O target");
|
||||
let file: FileHandle;
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user