fix(apple): preserve modern cache subtype metadata
This commit is contained in:
@@ -174,6 +174,40 @@ const IMAGES = [
|
||||
},
|
||||
];
|
||||
|
||||
it.each([
|
||||
{ type: 2, subtype: 0, expected: { id: 0, name: "development" } },
|
||||
{ type: 2, subtype: 1, expected: { id: 1, name: "production" } },
|
||||
{ type: 2, subtype: 9, expected: { id: 9, name: null } },
|
||||
{ type: 0, subtype: 1, expected: null },
|
||||
{ type: 1, subtype: 0, expected: null },
|
||||
])(
|
||||
"preserves applicable multi-cache subtype $subtype for type $type",
|
||||
async ({ type, subtype, expected }) => {
|
||||
const fixture = dyldCacheFixture(IMAGES);
|
||||
const main = Buffer.from(fixture.main);
|
||||
main.writeBigUInt64LE(BigInt(type), 0x68);
|
||||
main.writeUInt32LE(subtype, 0x1c8);
|
||||
const path = await writeCache({ ...fixture, main });
|
||||
const result = await inspectDyldSharedCache({ cache_path: path });
|
||||
if (!result.ok) throw result.error;
|
||||
const cache = dyldSharedCacheResultSchema.parse(result.value);
|
||||
expect(cache.cache_type).toBe(
|
||||
type === 2 ? "multi-cache" : type === 0 ? "development" : "production",
|
||||
);
|
||||
expect(cache.cache_subtype).toEqual(expected);
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps a legacy multi-cache subtype unknown when its header lacks the field", async () => {
|
||||
const fixture = dyldCacheFixture([], { legacy: true });
|
||||
const main = Buffer.from(fixture.main);
|
||||
main.writeBigUInt64LE(2n, 0x68);
|
||||
const path = await writeCache({ ...fixture, main });
|
||||
const result = await inspectDyldSharedCache({ cache_path: path });
|
||||
if (!result.ok) throw result.error;
|
||||
expect(result.value.cache_subtype).toBeNull();
|
||||
});
|
||||
|
||||
describe("dyld shared cache inspection", () => {
|
||||
it("reads the header, subcaches, image list and cached load commands", async () => {
|
||||
const path = await writeCache(dyldCacheFixture(IMAGES));
|
||||
|
||||
@@ -44,7 +44,10 @@ it("inspects a dyld shared cache through MCP without a target", async () => {
|
||||
}),
|
||||
},
|
||||
]);
|
||||
await writeFile(path, fixture.main);
|
||||
const main = Buffer.from(fixture.main);
|
||||
main.writeBigUInt64LE(2n, 0x68);
|
||||
main.writeUInt32LE(1, 0x1c8);
|
||||
await writeFile(path, main);
|
||||
|
||||
const tools = await client.listTools();
|
||||
expect(tools.tools.map(({ name }) => name)).toContain(
|
||||
@@ -62,6 +65,8 @@ it("inspects a dyld shared cache through MCP without a target", async () => {
|
||||
);
|
||||
expect(result).toMatchObject({
|
||||
architecture: "arm64e",
|
||||
cache_type: "multi-cache",
|
||||
cache_subtype: { id: 1, name: "production" },
|
||||
images_total: 1,
|
||||
inspected_images: [
|
||||
{ path: "/usr/lib/libSystem.B.dylib", status: "parsed" },
|
||||
|
||||
Reference in New Issue
Block a user