mirror of
https://github.com/morluto/rea
synced 2026-10-25 22:08:11 -04:00
d97db6ebaf
TShark resolves selected field aliases before writing packet JSON. Keep the requested selector in Evidence while accepting the canonical field key produced for it. Fixes #6595
26 lines
848 B
TypeScript
26 lines
848 B
TypeScript
import { z } from "zod";
|
|
import { AnalysisOutputError } from "../domain/analysisErrorCore.js";
|
|
import { packetFieldsSchema } from "../domain/captures/packetCapture.js";
|
|
|
|
// _index/_score are TShark export metadata, not captured packet fields.
|
|
const producerSchema = z.array(
|
|
z.object({ _source: z.object({ layers: packetFieldsSchema }) }),
|
|
);
|
|
export const parsePacketOutput = (text: string) => {
|
|
const decoded: unknown = JSON.parse(text);
|
|
const packets = producerSchema
|
|
.parse(decoded)
|
|
.map((packet) => packet._source.layers);
|
|
let previous = 0n;
|
|
for (const packet of packets) {
|
|
const frame = BigInt(packet["frame.number"][0]);
|
|
if (frame <= previous)
|
|
throw new AnalysisOutputError(
|
|
"inspect_packet_capture",
|
|
"TShark returned unordered frames.",
|
|
);
|
|
previous = frame;
|
|
}
|
|
return packets;
|
|
};
|