mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 11:33:10 +00:00
86 lines
3.5 KiB
TypeScript
86 lines
3.5 KiB
TypeScript
import { symlink, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { createPeLoadConfigService } from "../../../src/composition/binaryDiagnostics/peLoadConfig.js";
|
|
import { peLoadConfigSchema } from "../../../src/domain/native/peLoadConfig.js";
|
|
import { peLoadConfigImage } from "../../../src/native/pe/PeLoadConfig.fixture.js";
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import {
|
|
expectFileSnapshotFinalization,
|
|
fileSnapshotFinalizationModes,
|
|
} from "../../support/expectFileSnapshotFinalization.js";
|
|
import { expectFileSelectionErrors } from "../../support/expectFileSelectionErrors.js";
|
|
|
|
describe("PE load-config stable filesystem boundary", () => {
|
|
it("reports non-file and missing selections as caller input errors", async () => {
|
|
const root = await createTestTempDirectory("rea-pe-load-config-files-");
|
|
const path = join(root, "app.exe");
|
|
const alias = join(root, "alias.exe");
|
|
await writeFile(path, peLoadConfigImage());
|
|
await symlink(path, alias);
|
|
const service = createPeLoadConfigService();
|
|
await expectFileSelectionErrors(
|
|
service,
|
|
"inspect_pe_load_config",
|
|
{ root, alias, path },
|
|
".exe",
|
|
);
|
|
});
|
|
|
|
it("cites the TLS structure it read past a short directory Size", async () => {
|
|
// corkami tls.exe declares TLS Size 0; the loader reads the structure.
|
|
const root = await createTestTempDirectory("rea-pe-load-config-tls-");
|
|
const path = join(root, "app.exe");
|
|
await writeFile(path, peLoadConfigImage({ malformed: "tls-truncated" }));
|
|
const result = await createPeLoadConfigService().inspect({ path });
|
|
if (!result.ok) throw result.error;
|
|
const { tls } = peLoadConfigSchema.parse(result.value.normalized_result);
|
|
if (tls === null || tls.structure_location === undefined)
|
|
throw new Error("Expected a TLS structure location");
|
|
expect(tls.directory.size).toBe(8);
|
|
expect(tls.structure_location).toEqual({
|
|
offset: tls.directory.file_offset,
|
|
bytes: 40,
|
|
});
|
|
expect(result.value.locations).toContainEqual({
|
|
kind: "file-offset-range",
|
|
start: tls.directory.file_offset,
|
|
end: tls.directory.file_offset + 40,
|
|
});
|
|
});
|
|
|
|
it("returns typed resource and cancellation failures", async () => {
|
|
const root = await createTestTempDirectory("rea-pe-load-config-budget-");
|
|
const path = join(root, "app.exe");
|
|
await writeFile(path, peLoadConfigImage());
|
|
const service = createPeLoadConfigService();
|
|
const tooSmall = await service.inspect({ path, max_file_bytes: 64 });
|
|
if (tooSmall.ok) throw new Error("Expected resource budget failure");
|
|
expect(tooSmall.error._tag).toBe("AnalysisResourceConstraintError");
|
|
const cancelled = await service.inspect(
|
|
{ path },
|
|
{ signal: AbortSignal.abort() },
|
|
);
|
|
if (cancelled.ok) throw new Error("Expected cancellation");
|
|
expect(cancelled.error._tag).toBe("AnalysisCancelledError");
|
|
});
|
|
|
|
it.each(fileSnapshotFinalizationModes)(
|
|
"retains completed PE acquisition through %s",
|
|
async (mode) => {
|
|
const root = await createTestTempDirectory("rea-pe-config-finalize-");
|
|
const path = join(root, "app.exe");
|
|
const bytes = peLoadConfigImage();
|
|
await writeFile(path, bytes);
|
|
await expectFileSnapshotFinalization(
|
|
mode,
|
|
createPeLoadConfigService,
|
|
{ path, bytes },
|
|
{
|
|
load_config: { guard_flags: { raw: 0x500 } },
|
|
},
|
|
);
|
|
},
|
|
);
|
|
});
|