mirror of
https://github.com/morluto/rea.git
synced 2026-11-16 03:33:25 +00:00
refactor: remove redundant seams and preserve cleanup ownership (#10375)
* refactor: remove redundant seams and preserve cleanup ownership * fix: validate PE resource extents before budget checks
This commit is contained in:
1 parent
4b26f38d6f
commit
cdc4541ef7
369 files changed
+3847
-3662
No files matched your search
@@ -1,3 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { parseAppleIps } from "../../native/apple/AppleIpsParser.js";
|
||||
import { inspectAppleIpsInputSchema } from "../../domain/native/appleIps.js";
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { AppleIpsService } from "./AppleIpsService.js";
|
||||
@@ -10,52 +13,19 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = APPLE_IPS_PROVIDER;
|
||||
const report: AppleIps = {
|
||||
artifact: {
|
||||
path: "/artifacts/report.ips",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 128,
|
||||
const bytes = Buffer.from(
|
||||
'{"bug_type":"309"}\n{"procName":"rea-crash-fixture","threads":[],"usedImages":[]}',
|
||||
);
|
||||
const path = "/artifacts/report.ips";
|
||||
const report = parseAppleIps(
|
||||
bytes,
|
||||
{
|
||||
path,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.length,
|
||||
},
|
||||
metadata: {
|
||||
bug_type: "309",
|
||||
timestamp: null,
|
||||
os_version: null,
|
||||
bundle_id: null,
|
||||
incident_id: null,
|
||||
name: null,
|
||||
build_version: null,
|
||||
platform: null,
|
||||
unlisted_keys: [],
|
||||
},
|
||||
process: {
|
||||
name: "rea-crash-fixture",
|
||||
path: null,
|
||||
pid: null,
|
||||
parent: null,
|
||||
parent_pid: null,
|
||||
cpu_type: null,
|
||||
translated: null,
|
||||
os_version: null,
|
||||
},
|
||||
exception: null,
|
||||
termination: null,
|
||||
faulting_thread: null,
|
||||
threads: [],
|
||||
images: [],
|
||||
classification: { status: "unclassified", matches: [] },
|
||||
coverage: {
|
||||
status: "complete",
|
||||
reason: null,
|
||||
threads: 0,
|
||||
frames: 0,
|
||||
images: 0,
|
||||
registers: 0,
|
||||
type_mismatches: [],
|
||||
},
|
||||
unlisted_body_keys: [],
|
||||
join: null,
|
||||
limitations: ["Opened Mach-O and dSYM UUID joins remain unobserved."],
|
||||
};
|
||||
inspectAppleIpsInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it.each([0, 5])(
|
||||
"rejects an unresolved faulting thread %s without its mismatch",
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
import type { ExecutionOptions } from "../AnalysisProvider.js";
|
||||
import type {
|
||||
ExecutionOptions,
|
||||
ProviderIdentity,
|
||||
} from "../AnalysisProvider.js";
|
||||
import type { AnalysisError } from "../../domain/analysisErrorBase.js";
|
||||
import type {
|
||||
BinaryLayout,
|
||||
InspectBinaryLayoutInput,
|
||||
} from "../../domain/native/binaryLayout.js";
|
||||
import type { Result } from "../../domain/result.js";
|
||||
import type { ProviderIdentity } from "../AnalysisProvider.js";
|
||||
|
||||
/** Replaceable offline binary-layout provider; owns its parser and process protocol. */
|
||||
export interface BinaryLayoutPort {
|
||||
|
||||
@@ -5,10 +5,7 @@ import { expect, it, vi } from "vitest";
|
||||
import { createTestTempDirectory } from "../../../tests/fixtures/temporaryDirectory.js";
|
||||
import { byteEntropySchema } from "../../domain/native/byteEntropy.js";
|
||||
import { projectAnalysisError } from "../../domain/analysisErrorProjection.js";
|
||||
import {
|
||||
ByteEntropyService,
|
||||
MAX_BYTE_ENTROPY_BLOCKS,
|
||||
} from "./ByteEntropyService.js";
|
||||
import { ByteEntropyService } from "./ByteEntropyService.js";
|
||||
|
||||
it("keeps whole-file identity and entropy while selecting unaligned blocks and a partial tail", async () => {
|
||||
const root = await createTestTempDirectory("rea-entropy-");
|
||||
@@ -421,7 +418,7 @@ it("reports a changed artifact when its parent directory moves during streaming"
|
||||
it("refuses a block series above the output-row limit before scanning", async () => {
|
||||
const root = await createTestTempDirectory("rea-entropy-block-limit-");
|
||||
const path = join(root, "bytes");
|
||||
await writeFile(path, Buffer.alloc(MAX_BYTE_ENTROPY_BLOCKS * 256 + 1));
|
||||
await writeFile(path, Buffer.alloc(32_768 * 256 + 1));
|
||||
let reads = 0;
|
||||
const service = new ByteEntropyService({
|
||||
stat,
|
||||
@@ -443,8 +440,8 @@ it("refuses a block series above the output-row limit before scanning", async ()
|
||||
_tag: "AnalysisResourceConstraintError",
|
||||
resource: "capacity",
|
||||
reportedLimits: {
|
||||
max_blocks: MAX_BYTE_ENTROPY_BLOCKS,
|
||||
requested_blocks: MAX_BYTE_ENTROPY_BLOCKS + 1,
|
||||
max_blocks: 32_768,
|
||||
requested_blocks: 32_769,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
|
||||
/** Bound retained result rows before constructing the Evidence representation. */
|
||||
export const MAX_BYTE_ENTROPY_BLOCKS = 32_768;
|
||||
const MAX_BYTE_ENTROPY_BLOCKS = 32_768;
|
||||
|
||||
/** Generated files such as Linux /proc entries report size 0 but still hold bytes. */
|
||||
const ZERO_SIZE_LIMITATION =
|
||||
|
||||
@@ -2,7 +2,10 @@ import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { ElfNotesService } from "./ElfNotesService.js";
|
||||
import { ELF_NOTES_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import type { ElfNotes } from "../../domain/native/elfNotes.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { inspectElfNotesInputSchema } from "../../domain/native/elfNotes.js";
|
||||
import { elfNoteFixture } from "../../native/elf/ElfNotes.fixture.js";
|
||||
import { parseElfNotes } from "../../native/elf/ElfNoteParser.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
@@ -11,22 +14,17 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = ELF_NOTES_PROVIDER;
|
||||
const report: ElfNotes = {
|
||||
artifact: {
|
||||
path: "/artifacts/app",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 512,
|
||||
const path = "/artifacts/app";
|
||||
const bytes = elfNoteFixture({ ownership: "none" });
|
||||
const report = parseElfNotes(
|
||||
bytes,
|
||||
{
|
||||
path,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.length,
|
||||
},
|
||||
format: "elf64",
|
||||
byte_order: "little",
|
||||
machine: 62,
|
||||
type: 3,
|
||||
type_name: "shared",
|
||||
tables: [],
|
||||
entries: [],
|
||||
coverage: { status: "complete", examined_tables: 0, examined_entries: 0 },
|
||||
limitations: ["No PT_NOTE program header or SHT_NOTE section was declared."],
|
||||
};
|
||||
inspectElfNotesInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
|
||||
@@ -27,57 +27,6 @@ const undecodableHeaderPointer = (): Buffer => {
|
||||
bytes[Number(bytes.readBigUInt64LE(64 + 56 + 8)) + 1] = 0x0f;
|
||||
return bytes;
|
||||
};
|
||||
const report: ElfUnwindRanges = {
|
||||
artifact: {
|
||||
path: "/artifacts/app",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 512,
|
||||
},
|
||||
format: "elf64",
|
||||
byte_order: "little",
|
||||
machine: 62,
|
||||
type: 3,
|
||||
type_name: "shared",
|
||||
eh_frame: { status: "absent", source: null, location: null },
|
||||
eh_frame_hdr: {
|
||||
status: "absent",
|
||||
location: null,
|
||||
version: null,
|
||||
eh_frame_pointer_encoding: null,
|
||||
fde_count_encoding: null,
|
||||
table_encoding: null,
|
||||
eh_frame_pointer: null,
|
||||
fde_count: null,
|
||||
table_entries: 0,
|
||||
},
|
||||
debug_frame: { status: "absent", location: null },
|
||||
cies: [],
|
||||
ranges: [],
|
||||
page: {
|
||||
offset: 0,
|
||||
limit: 256,
|
||||
returned: 0,
|
||||
total: 0,
|
||||
next_offset: null,
|
||||
},
|
||||
coverage: {
|
||||
status: "complete",
|
||||
total_ranges: 0,
|
||||
total_cies: 0,
|
||||
ranges_with_symbols: 0,
|
||||
ranges_without_symbols: 0,
|
||||
eh_frame_hdr_agreement: "unavailable",
|
||||
examined_records: 0,
|
||||
},
|
||||
limitations: [
|
||||
"No .eh_frame section or PT_GNU_EH_FRAME segment was declared.",
|
||||
"No .eh_frame_hdr section or PT_GNU_EH_FRAME segment was declared.",
|
||||
"CFA instructions are counted but not evaluated.",
|
||||
".debug_frame is absent; only .eh_frame was examined.",
|
||||
"Symbol names, section names, and augmentation strings are target-derived and untrusted.",
|
||||
],
|
||||
};
|
||||
|
||||
const parsed = (
|
||||
bytes: Buffer,
|
||||
raw: Readonly<Record<string, unknown>> = {},
|
||||
@@ -97,6 +46,8 @@ const parsed = (
|
||||
);
|
||||
};
|
||||
|
||||
const report = parsed(elfUnwindAbsentFixture());
|
||||
|
||||
const accept = async (
|
||||
value: ElfUnwindRanges,
|
||||
raw: Readonly<Record<string, unknown>> = {},
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { inspectPeCertificatesInputSchema } from "../../domain/native/peCertificates.js";
|
||||
import { peCertificateFixture } from "../../native/pe/PeCertificates.fixture.js";
|
||||
import {
|
||||
peCertificateFixture,
|
||||
peWithoutCertificateTableFixture,
|
||||
} from "../../native/pe/PeCertificates.fixture.js";
|
||||
import { parsePeCertificates } from "../../native/pe/PeCertificateParser.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { PeCertificatesService } from "./PeCertificatesService.js";
|
||||
@@ -15,19 +18,17 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = PE_CERTIFICATES_PROVIDER;
|
||||
const report: PeCertificates = {
|
||||
artifact: {
|
||||
path: "/artifacts/app.exe",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 512,
|
||||
const path = "/artifacts/app.exe";
|
||||
const bytes = peWithoutCertificateTableFixture();
|
||||
const report = parsePeCertificates(
|
||||
bytes,
|
||||
{
|
||||
path,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.length,
|
||||
},
|
||||
format: "pe32",
|
||||
machine: 0x14c,
|
||||
table: null,
|
||||
entries: [],
|
||||
coverage: { status: "complete", examined_entries: 0, certificates: 0 },
|
||||
limitations: ["IMAGE_DIRECTORY_ENTRY_SECURITY is absent."],
|
||||
};
|
||||
inspectPeCertificatesInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { peWithoutImportTableFixture } from "../../../tests/fixtures/binaryDiagnostics/peImports.js";
|
||||
import { parsePeImports } from "../../native/pe/PeImportParser.js";
|
||||
import {
|
||||
inspectPeImportsInputSchema,
|
||||
peImportsSchema,
|
||||
type PeImports,
|
||||
} from "../../domain/native/peImports.js";
|
||||
import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { PeImportsService } from "./PeImportsService.js";
|
||||
import { PE_IMPORTS_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import type { PeImports } from "../../domain/native/peImports.js";
|
||||
import { peImportsSchema } from "../../domain/native/peImports.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
@@ -12,35 +18,17 @@ import {
|
||||
} from "../../domain/analysisErrorCore.js";
|
||||
|
||||
const identity = PE_IMPORTS_PROVIDER;
|
||||
const report: PeImports = {
|
||||
artifact: {
|
||||
path: "/artifacts/app.exe",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 512,
|
||||
const path = "/artifacts/app.exe";
|
||||
const bytes = peWithoutImportTableFixture();
|
||||
const report = await parsePeImports(
|
||||
bytes,
|
||||
{
|
||||
path,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.length,
|
||||
},
|
||||
format: "pe32-plus",
|
||||
machine: 0x8664,
|
||||
bits: 64,
|
||||
architecture: "amd64",
|
||||
import_directory: null,
|
||||
delay_import_directory: null,
|
||||
imports: [],
|
||||
delay_imports: [],
|
||||
imphash: {
|
||||
algorithm: "pefile",
|
||||
md5: null,
|
||||
reason: "IMAGE_DIRECTORY_ENTRY_IMPORT is absent.",
|
||||
},
|
||||
coverage: {
|
||||
status: "complete",
|
||||
reason: null,
|
||||
examined_dlls: 0,
|
||||
imports: 0,
|
||||
delay_imports: 0,
|
||||
},
|
||||
issues: [],
|
||||
limitations: ["IMAGE_DIRECTORY_ENTRY_IMPORT is absent."],
|
||||
};
|
||||
inspectPeImportsInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
@@ -189,7 +177,7 @@ it("publishes every consumed directory span as its own Evidence location", async
|
||||
size: 40,
|
||||
locations: [
|
||||
{ offset: 0x100, bytes: 20 },
|
||||
{ offset: 0x1f8, bytes: 20 },
|
||||
{ offset: report.artifact.bytes - 8, bytes: 20 },
|
||||
],
|
||||
},
|
||||
}),
|
||||
|
||||
@@ -11,7 +11,7 @@ import {
|
||||
type PeResourceIdentity,
|
||||
} from "../../domain/native/peResources.js";
|
||||
import { peSubjectArchitecture } from "../../domain/peMachine.js";
|
||||
import { err, ok, type Result } from "../../domain/result.js";
|
||||
import { err, type Result } from "../../domain/result.js";
|
||||
import { completeProviderEvidence } from "../ProviderOperationExecution.js";
|
||||
import { parseAnalysisInput } from "../AnalysisInput.js";
|
||||
|
||||
|
||||
@@ -2,7 +2,9 @@ import { parseEvidence } from "../../domain/evidence.js";
|
||||
import { expect, it } from "vitest";
|
||||
import { WindowsShortcutService } from "./WindowsShortcutService.js";
|
||||
import { WINDOWS_SHORTCUT_PROVIDER } from "../../domain/investigationProviders.js";
|
||||
import type { WindowsShortcut } from "../../domain/native/windowsShortcut.js";
|
||||
import { createHash } from "node:crypto";
|
||||
import { inspectWindowsShortcutInputSchema } from "../../domain/native/windowsShortcut.js";
|
||||
import { parseWindowsShortcut } from "../../native/windows/WindowsShortcutParser.js";
|
||||
import { ok } from "../../domain/result.js";
|
||||
import {
|
||||
AnalysisCancelledError,
|
||||
@@ -12,64 +14,20 @@ import {
|
||||
|
||||
const identity = WINDOWS_SHORTCUT_PROVIDER;
|
||||
|
||||
const report: WindowsShortcut = {
|
||||
artifact: {
|
||||
path: "/artifacts/shortcut.lnk",
|
||||
sha256: "a".repeat(64),
|
||||
bytes: 128,
|
||||
const path = "/artifacts/shortcut.lnk";
|
||||
const bytes = Buffer.alloc(80);
|
||||
bytes.writeUInt32LE(76, 0);
|
||||
Buffer.from("0114020000000000c000000000000046", "hex").copy(bytes, 4);
|
||||
bytes.writeUInt32LE(1, 60);
|
||||
const report = await parseWindowsShortcut(
|
||||
bytes,
|
||||
{
|
||||
path,
|
||||
sha256: createHash("sha256").update(bytes).digest("hex"),
|
||||
bytes: bytes.length,
|
||||
},
|
||||
header: {
|
||||
location: { offset: 0, bytes: 76 },
|
||||
header_size: 76,
|
||||
clsid: "00021401-0000-0000-C000-000000000046",
|
||||
link_flags: { raw: 0, decoded: [] },
|
||||
file_attributes: { raw: 0, decoded: [] },
|
||||
creation_time: { raw: "0", iso8601: null },
|
||||
access_time: { raw: "0", iso8601: null },
|
||||
write_time: { raw: "0", iso8601: null },
|
||||
file_size: 0,
|
||||
icon_index: 0,
|
||||
show_command: { raw: 1, decoded: "normal" },
|
||||
hotkey: {
|
||||
raw: 0,
|
||||
modifiers: [],
|
||||
virtual_key: null,
|
||||
virtual_key_name: null,
|
||||
},
|
||||
},
|
||||
id_list: null,
|
||||
link_info: null,
|
||||
string_data: {
|
||||
name: null,
|
||||
relative_path: null,
|
||||
working_dir: null,
|
||||
arguments: null,
|
||||
icon_location: null,
|
||||
},
|
||||
extra_data: { blocks: [], terminal_offset: null },
|
||||
observations: [
|
||||
{ kind: "arguments_present", evidence_kind: "derived", value: false },
|
||||
{ kind: "argument_length", evidence_kind: "derived", characters: 0 },
|
||||
{ kind: "target_extension", evidence_kind: "derived", extension: null },
|
||||
{ kind: "show_command_minimized", evidence_kind: "derived", value: false },
|
||||
{
|
||||
kind: "icon_location_differs_from_target",
|
||||
evidence_kind: "derived",
|
||||
value: null,
|
||||
},
|
||||
],
|
||||
coverage: {
|
||||
status: "complete",
|
||||
reason: null,
|
||||
examined_id_list_items: 0,
|
||||
examined_extra_data_blocks: 0,
|
||||
failing_offset: null,
|
||||
},
|
||||
issues: [],
|
||||
limitations: [
|
||||
"Rows reproduce the selected Shell Link bytes; they do not resolve, open, or execute the link target.",
|
||||
],
|
||||
};
|
||||
inspectWindowsShortcutInputSchema.parse({ path }),
|
||||
);
|
||||
|
||||
it("rejects a relative path and extra arguments before reading", async () => {
|
||||
let calls = 0;
|
||||
|
||||
Reference in new issue
Block a user