mirror of
https://github.com/morluto/rea.git
synced 2026-11-15 19:23:24 +00:00
fix(il2cpp): select universal binary slices through the shared Mach-O selection (#10661)
* fix(il2cpp): select universal binary slices through the shared Mach-O selection * test(il2cpp): assert selection facts instead of full sentences
This commit is contained in:
1 parent
ef15353c69
commit
2705aad365
11 files changed
+243
-139
No files matched your search
@@ -82,14 +82,13 @@ export function* linkIl2cppBinarySteps(
|
||||
bytes: Buffer,
|
||||
metadata: Il2cppMetadataDecoded,
|
||||
facts: Il2cppMetadataLinkFacts,
|
||||
architecture?: string,
|
||||
options: Il2cppBinaryReadOptions = {},
|
||||
): Generator<void, Il2cppBinaryLink> {
|
||||
const version = metadata.metadata_version;
|
||||
// Refuse an undecoded version before any table is read.
|
||||
if (options.genericInstances === true) genericMethodLayouts(version);
|
||||
yield;
|
||||
const image = yield* openImageSteps(bytes, architecture);
|
||||
const image = yield* openImageSteps(bytes);
|
||||
const modules = yield* findModules(image, metadata);
|
||||
const registration_ = yield* findCodeRegistration(image, modules);
|
||||
const methodImage = new Int32Array(metadata.methods.length).fill(-1);
|
||||
|
||||
@@ -4,9 +4,6 @@ export const IL2CPP_BINARY_BYTES = 1024 * 1024 * 1024;
|
||||
export const IL2CPP_BINARY_FAILURE_REASONS = {
|
||||
unsupported: [
|
||||
"unsupported-container",
|
||||
"slice-selection-required",
|
||||
"slice-not-found",
|
||||
"ambiguous-slice-selection",
|
||||
"unsupported-pointer-encoding",
|
||||
"unsupported-type-kind",
|
||||
"generic-methods-unsupported",
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import {
|
||||
readUniversalMachoImage,
|
||||
readUniversalMachoSlice,
|
||||
} from "../domain/apple/machoImageSelection.js";
|
||||
import { binaryMetadataArchitecture } from "../domain/binaryMetadataArchitecture.js";
|
||||
import {
|
||||
IL2CPP_SLICE_SELECTORS,
|
||||
type Il2cppBinaryArchitecture,
|
||||
} from "../domain/il2cpp/il2cppMetadata.js";
|
||||
import {
|
||||
BinaryFormatFailure,
|
||||
BinaryMappingFailure,
|
||||
@@ -14,6 +14,11 @@ import {
|
||||
type FileMappingIndex,
|
||||
} from "../native/metadata/BinaryContainer.js";
|
||||
import { readBinaryContainer } from "../native/metadata/readBinaryContainer.js";
|
||||
import {
|
||||
requireSelectedNativeImage,
|
||||
type SelectedNativeImage,
|
||||
type SliceSelectionInput,
|
||||
} from "../native/metadata/MachoSliceSelection.js";
|
||||
import {
|
||||
parsePointerFixupsSteps,
|
||||
type PointerFixups,
|
||||
@@ -31,60 +36,40 @@ import {
|
||||
Il2cppBinaryFormatFailure,
|
||||
IL2CPP_BINARY_BYTES,
|
||||
} from "./Il2cppBinaryFormat.js";
|
||||
const MACHO_CPU = new Map([
|
||||
[0x01000007, "amd64"],
|
||||
[0x0100000c, "arm64"],
|
||||
]);
|
||||
|
||||
/** Select one thin image; a universal Mach-O needs the caller's architecture. */
|
||||
const selectImage = (
|
||||
bytes: Buffer,
|
||||
architecture: string | undefined,
|
||||
): Buffer => {
|
||||
const container = readUniversalMachoImage(bytes);
|
||||
if (!container.ok)
|
||||
throw new Il2cppBinaryFormatFailure(
|
||||
"malformed-container",
|
||||
container.error.message,
|
||||
);
|
||||
const fat = container.value;
|
||||
if (fat === null) {
|
||||
if (architecture !== undefined)
|
||||
throw new Il2cppBinaryFormatFailure(
|
||||
"slice-not-found",
|
||||
`architecture ${architecture} was requested but the binary is not a universal Mach-O`,
|
||||
);
|
||||
return bytes;
|
||||
}
|
||||
const available = fat.slices.map(
|
||||
(slice) => MACHO_CPU.get(slice.cpuType) ?? `macho-cpu-${slice.cpuType}`,
|
||||
);
|
||||
if (architecture === undefined)
|
||||
throw new Il2cppBinaryFormatFailure(
|
||||
"slice-selection-required",
|
||||
`universal Mach-O holds ${available.join(", ")}; select one architecture`,
|
||||
);
|
||||
if (available.filter((value) => value === architecture).length > 1)
|
||||
throw new Il2cppBinaryFormatFailure(
|
||||
"ambiguous-slice-selection",
|
||||
`multiple universal slices declare ${architecture}; no slice was selected`,
|
||||
);
|
||||
const index = available.indexOf(architecture);
|
||||
const slice = fat.slices[index];
|
||||
if (slice === undefined)
|
||||
throw new Il2cppBinaryFormatFailure(
|
||||
"slice-not-found",
|
||||
`universal Mach-O holds ${available.join(", ")}, not ${architecture}`,
|
||||
);
|
||||
const selected = readUniversalMachoSlice(bytes, fat, slice);
|
||||
if (!selected.ok)
|
||||
throw new Il2cppBinaryFormatFailure(
|
||||
"malformed-container",
|
||||
selected.error.message,
|
||||
);
|
||||
return selected.value;
|
||||
/** Selection failures name the binary's inputs and IL2CPP's public spellings. */
|
||||
const IL2CPP_SLICE_SELECTION_INPUT: SliceSelectionInput = {
|
||||
pathField: "binary_path",
|
||||
architectureField: "binary_architecture",
|
||||
spelling: Object.fromEntries(
|
||||
Object.entries(IL2CPP_SLICE_SELECTORS).map(([publicName, selector]) => [
|
||||
selector,
|
||||
publicName,
|
||||
]),
|
||||
),
|
||||
};
|
||||
|
||||
/**
|
||||
* Select the thin image of the caller's binary: IL2CPP's `binary_architecture`
|
||||
* maps onto the shared slice selector here, once, and a selection failure
|
||||
* names `binary_architecture` or `binary_path`.
|
||||
*/
|
||||
export const requireIl2cppBinaryImage = (
|
||||
operation: string,
|
||||
path: string,
|
||||
bytes: Buffer,
|
||||
architecture: Il2cppBinaryArchitecture | undefined,
|
||||
): SelectedNativeImage =>
|
||||
requireSelectedNativeImage(
|
||||
operation,
|
||||
path,
|
||||
bytes,
|
||||
architecture === undefined
|
||||
? undefined
|
||||
: IL2CPP_SLICE_SELECTORS[architecture],
|
||||
IL2CPP_SLICE_SELECTION_INPUT,
|
||||
);
|
||||
|
||||
export interface NativeImage {
|
||||
readonly bytes: Buffer;
|
||||
readonly container: BinaryContainer;
|
||||
@@ -97,11 +82,8 @@ export interface NativeImage {
|
||||
readonly machoPointerFixups?: PointerFixups;
|
||||
}
|
||||
|
||||
export function* openImageSteps(
|
||||
bytes: Buffer,
|
||||
architecture: string | undefined,
|
||||
): Generator<void, NativeImage> {
|
||||
const image = selectImage(bytes, architecture);
|
||||
/** Open one thin image; a universal Mach-O slice is selected before this. */
|
||||
export function* openImageSteps(image: Buffer): Generator<void, NativeImage> {
|
||||
let container: BinaryContainer;
|
||||
try {
|
||||
container = readBinaryContainer(image);
|
||||
|
||||
@@ -32,7 +32,10 @@ import type { Il2cppMetadataPort } from "../application/il2cpp/Il2cppMetadataPor
|
||||
import { AnalysisError } from "../domain/analysisErrorBase.js";
|
||||
import { createEvidence } from "../domain/evidence.js";
|
||||
import { createIl2cppMetadataAdmission } from "./Il2cppMetadataAdmission.js";
|
||||
import { hexAddress as hex } from "./Il2cppBinaryImage.js";
|
||||
import {
|
||||
hexAddress as hex,
|
||||
requireIl2cppBinaryImage,
|
||||
} from "./Il2cppBinaryImage.js";
|
||||
import { jsonValueByteLength } from "../domain/jsonValueByteLength.js";
|
||||
import {
|
||||
AnalysisCapabilityUnavailableError,
|
||||
@@ -508,6 +511,7 @@ export class Il2cppMetadataProvider implements Il2cppMetadataPort {
|
||||
const decoded = "metadata" in value ? value.metadata : value;
|
||||
const link = "metadata" in value ? value.link : undefined;
|
||||
const binaryPath = input.binary_path;
|
||||
let sliceLimitations: readonly string[] = [];
|
||||
let linked: Pick<
|
||||
Il2cppMetadata,
|
||||
| "binary"
|
||||
@@ -540,11 +544,17 @@ export class Il2cppMetadataProvider implements Il2cppMetadataPort {
|
||||
},
|
||||
);
|
||||
assertArtifactReadActive(options?.signal);
|
||||
const linking = linkIl2cppBinarySteps(
|
||||
const selected = requireIl2cppBinaryImage(
|
||||
OPERATION,
|
||||
binaryPath,
|
||||
binary.bytes,
|
||||
input.binary_architecture,
|
||||
);
|
||||
sliceLimitations = selected.limitations;
|
||||
const linking = linkIl2cppBinarySteps(
|
||||
selected.bytes,
|
||||
decoded,
|
||||
link,
|
||||
input.binary_architecture,
|
||||
{
|
||||
...admission,
|
||||
genericInstances: input.generic_instances === true,
|
||||
@@ -613,6 +623,7 @@ export class Il2cppMetadataProvider implements Il2cppMetadataPort {
|
||||
: [
|
||||
"The binary/metadata pair is caller-selected. Module name/count/token agreement is structural evidence, not a cryptographic proof that both files come from the same build.",
|
||||
]),
|
||||
...sliceLimitations,
|
||||
"declaring_type for types is derived from the nestedTypes section, and member and parameter owners from the owners' index ranges; row positions are the metadata indices.",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user