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:
@@ -4,7 +4,10 @@ import {
|
||||
nativeDispatchMetadataResultSchema,
|
||||
type ObjcSwiftMetadata,
|
||||
} from "../domain/native/objcSwiftMetadata.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
isMachOFormat,
|
||||
type BinaryTarget,
|
||||
} from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
AnalysisResourceConstraintError,
|
||||
@@ -174,7 +177,7 @@ export const inspectAppleDispatchMetadata = async (
|
||||
maxRecords: number,
|
||||
signal?: AbortSignal,
|
||||
) => {
|
||||
if (target.kind !== "executable" || target.format !== "mach-o")
|
||||
if (target.kind !== "executable" || !isMachOFormat(target.format))
|
||||
throw new TypeError("Apple dispatch metadata requires a Mach-O target");
|
||||
const maximumBytes = 64 * 1024 * 1024;
|
||||
const capacityError = () =>
|
||||
|
||||
@@ -7,7 +7,10 @@ import {
|
||||
AnalysisInputError,
|
||||
} from "../domain/analysisErrorCore.js";
|
||||
import type { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
isMachOFormat,
|
||||
type BinaryTarget,
|
||||
} from "../domain/binaryTargetTypes.js";
|
||||
import { EvidenceIntegrityError } from "../domain/evidenceErrors.js";
|
||||
import { ProviderAdapterError } from "../domain/providerAdapterError.js";
|
||||
import type { JsonValue } from "../domain/jsonValue.js";
|
||||
@@ -40,7 +43,7 @@ export const observeNativeCalls = async (
|
||||
signal?: AbortSignal,
|
||||
readTargetDigest: typeof fileSha256 = fileSha256,
|
||||
): Promise<Result<NativeCallObservationResult, AnalysisError>> => {
|
||||
if (target.kind !== "executable" || target.format !== "mach-o")
|
||||
if (target.kind !== "executable" || !isMachOFormat(target.format))
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"native-macos",
|
||||
|
||||
@@ -24,7 +24,10 @@ import {
|
||||
NATIVE_TOOL_CONTRACTS,
|
||||
type NativeToolName,
|
||||
} from "../contracts/native/nativeToolContracts.js";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
isMachOFormat,
|
||||
type BinaryTarget,
|
||||
} from "../domain/binaryTargetTypes.js";
|
||||
import { toolContract } from "../contracts/toolContracts.js";
|
||||
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
|
||||
import type { EvidenceLocation } from "../domain/evidence.js";
|
||||
@@ -167,7 +170,10 @@ class NativeMacOSClient implements AnalysisClient {
|
||||
},
|
||||
),
|
||||
);
|
||||
if (this.target.kind !== "executable" || this.target.format !== "mach-o")
|
||||
if (
|
||||
this.target.kind !== "executable" ||
|
||||
!isMachOFormat(this.target.format)
|
||||
)
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
IDENTITY.id,
|
||||
@@ -454,7 +460,7 @@ class NativeMacOSClient implements AnalysisClient {
|
||||
): Promise<Result<NativeObservation, AnalysisError>> {
|
||||
// lipo reads only Mach-O; its refusal of a PE, ELF, or plist target is not
|
||||
// a tool failure that a retry or `rea doctor` could repair.
|
||||
if (this.target.format !== "mach-o")
|
||||
if (!isMachOFormat(this.target.format))
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
IDENTITY.id,
|
||||
@@ -782,7 +788,7 @@ class NativeMacOSClient implements AnalysisClient {
|
||||
async #inspectMacho(
|
||||
signal?: AbortSignal,
|
||||
): Promise<Result<NativeObservation, AnalysisError>> {
|
||||
if (this.target.format !== "mach-o")
|
||||
if (!isMachOFormat(this.target.format))
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
IDENTITY.id,
|
||||
@@ -995,7 +1001,7 @@ const codeSignArchitectures = (
|
||||
);
|
||||
if (architectures.length > 0) return [...new Set(architectures)];
|
||||
}
|
||||
if (target.kind !== "executable" || target.format !== "mach-o") return [];
|
||||
if (target.kind !== "executable" || !isMachOFormat(target.format)) return [];
|
||||
return target.availableArchitectures.map((architecture) =>
|
||||
architecture === "x86" ? "i386" : architecture,
|
||||
);
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { z } from "zod";
|
||||
import type { BinaryTarget } from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
isMachOFormat,
|
||||
type BinaryTarget,
|
||||
} from "../domain/binaryTargetTypes.js";
|
||||
import {
|
||||
nativeUiObservationInputSchema,
|
||||
nativeUiScenarioInputSchema,
|
||||
@@ -78,7 +81,7 @@ const observeWithHelper = async (
|
||||
).safeParse(parameters);
|
||||
if (!parsed.success)
|
||||
return err(new AnalysisInputError(operation, { cause: parsed.error }));
|
||||
if (target.kind !== "executable" || target.format !== "mach-o")
|
||||
if (target.kind !== "executable" || !isMachOFormat(target.format))
|
||||
return err(
|
||||
new AnalysisCapabilityUnavailableError(
|
||||
"native-macos",
|
||||
|
||||
Reference in New Issue
Block a user