Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cd38a59
refactor(macho): extract non-throwing container and slice load-comman…
chordpli Oct 20, 2026
2b41ca6
feat(macho): report per-slice encryption status in inspect_macho
chordpli Oct 20, 2026
f210a4f
fix(macho): keep slice facts and failures under large tables and clos…
chordpli Oct 20, 2026
ee6f565
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 20, 2026
c128c72
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 20, 2026
c6c8c75
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 21, 2026
15db4e6
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 22, 2026
c54ff26
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 24, 2026
0d506e2
fix(macho): map encrypted ranges only within segment VM extents
chordpli Oct 25, 2026
3bd1541
Merge remote-tracking branch 'origin/main' into HEAD
Oct 26, 2026
611ae1e
fix(macho): read encryption through the admitted descriptor facts
chordpli Oct 26, 2026
7e6d57f
fix(macho): retain a finished report when the target close fails
chordpli Oct 26, 2026
9c74d8d
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 26, 2026
d95f4e3
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 26, 2026
5a22d73
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 26, 2026
811c47d
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 26, 2026
08ed647
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 27, 2026
29f37e6
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 27, 2026
d3f63a8
test(native): supply readEncryption in merged dyld refusal cases
chordpli Oct 27, 2026
014a868
test(views): bind the Mach-O encryption page to its facet
chordpli Oct 27, 2026
c2c2e93
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 28, 2026
7fb4355
Merge remote-tracking branch 'origin/main' into tmp5359
chordpli Oct 28, 2026
3476a90
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 29, 2026
13904db
fix(macho): bound encryption commands and range mapping across slices
chordpli Oct 29, 2026
1bc25f6
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
chordpli Oct 29, 2026
27edcc0
style(macho): format encryption reader and binding test
chordpli Oct 29, 2026
c806969
fix(macho): stop retaining segments past the mapping budget
chordpli Oct 29, 2026
26280c7
feat(macho): preserve per-slice encryption facts and mapping budgets
gensokyo-dev Oct 29, 2026
90ee1c6
chore(macho): align encryption reporting with current main
gensokyo-dev Oct 29, 2026
0eba2e7
docs(macho): clarify retained mapping allowance
gensokyo-dev Oct 29, 2026
5ffb40d
fix(ci): own the Mach-O encryption test in Apple scope
gensokyo-dev Oct 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Merge remote-tracking branch 'origin/main' into feat/macho-encryption…
…-info
  • Loading branch information
chordpli committed Oct 29, 2026
commit 3476a90c07c513b2e0970a084ed5c65bf9f7183a
15 changes: 6 additions & 9 deletions docs/native-investigation.md
Original file line number Diff line number Diff line change
Expand Up @@ -589,15 +589,12 @@ while the slice keeps its encryption status. `architecture` is the lipo name of
size and CPU identity, and is null when no single record matches. A ciphertext
range adds a limitation naming its input-file bytes, because disassembly,
decompilation, strings and references derived from them do not describe
program code. The in-process read holds one regular-file descriptor while the
native tools read the path; the descriptor's and the path's stat identity
(device, inode, size, mode and timestamps) must match before and after inspection,
or the call reports `artifact_changed`. The comparison checks only those
endpoints and does not re-hash the bytes, so a path swapped and restored with
identical metadata while the tools ran is not detected. A symlinked,
non-regular or changing target is refused. A target that cannot be opened keeps the
tool facts and reports the encryption collection as non-exhaustive with the
missing-file or access failure, never as absent.
program code. Encryption is read through the same regular-file descriptor
that `inspect_macho` binds for its load-command reads, whose SHA-256 must match
the session target before and after the native tools run, or the call reports
`artifact_changed`. A target that cannot be opened, or a symlinked, non-regular
or changing target, fails the call instead of reporting tool facts without an
encryption status.

