fix(browser): preserve unknown storage inventory and fingerprint coverage (#2491)
* fix(browser): preserve unknown storage inventory and fingerprint coverage * fix(browser): compare known storage edits with incomplete inventories * test(browser): consolidate storage completeness regression workflows * test(ida): admit aligned FAT thinning fixtures on every platform --------- Co-authored-by: chAngE <172472630+chAng-L19@users.noreply.github.com> Co-authored-by: morluto <morluto@users.noreply.github.com> Co-authored-by: morluto <76467478+morluto@users.noreply.github.com>
This commit is contained in:
co-authored by
chAngE
morluto
morluto
parent
090b454350
commit
c7ceaadb70
@@ -21,12 +21,13 @@ afterEach(async () => {
|
||||
}
|
||||
});
|
||||
|
||||
/** Write a two-slice universal fixture and resolve it for the given host. */
|
||||
const universalTarget = async (hostArchitecture: "arm64" | "x64") => {
|
||||
const resolveUniversalTarget = async (
|
||||
bytes: Buffer,
|
||||
hostArchitecture: "arm64" | "x64",
|
||||
) => {
|
||||
const directory = await createTestTempDirectory("rea-ida-thin-");
|
||||
roots.push(directory);
|
||||
const path = join(directory, "universal");
|
||||
const bytes = fat([0x01000007, 0x0100000c]);
|
||||
await writeFile(path, bytes);
|
||||
const resolved = await parseBinaryTarget(path, { hostArchitecture });
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
@@ -35,6 +36,27 @@ const universalTarget = async (hostArchitecture: "arm64" | "x64") => {
|
||||
return { bytes, target: resolved.value };
|
||||
};
|
||||
|
||||
/** Write a two-slice universal fixture and resolve it for the given host. */
|
||||
const universalTarget = (hostArchitecture: "arm64" | "x64") =>
|
||||
resolveUniversalTarget(fat([0x01000007, 0x0100000c]), hostArchitecture);
|
||||
|
||||
const copySelectedSlice = async ({
|
||||
bytes,
|
||||
target,
|
||||
}: Awaited<ReturnType<typeof universalTarget>>) => {
|
||||
const workspace = await IdaWorkspace.allocate(target);
|
||||
roots.push(workspace.directory);
|
||||
await workspace.copyInput();
|
||||
const input = await readFile(workspace.inputPath);
|
||||
const { offset, size } = target.universalSlice;
|
||||
expect(input.length, "no byte after the slice is copied").toBe(size);
|
||||
expect(input.equals(bytes.subarray(offset, offset + size))).toBe(true);
|
||||
expect(workspace.inputSha256).toBe(
|
||||
createHash("sha256").update(input).digest("hex"),
|
||||
);
|
||||
return { workspace, input };
|
||||
};
|
||||
|
||||
/** One slice of a synthetic universal file: CPU type, offset and size. */
|
||||
interface Layout {
|
||||
readonly cpu: number;
|
||||
@@ -43,6 +65,12 @@ interface Layout {
|
||||
readonly alignmentExponent?: number;
|
||||
}
|
||||
|
||||
const multiSliceLayout: readonly Layout[] = [
|
||||
{ cpu: 0x01000007, offset: 4096, size: 8480, alignmentExponent: 12 },
|
||||
{ cpu: 0x0100000c, offset: 16384, size: 33464 },
|
||||
{ cpu: 0x00000007, offset: 65536, size: 33464 },
|
||||
];
|
||||
|
||||
/**
|
||||
* Write a universal file whose slices span more than one 64 KiB read, each
|
||||
* filled with its own byte so bytes outside the selected slice are visible.
|
||||
@@ -51,9 +79,6 @@ const largeUniversalTarget = async (
|
||||
layout: readonly Layout[],
|
||||
hostArchitecture: "arm64" | "x64",
|
||||
) => {
|
||||
const directory = await createTestTempDirectory("rea-ida-thin-large-");
|
||||
roots.push(directory);
|
||||
const path = join(directory, "universal");
|
||||
const total = Math.max(...layout.map(({ offset, size }) => offset + size));
|
||||
const bytes = Buffer.alloc(total);
|
||||
bytes.writeUInt32BE(0xcafebabe, 0);
|
||||
@@ -67,37 +92,27 @@ const largeUniversalTarget = async (
|
||||
bytes.fill(0x11 * (index + 1), offset, offset + size);
|
||||
thinMach(0xfeedfacf, cpu).copy(bytes, offset);
|
||||
});
|
||||
await writeFile(path, bytes);
|
||||
const resolved = await parseBinaryTarget(path, { hostArchitecture });
|
||||
if (!resolved.ok) throw resolved.error;
|
||||
if (resolved.value.format !== "mach-o-universal")
|
||||
throw new Error("the universal fixture did not resolve as a FAT container");
|
||||
return { bytes, target: resolved.value };
|
||||
return await resolveUniversalTarget(bytes, hostArchitecture);
|
||||
};
|
||||
|
||||
describe("IDA workspace input thinning", () => {
|
||||
it("admits the multi-read FAT fixture on every host platform", async () => {
|
||||
const { target } = await largeUniversalTarget(multiSliceLayout, "arm64");
|
||||
expect(target.universalSlice).toMatchObject({ offset: 16384, size: 33464 });
|
||||
});
|
||||
|
||||
it.skipIf(process.platform === "win32")(
|
||||
"thins the selected arm64 slice into the private headless input",
|
||||
async () => {
|
||||
const { bytes, target } = await universalTarget("arm64");
|
||||
const workspace = await IdaWorkspace.allocate(target);
|
||||
roots.push(workspace.directory);
|
||||
await workspace.copyInput();
|
||||
|
||||
const input = await readFile(workspace.inputPath);
|
||||
const { offset, size } = target.universalSlice;
|
||||
expect(offset).toBeGreaterThan(0);
|
||||
expect(input.equals(bytes.subarray(offset, offset + size))).toBe(true);
|
||||
expect(input.length).toBe(size);
|
||||
const { workspace, input } = await copySelectedSlice({ bytes, target });
|
||||
expect(target.universalSlice.offset).toBeGreaterThan(0);
|
||||
expect(input.readUInt32BE(0)).toBe(0xfeedfacf);
|
||||
expect(input.readUInt32BE(4)).toBe(0x0100000c);
|
||||
expect(parseExecutableHeader(input, "arm64")).toMatchObject({
|
||||
ok: true,
|
||||
value: { format: "mach-o", architecture: "arm64" },
|
||||
});
|
||||
expect(createHash("sha256").update(input).digest("hex")).toBe(
|
||||
workspace.inputSha256,
|
||||
);
|
||||
await workspace.remove();
|
||||
},
|
||||
);
|
||||
@@ -106,13 +121,7 @@ describe("IDA workspace input thinning", () => {
|
||||
"thins the x86_64 slice when the host is intel",
|
||||
async () => {
|
||||
const { bytes, target } = await universalTarget("x64");
|
||||
const workspace = await IdaWorkspace.allocate(target);
|
||||
roots.push(workspace.directory);
|
||||
await workspace.copyInput();
|
||||
|
||||
const input = await readFile(workspace.inputPath);
|
||||
const { offset, size } = target.universalSlice;
|
||||
expect(input.equals(bytes.subarray(offset, offset + size))).toBe(true);
|
||||
const { workspace, input } = await copySelectedSlice({ bytes, target });
|
||||
expect(input.readUInt32BE(4)).toBe(0x01000007);
|
||||
await workspace.remove();
|
||||
},
|
||||
@@ -122,31 +131,12 @@ describe("IDA workspace input thinning", () => {
|
||||
"copies exactly the selected slice when later slices follow it across read boundaries",
|
||||
async () => {
|
||||
const { bytes, target } = await largeUniversalTarget(
|
||||
[
|
||||
{
|
||||
cpu: 0x01000007,
|
||||
offset: 4096,
|
||||
size: 8480,
|
||||
alignmentExponent: 12,
|
||||
},
|
||||
{ cpu: 0x0100000c, offset: 16384, size: 33464 },
|
||||
{ cpu: 0x00000007, offset: 65536, size: 33464 },
|
||||
],
|
||||
multiSliceLayout,
|
||||
"arm64",
|
||||
);
|
||||
const workspace = await IdaWorkspace.allocate(target);
|
||||
roots.push(workspace.directory);
|
||||
await workspace.copyInput();
|
||||
|
||||
const input = await readFile(workspace.inputPath);
|
||||
const { offset, size } = target.universalSlice;
|
||||
expect(size, "the arm64 slice is selected").toBe(33464);
|
||||
expect(input.length, "no byte after the slice is copied").toBe(size);
|
||||
expect(input.equals(bytes.subarray(offset, offset + size))).toBe(true);
|
||||
expect(workspace.inputSha256).toBe(
|
||||
createHash("sha256")
|
||||
.update(bytes.subarray(offset, offset + size))
|
||||
.digest("hex"),
|
||||
const { workspace } = await copySelectedSlice({ bytes, target });
|
||||
expect(target.universalSlice.size, "the arm64 slice is selected").toBe(
|
||||
33464,
|
||||
);
|
||||
await workspace.remove();
|
||||
},
|
||||
@@ -162,15 +152,10 @@ describe("IDA workspace input thinning", () => {
|
||||
],
|
||||
"x64",
|
||||
);
|
||||
const workspace = await IdaWorkspace.allocate(target);
|
||||
roots.push(workspace.directory);
|
||||
await workspace.copyInput();
|
||||
|
||||
const input = await readFile(workspace.inputPath);
|
||||
const { offset, size } = target.universalSlice;
|
||||
expect(size, "the x86_64 slice is selected").toBe(37456);
|
||||
expect(input.length, "no byte after the slice is copied").toBe(size);
|
||||
expect(input.equals(bytes.subarray(offset, offset + size))).toBe(true);
|
||||
const { workspace } = await copySelectedSlice({ bytes, target });
|
||||
expect(target.universalSlice.size, "the x86_64 slice is selected").toBe(
|
||||
37456,
|
||||
);
|
||||
await workspace.remove();
|
||||
},
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user