@goodtools/wiregasm 1.2.0 → 1.3.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
@@ -31,6 +31,7 @@ Cross-compiling Wireshark for emscripten/WASM isn't straightforward as it also d
31
31
  * `0004-export-wireshark-common.patch` - Expose some headers and objects that are not part of `epan`
32
32
  * `0005-force-data-dir.patch` - Force `/wireshark` as the data directory. It is needed for loading preferences, profiles and color filters
33
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.
34
35
 
35
36
  ## Usage
36
37
  The Wiregasm `Dissect Session` implementation is effectively a tiny subset of `sharkd` APIs.
@@ -84,5 +85,19 @@ sess.delete();
84
85
  wg.destroy();
85
86
  ```
86
87
 
88
+ To add custom Lua dissectors, add your dissectors to the plugins directory
89
+ before initializing wiregasm:
90
+
91
+ ```javascript
92
+ // read lua file from local FS
93
+ const dissector_data = await fs.readFile("path/to/dissector.lua");
94
+
95
+ // write lua file to the virtual emscripten FS plugin directory
96
+ wg.FS.writeFile("/plugins/dissector.lua", dissector_data)
97
+
98
+ // initialize and use wiregasm as usual
99
+ wg.init();
100
+ ```
101
+
87
102
  ## License
88
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.
package/dist/main.js CHANGED
@@ -41,10 +41,12 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
41
41
  *
42
42
  * @param loader Loader function for the Emscripten module
43
43
  * @param overrides Overrides
44
- */ async init(loader, overrides = {}) {
44
+ */ async init(loader, overrides = {}, beforeInit = null) {
45
45
  if (this.initialized) return;
46
46
  this.lib = await loader(overrides);
47
47
  this.uploadDir = this.lib.getUploadDirectory();
48
+ this.pluginsDir = this.lib.getPluginsDirectory();
49
+ if (beforeInit !== null) await beforeInit(this.lib);
48
50
  this.lib.init();
49
51
  this.initialized = true;
50
52
  }
@@ -55,6 +57,13 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
55
57
  */ test_filter(filter) {
56
58
  return this.lib.checkFilter(filter);
57
59
  }
60
+ reload_lua_plugins() {
61
+ this.lib.reloadLuaPlugins();
62
+ }
63
+ add_plugin(name, data, opts = {}) {
64
+ const path = this.pluginsDir + "/" + name;
65
+ this.lib.FS.writeFile(path, data, opts);
66
+ }
58
67
  /**
59
68
  * Load a packet trace file for analysis.
60
69
  *
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACQO,SAAS,0CAAiB,GAAc,EAAO;IACpD,OAAO,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAO,IAAI,GAAG,CAAC;AAC9D;;ADVA;;;;;AAeO,MAAM;IAMX,aAAc;QACZ,IAAI,CAAC,WAAW,GAAG,KAAK;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI;IACrB;IAEA;;;;;GAKC,GACD,MAAM,KAAK,MAAsB,EAAE,YAAkC,CAAC,CAAC,EAAE;QACvE,IAAI,IAAI,CAAC,WAAW,EAClB;QAGF,IAAI,CAAC,GAAG,GAAG,MAAM,OAAO;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB;QAC5C,IAAI,CAAC,GAAG,CAAC,IAAI;QACb,IAAI,CAAC,WAAW,GAAG,IAAI;IACzB;IAEA;;;;GAIC,GACD,YAAY,MAAc,EAAuB;QAC/C,OAAO,IAAI,CAAC,GAAG,CAAC,WAAW,CAAC;IAC9B;IAEA;;;;GAIC,GACD,KACE,IAAY,EACZ,IAA8B,EAC9B,OAAe,CAAC,CAAC,EACH;QACd,IAAI,IAAI,CAAC,OAAO,IAAI,IAAI,EACtB,IAAI,CAAC,OAAO,CAAC,MAAM;QAGrB,MAAM,OAAO,IAAI,CAAC,SAAS,GAAG,MAAM;QACpC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,MAAM;QAElC,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;QAE3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI;IAC1B;IAEA;;;;;;GAMC,GACD,OAAO,MAAc,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAkB;QAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,MAAM;IAC9C;IAEA;;;;GAIC,GACD,MAAM,GAAW,EAAS;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B;IAEA,UAAU;QACR,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE;gBACzB,IAAI,CAAC,OAAO,CAAC,MAAM;gBACnB,IAAI,CAAC,OAAO,GAAG,IAAI;YACrB,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,OAAO;YAChB,IAAI,CAAC,WAAW,GAAG,KAAK;QAC1B,CAAC;IACH;IAEA;;GAEC,GACD,UAAoB;QAClB,MAAM,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU;QAE/B,oCAAoC;QACpC,OAAO,CAAA,GAAA,yCAAY,EAAE;IACvB;AACF","sources":["src/index.ts","src/utils.ts","src/types.ts"],"sourcesContent":["import {\n CheckFilterResponse,\n DissectSession,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\nimport { vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(loader: WiregasmLoader, overrides: WiregasmLibOverrides = {}) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.lib.init();\n this.initialized = true;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","import { Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n","export interface EmscriptenFileSystem {\n writeFile(\n path: string,\n data: string | ArrayBufferView,\n opts?: { flags?: string | undefined }\n ): void;\n readdir(path: string): string[];\n}\n\nexport interface EmscriptenHeap {\n buffer: ArrayBufferLike;\n}\n\nexport interface EmscriptenModule {\n FS: EmscriptenFileSystem;\n HEAPU8: EmscriptenHeap;\n _malloc(size: number): number;\n}\n\nexport interface Vector<T> {\n size(): number;\n get(index: number): T;\n}\n\nexport interface DataSource {\n name: string;\n data: string;\n}\n\nexport interface ProtoTree {\n label: string;\n filter: string;\n start: number;\n length: number;\n data_source_idx: number;\n tree: Vector<ProtoTree>;\n}\n\nexport interface Frame {\n number: number;\n comments: Vector<string>;\n data_sources: Vector<DataSource>;\n tree: Vector<ProtoTree>;\n}\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\n\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n}\n\nexport interface DissectSessionConstructable {\n new (path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * Clean up any memory associated with the lib\n */\n destroy(): void;\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n checkFilter(filter: string): CheckFilterResponse;\n\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;ACQO,SAAS,0CAAiB,GAAc,EAAO;IACpD,OAAO,IAAI,MAAM,IAAI,IAAI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AAM;QAElC,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;QAE3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI;IAC1B;IAEA;;;;;;GAMC,GACD,OAAO,MAAc,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAkB;QAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,MAAM;IAC9C;IAEA;;;;GAIC,GACD,MAAM,GAAW,EAAS;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B;IAEA,UAAU;QACR,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE;gBACzB,IAAI,CAAC,OAAO,CAAC,MAAM;gBACnB,IAAI,CAAC,OAAO,GAAG,IAAI;YACrB,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,OAAO;YAChB,IAAI,CAAC,WAAW,GAAG,KAAK;QAC1B,CAAC;IACH;IAEA;;GAEC,GACD,UAAoB;QAClB,MAAM,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU;QAE/B,oCAAoC;QACpC,OAAO,CAAA,GAAA,yCAAY,EAAE;IACvB;AACF","sources":["src/index.ts","src/utils.ts","src/types.ts"],"sourcesContent":["import {\n CheckFilterResponse,\n DissectSession,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n BeforeInitCallback,\n} from \"./types\";\nimport { vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","import { Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n","export interface EmscriptenFileSystem {\n writeFile(\n path: string,\n data: string | ArrayBufferView,\n opts?: { flags?: string | undefined }\n ): void;\n readdir(path: string): string[];\n mkdirTree(path: string, mode?: number);\n mkdir(path: string, mode?: number);\n}\n\nexport interface EmscriptenHeap {\n buffer: ArrayBufferLike;\n}\n\nexport interface EmscriptenModule {\n FS: EmscriptenFileSystem;\n HEAPU8: EmscriptenHeap;\n _malloc(size: number): number;\n}\n\nexport interface Vector<T> {\n size(): number;\n get(index: number): T;\n}\n\nexport interface DataSource {\n name: string;\n data: string;\n}\n\nexport interface ProtoTree {\n label: string;\n filter: string;\n start: number;\n length: number;\n data_source_idx: number;\n tree: Vector<ProtoTree>;\n}\n\nexport interface Frame {\n number: number;\n comments: Vector<string>;\n data_sources: Vector<DataSource>;\n tree: Vector<ProtoTree>;\n}\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\n\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n}\n\nexport interface DissectSessionConstructable {\n new (path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Returns the directory where plugins are stored\n *\n * @returns Path of the plugins directory\n */\n getPluginsDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * Reload lua plugins\n */\n reloadLuaPlugins(): boolean;\n\n /**\n * Clean up any memory associated with the lib\n */\n destroy(): void;\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n checkFilter(filter: string): CheckFilterResponse;\n\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -23,10 +23,12 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
23
23
  *
24
24
  * @param loader Loader function for the Emscripten module
25
25
  * @param overrides Overrides
26
- */ async init(loader, overrides = {}) {
26
+ */ async init(loader, overrides = {}, beforeInit = null) {
27
27
  if (this.initialized) return;
28
28
  this.lib = await loader(overrides);
29
29
  this.uploadDir = this.lib.getUploadDirectory();
30
+ this.pluginsDir = this.lib.getPluginsDirectory();
31
+ if (beforeInit !== null) await beforeInit(this.lib);
30
32
  this.lib.init();
31
33
  this.initialized = true;
32
34
  }
@@ -37,6 +39,13 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
37
39
  */ test_filter(filter) {
38
40
  return this.lib.checkFilter(filter);
39
41
  }
42
+ reload_lua_plugins() {
43
+ this.lib.reloadLuaPlugins();
44
+ }
45
+ add_plugin(name, data, opts = {}) {
46
+ const path = this.pluginsDir + "/" + name;
47
+ this.lib.FS.writeFile(path, data, opts);
48
+ }
40
49
  /**
41
50
  * Load a packet trace file for analysis.
42
51
  *
@@ -1 +1 @@
1
- {"mappings":";;;;;;ACQO,SAAS,0CAAiB,GAAc,EAAO;IACpD,OAAO,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAO,IAAI,GAAG,CAAC;AAC9D;;ADVA;;;;;AAeO,MAAM;IAMX,aAAc;QACZ,IAAI,CAAC,WAAW,GAAG,KAAK;QACxB,IAAI,CAAC,OAAO,GAAG,IA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AG,CAAC,OAAO;YAChB,IAAI,CAAC,WAAW,GAAG,KAAK;QAC1B,CAAC;IACH;IAEA;;GAEC,GACD,UAAoB;QAClB,MAAM,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU;QAE/B,oCAAoC;QACpC,OAAO,CAAA,GAAA,yCAAY,EAAE;IACvB;AACF","sources":["src/index.ts","src/utils.ts","src/types.ts"],"sourcesContent":["import {\n CheckFilterResponse,\n DissectSession,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\nimport { vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(loader: WiregasmLoader, overrides: WiregasmLibOverrides = {}) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.lib.init();\n this.initialized = true;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","import { Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n","export interface EmscriptenFileSystem {\n writeFile(\n path: string,\n data: string | ArrayBufferView,\n opts?: { flags?: string | undefined }\n ): void;\n readdir(path: string): string[];\n}\n\nexport interface EmscriptenHeap {\n buffer: ArrayBufferLike;\n}\n\nexport interface EmscriptenModule {\n FS: EmscriptenFileSystem;\n HEAPU8: EmscriptenHeap;\n _malloc(size: number): number;\n}\n\nexport interface Vector<T> {\n size(): number;\n get(index: number): T;\n}\n\nexport interface DataSource {\n name: string;\n data: string;\n}\n\nexport interface ProtoTree {\n label: string;\n filter: string;\n start: number;\n length: number;\n data_source_idx: number;\n tree: Vector<ProtoTree>;\n}\n\nexport interface Frame {\n number: number;\n comments: Vector<string>;\n data_sources: Vector<DataSource>;\n tree: Vector<ProtoTree>;\n}\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\n\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n}\n\nexport interface DissectSessionConstructable {\n new (path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * Clean up any memory associated with the lib\n */\n destroy(): void;\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n checkFilter(filter: string): CheckFilterResponse;\n\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;ACQO,SAAS,0CAAiB,GAAc,EAAO;IACpD,OAAO,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAO,IAAI,GAAG,CAAC;AAC9D;;ADVA;;;;;AAgBO,MAAM;IAOX,aAAc;QACZ,IAAI,CAAC,WAAW,GAAG,KAAK;QACxB,IAAI,CAAC,OAAO,GAAG,IAAI;IACrB;IAEA;;;;;GAKC,GACD,MAAM,KACJ,MAAsB,EACtB,YAAkC,CAAC,CAAC,EACpC,aAAiC,IAAI,EACrC;QACA,IAAI,IAAI,CAAC,WAAW,EAClB;QAGF,IAAI,CAAC,GAAG,GAAG,MAAM,OAAO;QACxB,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,CAAC,kBAAkB;QAC5C,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,GAAG,CAAC,mBAAmB;QAE9C,IAAI,eAAe,IAAI,EACrB,MAAM,WAAW,IAAI,CAAC,GAAG;QAG3B,IAAI,CAAC,GAAG,CAAC,IAAI;QACb,IAAI,CAAC,WAAW,GAAG,IAAI;IACzB;IAEA;;;;GAIC,GACD,YAAY,MAAc,EAAuB;QAC/C,OA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MAAM,IAAI,CAAC,GAAG,CAAC,UAAU;QAE/B,oCAAoC;QACpC,OAAO,CAAA,GAAA,yCAAY,EAAE;IACvB;AACF","sources":["src/index.ts","src/utils.ts","src/types.ts"],"sourcesContent":["import {\n CheckFilterResponse,\n DissectSession,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n BeforeInitCallback,\n} from \"./types\";\nimport { vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","import { Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n","export interface EmscriptenFileSystem {\n writeFile(\n path: string,\n data: string | ArrayBufferView,\n opts?: { flags?: string | undefined }\n ): void;\n readdir(path: string): string[];\n mkdirTree(path: string, mode?: number);\n mkdir(path: string, mode?: number);\n}\n\nexport interface EmscriptenHeap {\n buffer: ArrayBufferLike;\n}\n\nexport interface EmscriptenModule {\n FS: EmscriptenFileSystem;\n HEAPU8: EmscriptenHeap;\n _malloc(size: number): number;\n}\n\nexport interface Vector<T> {\n size(): number;\n get(index: number): T;\n}\n\nexport interface DataSource {\n name: string;\n data: string;\n}\n\nexport interface ProtoTree {\n label: string;\n filter: string;\n start: number;\n length: number;\n data_source_idx: number;\n tree: Vector<ProtoTree>;\n}\n\nexport interface Frame {\n number: number;\n comments: Vector<string>;\n data_sources: Vector<DataSource>;\n tree: Vector<ProtoTree>;\n}\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\n\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n}\n\nexport interface DissectSessionConstructable {\n new (path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Returns the directory where plugins are stored\n *\n * @returns Path of the plugins directory\n */\n getPluginsDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * Reload lua plugins\n */\n reloadLuaPlugins(): boolean;\n\n /**\n * Clean up any memory associated with the lib\n */\n destroy(): void;\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n checkFilter(filter: string): CheckFilterResponse;\n\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -3,6 +3,8 @@ export interface EmscriptenFileSystem {
3
3
  flags?: string | undefined;
4
4
  }): void;
5
5
  readdir(path: string): string[];
6
+ mkdirTree(path: string, mode?: number): any;
7
+ mkdir(path: string, mode?: number): any;
6
8
  }
7
9
  export interface EmscriptenHeap {
8
10
  buffer: ArrayBufferLike;
@@ -152,10 +154,20 @@ export interface WiregasmLib extends EmscriptenModule {
152
154
  * @returns Path of the directory
153
155
  */
154
156
  getUploadDirectory(): string;
157
+ /**
158
+ * Returns the directory where plugins are stored
159
+ *
160
+ * @returns Path of the plugins directory
161
+ */
162
+ getPluginsDirectory(): string;
155
163
  /**
156
164
  * Initialize the library, load preferences and register dissectors
157
165
  */
158
166
  init(): boolean;
167
+ /**
168
+ * Reload lua plugins
169
+ */
170
+ reloadLuaPlugins(): boolean;
159
171
  /**
160
172
  * Clean up any memory associated with the lib
161
173
  */
@@ -180,6 +192,7 @@ export interface WiregasmLib extends EmscriptenModule {
180
192
  upload(file_name: string, data_ptr: number, length: number): string;
181
193
  }
182
194
  export type WiregasmLoader = (overrides: WiregasmLibOverrides) => Promise<WiregasmLib>;
195
+ export type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;
183
196
  /**
184
197
  * Converts a Vector to a JS array
185
198
  *
@@ -195,6 +208,7 @@ export class Wiregasm {
195
208
  initialized: boolean;
196
209
  session: DissectSession | null;
197
210
  uploadDir: string;
211
+ pluginsDir: string;
198
212
  constructor();
199
213
  /**
200
214
  * Initialize the wrapper and the Wiregasm module
@@ -202,13 +216,15 @@ export class Wiregasm {
202
216
  * @param loader Loader function for the Emscripten module
203
217
  * @param overrides Overrides
204
218
  */
205
- init(loader: WiregasmLoader, overrides?: WiregasmLibOverrides): Promise<void>;
219
+ init(loader: WiregasmLoader, overrides?: WiregasmLibOverrides, beforeInit?: BeforeInitCallback): Promise<void>;
206
220
  /**
207
221
  * Check the validity of a filter expression.
208
222
  *
209
223
  * @param filter A display filter expression
210
224
  */
211
225
  test_filter(filter: string): CheckFilterResponse;
226
+ reload_lua_plugins(): void;
227
+ add_plugin(name: string, data: string | ArrayBufferView, opts?: object): void;
212
228
  /**
213
229
  * Load a packet trace file for analysis.
214
230
  *
@@ -1 +1 @@
1
- {"mappings":"AAAA;IACE,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GACpC,IAAI,CAAC;IACR,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAA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C;IAEhB;;OAEG;IACH,OAAO,IAAI,IAAI,CAAC;IAEhB;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB,CAAC;IAEjD;;OAEG;IACH,UAAU,IAAI,OAAO,MAAM,CAAC,CAAC;IAE7B;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACrE;AAED,6BAA6B,CAC3B,SAAS,EAAE,oBAAoB,KAC5B,OAAO,CAAC,WAAW,CAAC,CAAC;ACrN1B;;;;;GAKG;AACH,8BAA8B,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC,GAAG,CAAC,EAAE,CAEpD;ACED;;GAEG;AACH;IACE,GAAG,EAAE,WAAW,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,OAAO,EAAE,cAAc,GAAG,IAAI,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;;IAOlB;;;;;OAKG;IACG,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE,SAAS,GAAE,oBAAyB;IAWvE;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB;IAIhD;;;;OAIG;IACH,IAAI,CACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,GAAE,MAAW,GAChB,YAAY;IAaf;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,SAAI,EAAE,KAAK,SAAI,GAAG,cAAc;IAI3D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIzB,OAAO;IAYP;;OAEG;IACH,OAAO,IAAI,MAAM,EAAE;CAMpB","sources":["src/src/types.ts","src/src/utils.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,"import {\n CheckFilterResponse,\n DissectSession,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\nimport { vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(loader: WiregasmLoader, overrides: WiregasmLibOverrides = {}) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.lib.init();\n this.initialized = true;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n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,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;;IAOnB;;;;;OAKG;IACG,IAAI,CACR,MAAM,EAAE,cAAc,EACtB,SAAS,GAAE,oBAAyB,EACpC,UAAU,GAAE,kBAAyB;IAkBvC;;;;OAIG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB;IAIhD,kBAAkB;IAIlB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,IAAI,GAAE,MAAW;IAK1E;;;;OAIG;IACH,IAAI,CACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,GAAE,MAAW,GAChB,YAAY;IAaf;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,SAAI,EAAE,KAAK,SAAI,GAAG,cAAc;IAI3D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIzB,OAAO;IAYP;;OAEG;IACH,OAAO,IAAI,MAAM,EAAE;CAMpB","sources":["src/src/types.ts","src/src/utils.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,"import {\n CheckFilterResponse,\n DissectSession,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n BeforeInitCallback,\n} from \"./types\";\nimport { vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n"],"names":[],"version":3,"file":"types.d.ts.map"}