@cto.af/pcap-ng-parser 2.1.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,249 +0,0 @@
1
- export namespace sectionHeaderBlock {
2
- namespace byteOrderMagic {
3
- let size: number;
4
- }
5
- namespace majorVersion {
6
- let size_1: number;
7
- export { size_1 as size };
8
- }
9
- namespace minorVersion {
10
- let size_2: number;
11
- export { size_2 as size };
12
- }
13
- namespace sectionLength {
14
- let size_3: number;
15
- export { size_3 as size };
16
- export let signed: boolean;
17
- }
18
- }
19
- export namespace blockType {
20
- namespace blockType {
21
- let size_4: number;
22
- export { size_4 as size };
23
- let signed_1: boolean;
24
- export { signed_1 as signed };
25
- }
26
- }
27
- export namespace blockTotalLength {
28
- namespace blockTotalLength {
29
- let size_5: number;
30
- export { size_5 as size };
31
- }
32
- }
33
- export namespace interfaceDescriptionBlockFormat {
34
- namespace linkType {
35
- let size_6: number;
36
- export { size_6 as size };
37
- }
38
- namespace reserved {
39
- let size_7: number;
40
- export { size_7 as size };
41
- }
42
- namespace snapLen {
43
- let size_8: number;
44
- export { size_8 as size };
45
- }
46
- }
47
- export namespace simplePacketFormat {
48
- namespace originalPacketLength {
49
- let size_9: number;
50
- export { size_9 as size };
51
- }
52
- }
53
- export namespace nameResolutionFormat {
54
- namespace recordType {
55
- let size_10: number;
56
- export { size_10 as size };
57
- }
58
- namespace recordValueLength {
59
- let size_11: number;
60
- export { size_11 as size };
61
- }
62
- }
63
- export namespace enhancedPacketBlockFormat {
64
- export namespace interfaceId {
65
- let size_12: number;
66
- export { size_12 as size };
67
- }
68
- export namespace timestampHigh {
69
- let size_13: number;
70
- export { size_13 as size };
71
- }
72
- export namespace timestampLow {
73
- let size_14: number;
74
- export { size_14 as size };
75
- }
76
- export namespace capturedPacketLength {
77
- let size_15: number;
78
- export { size_15 as size };
79
- }
80
- export namespace originalPacketLength_1 {
81
- let size_16: number;
82
- export { size_16 as size };
83
- }
84
- export { originalPacketLength_1 as originalPacketLength };
85
- }
86
- export namespace optionBlock {
87
- namespace optionType {
88
- let size_17: number;
89
- export { size_17 as size };
90
- }
91
- namespace dataLength {
92
- let size_18: number;
93
- export { size_18 as size };
94
- }
95
- }
96
- export namespace endLength {
97
- namespace endTotalLength {
98
- let size_19: number;
99
- export { size_19 as size };
100
- }
101
- }
102
- export namespace privateEnterpriseNumber {
103
- namespace pen {
104
- let size_20: number;
105
- export { size_20 as size };
106
- }
107
- }
108
- export namespace interfaceStatisticsFormat {
109
- export namespace interfaceId_1 {
110
- let size_21: number;
111
- export { size_21 as size };
112
- }
113
- export { interfaceId_1 as interfaceId };
114
- export namespace timestampHigh_1 {
115
- let size_22: number;
116
- export { size_22 as size };
117
- }
118
- export { timestampHigh_1 as timestampHigh };
119
- export namespace timestampLow_1 {
120
- let size_23: number;
121
- export { size_23 as size };
122
- }
123
- export { timestampLow_1 as timestampLow };
124
- }
125
- export namespace decryptionSecretsFormat {
126
- namespace secretsType {
127
- let size_24: number;
128
- export { size_24 as size };
129
- }
130
- namespace secretsLength {
131
- let size_25: number;
132
- export { size_25 as size };
133
- }
134
- }
135
- export namespace epbFlagsFormat {
136
- namespace flags {
137
- let size_26: number;
138
- export { size_26 as size };
139
- }
140
- }
141
- export namespace ifTsOffsetFormat {
142
- namespace tsoffset {
143
- let size_27: number;
144
- export { size_27 as size };
145
- export let sign: boolean;
146
- }
147
- }
148
- export namespace ipv4MaskFormat {
149
- namespace ipv4 {
150
- let size_28: number;
151
- export { size_28 as size };
152
- }
153
- namespace mask {
154
- let size_29: number;
155
- export { size_29 as size };
156
- }
157
- }
158
- export namespace u32Format {
159
- namespace u32 {
160
- let size_30: number;
161
- export { size_30 as size };
162
- }
163
- }
164
- export namespace u64Format {
165
- namespace u64 {
166
- let size_31: number;
167
- export { size_31 as size };
168
- }
169
- }
170
- export namespace timestampFormat {
171
- export namespace timestampHigh_2 {
172
- let size_32: number;
173
- export { size_32 as size };
174
- }
175
- export { timestampHigh_2 as timestampHigh };
176
- export namespace timestampLow_2 {
177
- let size_33: number;
178
- export { size_33 as size };
179
- }
180
- export { timestampLow_2 as timestampLow };
181
- }
182
- export namespace pcapHeaderFormat {
183
- export namespace byteOrderMagic_1 {
184
- let size_34: number;
185
- export { size_34 as size };
186
- }
187
- export { byteOrderMagic_1 as byteOrderMagic };
188
- export namespace majorVersion_1 {
189
- let size_35: number;
190
- export { size_35 as size };
191
- }
192
- export { majorVersion_1 as majorVersion };
193
- export namespace minorVersion_1 {
194
- let size_36: number;
195
- export { size_36 as size };
196
- }
197
- export { minorVersion_1 as minorVersion };
198
- export namespace reserved1 {
199
- let size_37: number;
200
- export { size_37 as size };
201
- }
202
- export namespace reserved2 {
203
- let size_38: number;
204
- export { size_38 as size };
205
- }
206
- export namespace snapLen_1 {
207
- let size_39: number;
208
- export { size_39 as size };
209
- }
210
- export { snapLen_1 as snapLen };
211
- export namespace linkType_1 {
212
- let size_40: number;
213
- export { size_40 as size };
214
- }
215
- export { linkType_1 as linkType };
216
- }
217
- export namespace pcapPacketFormat {
218
- export namespace timestampHigh_3 {
219
- let size_41: number;
220
- export { size_41 as size };
221
- }
222
- export { timestampHigh_3 as timestampHigh };
223
- export namespace timestampLow_3 {
224
- let size_42: number;
225
- export { size_42 as size };
226
- }
227
- export { timestampLow_3 as timestampLow };
228
- export namespace capturedPacketLength_1 {
229
- let size_43: number;
230
- export { size_43 as size };
231
- }
232
- export { capturedPacketLength_1 as capturedPacketLength };
233
- export namespace originalPacketLength_2 {
234
- let size_44: number;
235
- export { size_44 as size };
236
- }
237
- export { originalPacketLength_2 as originalPacketLength };
238
- }
239
- export type BlockProperty = {
240
- /**
241
- * Bytes.
242
- */
243
- size: number;
244
- /**
245
- * If true, read signed.
246
- */
247
- signed?: boolean;
248
- };
249
- export type BlockDescriptor = Record<string, BlockProperty>;
@@ -1,426 +0,0 @@
1
- /**
2
- * @typedef {object} Interface
3
- * @property {number} linkType See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
4
- * @property {string} [linkTypeName]
5
- * @property {number} snapLen Capture length.
6
- * @property {string} [name] Interface name.
7
- * @property {bigint} tsoffset Offset, in MS, applied to each timestamp.
8
- * @property {bigint} tsresol Timestamp resolution in MS.
9
- * @property {Option[]} options All interface options.
10
- */
11
- /**
12
- * @typedef {object} IPv4ResolutionRecord
13
- * @property {'nrb_record_ipv4'} name
14
- * @property {string} ipv4
15
- * @property {string[]} entries
16
- */
17
- /**
18
- * @typedef {object} IPv6ResolutionRecord
19
- * @property {'nrb_record_ipv6'} name
20
- * @property {string} ipv6
21
- * @property {string[]} entries
22
- */
23
- /**
24
- * @typedef {object} EUI48ResolutionRecord
25
- * @property {'nrb_record_eui48'} name
26
- * @property {string} eui48
27
- * @property {string[]} entries
28
- */
29
- /**
30
- * @typedef {object} EUI64ResolutionRecord
31
- * @property {'nrb_record_eui64'} name
32
- * @property {string} eui64
33
- * @property {string[]} entries
34
- */
35
- /**
36
- * @typedef {IPv4ResolutionRecord | IPv6ResolutionRecord |
37
- * EUI48ResolutionRecord | EUI64ResolutionRecord} NameResolutionRecord
38
- */
39
- /**
40
- * @typedef {object} NameResolution
41
- * @property {NameResolutionRecord[]} records
42
- * @property {Option[]} options NameResolution options.
43
- */
44
- /**
45
- * @typedef {object} PacketFlags
46
- * @property {typeof EPB_FLAGS_DIRECTIONS[number]} [direction]
47
- * @property {typeof EPB_FLAGS_RECEPTION[number]} [reception]
48
- * @property {number} FCSlen
49
- * @property {boolean} [noChecksum]
50
- * @property {boolean} [checksumValid]
51
- * @property {boolean} [TCPsegmentationOfflad]
52
- * @property {typeof EPB_FLAGS_LINK_LAYER_ERRORS[number][]} [linkLayerErrors]
53
- */
54
- /**
55
- * @typedef {object} Packet
56
- * @property {number} interfaceId
57
- * @property {Date} [timestamp]
58
- * @property {PacketFlags} [flags]
59
- * @property {number} originalPacketLength
60
- * @property {Buffer} data
61
- * @property {Option[]} options
62
- */
63
- /**
64
- * @typedef {object} InterfaceStatistics
65
- * @property {number} interfaceId
66
- * @property {Date} timestamp
67
- * @property {Option[]} options
68
- */
69
- /**
70
- * @typedef {object} DecryptionSecrets
71
- * @property {number} secretsType
72
- * @property {Buffer} data
73
- * @property {Option[]} options
74
- */
75
- /**
76
- * @typedef {object} CustomBlock
77
- * @property {number} pen
78
- * @property {Buffer} data
79
- * @property {boolean} copy
80
- */
81
- /**
82
- * @typedef {object} BlockConfig
83
- * @property {number} blockType
84
- * @property {number} blockTotalLength
85
- */
86
- /**
87
- * @typedef {object} Data
88
- * @property {NoFilter} data
89
- */
90
- /**
91
- * @typedef {BlockConfig & Data} Block
92
- */
93
- /**
94
- * @typedef {object} GenericOption
95
- * @property {number} optionType
96
- * @property {number} [dataLength]
97
- * @property {Buffer} [data]
98
- * @property {string} [str]
99
- * @property {bigint} [bigint]
100
- * @property {Date} [date]
101
- * @property {string} [name]
102
- * @property {boolean} [private]
103
- */
104
- /**
105
- * @typedef {object} PrivateEnterpriseNumber
106
- * @property {number} [pen]
107
- */
108
- /** @typedef {GenericOption & PrivateEnterpriseNumber} Option */
109
- /** @typedef {"BE" | "LE"} Endianess */
110
- /**
111
- * @typedef {object} SectionHeader
112
- * @property {Endianess} endianess
113
- * @property {number} majorVersion
114
- * @property {number} minorVersion
115
- * @property {number} sectionLength
116
- * @property {Option[]} [options]
117
- */
118
- /**
119
- * @typedef {object} ParseEvents
120
- * @property {[number]} blockType Unknown block type received.
121
- * @property {[]} close Both ends of the stream have closed.
122
- * @property {[CustomBlock]} custom A Custom block was read.
123
- * @property {[Packet]} data A Simple or Extended Packet was read.
124
- * @property {[]} drain If a call to stream.write(chunk) returns false, the
125
- * 'drain' event will be emitted when it is appropriate to resume writing
126
- * data to the stream.
127
- * @property {[]} end There is no more data to be consumed from the stream.
128
- * @property {[unknown]} error Error in parsing.
129
- * @property {[]} finish The input to the parse stream has ended.
130
- * @property {[Interface]} interface An Interface record was read.
131
- * @property {[NameResolution]} names A NameResolution record was read.
132
- * @property {[]} pause `stream.pause()` was called.
133
- * @property {[Readable]} pipe Output of stream was redirect.
134
- * @property {[SectionHeader]} section A new Section has started. Always emitted
135
- * before other parse events in a valid file.
136
- * @property {[]} readable Data is available to be read from the stream.
137
- * @property {[]} resume `stream.resume()` was called.
138
- * @property {[DecryptionSecrets]} secrets A Decryption Secrets block was read.
139
- * @property {[InterfaceStatistics]} stats Interface Statistics block was read.
140
- * @property {[Readable]} unpipe `stream.unpipe()` was called.
141
- */
142
- /**
143
- * @typedef {object} ParserOptions
144
- * @property {AbortSignal} [signal]
145
- */
146
- export class PCAPNGParser extends Transform {
147
- /**
148
- * @param {ParserOptions} opts
149
- */
150
- constructor(opts?: ParserOptions);
151
- /** @type {Interface[]} */
152
- interfaces: Interface[];
153
- /**
154
- * Is this file in the pcap-ng format?
155
- *
156
- * @returns If false, in the old pcap format.
157
- */
158
- get ng(): boolean;
159
- /**
160
- * Transform chunks of data into packets and interface events.
161
- * DO NOT call directly.
162
- *
163
- * @param {Buffer} chunk Data to process.
164
- * @param {string} _encoding Ignored.
165
- * @param {TransformCallback} callback Called when finished with chunk.
166
- */
167
- _transform(chunk: Buffer, _encoding: string, callback: TransformCallback): void;
168
- /**
169
- * @template {keyof ParseEvents} K Event name.
170
- * @param {K} eventName
171
- * @param {ParseEvents[K]} args
172
- * @returns {boolean}
173
- */
174
- emit<K extends keyof ParseEvents>(eventName: K, ...args: ParseEvents[K]): boolean;
175
- /**
176
- * @template {keyof ParseEvents} K Event name.
177
- * @param {K} eventName
178
- * @param {(...args: ParseEvents[K]) => void} listener
179
- * @returns {this}
180
- */
181
- addListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
182
- /**
183
- * @template {keyof ParseEvents} K Event name.
184
- * @param {K} eventName
185
- * @param {(...args: ParseEvents[K]) => void} listener
186
- * @returns {this}
187
- */
188
- prependListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
189
- /**
190
- * @template {keyof ParseEvents} K Event name.
191
- * @param {K} eventName
192
- * @param {(...args: ParseEvents[K]) => void} listener
193
- * @returns {this}
194
- */
195
- prependOnceListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
196
- /**
197
- * @template {keyof ParseEvents} K Event name.
198
- * @param {K} eventName
199
- * @param {(...args: ParseEvents[K]) => void} listener
200
- * @returns {this}
201
- */
202
- removeListener<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
203
- /**
204
- * @template {keyof ParseEvents} K Event name.
205
- * @param {K} eventName
206
- * @param {(...args: ParseEvents[K]) => void} listener
207
- * @returns {this}
208
- */
209
- on<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
210
- /**
211
- * @template {keyof ParseEvents} K Event name.
212
- * @param {K} eventName
213
- * @param {(...args: ParseEvents[K]) => void} listener
214
- * @returns {this}
215
- */
216
- once<K extends keyof ParseEvents>(eventName: K, listener: (...args: ParseEvents[K]) => void): this;
217
- #private;
218
- }
219
- export default PCAPNGParser;
220
- export type Interface = {
221
- /**
222
- * See https://datatracker.ietf.org/doc/html/draft-ietf-opsawg-pcaplinktype for info.
223
- */
224
- linkType: number;
225
- linkTypeName?: string;
226
- /**
227
- * Capture length.
228
- */
229
- snapLen: number;
230
- /**
231
- * Interface name.
232
- */
233
- name?: string;
234
- /**
235
- * Offset, in MS, applied to each timestamp.
236
- */
237
- tsoffset: bigint;
238
- /**
239
- * Timestamp resolution in MS.
240
- */
241
- tsresol: bigint;
242
- /**
243
- * All interface options.
244
- */
245
- options: Option[];
246
- };
247
- export type IPv4ResolutionRecord = {
248
- name: "nrb_record_ipv4";
249
- ipv4: string;
250
- entries: string[];
251
- };
252
- export type IPv6ResolutionRecord = {
253
- name: "nrb_record_ipv6";
254
- ipv6: string;
255
- entries: string[];
256
- };
257
- export type EUI48ResolutionRecord = {
258
- name: "nrb_record_eui48";
259
- eui48: string;
260
- entries: string[];
261
- };
262
- export type EUI64ResolutionRecord = {
263
- name: "nrb_record_eui64";
264
- eui64: string;
265
- entries: string[];
266
- };
267
- export type NameResolutionRecord = IPv4ResolutionRecord | IPv6ResolutionRecord | EUI48ResolutionRecord | EUI64ResolutionRecord;
268
- export type NameResolution = {
269
- records: NameResolutionRecord[];
270
- /**
271
- * NameResolution options.
272
- */
273
- options: Option[];
274
- };
275
- export type PacketFlags = {
276
- direction?: (typeof EPB_FLAGS_DIRECTIONS)[number];
277
- reception?: (typeof EPB_FLAGS_RECEPTION)[number];
278
- FCSlen: number;
279
- noChecksum?: boolean;
280
- checksumValid?: boolean;
281
- TCPsegmentationOfflad?: boolean;
282
- linkLayerErrors?: (typeof EPB_FLAGS_LINK_LAYER_ERRORS)[number][];
283
- };
284
- export type Packet = {
285
- interfaceId: number;
286
- timestamp?: Date;
287
- flags?: PacketFlags;
288
- originalPacketLength: number;
289
- data: Buffer;
290
- options: Option[];
291
- };
292
- export type InterfaceStatistics = {
293
- interfaceId: number;
294
- timestamp: Date;
295
- options: Option[];
296
- };
297
- export type DecryptionSecrets = {
298
- secretsType: number;
299
- data: Buffer;
300
- options: Option[];
301
- };
302
- export type CustomBlock = {
303
- pen: number;
304
- data: Buffer;
305
- copy: boolean;
306
- };
307
- export type BlockConfig = {
308
- blockType: number;
309
- blockTotalLength: number;
310
- };
311
- export type Data = {
312
- data: NoFilter;
313
- };
314
- export type Block = BlockConfig & Data;
315
- export type GenericOption = {
316
- optionType: number;
317
- dataLength?: number;
318
- data?: Buffer;
319
- str?: string;
320
- bigint?: bigint;
321
- date?: Date;
322
- name?: string;
323
- private?: boolean;
324
- };
325
- export type PrivateEnterpriseNumber = {
326
- pen?: number;
327
- };
328
- export type Option = GenericOption & PrivateEnterpriseNumber;
329
- export type Endianess = "BE" | "LE";
330
- export type SectionHeader = {
331
- endianess: Endianess;
332
- majorVersion: number;
333
- minorVersion: number;
334
- sectionLength: number;
335
- options?: Option[];
336
- };
337
- export type ParseEvents = {
338
- /**
339
- * Unknown block type received.
340
- */
341
- blockType: [number];
342
- /**
343
- * Both ends of the stream have closed.
344
- */
345
- close: [];
346
- /**
347
- * A Custom block was read.
348
- */
349
- custom: [CustomBlock];
350
- /**
351
- * A Simple or Extended Packet was read.
352
- */
353
- data: [Packet];
354
- /**
355
- * If a call to stream.write(chunk) returns false, the
356
- * 'drain' event will be emitted when it is appropriate to resume writing
357
- * data to the stream.
358
- */
359
- drain: [];
360
- /**
361
- * There is no more data to be consumed from the stream.
362
- */
363
- end: [];
364
- /**
365
- * Error in parsing.
366
- */
367
- error: [unknown];
368
- /**
369
- * The input to the parse stream has ended.
370
- */
371
- finish: [];
372
- /**
373
- * An Interface record was read.
374
- */
375
- interface: [Interface];
376
- /**
377
- * A NameResolution record was read.
378
- */
379
- names: [NameResolution];
380
- /**
381
- * `stream.pause()` was called.
382
- */
383
- pause: [];
384
- /**
385
- * Output of stream was redirect.
386
- */
387
- pipe: [Readable];
388
- /**
389
- * A new Section has started. Always emitted
390
- * before other parse events in a valid file.
391
- */
392
- section: [SectionHeader];
393
- /**
394
- * Data is available to be read from the stream.
395
- */
396
- readable: [];
397
- /**
398
- * `stream.resume()` was called.
399
- */
400
- resume: [];
401
- /**
402
- * A Decryption Secrets block was read.
403
- */
404
- secrets: [DecryptionSecrets];
405
- /**
406
- * Interface Statistics block was read.
407
- */
408
- stats: [InterfaceStatistics];
409
- /**
410
- * `stream.unpipe()` was called.
411
- */
412
- unpipe: [Readable];
413
- };
414
- export type ParserOptions = {
415
- signal?: AbortSignal;
416
- };
417
- import { Transform } from 'node:stream';
418
- import { Buffer } from 'node:buffer';
419
- import type { TransformCallback } from 'node:stream';
420
- /** @import {Readable, TransformCallback} from 'node:stream' */
421
- /** @import {OptionType} from './options.js' */
422
- declare const EPB_FLAGS_DIRECTIONS: readonly ["notAvailable", "inbound", "outbound", "invalid"];
423
- declare const EPB_FLAGS_RECEPTION: readonly ["notSpecified", "unicast", "multicast", "broadcast", "promiscuous", "invalid", "invalid", "invalid"];
424
- declare const EPB_FLAGS_LINK_LAYER_ERRORS: readonly ["symbol", "preamble", "startFrameDelimiter", "unalignedFrame", "wrongInterFrameGap", "packetTooShort", "packetTooLong", "CRC", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid", "invalid"];
425
- import { NoFilter } from 'nofilter';
426
- import type { Readable } from 'node:stream';
@@ -1,6 +0,0 @@
1
- /**
2
- * This will eventually have come from an IANA registry.
3
- *
4
- * @see https://www.ietf.org/archive/id/draft-ietf-opsawg-pcaplinktype-13.html
5
- */
6
- export const LINK_TYPE_NAMES: Map<number, string>;
@@ -1,24 +0,0 @@
1
- export const SECTION_HEADER: 168627466;
2
- export const INTERFACE_DESCRIPTION: 1;
3
- export const SIMPLE_PACKET: 3;
4
- export const NAME_RESOLUTION: 4;
5
- export const INTERFACE_STATISTICS: 5;
6
- export const ENHANCED_PACKET: 6;
7
- export const DECRYPTION_SECRETS: 10;
8
- export const CUSTOM_COPY: 2989;
9
- export const CUSTOM_NOCOPY: 1073744813;
10
- /**
11
- * @typedef {'ipv4' | 'ipv6' | 'ipv4mask' | 'ipv6prefix' | 'eui' |
12
- * 'u32' | 'u64' | 'timestamp' | 'string' | undefined} OptionType
13
- */
14
- /**
15
- * @typedef {[name: string, typ?: OptionType, pen?: boolean]} OptionDescription
16
- */
17
- /** @typedef {Map<number, OptionDescription>} BlockOpts*/
18
- /**
19
- * @type {Map<number, BlockOpts>}
20
- */
21
- export const OPTION_NAMES: Map<number, BlockOpts>;
22
- export type OptionType = "ipv4" | "ipv6" | "ipv4mask" | "ipv6prefix" | "eui" | "u32" | "u64" | "timestamp" | "string" | undefined;
23
- export type OptionDescription = [name: string, typ?: OptionType, pen?: boolean];
24
- export type BlockOpts = Map<number, OptionDescription>;
File without changes