mirror of
https://github.com/morluto/rea.git
synced 2026-12-02 13:11:18 -05:00
44fbcfc787
* feat(evtx): page event records with offset and report page facts
inspect_evtx_archive stopped walking at max_records, so records past the first 20,000 (the newest events of a default-size Application log) could not be listed. The walk now covers every record. max_records stays a 20,000-record page bound, which limits retained Evidence. A new zero-based offset selects the first record listed. The result reports page { offset, limit, returned, total, next_offset }, and the record-limit-reached diagnostic names offset=next_offset. Coverage now describes parse loss only, so a page that leaves records out by selection is no longer partial, and chunk ending facts and endpoint checks cover records past the page.
Fixes #15612
* feat(evtx)!: qualify the file-tail offset for small and wrapped logs
The suggested tail offset is now the larger of 0 and page.total minus max_records, so a log smaller than one page gets a valid offset. File order is oldest first only in a log that has not wrapped; the guide and descriptions now say how chunks[] locates the newest records in a wrapped log.
BREAKING CHANGE: inspect_evtx_archive results now require page. Evidence saved before this change has no page, and inspect_analysis_view refuses to summarise it. Re-run inspect_evtx_archive on the log to produce current Evidence.
57 lines
1.9 KiB
TypeScript
57 lines
1.9 KiB
TypeScript
import { crc32 } from "node:zlib";
|
|
|
|
const CHUNK_BYTES = 65_536;
|
|
const CHUNK_HEADER_BYTES = 512;
|
|
const HEADER_BLOCK_BYTES = 4096;
|
|
/** Smallest record envelope: 24-byte header, no XML, 4-byte size trailer. */
|
|
const RECORD_BYTES = 28;
|
|
const RECORDS_PER_CHUNK = Math.floor(
|
|
(CHUNK_BYTES - CHUNK_HEADER_BYTES) / RECORD_BYTES,
|
|
);
|
|
|
|
/**
|
|
* An EVTX 3.2 file shaped like a `wevtutil epl` export: a 4 KiB header block,
|
|
* signed chunks holding records 1..`records` in file order, then any spare
|
|
* slots the caller appends after the declared chunks.
|
|
*/
|
|
export const evtxLog = (
|
|
records: number,
|
|
spareSlots: readonly Buffer[] = [],
|
|
): Buffer => {
|
|
const chunks: Buffer[] = [];
|
|
for (let first = 1; first <= records; first += RECORDS_PER_CHUNK) {
|
|
const last = Math.min(records, first + RECORDS_PER_CHUNK - 1);
|
|
const chunk = Buffer.alloc(CHUNK_BYTES);
|
|
chunk.write("ElfChnk\0", 0, "latin1");
|
|
chunk.writeBigUInt64LE(BigInt(first), 0x18);
|
|
chunk.writeBigUInt64LE(BigInt(last), 0x20);
|
|
let cursor = CHUNK_HEADER_BYTES;
|
|
for (let id = first; id <= last; id += 1) {
|
|
chunk.writeUInt32LE(0x2a2a, cursor);
|
|
chunk.writeUInt32LE(RECORD_BYTES, cursor + 4);
|
|
chunk.writeBigUInt64LE(BigInt(id), cursor + 8);
|
|
chunk.writeUInt32LE(RECORD_BYTES, cursor + RECORD_BYTES - 4);
|
|
chunk.writeUInt32LE(cursor, 0x2c);
|
|
cursor += RECORD_BYTES;
|
|
}
|
|
chunk.writeUInt32LE(cursor, 0x30);
|
|
chunk.writeUInt32LE(
|
|
crc32(
|
|
Buffer.concat([
|
|
chunk.subarray(0, 0x78),
|
|
chunk.subarray(0x80, CHUNK_HEADER_BYTES),
|
|
]),
|
|
),
|
|
0x7c,
|
|
);
|
|
chunks.push(chunk);
|
|
}
|
|
const header = Buffer.alloc(HEADER_BLOCK_BYTES);
|
|
header.write("ElfFile\0", 0, "latin1");
|
|
header.writeUInt16LE(2, 0x24);
|
|
header.writeUInt16LE(3, 0x26);
|
|
header.writeUInt16LE(HEADER_BLOCK_BYTES, 0x28);
|
|
header.writeUInt16LE(chunks.length, 0x2a);
|
|
return Buffer.concat([header, ...chunks, ...spareSlots]);
|
|
};
|