fix(native): capture Mach-O header metadata alongside load commands (#525)
* fix(native): capture Mach-O header metadata alongside load commands Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> * style(test): format native Mach-O header regression Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> * fix(native): drop dead bare otool override in header test --------- Signed-off-by: Rudy Celekli <47457359+rudycelekli@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
morluto
parent
31ed005183
commit
a8195ba2cc
@@ -0,0 +1,44 @@
|
||||
import { expect, it } from "vitest";
|
||||
|
||||
import { NativeMacOSProvider } from "../../../../src/native/NativeMacOSProvider.js";
|
||||
import { parseOtoolLoadCommands } from "../../../../src/native/parsers/otool.js";
|
||||
import {
|
||||
NativeFixtureRunner,
|
||||
nativeFixture,
|
||||
nativeMachoTarget,
|
||||
} from "../../../fixtures/nativeCommands.js";
|
||||
|
||||
it("collects the actual Mach header alongside the native load commands", async () => {
|
||||
// The provider always invokes `otool -h -l`, which the runner resolves
|
||||
// via the "otool:-h" key; no bare `otool` override is needed.
|
||||
const runner = new NativeFixtureRunner({
|
||||
"otool:-h": await nativeFixture(
|
||||
"native-macho-header/otool-header-load.txt",
|
||||
),
|
||||
});
|
||||
const client = new NativeMacOSProvider(runner, "darwin").createClient(
|
||||
nativeMachoTarget("/owned/fixture"),
|
||||
);
|
||||
const result = await client.execute("inspect_macho", {});
|
||||
expect(result.ok).toBe(true);
|
||||
if (!result.ok) return;
|
||||
expect(result.value.result).toMatchObject({
|
||||
file_type: "2",
|
||||
flags: ["0x00200085"],
|
||||
segments: {
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({ name: "__TEXT" }),
|
||||
]),
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("does not reinterpret segment and section flags as Mach header flags", async () => {
|
||||
const load = parseOtoolLoadCommands(
|
||||
await nativeFixture("native-macho-header/otool-header-load.txt"),
|
||||
);
|
||||
expect(load.flags).toEqual(["0x00200085"]);
|
||||
expect(load.commands.some((command) => command.fields.flags === 0)).toBe(
|
||||
true,
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user