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:
morluto
2026-10-12 09:29:07 +08:00
parent 87b9793c53
commit b38429cb6a
28 changed files with 608 additions and 143 deletions
+21 -17
View File
@@ -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":