refactor(macho): share unsigned dispatch metadata reads (#12668)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 02:17:09 +00:00
1 parent cf64e4ce3c
commit ed96765d11
2 files changed
+10 -5

No files matched your search

@@ -2,7 +2,7 @@
"src/domain/apple/machoLoadCommandReader.ts": 2,
"src/domain/desktop/openPgpKeys.ts": 2,
"src/domain/managed/managedMetadataInventoryRows.ts": 2,
"src/native/AppleDispatchMetadata.ts": 4,
"src/native/AppleDispatchMetadata.ts": 1,
"src/native/AppleObjcDispatchFacets.ts": 1,
"src/native/AppleSwiftDispatchFacets.ts": 1,
"src/native/elf/ElfNoteParser.ts": 6,
+9 -4
View File
@@ -47,7 +47,10 @@ import { readBoundedFileBytes } from "../process/BoundedFileBytes.js";
import { EvidenceIntegrityError } from "../domain/evidenceErrors.js";
import { pushDispatchCoverage } from "./AppleDispatchCoverage.js";
import { parsePointerFixupsSteps } from "../domain/apple/appleMachoFixups.js";
import { BinaryFormatFailure } from "../domain/binaryContainer.js";
import {
BinaryFormatFailure,
BinaryReader,
} from "../domain/binaryContainer.js";
import { parseMachoLayout } from "../domain/apple/appleMachoSelection.js";
import {
selectMachoSlice,
@@ -102,6 +105,7 @@ export function* decodeAppleDispatchMetadataSteps(
}
const layout = parseMachoLayout(bytes, selected.value);
const { segments, sections, offset } = layout;
const metadata = new BinaryReader(bytes, true, "macho");
const fixups = yield* parsePointerFixupsSteps(
bytes,
layout.fixups,
@@ -116,9 +120,10 @@ export function* decodeAppleDispatchMetadataSteps(
addressesComplete: objcClassImportAddressesComplete,
maxRecords,
});
const u32 = (address: bigint) => bytes.readUInt32LE(offset(address, 4));
const u32 = (address: bigint) => metadata.u32(offset(address, 4));
const u64 = (address: bigint) => metadata.word(offset(address, 8), 64);
const decodePointer = (address: bigint) =>
fixups.decode(address, bytes.readBigUInt64LE(offset(address, 8)));
fixups.decode(address, u64(address));
/** In-image target of a raw or rebased pointer; a bind is not an address. */
const pointer = (address: bigint) => {
const decodedPointer = decodePointer(address);
@@ -212,7 +217,7 @@ export function* decodeAppleDispatchMetadataSteps(
const readers = {
u32,
i32: (address: bigint) => bytes.readInt32LE(offset(address, 4)),
u64: (address: bigint) => bytes.readBigUInt64LE(offset(address, 8)),
u64,
pointer,
resolvePointer: decodePointer,
bound,