netkitty 0.0.22 → 0.0.23

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.
Files changed (28) hide show
  1. package/dist/lib/codec/headers/TLS_Alert.d.ts.map +1 -1
  2. package/dist/lib/codec/headers/TLS_Alert.js +1 -1
  3. package/dist/lib/codec/headers/TLS_ApplicationData.d.ts.map +1 -1
  4. package/dist/lib/codec/headers/TLS_ApplicationData.js +1 -1
  5. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.d.ts.map +1 -1
  6. package/dist/lib/codec/headers/TLS_ChangeCipherSpec.js +1 -1
  7. package/dist/lib/codec/headers/TLS_Handshake.d.ts.map +1 -1
  8. package/dist/lib/codec/headers/TLS_Handshake.js +1 -1
  9. package/dist/lib/codec/headers/TLS_Heartbeat.d.ts.map +1 -1
  10. package/dist/lib/codec/headers/TLS_Heartbeat.js +1 -1
  11. package/dist/lib/nodepcap/Capture.d.ts +7 -1
  12. package/dist/lib/nodepcap/Capture.d.ts.map +1 -1
  13. package/dist/lib/nodepcap/Capture.js +19 -5
  14. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts +4 -0
  15. package/dist/lib/nodepcap/interfaces/ICaptureOptions.d.ts.map +1 -1
  16. package/dist/lib/pcap/PcapWriter.d.ts.map +1 -1
  17. package/dist/lib/pcap/PcapWriter.js +10 -4
  18. package/dist/tests/units/CaptureTest.spec.js +1 -0
  19. package/package.json +1 -1
  20. package/src/lib/codec/headers/TLS_Alert.ts +1 -1
  21. package/src/lib/codec/headers/TLS_ApplicationData.ts +1 -1
  22. package/src/lib/codec/headers/TLS_ChangeCipherSpec.ts +1 -1
  23. package/src/lib/codec/headers/TLS_Handshake.ts +1 -1
  24. package/src/lib/codec/headers/TLS_Heartbeat.ts +1 -1
  25. package/src/lib/nodepcap/Capture.ts +20 -7
  26. package/src/lib/nodepcap/interfaces/ICaptureOptions.ts +5 -0
  27. package/src/lib/pcap/PcapWriter.ts +10 -5
  28. package/src/tests/units/CaptureTest.spec.ts +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"TLS_Alert.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Alert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAiDlD,qBAAa,SAAU,SAAQ,UAAU;IAC9B,MAAM,EAAE,kBAAkB,CA0dhC;IACM,EAAE,EAAE,MAAM,CAAc;IACxB,IAAI,EAAE,MAAM,CAA6C;IACzD,QAAQ,EAAE,MAAM,CAAQ;IAExB,KAAK,IAAI,OAAO;CAQ1B"}
1
+ {"version":3,"file":"TLS_Alert.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Alert.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAiDlD,qBAAa,SAAU,SAAQ,UAAU;IAC9B,MAAM,EAAE,kBAAkB,CA0dhC;IACM,EAAE,EAAE,MAAM,CAAc;IACxB,IAAI,EAAE,MAAM,CAA6C;IACzD,QAAQ,EAAE,MAAM,CAAc;IAE9B,KAAK,IAAI,OAAO;CAQ1B"}
@@ -608,7 +608,7 @@ class TLS_Alert extends BaseHeader_1.BaseHeader {
608
608
  };
609
609
  this.id = 'tls-alert';
610
610
  this.name = 'Transport Layer Security(Alert Protocol)';
611
- this.nickname = 'TLS';
611
+ this.nickname = 'TLS-Alert';
612
612
  }
