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
fix(macho): stop retaining segments past the mapping budget
Segment commands are collected during framing only while their mapping
records still fit in the budget shared by all slices, and the budget is
charged only when the slice maps its range.
  • Loading branch information
chordpli committed Oct 29, 2026
commit c8069690e01d05c1146f30e4c31ed352aaac0be3
20 changes: 20 additions & 0 deletions src/artifacts/apple/MachoEncryptionReader.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,26 @@ describe("Mach-O encryption reader: large universal files", () => {
});

describe("Mach-O encryption reader: mapping budget", () => {
it("leaves the budget to later slices when a slice does not map its range", async () => {
const facts = await read(
fatImage([
{
cpu: CPU.x86_64,
bytes: padded(machoImage({ cpu: CPU.x86_64, commands: [text()] })),
},
{ cpu: CPU.arm64, bytes: encrypted() },
]),
5,
);
if (facts.status !== "parsed") throw new Error(facts.status);
expect(
facts.slices.map(({ status, range }) => [status, range?.mapping.status]),
).toEqual([
["absent", undefined],
["encrypted", "mapped"],
]);
});

it("shares one mapping budget across slices and keeps each status", async () => {
// text() is one segment with three section records: five mapping records.
const facts = await read(
Expand Down
58 changes: 34 additions & 24 deletions src/artifacts/apple/MachoEncryptionReader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ const readSlice = async (
// and dropped so a large table of small commands stays one buffer.
const commands: MachoEncryptionCommand[] = [];
let encryptionCommands = 0;
const segments: MachoLoadCommand[] = [];
// Null once this slice's segments need more records than the shared
// mapping budget has left; none are retained past that point.
let segments: MachoLoadCommand[] | null = [];
let segmentRecords = 0;
// Commands seen before a failure stay as partial facts; an incomplete walk
// can never prove the command is absent.
const incomplete = ({
Expand All @@ -163,10 +166,13 @@ const readSlice = async (
if (commands.length < RETAINED_ENCRYPTION_COMMANDS)
commands.push(decodeEncryptionCommand(command));
} else if (
command.command === LC_SEGMENT ||
command.command === LC_SEGMENT_64
)
segments.push(command);
segments !== null &&
(command.command === LC_SEGMENT || command.command === LC_SEGMENT_64)
) {
segmentRecords += mappingRecords(command);
if (segmentRecords > budget.remaining) segments = null;
else segments.push(command);
}
});
if (framed.status !== "framed") return incomplete(framed);
const identityIssue =
Expand All @@ -187,6 +193,8 @@ const readSlice = async (
const outcome = classify(commands, encryptionCommands, header, slice.size);
if (outcome.status !== "valid")
return { ...base, ...outcome, commands, range: null };
// Only a slice that maps its range consumes the shared budget.
if (segments !== null) budget.remaining -= segmentRecords;
Comment thread
gensokyo-dev marked this conversation as resolved.
Resolved
return {
...base,
status: outcome.command.cryptid === 0 ? "not-encrypted" : "encrypted",
Expand All @@ -197,7 +205,7 @@ const readSlice = async (
header,
segments,
slice.offset,
budget,
budget.maximum,
),
};
};
Expand Down Expand Up @@ -290,9 +298,9 @@ const encryptedRange = (
readonly cryptid: number;
},
header: MachoSliceHeader,
segmentCommands: readonly MachoLoadCommand[],
segmentCommands: readonly MachoLoadCommand[] | null,
containerOffset: number,
budget: MappingBudget,
maximumMappingRecords: number,
): MachoEncryptedRange => {
const start = command.cryptoff;
const end = command.cryptoff + command.cryptsize;
Expand All @@ -302,7 +310,13 @@ const encryptedRange = (
slice_end: end,
container_start: containerOffset + start,
container_end: containerOffset + end,
mapping: mapRange(start, end, header, segmentCommands, budget),
mapping:
segmentCommands === null
? {
status: "unknown",
reason: `mapping needs more than the ${maximumMappingRecords} segment and section records shared by all slices`,
}
: mapRange(start, end, header, segmentCommands),
};
};

Expand All @@ -326,19 +340,9 @@ const mapRange = (
end: number,
header: MachoSliceHeader,
segmentCommands: readonly MachoLoadCommand[],
budget: MappingBudget,
): MachoEncryptedRange["mapping"] => {
const segments: SegmentFacts[] = [];
for (const command of segmentCommands) {
// Charge before decoding: a segment yields at most two fragments, and
// each section record it can hold is decoded and reported at most once.
const records = 2 + sectionCapacity(command);
if (records > budget.remaining)
return {
status: "unknown",
reason: `mapping needs more than the ${budget.maximum} segment and section records shared by all slices`,
};
budget.remaining -= records;
if ((command.command === LC_SEGMENT_64) !== header.wide)
return {
status: "unknown",
Expand Down Expand Up @@ -416,12 +420,18 @@ const unmapped = (from: number, to: number) => ({
vm_end: null,
});

/** Section records that fit in a segment command's `cmdsize`. */
const sectionCapacity = ({ command, body }: MachoLoadCommand): number => {
/**
* Mapping records a segment command can produce: at most two fragments, and
* each section record that fits in its `cmdsize`, decoded and reported once.
*/
const mappingRecords = ({ command, body }: MachoLoadCommand): number => {
const wide = command === LC_SEGMENT_64;
return Math.max(
0,
Math.floor((body.byteLength - (wide ? 72 : 56)) / (wide ? 80 : 68)),
return (
2 +
Math.max(
0,
Math.floor((body.byteLength - (wide ? 72 : 56)) / (wide ? 80 : 68)),
)
);
};

Expand Down
Loading