@goodtools/wiregasm 1.9.1 → 2.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.
package/README.md CHANGED
@@ -1,103 +1,120 @@
1
1
  # Wiregasm
2
- ![Build](https://github.com/good-tools/wiregasm/actions/workflows/ci.yml/badge.svg?branch=master)
3
- ![Build](https://img.shields.io/npm/dm/@goodtools/wiregasm)
2
+ [![Build & Test](https://github.com/good-tools/wiregasm/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/good-tools/wiregasm/actions/workflows/ci.yml)
3
+ [![npm](https://img.shields.io/npm/v/@goodtools/wiregasm)](https://www.npmjs.com/package/@goodtools/wiregasm)
4
+ [![Downloads](https://img.shields.io/npm/dm/@goodtools/wiregasm)](https://www.npmjs.com/package/@goodtools/wiregasm)
4
5
 
5
- Packet Analyzer powered by Wireshark compiled for WebAssembly.
6
+ Packet analyzer powered by [Wireshark](https://www.wireshark.org/) (4.6) compiled to WebAssembly. Load a capture, list and filter its packets, and get Wireshark's full protocol tree, follow streams, conversations, export objects and IO graphs, in the browser or in Node.js.
6
7
 
7
8
  Demo it on [good.tools](https://good.tools/packet-dissector).
8
9
 
9
- ## Build
10
- The library can be built in two ways:
11
- 1. `npm run build:emscripten` using a docker image with all of the build tools installed
12
- 2. `npm run build:emscripten-local` requires the build environment to be set up. A list of the tools and dependencies can be found in the build [Dockerfile](docker/build.Dockerfile)
13
-
14
- After the WASM library is built, the wrapper lib can be built using `npm run build`. The `wiregasm.js` output file produced by the emscripten compiler is not processed by `packer` in the build step and gets added directly to `dist`. This is intentional as it provides consumers to use it for any enviornment they wish, be it nodejs or a browser.
15
-
16
- See [lib/Makefile](lib/Makefile) for more information on how dependencies are built.
17
-
18
- ### Patches
19
- Cross-compiling Wireshark for emscripten/WASM isn't straightforward as it also depends on several other libraries to make it work, and those libraries also need to be ported to emscripten.
20
-
21
- * libffi
22
- * https://github.com/libffi/libffi/compare/v3.4.4...kleisauke:wasm-vips.patch by [kleisauke](https://github.com/kleisauke)
23
- * glib
24
- * https://github.com/GNOME/glib/compare/2.75.0...kleisauke:wasm-vips-2.75.0.patch by [kleisauke](https://github.com/kleisauke)
25
- * wireshark
26
- * `0001-dont-build-radiotap-lemon.patch`
27
- * Disables building `Lemon` - Wireshark builds the tool and uses it to process files within the build process. Instead of building it, we provide it externally.
28
- * Disables building `radiotap` subdir - It has a dependency on `libpcap`
29
- * `0002-fix-cpu-name-unknown.patch` - Fix compilation error for undefined `model_name` variable
30
- * `0003-disable-snort-emscripten.patch` - Disable the Snort dissector
31
- * `0004-export-wireshark-common.patch` - Expose some headers and objects that are not part of `epan`
32
- * `0005-force-data-dir.patch` - Force `/wireshark` as the data directory. It is needed for loading preferences, profiles and color filters
33
- * `0006-threadless-registration.patch` - Makes dissector registrations threadless
34
- * `0007-export-lrexlib.patch` - Expose `lrexlib`, which is really a private dependency, but which isn't linked properly if not exported.
10
+ ## Supported environments
11
+ * **Node.js** 22 or later (the maintained LTS lines)
12
+ * **Browsers** with WebAssembly BigInt integration and bulk memory (Chrome 85+, Firefox 79+, Safari 15+)
13
+
14
+ ## Install
15
+
16
+ ```sh
17
+ npm install @goodtools/wiregasm
18
+ ```
19
+
20
+ The package ships the wrapper (`dist/main.js`, `dist/module.js`, typings) and the Emscripten build: `dist/wiregasm.js` (loader), `dist/wiregasm.wasm` and `dist/wiregasm.data` (Wireshark's data files), plus `.gz` versions of the last two.
35
21
 
36
22
  ## Usage
37
- The Wiregasm `Dissect Session` implementation is effectively a tiny subset of `sharkd` APIs.
38
23
 
39
- | **sharkd** | **Wiregasm** |
40
- |------------|--------------|
41
- | load | load |
42
- | frames | getFrames |
43
- | frame | getFrame |
24
+ The `Wiregasm` class wraps the module and manages one capture at a time:
44
25
 
45
26
  ```javascript
46
- import loadWiregasm from '@goodtools/wiregasm/dist/wiregasm'
47
-
48
- // override default locateFile to supply paths to data/wasm files
49
- const wg = await loadWiregasm({
50
- locateFile: (path, prefix) => {
51
- if (path.endsWith(".data")) return "path/to/wiregasm.data";
52
- if (path.endsWith(".wasm")) return "path/to/wiregasm.wasm";
53
- return prefix + path;
54
- }
27
+ import { Wiregasm } from "@goodtools/wiregasm";
28
+ import loadWiregasm from "@goodtools/wiregasm/dist/wiregasm";
29
+
30
+ const wg = new Wiregasm();
31
+
32
+ await wg.init(loadWiregasm, {
33
+ // where to fetch wiregasm.wasm and wiregasm.data from (see below)
34
+ locateFile: (path, prefix) => `/assets/wiregasm/${path}`,
35
+ handleStatus: (type, message) => console.log(type, message),
55
36
  });
56
37
 
57
- // initialize prefs and dissectors
58
- wg.init();
38
+ const loaded = wg.load("capture.pcap", bytes); // Uint8Array of the capture file
39
+ // loaded.code === 0, loaded.summary.packet_count, ...
59
40
 
60
- // read file from local FS
61
- const data = await fs.readFile("path/to/file.pcap");
41
+ const list = wg.frames("http", 0, 100); // display filter, skip, limit
42
+ const frame = wg.frame(1); // protocol tree, data sources, follow candidates
62
43
 
63
- // write file to the virtual emscripten FS
64
- wg.FS.writeFile("/uploads/file.pcap", data);
44
+ wg.destroy();
45
+ ```
65
46
 
66
- // create a new dissect session
67
- const sess = new wg.DissectSession("/uploads/file.pcap");
47
+ Other methods include `follow`, `tap` (conversations, endpoints, export objects), `download` (export object payloads), `iograph`, `testFilter`, `completeFilter`, the preference methods (`listModules`, `listPrefs`, `getPref`, `setPref`, `applyPrefs`), `listProtocols`/`setProtocolEnabled(ByName)` and `listHeuristicDissectors`/`setHeuristicEnabled`. See `src/index.ts` and the typings for the full API.
68
48
 
69
- // load the file
70
- const ret = sess.load(); // res.code == 0
49
+ ### Loading the asset files
71
50
 
72
- // load frames
73
- const filter = "";
74
- const skip = 0;
75
- const limit = 0;
76
- const frames = sess.getFrames(filter, skip, limit);
51
+ The loader needs `wiregasm.wasm` and `wiregasm.data`:
77
52
 
78
- // get all details including protocol tree for frame
79
- const frame = sess.getFrame(1);
53
+ * **Browser:** serve both next to your app and point `locateFile` at them (the data file is requested with an empty prefix, so always return a full URL). To save bandwidth, fetch the `.gz` versions yourself, inflate them, and pass `wasmBinary` and `getPreloadedPackage(name, size)` instead; see [examples/vanilla](examples/vanilla).
54
+ * **Node.js:** `locateFile` is required for the data file, which is otherwise looked up in the current working directory:
80
55
 
81
- // destroy the session
82
- sess.delete();
56
+ ```javascript
57
+ const loadWiregasm = require("@goodtools/wiregasm/dist/wiregasm.js");
58
+ await wg.init(loadWiregasm, {
59
+ locateFile: (file) => require.resolve(`@goodtools/wiregasm/dist/${file}`),
60
+ });
61
+ ```
83
62
 
84
- // destroy the lib
85
- wg.destroy();
86
- ```
63
+ ### Lua dissectors
87
64
 
88
- To add custom Lua dissectors, add your dissectors to the plugins directory
89
- before initializing wiregasm:
65
+ Add Lua dissectors to the plugins directory before initializing:
90
66
 
91
67
  ```javascript
92
- // read lua file from local FS
93
- const dissector_data = await fs.readFile("path/to/dissector.lua");
68
+ await wg.init(loadWiregasm, overrides, async (lib) => {
69
+ lib.FS.writeFile(`${lib.getPluginsDirectory()}/dissector.lua`, luaSource);
70
+ });
71
+ // or, after init: wg.addPlugin("dissector.lua", luaSource); wg.reloadLuaPlugins();
72
+ ```
94
73
 
95
- // write lua file to the virtual emscripten FS plugin directory
96
- wg.FS.writeFile("/plugins/dissector.lua", dissector_data)
74
+ ### Low-level API
97
75
 
98
- // initialize and use wiregasm as usual
99
- wg.init();
76
+ The Emscripten module can also be used directly. Its `DissectSession` is a small subset of `sharkd`'s API (`load`, `getFrames`, `getFrame`, ...):
77
+
78
+ ```javascript
79
+ const lib = await loadWiregasm({ locateFile });
80
+ lib.init();
81
+ lib.FS.writeFile("/uploads/file.pcap", bytes);
82
+ const session = new lib.DissectSession("/uploads/file.pcap");
83
+ session.load();
84
+ const frames = session.getFrames("", 0, 0);
85
+ session.delete(); // embind objects live on the wasm heap until deleted
100
86
  ```
101
87
 
88
+ ### Upgrading from 1.x
89
+ * The `Wiregasm` wrapper methods are camelCase:
90
+
91
+ | 1.x | 2.x |
92
+ |---|---|
93
+ | `list_modules` | `listModules` |
94
+ | `list_prefs` | `listPrefs` |
95
+ | `apply_prefs` | `applyPrefs` |
96
+ | `set_pref` | `setPref` |
97
+ | `get_pref` | `getPref` |
98
+ | `test_filter` | `testFilter` |
99
+ | `complete_filter` | `completeFilter` |
100
+ | `reload_lua_plugins` | `reloadLuaPlugins` |
101
+ | `add_plugin` | `addPlugin` |
102
+ | `is_eo_tap` | `isEoTap` |
103
+ | `is_conv_tap` | `isConvTap` |
104
+ | `list_protocols` | `listProtocols` |
105
+ | `set_protocol_enabled` | `setProtocolEnabled` |
106
+ | `set_protocol_enabled_by_name` | `setProtocolEnabledByName` |
107
+ | `list_heuristic_dissectors` | `listHeuristicDissectors` |
108
+ | `set_heuristic_enabled` | `setHeuristicEnabled` |
109
+
110
+ * Node.js older than 22 is no longer supported.
111
+ * Only the documented loader options are read from the object passed to `loadWiregasm`: `locateFile`, `print`, `printErr`, `handleStatus`, `wasmBinary` and `getPreloadedPackage`, plus Emscripten's standard ones such as `instantiateWasm`.
112
+
113
+ ## Contributing
114
+
115
+ Building, testing, the patch workflow and Wireshark upgrades are described in [CONTRIBUTING.md](CONTRIBUTING.md).
116
+
102
117
  ## License
103
- Wiregasm is a derivative work of the [Wireshark](https://github.com/wireshark/wireshark) project, hence it is licensed under the same [GNU GPLv2](LICENSE) license.
118
+ Wiregasm is a derivative work of the [Wireshark](https://github.com/wireshark/wireshark) project and, like Wireshark, is licensed under the **GNU General Public License, version 2 or (at your option) any later version** (`GPL-2.0-or-later`). The full GPLv2 text is in [LICENSE](LICENSE), and each source file carries an `SPDX-License-Identifier: GPL-2.0-or-later` header.
119
+
120
+ The upstream sources that the build downloads and patches (Wireshark, glib and the other dependencies) keep their own licenses; `patches/` and `overlay/` are modifications to them.
package/dist/main.js CHANGED
@@ -18,19 +18,21 @@ function $parcel$export(e, n, v, s) {
18
18
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
19
19
  }
20
20
 
21
- $parcel$export(module.exports, "Wiregasm", () => $882b6d93070905b3$export$c4e6ddb7806910b1);
22
- var $faefaad95e5fcca0$exports = {};
21
+ $parcel$export(module.exports, "Wiregasm", () => $c7bca2c533673960$export$c4e6ddb7806910b1);
22
+ // SPDX-License-Identifier: GPL-2.0-or-later
23
+ var $6f31ecb894015585$exports = {};
23
24
 
24
- $parcel$export($faefaad95e5fcca0$exports, "PrefSetResult", () => $faefaad95e5fcca0$export$9511720e10589113);
25
- $parcel$export($faefaad95e5fcca0$exports, "PrefType", () => $faefaad95e5fcca0$export$eeff8db21dc74b3d);
26
- let $faefaad95e5fcca0$export$9511720e10589113;
25
+ $parcel$export($6f31ecb894015585$exports, "PrefSetResult", () => $6f31ecb894015585$export$9511720e10589113);
26
+ $parcel$export($6f31ecb894015585$exports, "PrefType", () => $6f31ecb894015585$export$eeff8db21dc74b3d);
27
+ // SPDX-License-Identifier: GPL-2.0-or-later
28
+ let $6f31ecb894015585$export$9511720e10589113;
27
29
  (function(PrefSetResult) {
28
30
  PrefSetResult[PrefSetResult["PREFS_SET_OK"] = 0] = "PREFS_SET_OK";
29
31
  PrefSetResult[PrefSetResult["PREFS_SET_SYNTAX_ERR"] = 1] = "PREFS_SET_SYNTAX_ERR";
30
32
  PrefSetResult[PrefSetResult["PREFS_SET_NO_SUCH_PREF"] = 2] = "PREFS_SET_NO_SUCH_PREF";
31
33
  PrefSetResult[PrefSetResult["PREFS_SET_OBSOLETE"] = 3] = "PREFS_SET_OBSOLETE";
32
- })($faefaad95e5fcca0$export$9511720e10589113 || ($faefaad95e5fcca0$export$9511720e10589113 = {}));
33
- let $faefaad95e5fcca0$export$eeff8db21dc74b3d;
34
+ })($6f31ecb894015585$export$9511720e10589113 || ($6f31ecb894015585$export$9511720e10589113 = {}));
35
+ let $6f31ecb894015585$export$eeff8db21dc74b3d;
34
36
  (function(PrefType) {
35
37
  PrefType[PrefType["PREF_UINT"] = 1] = "PREF_UINT";
36
38
  PrefType[PrefType["PREF_BOOL"] = 2] = "PREF_BOOL";
@@ -48,24 +50,38 @@ let $faefaad95e5fcca0$export$eeff8db21dc74b3d;
48
50
  PrefType[PrefType["PREF_DECODE_AS_RANGE"] = 8192] = "PREF_DECODE_AS_RANGE";
49
51
  PrefType[PrefType["PREF_OPEN_FILENAME"] = 16384] = "PREF_OPEN_FILENAME";
50
52
  PrefType[PrefType["PREF_PASSWORD"] = 32768] = "PREF_PASSWORD";
51
- })($faefaad95e5fcca0$export$eeff8db21dc74b3d || ($faefaad95e5fcca0$export$eeff8db21dc74b3d = {}));
53
+ PrefType[PrefType["PREF_PROTO_TCP_SNDAMB_ENUM"] = 65536] = "PREF_PROTO_TCP_SNDAMB_ENUM";
54
+ PrefType[PrefType["PREF_DISSECTOR"] = 131072] = "PREF_DISSECTOR";
55
+ })($6f31ecb894015585$export$eeff8db21dc74b3d || ($6f31ecb894015585$export$eeff8db21dc74b3d = {}));
52
56
 
53
57
 
54
- var $9ba0f9a5c47c04f2$exports = {};
58
+ var $d7188c8122f08803$exports = {};
55
59
 
56
- $parcel$export($9ba0f9a5c47c04f2$exports, "vectorToArray", () => $9ba0f9a5c47c04f2$export$4b978bcb0889dc66);
57
- $parcel$export($9ba0f9a5c47c04f2$exports, "preferenceSetCodeToError", () => $9ba0f9a5c47c04f2$export$a6506e3cba6c4388);
60
+ $parcel$export($d7188c8122f08803$exports, "vectorToArray", () => $d7188c8122f08803$export$4b978bcb0889dc66);
61
+ $parcel$export($d7188c8122f08803$exports, "free", () => $d7188c8122f08803$export$13e2de3c33d99539);
62
+ $parcel$export($d7188c8122f08803$exports, "preferenceSetCodeToError", () => $d7188c8122f08803$export$a6506e3cba6c4388);
63
+ // SPDX-License-Identifier: GPL-2.0-or-later
58
64
 
59
- function $9ba0f9a5c47c04f2$export$4b978bcb0889dc66(vec) {
60
- return new Array(vec.size()).fill(0).map((_, id)=>vec.get(id));
65
+ function $d7188c8122f08803$export$4b978bcb0889dc66(vec) {
66
+ try {
67
+ return Array.from({
68
+ length: vec.size()
69
+ }, (_, i)=>vec.get(i));
70
+ } finally{
71
+ // the elements are copied out; free the vector on the wasm heap
72
+ vec.delete();
73
+ }
74
+ }
75
+ function $d7188c8122f08803$export$13e2de3c33d99539(handle) {
76
+ handle.delete();
61
77
  }
62
- function $9ba0f9a5c47c04f2$export$a6506e3cba6c4388(code) {
78
+ function $d7188c8122f08803$export$a6506e3cba6c4388(code) {
63
79
  switch(code){
64
- case (0, $faefaad95e5fcca0$export$9511720e10589113).PREFS_SET_SYNTAX_ERR:
80
+ case (0, $6f31ecb894015585$export$9511720e10589113).PREFS_SET_SYNTAX_ERR:
65
81
  return "Syntax error in string";
66
- case (0, $faefaad95e5fcca0$export$9511720e10589113).PREFS_SET_NO_SUCH_PREF:
82
+ case (0, $6f31ecb894015585$export$9511720e10589113).PREFS_SET_NO_SUCH_PREF:
67
83
  return "No such preference";
68
- case (0, $faefaad95e5fcca0$export$9511720e10589113).PREFS_SET_OBSOLETE:
84
+ case (0, $6f31ecb894015585$export$9511720e10589113).PREFS_SET_OBSOLETE:
69
85
  return "Preference used to exist but no longer does";
70
86
  default:
71
87
  return "Unknown error";
@@ -75,7 +91,7 @@ function $9ba0f9a5c47c04f2$export$a6506e3cba6c4388(code) {
75
91
 
76
92
 
77
93
 
78
- const $882b6d93070905b3$var$ALLOWED_TAP_KEYS = new Set([
94
+ const $c7bca2c533673960$var$ALLOWED_TAP_KEYS = new Set([
79
95
  ...Array.from({
80
96
  length: 15
81
97
  }, (_, i)=>`tap${i}`),
@@ -83,7 +99,7 @@ const $882b6d93070905b3$var$ALLOWED_TAP_KEYS = new Set([
83
99
  length: 15
84
100
  }, (_, i)=>`filter${i}`)
85
101
  ]);
86
- const $882b6d93070905b3$var$ALLOWED_GRAPH_KEYS = new Set([
102
+ const $c7bca2c533673960$var$ALLOWED_GRAPH_KEYS = new Set([
87
103
  "filter",
88
104
  "interval",
89
105
  ...Array.from({
@@ -93,7 +109,7 @@ const $882b6d93070905b3$var$ALLOWED_GRAPH_KEYS = new Set([
93
109
  length: 9
94
110
  }, (_, i)=>`filter${i}`)
95
111
  ]);
96
- class $882b6d93070905b3$export$c4e6ddb7806910b1 {
112
+ class $c7bca2c533673960$export$c4e6ddb7806910b1 {
97
113
  constructor(){
98
114
  this.initialized = false;
99
115
  this.session = null;
@@ -112,96 +128,109 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
112
128
  this.pluginsDir = this.lib.getPluginsDirectory();
113
129
  this.initialized = true;
114
130
  }
115
- list_modules() {
131
+ listModules() {
116
132
  return this.lib.listModules();
117
133
  }
118
- list_prefs(module) {
134
+ listPrefs(module) {
119
135
  return this.lib.listPreferences(module);
120
136
  }
121
- apply_prefs() {
137
+ applyPrefs() {
122
138
  this.lib.applyPreferences();
123
139
  }
124
- set_pref(module, key, value) {
140
+ setPref(module, key, value) {
125
141
  const ret = this.lib.setPref(module, key, value);
126
- if (ret.code != (0, $faefaad95e5fcca0$export$9511720e10589113).PREFS_SET_OK) {
127
- const message = ret.error != "" ? ret.error : (0, $9ba0f9a5c47c04f2$export$a6506e3cba6c4388)(ret.code);
142
+ if (ret.code !== (0, $6f31ecb894015585$export$9511720e10589113).PREFS_SET_OK) {
143
+ const message = ret.error !== "" ? ret.error : (0, $d7188c8122f08803$export$a6506e3cba6c4388)(ret.code);
128
144
  throw new Error(`Failed to set preference (${module}.${key}): ${message}`);
129
145
  }
130
146
  }
131
- get_pref(module, key) {
147
+ getPref(module, key) {
132
148
  const response = this.lib.getPref(module, key);
133
- if (response.code != 0) throw new Error(`Failed to get preference (${module}.${key})`);
149
+ if (response.code !== 0) throw new Error(`Failed to get preference (${module}.${key})`);
134
150
  return response.data;
135
151
  }
136
152
  /**
137
153
  * Check the validity of a filter expression.
138
154
  *
139
155
  * @param filter A display filter expression
140
- */ test_filter(filter) {
156
+ */ testFilter(filter) {
141
157
  return this.lib.checkFilter(filter);
142
158
  }
143
- complete_filter(filter) {
159
+ completeFilter(filter) {
144
160
  const out = this.lib.completeFilter(filter);
145
161
  return {
146
- fields: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(out.fields)
162
+ fields: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(out.fields)
147
163
  };
148
164
  }
149
165
  tap(taps) {
150
166
  // Validate keys.
151
167
  if (!("tap0" in taps)) throw new Error("tap0 is mandatory.");
152
- if (!Object.keys(taps).every((k)=>$882b6d93070905b3$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($882b6d93070905b3$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
168
+ if (!Object.keys(taps).every((k)=>$c7bca2c533673960$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($c7bca2c533673960$var$ALLOWED_TAP_KEYS).join(", ")}.`);
169
+ const session = this.loadedSession();
153
170
  const args = new this.lib.MapInput();
154
- Object.entries(taps).forEach(([k, v])=>args.set(k, v));
155
- const response = this.session.tap(args);
171
+ for (const [k, v] of Object.entries(taps))args.set(k, v);
172
+ let response;
173
+ try {
174
+ response = session.tap(args);
175
+ } finally{
176
+ (0, $d7188c8122f08803$export$13e2de3c33d99539)(args);
177
+ }
156
178
  return {
157
179
  error: response.error,
158
- taps: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(response.taps).map((tap)=>{
180
+ taps: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(response.taps).map((tap)=>{
181
+ // biome-ignore lint/suspicious/noExplicitAny: keeps the public return type of tap() unchanged
159
182
  let res;
160
- if (this.is_conv_tap(tap)) res = {
183
+ if (this.isConvTap(tap)) res = {
161
184
  proto: tap.proto,
162
185
  tap: tap.tap,
163
186
  type: tap.type,
164
187
  geoip: tap.geoip,
165
- convs: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(tap.convs),
166
- hosts: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(tap.hosts)
188
+ convs: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(tap.convs),
189
+ hosts: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(tap.hosts)
167
190
  };
168
- else if (this.is_eo_tap(tap)) res = {
191
+ else if (this.isEoTap(tap)) res = {
169
192
  proto: tap.proto,
170
193
  tap: tap.tap,
171
194
  type: tap.type,
172
- objects: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(tap.objects)
195
+ objects: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(tap.objects)
173
196
  };
174
197
  else {
175
- tap.delete();
198
+ (0, $d7188c8122f08803$export$13e2de3c33d99539)(tap);
176
199
  throw new Error("Unknown tap result");
177
200
  }
178
- tap.delete();
201
+ (0, $d7188c8122f08803$export$13e2de3c33d99539)(tap);
179
202
  return res;
180
203
  })
181
204
  };
182
205
  }
183
206
  download(token) {
184
- return this.session.download(token);
207
+ return this.loadedSession().download(token);
185
208
  }
186
209
  iograph(input) {
187
210
  // Validate keys.
188
211
  if (!("graph0" in input)) throw new Error("graph0 is mandatory.");
189
- if (!Object.keys(input).every((k)=>$882b6d93070905b3$var$ALLOWED_GRAPH_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($882b6d93070905b3$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
212
+ if (!Object.keys(input).every((k)=>$c7bca2c533673960$var$ALLOWED_GRAPH_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($c7bca2c533673960$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
213
+ const session = this.loadedSession();
190
214
  const args = new this.lib.MapInput();
191
- Object.entries(input).forEach(([k, v])=>args.set(k, v));
192
- const out = this.session.iograph(args);
215
+ for (const [k, v] of Object.entries(input))args.set(k, v);
216
+ let out;
217
+ try {
218
+ out = session.iograph(args);
219
+ } finally{
220
+ (0, $d7188c8122f08803$export$13e2de3c33d99539)(args);
221
+ }
193
222
  return {
194
223
  ...out,
195
- iograph: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(out.iograph).map((t)=>({
196
- items: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(t.items)
224
+ iograph: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(out.iograph).map((t)=>({
225
+ items: (0, $d7188c8122f08803$export$4b978bcb0889dc66)(t.items)
197
226
  }))
198
227
  };
199
228
  }
200
- reload_lua_plugins() {
229
+ reloadLuaPlugins() {
201
230
  this.lib.reloadLuaPlugins();
202
231
  }
203
- add_plugin(name, data, opts = {}) {
204
- const path = this.pluginsDir + "/" + name;
232
+ addPlugin(name, data, opts = {}) {
233
+ const path = `${this.pluginsDir}/${name}`;
205
234
  this.lib.FS.writeFile(path, data, opts);
206
235
  }
207
236
  /**
@@ -210,10 +239,16 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
210
239
  * @returns Response containing the status and summary
211
240
  */ load(name, data, opts = {}) {
212
241
  if (this.session != null) this.session.delete();
213
- const path = this.uploadDir + "/" + name;
242
+ const path = `${this.uploadDir}/${name}`;
214
243
  this.lib.FS.writeFile(path, data, opts);
215
244
  this.session = new this.lib.DissectSession(path);
216
- return this.session.load();
245
+ const response = this.session.load();
246
+ if (response.code !== 0) {
247
+ // Don't keep a session for a file that failed to open.
248
+ this.session.delete();
249
+ this.session = null;
250
+ }
251
+ return response;
217
252
  }
218
253
  /**
219
254
  * Get Packet List information for a range of packets.
@@ -222,17 +257,21 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
222
257
  * @param skip Skip N frames
223
258
  * @param limit Limit the output to N frames
224
259
  */ frames(filter, skip = 0, limit = 0) {
225
- return this.session.getFrames(filter, skip, limit);
260
+ return this.loadedSession().getFrames(filter, skip, limit);
226
261
  }
227
262
  /**
228
263
  * Get full information about a frame including the protocol tree.
229
264
  *
230
265
  * @param number Frame number
231
266
  */ frame(num) {
232
- return this.session.getFrame(num);
267
+ return this.loadedSession().getFrame(num);
233
268
  }
234
269
  follow(follow, filter) {
235
- return this.session.follow(follow, filter);
270
+ return this.loadedSession().follow(follow, filter);
271
+ }
272
+ loadedSession() {
273
+ if (this.session === null) throw new Error("No capture file loaded, call load() first.");
274
+ return this.session;
236
275
  }
237
276
  destroy() {
238
277
  if (this.initialized) {
@@ -249,17 +288,60 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
249
288
  */ columns() {
250
289
  const vec = this.lib.getColumns();
251
290
  // convert it from a vector to array
252
- return (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(vec);
291
+ return (0, $d7188c8122f08803$export$4b978bcb0889dc66)(vec);
253
292
  }
254
- is_eo_tap(tap) {
293
+ isEoTap(tap) {
255
294
  return tap instanceof this.lib.TapExportObject;
256
295
  }
257
- is_conv_tap(tap) {
296
+ isConvTap(tap) {
258
297
  return tap instanceof this.lib.TapConvResponse;
259
298
  }
299
+ // Protocol enable/disable methods
300
+ /**
301
+ * List all registered protocols
302
+ *
303
+ * @returns Array of all protocols with their enabled state
304
+ */ listProtocols() {
305
+ return (0, $d7188c8122f08803$export$4b978bcb0889dc66)(this.lib.listProtocols());
306
+ }
307
+ /**
308
+ * Enable or disable a protocol by its ID
309
+ *
310
+ * @param protoId Protocol ID
311
+ * @param enabled Whether to enable or disable the protocol
312
+ * @returns true if successful, false otherwise
313
+ */ setProtocolEnabled(protoId, enabled) {
314
+ return this.lib.setProtocolEnabled(protoId, enabled);
315
+ }
316
+ /**
317
+ * Enable or disable a protocol by its filter name
318
+ *
319
+ * @param protoName Protocol filter name (e.g., "tcp", "udp")
320
+ * @param enabled Whether to enable or disable the protocol
321
+ * @returns true if successful, false otherwise
322
+ */ setProtocolEnabledByName(protoName, enabled) {
323
+ return this.lib.setProtocolEnabledByName(protoName, enabled);
324
+ }
325
+ // Heuristic dissector enable/disable methods
326
+ /**
327
+ * List all registered heuristic dissectors
328
+ *
329
+ * @returns Array of all heuristic dissectors with their enabled state
330
+ */ listHeuristicDissectors() {
331
+ return (0, $d7188c8122f08803$export$4b978bcb0889dc66)(this.lib.listHeuristicDissectors());
332
+ }
333
+ /**
334
+ * Enable or disable a heuristic dissector by its unique short name
335
+ *
336
+ * @param shortName Unique short name of the heuristic dissector (e.g., "mac_nr_udp")
337
+ * @param enabled Whether to enable or disable the heuristic
338
+ * @returns true if successful, false otherwise
339
+ */ setHeuristicEnabled(shortName, enabled) {
340
+ return this.lib.setHeuristicEnabled(shortName, enabled);
341
+ }
260
342
  }
261
- $parcel$exportWildcard(module.exports, $faefaad95e5fcca0$exports);
262
- $parcel$exportWildcard(module.exports, $9ba0f9a5c47c04f2$exports);
343
+ $parcel$exportWildcard(module.exports, $6f31ecb894015585$exports);
344
+ $parcel$exportWildcard(module.exports, $d7188c8122f08803$exports);
263
345
 
264
346
 
265
347
  //# sourceMappingURL=main.js.map