613
613
  match() {
614
614
  if (!this.prevCodecModule)
@@ -1 +1 @@
1
- {"version":3,"file":"TLS_ApplicationData.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_ApplicationData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,mBAAoB,SAAQ,UAAU;IACxC,MAAM,EAAE,kBAAkB,CAmHhC;IACM,EAAE,EAAE,MAAM,CAAgB;IAC1B,IAAI,EAAE,MAAM,CAAwD;IACpE,QAAQ,EAAE,MAAM,CAAQ;IAExB,KAAK,IAAI,OAAO;CAQ1B"}
1
+ {"version":3,"file":"TLS_ApplicationData.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_ApplicationData.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,mBAAoB,SAAQ,UAAU;IACxC,MAAM,EAAE,kBAAkB,CAmHhC;IACM,EAAE,EAAE,MAAM,CAAgB;IAC1B,IAAI,EAAE,MAAM,CAAwD;IACpE,QAAQ,EAAE,MAAM,CAAgB;IAEhC,KAAK,IAAI,OAAO;CAQ1B"}
@@ -140,7 +140,7 @@ class TLS_ApplicationData extends BaseHeader_1.BaseHeader {
140
140
  };
141
141
  this.id = 'tls-appdata';
142
142
  this.name = 'Transport Layer Security(Application Data Protocol)';
143
- this.nickname = 'TLS';
143
+ this.nickname = 'TLS-AppData';
144
144
  }
145
145
  match() {
146
146
  if (!this.prevCodecModule)
@@ -1 +1 @@
1
- {"version":3,"file":"TLS_ChangeCipherSpec.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_ChangeCipherSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,oBAAqB,SAAQ,UAAU;IACzC,MAAM,EAAE,kBAAkB,CAoHhC;IACM,EAAE,EAAE,MAAM,CAAa;IACvB,IAAI,EAAE,MAAM,CAAwD;IACpE,QAAQ,EAAE,MAAM,CAAQ;IAExB,KAAK,IAAI,OAAO;CAQ1B"}
1
+ {"version":3,"file":"TLS_ChangeCipherSpec.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_ChangeCipherSpec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,oBAAqB,SAAQ,UAAU;IACzC,MAAM,EAAE,kBAAkB,CAoHhC;IACM,EAAE,EAAE,MAAM,CAAa;IACvB,IAAI,EAAE,MAAM,CAAwD;IACpE,QAAQ,EAAE,MAAM,CAAyB;IAEzC,KAAK,IAAI,OAAO;CAQ1B"}
@@ -139,7 +139,7 @@ class TLS_ChangeCipherSpec extends BaseHeader_1.BaseHeader {
139
139
  };
140
140
  this.id = 'tls-ccsp';
141
141
  this.name = 'Transport Layer Security(ChangeCipherSpec Protocol)';
142
- this.nickname = 'TLS';
142
+ this.nickname = 'TLS-ChangeCipherSpec';
143
143
  }
144
144
  match() {
145
145
  if (!this.prevCodecModule)
@@ -1 +1 @@
1
- {"version":3,"file":"TLS_Handshake.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAkClD,qBAAa,aAAc,SAAQ,UAAU;IAClC,MAAM,EAAE,kBAAkB,CAuQhC;IACM,EAAE,EAAE,MAAM,CAAkB;IAC5B,IAAI,EAAE,MAAM,CAAiD;IAC7D,QAAQ,EAAE,MAAM,CAAQ;IAExB,KAAK,IAAI,OAAO;CAQ1B"}
1
+ {"version":3,"file":"TLS_Handshake.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Handshake.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAkClD,qBAAa,aAAc,SAAQ,UAAU;IAClC,MAAM,EAAE,kBAAkB,CAuQhC;IACM,EAAE,EAAE,MAAM,CAAkB;IAC5B,IAAI,EAAE,MAAM,CAAiD;IAC7D,QAAQ,EAAE,MAAM,CAAkB;IAElC,KAAK,IAAI,OAAO;CAQ1B"}
@@ -324,7 +324,7 @@ class TLS_Handshake extends BaseHeader_1.BaseHeader {
324
324
  };
325
325
  this.id = 'tls-handshake';
326
326
  this.name = 'Transport Layer Security(Handshake Protocol)';
327
- this.nickname = 'TLS';
327
+ this.nickname = 'TLS-Handshake';
328
328
  }
