Files
reverse-engineering-anything/src/domain/analysisSettings.ts
T
morluto c06a0b9ee8 feat(pcap): read tshark JSON packets through one envelope owner with an adjustable expansion bound (#10788)
* refactor(pcap): read tshark JSON packets through one envelope owner

PcapOutput and the packet-capture reader each decoded tshark -T json and checked the packet envelope. The capture reader let SyntaxError escape and accepted any shape until its field schema ran. src/pcap/TsharkJsonPackets.ts now owns the envelope (malformed JSON, the packet array, each packet's _source.layers) as typed failures, and the pcap byte and expansion budget. Both consumers map those failures to their existing error kinds. An architecture guard keeps _source.layers reads in the owner.

* fix(captures): keep producer output on a refused packet reply

parsePacketOutput threw AnalysisOutputError itself, so the provider's failure mapping returned it without the captured stdout and stderr, both for envelope refusals and for unordered or out-of-limit frames. It now returns a Result with the reason and cause, and the provider builds the AnalysisOutputError with capturedOutput.

* feat(captures): bound packet-capture JSON expansion by an adjustable setting

The capture path parsed TShark's selected-field JSON without the expansion
estimate the pcap reader charges. It now reads through readTsharkJsonPackets
under capture.packet_json_expansion_bytes (REA_CAPTURE_PACKET_JSON_EXPANSION_BYTES).
The estimate charges at most 130 bytes per code unit and the output is one
Node string, so no admissible output reaches 69,793,215,440 bytes; the default
and maximum are 128 GiB, so the budget refuses only when lowered. A refusal is
an adjustable_budget resource constraint naming the setting and keeps the
producer output; a malformed launch seed is refused before the capture is read.
2026-11-15 16:17:24 +08:00

85 lines
3.7 KiB
TypeScript

/** Runtime policy overrides, separate from target state and launch environment. */
export interface AnalysisSettingValues {
readonly "asar.max_header_bytes": number;
readonly "asar.max_listing_bytes": number;
readonly "ghidra.value_flow_max_operations": number;
readonly "ghidra.value_flow_max_inputs_per_operation": number;
readonly "ghidra.value_flow_max_edges": number;
readonly "ghidra.startup_timeout_ms": number;
readonly "hopper.startup_timeout_ms": number;
readonly "ghidra.decompile_timeout_seconds": number | null;
readonly "ghidra.decompile_max_payload_mib": number | null;
readonly "jadx.operation_timeout_ms": number;
readonly "regex.matching_deadline_ms": number;
readonly "regex.worker_heap_request_mib": number;
readonly "capture.decoder_old_generation_mib": number;
readonly "capture.packet_json_expansion_bytes": number;
readonly "javascript.analysis_timeout_ms": number;
readonly "javascript.max_heap_mb": number;
readonly "wasm.command_timeout_ms": number;
readonly "native.matching_representation_bytes": number;
readonly "bridge.max_request_bytes": number;
readonly "debugger.command_deadline_ms": number;
readonly "debugger.max_command_output_bytes": number;
readonly "hopper.caller_scan_budget_ms": number;
readonly "jeb.mcp_timeout_ms": number;
readonly "kuna.project_timeout_ms": number;
readonly "kuna.function_timeout_ms": number;
readonly "pwntools.max_input_bytes": number;
readonly "windows.change_time_drift_ms": number;
readonly "windows.change_time_settle_poll_ms": number;
readonly "windows.change_time_settle_max_polls": number;
}
export type AnalysisSettingId = keyof AnalysisSettingValues;
export interface AnalysisSettingsSnapshot {
readonly revision: number;
readonly overrides: Readonly<Partial<AnalysisSettingValues>>;
}
/** Injected by the runtime owner; reads the accepted operation's immutable snapshot. */
export type AnalysisSettingsReader = () => AnalysisSettingsSnapshot;
/**
* Whether `update_analysis_settings` can change the active value.
* `runtime` applies inside this process. `restart` stays at the value this
* process already started with. A limit fact uses `parameter` when its value
* is adjustable through a per-call argument; its source is recorded separately.
*/
export type AnalysisSettingUpdateMode = "runtime" | "restart";
/** Limit facts supplied by the failing owner, never inferred from error prose. */
export interface AnalysisSettingLimit {
readonly setting: AnalysisSettingId;
readonly effective_value: number | null;
readonly unit: "bytes" | "ms" | "seconds" | "MiB" | "count";
readonly minimum: number;
readonly maximum: number;
readonly source?: "default" | "setting" | "runtime" | "request";
readonly applies_at: "next_operation" | "next_worker" | "next_startup";
readonly agent_editable: true;
readonly scope: "rea-runtime";
readonly update_mode: AnalysisSettingUpdateMode | "parameter";
/**
* True only when a configured value is not the one this process is using.
* The reported effective value is active, so limit errors leave this false.
*/
readonly pending_restart: false;
readonly required_value?: number;
readonly parameter?: string;
}
/**
* The same limit for a caller whose REA runtime ended with one invocation. No
* runtime override can reach it; a new invocation reads the launch
* environment seed or the per-call argument. The caller can still choose that
* value, and no running REA process needs a restart.
*/
export interface AnalysisInvocationSettingLimit extends Omit<
AnalysisSettingLimit,
"applies_at" | "scope"
> {
readonly applies_at: "next_invocation";
readonly scope: "rea-invocation";
/** Launch-environment seed that a new invocation reads, when one exists. */
readonly environment?: string;
}