mirror of
https://github.com/morluto/rea.git
synced 2026-10-22 13:52:32 -05:00
inspect-macho projected an empty Mach-O segment or section name as the display label "unknown", so an exhaustive segment inventory for an ordinary MH_OBJECT reported a segment literally named "unknown" while the raw LC_SEGMENT_64 field showed "". Object files place every section in one unnamed segment, so the empty name is a source value. Segment and section names are now reported exactly as observed. Fixes #3875 Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
56 lines
1.9 KiB
TypeScript
56 lines
1.9 KiB
TypeScript
import { join } from "node:path";
|
|
import { writeFile } from "node:fs/promises";
|
|
|
|
import { describe, expect } from "vitest";
|
|
import { z } from "zod";
|
|
|
|
import { inspectMachoSchema } from "../../../src/domain/native/nativeInspection.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
|
|
const evidenceSchema = z.object({ normalized_result: inspectMachoSchema });
|
|
|
|
describe.skipIf(process.platform !== "darwin")(
|
|
"native Mach-O CLI object segment",
|
|
() => {
|
|
cliTest(
|
|
"reports an object file's unnamed segment by its observed empty name",
|
|
async ({ cli, processes }) => {
|
|
const directory = await createTestTempDirectory("rea-object-segment-");
|
|
const source = join(directory, "qa.c");
|
|
const object = join(directory, "qa.o");
|
|
await writeFile(source, "int qa(void) { return 7; }\n");
|
|
const compiled = await processes.run(
|
|
"/usr/bin/xcrun",
|
|
["clang", "-c", source, "-o", object],
|
|
{ timeoutMs: 30_000 },
|
|
);
|
|
expect(compiled.exitCode, compiled.stderr).toBe(0);
|
|
const result = await cli.run({
|
|
arguments: ["inspect-macho", object, "--json"],
|
|
environment: { REA_LOG_LEVEL: "silent" },
|
|
});
|
|
expect(result.exitCode).toBe(0);
|
|
const inspected = evidenceSchema.parse(result.json).normalized_result;
|
|
expect(inspected.load_commands.items[0]?.fields.segname).toBe("");
|
|
expect(inspected.segments).toMatchObject({
|
|
items: [
|
|
{
|
|
name: "",
|
|
sections: {
|
|
items: expect.arrayContaining([
|
|
expect.objectContaining({
|
|
segment: "__TEXT",
|
|
name: "__text",
|
|
}),
|
|
]),
|
|
},
|
|
},
|
|
],
|
|
exhaustive: true,
|
|
});
|
|
},
|
|
);
|
|
},
|
|
);
|