329
329
  match() {
330
330
  if (!this.prevCodecModule)
@@ -1 +1 @@
1
- {"version":3,"file":"TLS_Heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,aAAc,SAAQ,UAAU;IAClC,MAAM,EAAE,kBAAkB,CA+JhC;IACM,EAAE,EAAE,MAAM,CAAkB;IAC5B,IAAI,EAAE,MAAM,CAAiD;IAC7D,QAAQ,EAAE,MAAM,CAAQ;IAExB,KAAK,IAAI,OAAO;CAO1B"}
1
+ {"version":3,"file":"TLS_Heartbeat.d.ts","sourceRoot":"","sources":["../../../../src/lib/codec/headers/TLS_Heartbeat.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,kBAAkB,EAAC,MAAM,iCAAiC,CAAA;AAClE,OAAO,EAAC,UAAU,EAAC,MAAM,yBAAyB,CAAA;AAclD,qBAAa,aAAc,SAAQ,UAAU;IAClC,MAAM,EAAE,kBAAkB,CA+JhC;IACM,EAAE,EAAE,MAAM,CAAkB;IAC5B,IAAI,EAAE,MAAM,CAAiD;IAC7D,QAAQ,EAAE,MAAM,CAAkB;IAElC,KAAK,IAAI,OAAO;CAO1B"}
@@ -191,7 +191,7 @@ class TLS_Heartbeat extends BaseHeader_1.BaseHeader {
191
191
  };
192
192
  this.id = 'tls-heartbeat';
193
193
  this.name = 'Transport Layer Security(Heartbeat Protocol)';
194
- this.nickname = 'TLS';
194
+ this.nickname = 'TLS-Heartbeat';
195
195
  }
196
196
  match() {
197
197
  if (!this.prevCodecModule)
@@ -29,9 +29,15 @@ export declare class Capture extends EventEmitter {
29
29
  protected getWorkerSocket(): Promise<PipeClientSocket>;
30
30
  /**
31
31
  * Clean resources before start capture
32
+ * @param removeTmpFile
32
33
  * @protected
33
34
  */
34
- protected cleanResources(): Promise<void>;
35
+ protected cleanResources(removeTmpFile?: boolean): Promise<void>;
36
+ /**
37
+ * Clean temporary pcap file
38
+ * @protected
39
+ */
40
+ protected cleanTemporaryFile(): void;
35
41
  /**
36
42
  * Wait other operation done
37
43
  * @protected
@@ -1 +1 @@
1
- {"version":3,"file":"Capture.d.ts","sourceRoot":"","sources":["../../../src/lib/nodepcap/Capture.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAA;AAS5D,OAAO,EAAC,gBAAgB,EAAC,MAAM,0BAA0B,CAAA;AAGzD,OAAO,YAAY,MAAM,QAAQ,CAAA;AAGjC,OAAO,EAAC,eAAe,EAAC,MAAM,oCAAoC,CAAA;AAElE,qBAAa,OAAQ,SAAQ,YAAY;;IAgCrC,IAAW,MAAM,IAAI,MAAM,CAE1B;IAED,IAAW,iBAAiB,IAAI,MAAM,CAErC;IAED,IAAW,KAAK,IAAI,MAAM,CAEzB;IAED;;;OAGG;gBACS,OAAO,EAAE,eAAe;IAcpC;;;OAGG;IACH,SAAS,CAAC,mBAAmB,IAAI,IAAI;IAsBrC;;;OAGG;cACa,oBAAoB,IAAI,OAAO,CAAC,IAAI,CAAC;IA6BrD;;;OAGG;cACa,eAAe,IAAI,OAAO,CAAC,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E,CAAC,cAAc,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;IAClF,EAAE,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;IAM1H,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,cAAc,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;IACpF,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,KAAK,IAAI,GAAG,IAAI;CAKtI"}
@@ -50,6 +50,7 @@ const promises_1 = require("node:fs/promises");
50
50
  const events_1 = __importDefault(require("events"));
51
51
  const DeviceNotFoundError_1 = require("../../errors/DeviceNotFoundError");
52
52
  const node_os_1 = require("node:os");
53
+ const PCAPGenerator_1 = require("../pcap/PCAPGenerator");
53
54
  class Capture extends events_1.default {
54
55
  #workerModule = node_path_1.default.resolve(__dirname, './workers/CaptureWorker.js');
55
56
  #device;
@@ -90,8 +91,10 @@ class Capture extends events_1.default {
90
91
  if (!(0, GetNetworkInterfaces_1.GetNetworkInterfaces)().filter((availableDevice) => availableDevice.name === this.#device).length)
91
92
  throw new DeviceNotFoundError_1.DeviceNotFoundError(`Device ${this.#device} not found`);
92
93
  }
93
- this.#temporaryFilename = (0, GetDeviceCaptureTemporaryFilename_1.GetDeviceCaptureTemporaryFilename)(this.#device, this.#tmpDir);
94
+ this.#temporaryFilename = options.temporaryFilename ? options.temporaryFilename : (0, GetDeviceCaptureTemporaryFilename_1.GetDeviceCaptureTemporaryFilename)(this.#device, this.#tmpDir);
94
95
  this.#pipeServer = new PipeServer_1.PipeServer();
96
+ this.cleanTemporaryFile();
97
+ (0, node_fs_1.writeFileSync)(this.#temporaryFilename, (0, PCAPGenerator_1.GeneratePCAPHeader)());
95
98
  }
96
99
  /**
97
100
  * Create and initialize capture worker
@@ -169,16 +172,27 @@ class Capture extends events_1.default {
169
172
  }
170
173
  /**
171
174
  * Clean resources before start capture
175
+ * @param removeTmpFile
172
176
  * @protected
173
177
  */
174
- async cleanResources() {
178
+ async cleanResources(removeTmpFile = true) {
175
179
  //Clean cached capture data
176
- if ((0, node_fs_1.existsSync)(this.#temporaryFilename))
177
- await (0, promises_1.rm)(this.#temporaryFilename, { recursive: true, force: true });
180
+ if ((0, node_fs_1.existsSync)(this.#temporaryFilename) && removeTmpFile)
181
+ this.cleanTemporaryFile();
178
182
  //Clean old worker resources
179
183
  if (this.#worker && this.#workerSocket)
180
184
  await this.destroyCaptureWorker();
181
185
  }
186
+ /**
187
+ * Clean temporary pcap file
188
+ * @protected
189
+ */
190
+ cleanTemporaryFile() {
191
+ (0, node_fs_1.rmSync)(this.#temporaryFilename, {
192
+ recursive: true,
193
+ force: true
194
+ });
195
+ }
182
196
  /**
183
197
  * Wait other operation done
184
198
  * @protected
@@ -199,7 +213,7 @@ class Capture extends events_1.default {
199
213
  this.#operating = true;
200
214
  try {
201
215
  this.#started = true;
202
- await this.cleanResources();
216
+ await this.cleanResources(false);
203
217
  this.createCaptureWorker();
204
218
  const workerSocket = await this.getWorkerSocket();
205
219
  await workerSocket.invoke('start');
@@ -15,5 +15,9 @@ export interface ICaptureOptions {
15
15
  * The temporary folder path for storing captured pcap files
16
16
  */
17
17
  tmpDir?: string;
18
+ /**
19
+ * Temporary filename
20
+ */
21
+ temporaryFilename?: string;
18
22
  }
19
23
  //# sourceMappingURL=ICaptureOptions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ICaptureOptions.d.ts","sourceRoot":"","sources":["../../../../src/lib/nodepcap/interfaces/ICaptureOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB"}
1
+ {"version":3,"file":"ICaptureOptions.d.ts","sourceRoot":"","sources":["../../../../src/lib/nodepcap/interfaces/ICaptureOptions.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IACd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IACf;;OAEG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IAErB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAA;IAEf;;OAEG;IACH,iBAAiB,CAAC,EAAC,MAAM,CAAA;CAC5B"}
@@ -1 +1 @@
1
- {"version":3,"file":"PcapWriter.d.ts","sourceRoot":"","sources":["../../../src/lib/pcap/PcapWriter.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,QAAQ,CAAA;AACjC,OAAO,EAAoB,WAAW,EAAC,MAAM,SAAS,CAAA;AAEtD,OAAO,EAAC,eAAe,EAAC,MAAM,8BAA8B,CAAA;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,qBAAa,UAAW,SAAQ,YAAY;IAExC,SAAgB,QAAQ,EAAE,MAAM,CAAA;IAEhC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAA;IAE3C,SAAS,CAAC,MAAM,EAAE,OAAO,CAAQ;IAEjC,SAAS,CAAC,KAAK,EAAE,MAAM,CAAI;IAE3B,SAAS,CAAC,MAAM,EAAE,MAAM,CAAI;IAE5B,IAAW,UAAU,IAAI,MAAM,CAE9B;gBAEW,OAAO,EAAE,kBAAkB;IASvC;;;;;OAKG;IACI,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,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AAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,eAAe,KAAK,IAAI,GAAG,IAAI;CAK/F"}
@@ -17,10 +17,16 @@ class PcapWriter extends events_1.default {
17
17
  this.index = 0;
18
18
  this.offset = 0;
19
19
  this.filename = options.filename;
20
- this.writeStream = (0, node_fs_1.createWriteStream)(this.filename, { autoClose: false, flags: 'w' });
21
- const header = (0, PCAPGenerator_1.GeneratePCAPHeader)();
22
- this.writeStream.write(header);
23
- this.offset += header.length;
20
+ if (!(0, node_fs_1.existsSync)(this.filename)) {
21
+ this.writeStream = (0, node_fs_1.createWriteStream)(this.filename, { autoClose: false, flags: 'w' });
22
+ const header = (0, PCAPGenerator_1.GeneratePCAPHeader)();
23
+ this.writeStream.write(header);
24
+ this.offset += header.length;
25
+ }
26
+ else {
27
+ this.writeStream = (0, node_fs_1.createWriteStream)(this.filename, { autoClose: false, flags: 'a' });
28
+ this.offset += (0, node_fs_1.statSync)(this.filename).size;
29
+ }
24
30
  }
25
31
  /**
26
32
  * Write packet to pcap file
@@ -4,6 +4,7 @@ const Capture_1 = require("../../lib/nodepcap/Capture");
4
4
  const PcapReader_1 = require("../../lib/pcap/PcapReader");
5
5
  (async () => {
6
6
  const capture = new Capture_1.Capture({ device: 'en0' });
7
+ console.log(capture.temporaryFilename);
7
8
  const pcapReader = new PcapReader_1.PcapReader({ filename: capture.temporaryFilename, watch: true });
8
9
  pcapReader.on('packet', async (info) => {
9
10
  // const buf = await pcapReader.readPacket(info.offset, info.length)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "netkitty",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "Network tools kit",
5
5
  "exports": {
6
6
  "./network": {
@@ -526,7 +526,7 @@ export class TLS_Alert extends BaseHeader {
526
526
  }
527
527
  public id: string = 'tls-alert'
528
528
  public name: string = 'Transport Layer Security(Alert Protocol)'
529
- public nickname: string = 'TLS'
529
+ public nickname: string = 'TLS-Alert'
530
530
 
531
531
  public match(): boolean {
532
532
  if (!this.prevCodecModule) return false
@@ -132,7 +132,7 @@ export class TLS_ApplicationData extends BaseHeader {
132
132
  }
133
133
  public id: string = 'tls-appdata'
134
134
  public name: string = 'Transport Layer Security(Application Data Protocol)'
135
- public nickname: string = 'TLS'
135
+ public nickname: string = 'TLS-AppData'
136
136
 
137
137
  public match(): boolean {
138
138
  if (!this.prevCodecModule) return false
@@ -133,7 +133,7 @@ export class TLS_ChangeCipherSpec extends BaseHeader {
133
133
  }
134
134
  public id: string = 'tls-ccsp'
135
135
  public name: string = 'Transport Layer Security(ChangeCipherSpec Protocol)'
136
- public nickname: string = 'TLS'
136
+ public nickname: string = 'TLS-ChangeCipherSpec'
137
137
 
138
138
  public match(): boolean {
139
139
  if (!this.prevCodecModule) return false
@@ -300,7 +300,7 @@ export class TLS_Handshake extends BaseHeader {
300
300
  }
301
301
  public id: string = 'tls-handshake'
302
302
  public name: string = 'Transport Layer Security(Handshake Protocol)'
303
- public nickname: string = 'TLS'
303
+ public nickname: string = 'TLS-Handshake'
304
304
 
305
305
  public match(): boolean {
306
306
  if (!this.prevCodecModule) return false
@@ -176,7 +176,7 @@ export class TLS_Heartbeat extends BaseHeader {
176
176
  }
177
177
  public id: string = 'tls-heartbeat'
178
178
  public name: string = 'Transport Layer Security(Heartbeat Protocol)'
179
- public nickname: string = 'TLS'
179
+ public nickname: string = 'TLS-Heartbeat'
180
180
 
181
181
  public match(): boolean {
182
182
  if (!this.prevCodecModule) return false
@@ -1,7 +1,7 @@
1
1
  import {GetNetworkInterfaces} from './GetNetworkInterfaces'
2
2
  import {INetworkInterface} from './interfaces/INetworkInterface'
3
3
  import {ICaptureOptions} from './interfaces/ICaptureOptions'
4
- import {existsSync} from 'node:fs'
4
+ import {existsSync, rmSync, writeFileSync} from 'node:fs'
5
5
  import {GetDeviceCaptureTemporaryFilename} from '../GetDeviceCaptureTemporaryFilename'
6
6
  import {ChildProcess} from 'node:child_process'
7
7
  import path from 'node:path'
@@ -16,6 +16,7 @@ import EventEmitter from 'events'
16
16
  import {DeviceNotFoundError} from '../../errors/DeviceNotFoundError'
17
17
  import {tmpdir} from 'node:os'
18
18
  import {IPcapPacketInfo} from '../pcap/interfaces/IPcapPacketInfo'
19
+ import {GeneratePCAPHeader} from '../pcap/PCAPGenerator'
19
20
 
20
21
  export class Capture extends EventEmitter {
21
22
 
@@ -75,8 +76,10 @@ export class Capture extends EventEmitter {
75
76
  //Use origin worker module, check capture device is available
76
77
  if (!GetNetworkInterfaces().filter((availableDevice: INetworkInterface): boolean => availableDevice.name === this.#device).length) throw new DeviceNotFoundError(`Device ${this.#device} not found`)
77
78
  }
78
- this.#temporaryFilename = GetDeviceCaptureTemporaryFilename(this.#device, this.#tmpDir)
79
+ this.#temporaryFilename = options.temporaryFilename ? options.temporaryFilename : GetDeviceCaptureTemporaryFilename(this.#device, this.#tmpDir)
79
80
  this.#pipeServer = new PipeServer()
81
+ this.cleanTemporaryFile()
82
+ writeFileSync(this.#temporaryFilename, GeneratePCAPHeader())
80
83
  }
81
84
 
82
85
  /**
@@ -101,8 +104,6 @@ export class Capture extends EventEmitter {
101
104
  })
102
105
  })
103
106
  this.#worker = isElectron() ? utilityProcess.fork(this.#workerModule, [], {env: env}) : childProcess.fork(this.#workerModule, [], {env: env})
104
-
105
-
106
107
  }
107
108
 
108
109
  /**
@@ -157,15 +158,27 @@ export class Capture extends EventEmitter {
157
158
 
158
159
  /**
159
160
  * Clean resources before start capture
161
+ * @param removeTmpFile
160
162
  * @protected
161
163
  */
162
- protected async cleanResources(): Promise<void> {
164
+ protected async cleanResources(removeTmpFile: boolean = true): Promise<void> {
163
165
  //Clean cached capture data
164
- if (existsSync(this.#temporaryFilename)) await rm(this.#temporaryFilename, {recursive: true, force: true})
166
+ if (existsSync(this.#temporaryFilename) && removeTmpFile) this.cleanTemporaryFile()
165
167
  //Clean old worker resources
166
168
  if (this.#worker && this.#workerSocket) await this.destroyCaptureWorker()
167
169
  }
168
170
 
171
+ /**
172
+ * Clean temporary pcap file
173
+ * @protected
174
+ */
175
+ protected cleanTemporaryFile(): void {
176
+ rmSync(this.#temporaryFilename, {
177
+ recursive: true,
178
+ force: true
179
+ })
180
+ }
181
+
169
182
  /**
170
183
  * Wait other operation done
171
184
  * @protected
@@ -184,7 +197,7 @@ export class Capture extends EventEmitter {
184
197
  this.#operating = true
185
198
  try {
186
199
  this.#started = true
187
- await this.cleanResources()
200
+ await this.cleanResources(false)
188
201
  this.createCaptureWorker()
189
202
  const workerSocket: PipeClientSocket = await this.getWorkerSocket()
190
203
  await workerSocket.invoke('start')
@@ -16,4 +16,9 @@ export interface ICaptureOptions {
16
16
  * The temporary folder path for storing captured pcap files
17
17
  */
18
18
  tmpDir?: string
19
+
20
+ /**
21
+ * Temporary filename
22
+ */
23
+ temporaryFilename?:string
19
24
  }
@@ -1,5 +1,5 @@
1
1
  import EventEmitter from 'events'
2
- import {createWriteStream, WriteStream} from 'node:fs'
2
+ import {createWriteStream, existsSync, statSync, WriteStream} from 'node:fs'
3
3
  import {GeneratePCAPData, GeneratePCAPHeader} from './PCAPGenerator'
4
4
  import {IPcapPacketInfo} from './interfaces/IPcapPacketInfo'
5
5
 
@@ -26,10 +26,15 @@ export class PcapWriter extends EventEmitter {
26
26
  constructor(options: IPcapWriterOptions) {
27
27
  super()
28
28
  this.filename = options.filename
29
- this.writeStream = createWriteStream(this.filename, {autoClose: false, flags: 'w'})
30
- const header: Buffer = GeneratePCAPHeader()
31
- this.writeStream.write(header)
32
- this.offset += header.length
29
+ if (!existsSync(this.filename)) {
30
+ this.writeStream = createWriteStream(this.filename, {autoClose: false, flags: 'w'})
31
+ const header: Buffer = GeneratePCAPHeader()
32
+ this.writeStream.write(header)
33
+ this.offset += header.length
34
+ } else {
35
+ this.writeStream = createWriteStream(this.filename, {autoClose: false, flags: 'a'})
36
+ this.offset += statSync(this.filename).size
37
+ }
33
38
  }
34
39
 
35
40
  /**
@@ -3,6 +3,7 @@ import {PcapReader} from '../../lib/pcap/PcapReader'
3
3
 
4
4
  (async (): Promise<void> => {
5
5
  const capture = new Capture({device: 'en0'})
6
+ console.log(capture.temporaryFilename)
6
7
  const pcapReader: PcapReader = new PcapReader({filename: capture.temporaryFilename, watch: true})
7
8
  pcapReader.on('packet', async (info) => {
8
9
  // const buf = await pcapReader.readPacket(info.offset, info.length)