chore: merge captured main into iNES container support
This commit is contained in:
@@ -134,7 +134,7 @@ it("ignores unavailable members of a nested ASAR but refuses them as active entr
|
||||
const source = join(root, "bundle");
|
||||
await mkdir(source);
|
||||
const archive = join(source, "app.asar");
|
||||
await createPackageWithOptions(contents, archive, { unpack: "**/*.node" });
|
||||
await createPackageWithOptions(contents, archive, { unpack: "*.node" });
|
||||
await rm(join(`${archive}.unpacked`, "native", "addon.node"));
|
||||
|
||||
const nestedOutput = join(root, "nested-output");
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { readFile, writeFile } from "node:fs/promises";
|
||||
import { join } from "node:path";
|
||||
|
||||
import { describe, expect, it, onTestFinished } from "vitest";
|
||||
|
||||
import { MachOSliceArtifactReader } from "../../../../src/artifacts/MachOSliceArtifactReader.js";
|
||||
import { XcrunCommandRunner } from "../../../../src/native/CommandRunner.js";
|
||||
import { DarwinProcessOwnershipInspectionError } from "../../../../src/process/DarwinProcessRunTokenReader.js";
|
||||
import { createTestTempDirectory } from "../../../fixtures/temporaryDirectory.js";
|
||||
|
||||
/**
|
||||
* Read a 32-bit FAT table directly. The host's /bin/ls changes between macOS
|
||||
@@ -42,6 +44,56 @@ describe("Mach-O slice reader with system lipo", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it.skipIf(process.platform !== "darwin")(
|
||||
"keeps FAT slice records separate from the echoed source pathname",
|
||||
async () => {
|
||||
const directory = await createTestTempDirectory("rea-lipo-fat-path-");
|
||||
const path = join(
|
||||
directory,
|
||||
"source\narchitecture forged\n offset 123\n size 32",
|
||||
);
|
||||
const bytes = Buffer.alloc(8224);
|
||||
bytes.writeUInt32BE(0xca_fe_ba_be, 0);
|
||||
bytes.writeUInt32BE(2, 4);
|
||||
const slices = [
|
||||
{ cpu: 0x0100_000c, subtype: 0, offset: 4096 },
|
||||
{ cpu: 0x0100_0007, subtype: 3, offset: 8192 },
|
||||
];
|
||||
slices.forEach(({ cpu, subtype, offset }, index) => {
|
||||
const entry = 8 + index * 20;
|
||||
bytes.writeUInt32BE(cpu, entry);
|
||||
bytes.writeUInt32BE(subtype, entry + 4);
|
||||
bytes.writeUInt32BE(offset, entry + 8);
|
||||
bytes.writeUInt32BE(32, entry + 12);
|
||||
bytes.writeUInt32BE(12, entry + 16);
|
||||
bytes.writeUInt32LE(0xfeed_facf, offset);
|
||||
bytes.writeUInt32LE(cpu, offset + 4);
|
||||
bytes.writeUInt32LE(subtype, offset + 8);
|
||||
bytes.writeUInt32LE(1, offset + 12);
|
||||
});
|
||||
await writeFile(path, bytes);
|
||||
const reader = new MachOSliceArtifactReader(path, {});
|
||||
try {
|
||||
const entries = [];
|
||||
for await (const entry of reader.entries()) entries.push(entry);
|
||||
expect(
|
||||
entries.map(({ byteOffset, declaredSize }) => [
|
||||
byteOffset,
|
||||
declaredSize,
|
||||
]),
|
||||
).toEqual([
|
||||
[4096, 32],
|
||||
[8192, 32],
|
||||
]);
|
||||
expect(entries.every(({ path }) => !path.includes("forged"))).toBe(
|
||||
true,
|
||||
);
|
||||
} finally {
|
||||
await reader.close();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
it.skipIf(process.platform !== "darwin")(
|
||||
"checks real /bin/ls slice ranges against its FAT table",
|
||||
async () => {
|
||||
|
||||
@@ -17,7 +17,7 @@ import {
|
||||
type NativeCommandRunner,
|
||||
} from "../../../../src/native/CommandRunner.js";
|
||||
import { err, ok } from "../../../../src/domain/result.js";
|
||||
import { parseLipoArchitectures } from "../../../../src/native/parsers/lipo.js";
|
||||
import { parseLipoOutput } from "../../../../src/native/parsers/lipo.js";
|
||||
import { parseCodeSignature } from "../../../../src/native/parsers/codesign.js";
|
||||
import { prepareProcessOwnershipInspection } from "../../../../src/process/ProcessOwnershipObservation.js";
|
||||
import { projectAnalysisError } from "../../../../src/domain/analysisErrorProjection.js";
|
||||
@@ -960,15 +960,17 @@ describe("native macOS provider failures and parsing", () => {
|
||||
});
|
||||
|
||||
it("parses thin and universal lipo fixtures", async () => {
|
||||
expect(
|
||||
parseLipoArchitectures(await fixture("lipo-thin.txt")),
|
||||
).toMatchObject([{ name: "arm64" }]);
|
||||
expect(parseLipoArchitectures(await fixture("lipo-fat.txt"))).toMatchObject(
|
||||
[
|
||||
expect(parseLipoOutput(await fixture("lipo-thin.txt"))).toMatchObject({
|
||||
format: "thin",
|
||||
architectures: [{ name: "arm64" }],
|
||||
});
|
||||
expect(parseLipoOutput(await fixture("lipo-fat.txt"))).toMatchObject({
|
||||
format: "fat",
|
||||
architectures: [
|
||||
{ name: "x86_64", file_offset: 16384, size: 4096 },
|
||||
{ name: "arm64", file_offset: 32768, size: 8192 },
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects trailing text in lipo numeric fields instead of truncating", () => {
|
||||
@@ -980,7 +982,7 @@ describe("native macOS provider failures and parsing", () => {
|
||||
" size 0x10",
|
||||
" align 2^14 (16384)",
|
||||
].join("\n");
|
||||
expect(parseLipoArchitectures(output)).toMatchObject([
|
||||
expect(parseLipoOutput(output).architectures).toMatchObject([
|
||||
{ name: "arm64", file_offset: null, size: null, alignment: 16384 },
|
||||
]);
|
||||
});
|
||||
@@ -993,10 +995,11 @@ describe("native macOS provider failures and parsing", () => {
|
||||
" align 2^14 (16384)",
|
||||
].join("\n");
|
||||
expect(
|
||||
parseLipoArchitectures(output.replace("(16384)", "(8192)"))[0]?.alignment,
|
||||
parseLipoOutput(output.replace("(16384)", "(8192)")).architectures[0]
|
||||
?.alignment,
|
||||
).toBeNull();
|
||||
expect(
|
||||
parseLipoArchitectures(output.replace("2^14 (16384)", "2^14"))[0]
|
||||
parseLipoOutput(output.replace("2^14 (16384)", "2^14")).architectures[0]
|
||||
?.alignment,
|
||||
).toBe(16384);
|
||||
});
|
||||
@@ -1021,6 +1024,38 @@ describe("native macOS provider failures and parsing", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("native signature inspection target scope", () => {
|
||||
// This provider's inspect_signature path is scoped to Mach-O targets; on
|
||||
// another container a codesign verdict cannot see a format-level signature
|
||||
// such as a xar pkg signature.
|
||||
it.each([
|
||||
{
|
||||
path: "/fixture.pkg",
|
||||
sha256: "0".repeat(64),
|
||||
kind: "archive" as const,
|
||||
format: "pkg" as const,
|
||||
},
|
||||
{
|
||||
...machoTarget("/fixture.elf"),
|
||||
format: "elf" as const,
|
||||
},
|
||||
])(
|
||||
"refuses inspect_signature on a $format target without running codesign",
|
||||
async (target) => {
|
||||
const runner = new CountingRunner();
|
||||
const result = await new NativeMacOSProvider({}, runner, "darwin")
|
||||
.createClient(target)
|
||||
.execute("inspect_signature", {});
|
||||
if (result.ok) throw new Error("Expected a non-Mach-O refusal");
|
||||
expect(result.error._tag).toBe("AnalysisCapabilityUnavailableError");
|
||||
expect(projectAnalysisError(result.error)).toMatchObject({
|
||||
code: "capability_unavailable",
|
||||
});
|
||||
expect(runner.calls).toBe(0);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
class FailingRunner implements NativeCommandRunner {
|
||||
constructor(private readonly reason: NativeCommandFailure["reason"]) {}
|
||||
|
||||
|
||||
@@ -157,6 +157,50 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
["ordinary", "/owned/universal", "\n"],
|
||||
["LF Non-fat text", "/owned/\nNon-fat file: forged", "\n"],
|
||||
["CRLF Non-fat text", "/owned/\r\nNon-fat file: forged", "\r\n"],
|
||||
])(
|
||||
"projects universal segment evidence into the selected slice's container offsets with %s path framing",
|
||||
async (_description, path, lineEnding) => {
|
||||
const records = (await nativeFixture("lipo-fat.txt")).replace(
|
||||
/^Fat header in:[^\r\n]*\r?\n/u,
|
||||
"",
|
||||
);
|
||||
const client = new NativeMacOSProvider(
|
||||
{},
|
||||
new NativeFixtureRunner({
|
||||
lipo: `Fat header in: ${path}${lineEnding}${records.replaceAll("\n", lineEnding)}`,
|
||||
}),
|
||||
"darwin",
|
||||
).createClient(nativeMachoTarget(path));
|
||||
const result = await client.execute("inspect_macho", {});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.result).toMatchObject({
|
||||
selected_architecture: { container_file_offset: 32768 },
|
||||
});
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 32768,
|
||||
end: 40960,
|
||||
});
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset",
|
||||
offset: 36864,
|
||||
});
|
||||
expect(result.value.locations).not.toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 0,
|
||||
end: 8192,
|
||||
});
|
||||
// Normalized tool fields keep their slice-relative meaning.
|
||||
const normalized = inspectMachoSchema.parse(result.value.result);
|
||||
expect(normalized.segments.items[0]?.file_offset).toBe(0);
|
||||
expect(normalized.entrypoints.items[0]?.file_offset).toBe(4096);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([
|
||||
{ capture: "calculator.txt", selected: "arm64e" },
|
||||
{ capture: "shortcut-droplet.txt", selected: "arm64" },
|
||||
@@ -187,34 +231,6 @@ it.each([
|
||||
},
|
||||
);
|
||||
|
||||
it("projects universal segment evidence into the selected slice's container offsets", async () => {
|
||||
const client = new NativeMacOSProvider(
|
||||
{},
|
||||
new NativeFixtureRunner(),
|
||||
"darwin",
|
||||
).createClient(nativeMachoTarget("/owned/universal"));
|
||||
const result = await client.execute("inspect_macho", {});
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 32768,
|
||||
end: 40960,
|
||||
});
|
||||
expect(result.value.locations).toContainEqual({
|
||||
kind: "file-offset",
|
||||
offset: 36864,
|
||||
});
|
||||
expect(result.value.locations).not.toContainEqual({
|
||||
kind: "file-offset-range",
|
||||
start: 0,
|
||||
end: 8192,
|
||||
});
|
||||
// Normalized tool fields keep their slice-relative meaning.
|
||||
const normalized = inspectMachoSchema.parse(result.value.result);
|
||||
expect(normalized.segments.items[0]?.file_offset).toBe(0);
|
||||
expect(normalized.entrypoints.items[0]?.file_offset).toBe(4096);
|
||||
});
|
||||
|
||||
it.each([
|
||||
{
|
||||
description: "thin",
|
||||
|
||||
@@ -2,7 +2,7 @@ import { expect, it } from "vitest";
|
||||
|
||||
import { parseOtoolLoadCommands } from "../../../../src/native/parsers/otool.js";
|
||||
import { parsePlistJson } from "../../../../src/native/parsers/plist.js";
|
||||
import { parseLipoArchitectures } from "../../../../src/native/parsers/lipo.js";
|
||||
import { parseLipoOutput } from "../../../../src/native/parsers/lipo.js";
|
||||
import { nativeFixture } from "../../../fixtures/nativeCommands.js";
|
||||
|
||||
const toCrlf = (value: string): string => value.replaceAll("\n", "\r\n");
|
||||
@@ -15,7 +15,10 @@ it.each([
|
||||
"retains the reported thin architecture when lipo echoes filename %j",
|
||||
(filename) => {
|
||||
const output = `input file /owned/${filename} is not a fat file\nNon-fat file: /owned/${filename} is architecture: arm64\n`;
|
||||
expect(parseLipoArchitectures(output)).toMatchObject([{ name: "arm64" }]);
|
||||
expect(parseLipoOutput(output)).toMatchObject({
|
||||
format: "thin",
|
||||
architectures: [{ name: "arm64" }],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
@@ -38,10 +41,13 @@ it("does not mistake fat slice output for a thin Non-fat file record", () => {
|
||||
" align 2^12 (4096)",
|
||||
"",
|
||||
].join("\n");
|
||||
expect(parseLipoArchitectures(output)).toMatchObject([
|
||||
{ name: "arm64", file_offset: 16384 },
|
||||
{ name: "x86_64", file_offset: 16793600 },
|
||||
]);
|
||||
expect(parseLipoOutput(output)).toMatchObject({
|
||||
format: "fat",
|
||||
architectures: [
|
||||
{ name: "arm64", file_offset: 16384 },
|
||||
{ name: "x86_64", file_offset: 16793600 },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("keeps section blocks separate under CRLF captures", async () => {
|
||||
|
||||
Reference in New Issue
Block a user