Hopper's `address_to_file_offset` combines the native image-relative mapping with
original-file coordinates only after checking the source against the session's
Expand Down
6 changes: 1 addition & 5 deletions src/domain/analysisErrorBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,7 @@ import type {
AdbPackagePullPartialObservation,
AdbDisplayPartialObservation,
} from "./adb/adbDeviceAnalysis.js";
import type {
InspectMacho,
InspectSignature,
} from "./native/nativeInspection.js";
import type { InspectSignature } from "./native/nativeInspection.js";
import type { NativeUiObservationResult } from "./native/nativeUiObservation.js";
import type { BinaryLayout } from "./native/binaryLayout.js";
import type {
Expand Down Expand Up @@ -340,7 +337,6 @@ export type AnalysisPartialObservation =
| FirmwarePartialObservation
| NativeUiObservationResult
| InspectSignature
| InspectMacho
| ElectronPagePartialObservation
| AdbActivityStartPartialObservation
| AdbAcquiredFilePartialObservation
Expand Down
2 changes: 1 addition & 1 deletion src/domain/analysisView/machoView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const projectMachoView = (
...(incomplete.length === 0
? []
: [
`inspect_macho did not report exhaustive ${incomplete.join(", ")}; page exhaustion does not establish absence of unreturned rows.`,
`Inspection did not establish exhaustive ${incomplete.join(", ")}; page exhaustion does not establish absence of unreturned rows.`,
]),
...(parent.subject == null
? [
Expand Down
24 changes: 10 additions & 14 deletions src/native/AppleDispatchMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,6 @@ export const inspectAppleDispatchMetadata = async (
export const appleDispatchMetadataFailure = (
cause: unknown,
path: string,
operation: string = OPERATION,
): AnalysisError => {
if (cause instanceof ArtifactReaderFailure && cause.cleanup !== undefined) {
const physical =
Expand All @@ -415,11 +414,10 @@ export const appleDispatchMetadataFailure = (
? appleDispatchMetadataPrimaryFailure(
artifactFilePrimaryFacts(cause),
path,
operation,
)
: physical?.completionCancellation === undefined
? undefined
: new AnalysisCancelledError(operation, {
: new AnalysisCancelledError(OPERATION, {
cause: physical.completionCancellation.reason,
});
const failure = new ProviderCleanupError(
Expand All @@ -430,34 +428,32 @@ export const appleDispatchMetadataFailure = (
previous_error:
previous === undefined ? null : projectAnalysisError(previous),
},
{ operation, cause, cleanupPrimary: previous },
{ operation: OPERATION, cause, cleanupPrimary: previous },
);
bindArtifactFileCleanup(cause, failure);
return failure;
}
return appleDispatchMetadataPrimaryFailure(
artifactFilePrimaryFacts(cause),
path,
operation,
);
};

const appleDispatchMetadataPrimaryFailure = (
{ cause, origin }: ArtifactFilePrimaryFacts,
path: string,
operation: string,
): AnalysisError => {
if (origin === "owned-or-classified") {
if (cause instanceof AnalysisError) return cause;
if (cause instanceof UnsupportedMachoMetadataFormatError)
return new AnalysisCapabilityUnavailableError(
IDENTITY.id,
operation,
OPERATION,
cause.message,
{ cause },
);
if (cause instanceof ArtifactReaderFailure && cause.reason === "cancelled")
return new AnalysisCancelledError(operation, {
return new AnalysisCancelledError(OPERATION, {
cause: artifactFileCancellationCause(cause),
});
if (
Expand All @@ -466,16 +462,16 @@ const appleDispatchMetadataPrimaryFailure = (
)
return new AnalysisCapabilityUnavailableError(
IDENTITY.id,
operation,
OPERATION,
cause.message,
{ cause },
);
if (cause instanceof ArtifactReaderFailure && cause.reason === "integrity")
return new AnalysisArtifactChangedError(operation, path, cause.message, {
return new AnalysisArtifactChangedError(OPERATION, path, cause.message, {
cause,
});
if (cause instanceof ArtifactReaderFailure && cause.reason === "path")
return new AnalysisArtifactChangedError(operation, path, cause.message, {
return new AnalysisArtifactChangedError(OPERATION, path, cause.message, {
cause,
});
}
Expand All @@ -490,19 +486,19 @@ const appleDispatchMetadataPrimaryFailure = (
"code" in readCause &&
(readCause.code === "EACCES" || readCause.code === "EPERM")
)
return new AnalysisAccessDeniedError(operation, path, readCause.code, {
return new AnalysisAccessDeniedError(OPERATION, path, readCause.code, {
cause,
});
// This path already belongs to the bound target; loss of readability is a
// change to that artifact, rather than a new caller input-selection error.
if (isSelectedRegularFileError(readCause))
return new AnalysisArtifactChangedError(
operation,
OPERATION,
path,
`Bound metadata target could not be read (${readCause.code}): ${path}`,
{ cause },
);
return new ProviderAdapterError(IDENTITY.id, operation, {
return new ProviderAdapterError(IDENTITY.id, OPERATION, {
cause,
diagnostics: {
target_path: path,
Expand Down
164 changes: 64 additions & 100 deletions src/native/NativeMacOSProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
resolveBundleResourcePlistSelection,
} from "./NativePlistSource.js";
import {
artifactFileCompletion,
assertArtifactReadActive,
bindArtifactFileCleanup,
withArtifactRegularFile,
artifactFileCompletion,
artifactFilePrimaryFacts,
artifactFileCancellationCause,
ArtifactFileCleanupFailure,
type ArtifactFilePrimaryFacts,
} from "../artifacts/ArtifactFileOperation.js";
import { readMachoEncryption } from "../artifacts/apple/MachoEncryptionReader.js";
import type { ReadAt } from "../artifacts/apple/MachoLoadCommandReader.js";
import { sameRegularFileState } from "../filesystem/RegularFile.js";
import { snapshotEnvironment } from "../process/snapshotEnvironment.js";
import {
APPLE_DISPATCH_METADATA_ANALYSIS_PROFILE,
Expand All @@ -37,7 +37,8 @@ import {
import { NativeUiCleanupError } from "./NativeUiCleanupError.js";
import { LldbCallTracer, type NativeCallTracer } from "./LldbCallTracer.js";
import { observeNativeCalls } from "./NativeCallObservation.js";
import { lstat, realpath, type FileHandle } from "node:fs/promises";
import { realpath } from "node:fs/promises";
import { createAnalysisExecutionEvidence } from "../domain/analysisObservation.js";

import { z } from "zod";

Expand All @@ -64,7 +65,6 @@ import {
import { analysisInputErrorFromIssues } from "../domain/inputIssueProjection.js";
import type { EvidenceLocation } from "../domain/evidence.js";
import {
AnalysisArtifactChangedError,
AnalysisCancelledError,
AnalysisArtifactChangedError,
AnalysisCapabilityUnavailableError,
Expand Down Expand Up @@ -98,7 +98,6 @@ import type { NativeUiObservationResult } from "../domain/native/nativeUiObserva
import { parseXmlPropertyList } from "../domain/propertyListKeys.js";
import {
demangleSwiftSchema,
inspectMachoSchema,
inspectPlistSchema,
inspectSignatureSchema,
type InspectSignature,
Expand Down Expand Up @@ -135,7 +134,6 @@ import { XmlPlistTextDecodeError } from "../domain/propertyListXmlText.js";
import {
architectureLocations,
inspectNativeMacho,
type MachoEncryptionRead,
} from "./NativeMachoInspection.js";
import { analysisErrorWithCleanupFailure } from "../domain/analysisErrorCleanup.js";
import { ArtifactResourceScope } from "../artifacts/ArtifactResourceScope.js";
Expand Down Expand Up @@ -1270,82 +1268,70 @@ class NativeMacOSClient implements AnalysisClient {
"Active artifact is not Mach-O.",
),
);
const inspect = (readEncryption: () => Promise<MachoEncryptionRead>) =>
inspectNativeMacho({
target: this.target,
...(signal === undefined ? {} : { signal }),
run: (tool, arguments_, commandSignal, acceptNonZeroIf) =>
this.#run("inspect_macho", tool, arguments_, {
signal: commandSignal,
timeoutMs,
...(acceptNonZeroIf === undefined ? {} : { acceptNonZeroIf }),
}),
invocation: (capture) => invocation(capture, this.target.path),
readEncryption,
});
const { path } = this.target;
let admitted = false;
try {
// The tools read the path; the in-process read and both identity checks
// bracket them, so every fact describes one unchanged regular file.
return await this.#machoResources.run(() =>
withArtifactRegularFile(
path,
withNativeMachoSource(
this.target,
this.#machoResources,
signal,
async ({ handle, initial }) => {
admitted = true;
const result = await inspect(() =>
readMachoEncryption(fileReadAt(handle, signal), initial.size),
);
// Failures are thrown so a descriptor close failure keeps them
// as its primary error instead of reporting a completed read.
if (!result.ok) throw result.error;
const [after, current] = await Promise.all([
handle.stat(),
lstat(path),
]);
if (
!sameRegularFileState(initial, after) ||
!sameRegularFileState(initial, current)
)
throw new AnalysisArtifactChangedError(
"inspect_macho",
path,
"the Mach-O file changed while it was inspected",
);
return result;
},
"reject",
(source) =>
inspectNativeMacho({
target: this.target,
...(signal === undefined ? {} : { signal }),
run: (tool, arguments_, commandSignal, acceptNonZeroIf) =>
this.#run("inspect_macho", tool, arguments_, {
signal: commandSignal,
timeoutMs,
...(acceptNonZeroIf === undefined ? {} : { acceptNonZeroIf }),
}),
invocation: (capture) => invocation(capture, this.target.path),
// Encryption facts come from the same identity-bound descriptor.
readEncryption: () =>
readMachoEncryption(
(at, length) =>
source.readSlice(
0,
source.bytes,
Math.min(at, source.bytes),
Math.max(0, Math.min(length, source.bytes - at)),
),
source.bytes,
),
resolveSlice: (selected) =>
resolveSelectedMachoSlice(
source,
selected,
Math.floor(NATIVE_COMMAND_OUTPUT_BUDGET_BYTES / 256),
),
readCommandNames: async (offset, size, selected) => {
const length = size ?? source.bytes - offset;
// Binary strings can expand to hex and escaped JSON, and each
// record becomes several objects. Reserve room for those forms.
const maximum = Math.floor(
NATIVE_COMMAND_OUTPUT_BUDGET_BYTES / 12,
);
const maximumRecords = Math.floor(
NATIVE_COMMAND_OUTPUT_BUDGET_BYTES / 256,
);
const binary = await readMachoCommandNames(
(at, bytes) => source.readSlice(offset, length, at, bytes),
length,
maximum,
maximumRecords,
NATIVE_COMMAND_OUTPUT_BUDGET_BYTES,
);
if (size !== null) {
if (selected === undefined)
throw new TypeError("Selected Mach-O slice is unavailable");
assertSelectedMachoSlice(source, selected, binary);
}
return binary;
},
}),
),
);
} catch (cause: unknown) {
// Only an unopenable target leaves the tool facts without a byte read;
// cancellation, read and cleanup failures stay errors.
if (admitted || signal?.aborted === true || !isUnopenableTarget(cause)) {
const failure = appleDispatchMetadataFailure(
cause,
path,
"inspect_macho",
);
// A report finished before close failed or was cancelled survives.
const completed = artifactFileCompletion(cause)?.value as
| Awaited<ReturnType<typeof inspect>>
| undefined;
const report =
completed?.ok === true
? inspectMachoSchema.safeParse(completed.value.result)
: undefined;
if (report?.success === true)
failure.retainPartialObservation(report.data);
return err(failure);
}
return inspect(() =>
Promise.resolve({
status: "unread",
reason: `the target could not be opened for reading (${cause.code})`,
}),
);
return err(nativeMachoSourceFailure(cause, this.target, parameters));
}
}

Expand Down Expand Up @@ -1876,25 +1862,3 @@ const plutilDiagnostic = (
? "plutil printed no diagnostic"
: diagnostics.join("\n");
};

/** Positioned reads that observe the caller's cancellation before each read. */
const fileReadAt =
(file: FileHandle, signal: AbortSignal | undefined): ReadAt =>
async (offset, length) => {
assertArtifactReadActive(signal);
const bytes = Buffer.alloc(length);
const { bytesRead } = await file.read(bytes, 0, length, offset);
return bytes.subarray(0, bytesRead);
};

// Only absence or denied access leaves the path for the tools to report;
// non-regular, changed or symlinked targets and descriptor exhaustion stay errors.
const UNOPENABLE_TARGET_CODES = new Set(["ENOENT", "EACCES", "EPERM"]);

const isUnopenableTarget = (
cause: unknown,
): cause is NodeJS.ErrnoException & { readonly code: string } =>
cause instanceof Error &&
"code" in cause &&
typeof cause.code === "string" &&
UNOPENABLE_TARGET_CODES.has(cause.code);
7 changes: 7 additions & 0 deletions src/native/NativeMachoInspection.fixture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,10 @@ export const inspectionReader =
(image = inspectionImage()) =>
() =>
readMachoCommandNames(readerOf(image), image.length, 1024 * 1024, 10000);

/** Encryption facts for inspections whose assertions do not involve them. */
export const unreadEncryption = () =>
Promise.resolve({
status: "unread",
reason: "not read in this test",
} as const);
Loading
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.