@goodtools/wiregasm 1.2.0 → 1.4.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 +15 -0
- package/dist/main.js +20 -1
- package/dist/main.js.map +1 -1
- package/dist/module.js +20 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +50 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/wiregasm.data +1089 -1
- package/dist/wiregasm.data.gz +0 -0
- package/dist/wiregasm.js +101 -26
- package/dist/wiregasm.wasm +0 -0
- package/dist/wiregasm.wasm.gz +0 -0
- package/package.json +1 -1
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,20 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
|
|
|
55
57
|
*/ test_filter(filter) {
|
|
56
58
|
return this.lib.checkFilter(filter);
|
|
57
59
|
}
|
|
60
|
+
complete_filter(filter) {
|
|
61
|
+
const out = this.lib.completeFilter(filter);
|
|
62
|
+
return {
|
|
63
|
+
err: out.err,
|
|
64
|
+
fields: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(out.fields)
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
reload_lua_plugins() {
|
|
68
|
+
this.lib.reloadLuaPlugins();
|
|
69
|
+
}
|
|
70
|
+
add_plugin(name, data, opts = {}) {
|
|
71
|
+
const path = this.pluginsDir + "/" + name;
|
|
72
|
+
this.lib.FS.writeFile(path, data, opts);
|
|
73
|
+
}
|
|
58
74
|
/**
|
|
59
75
|
* Load a packet trace file for analysis.
|
|
60
76
|
*
|
|
@@ -82,6 +98,9 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
|
|
|
82
98
|
*/ frame(num) {
|
|
83
99
|
return this.session.getFrame(num);
|
|
84
100
|
}
|
|
101
|
+
follow(follow, filter) {
|
|
102
|
+
return this.session.follow(follow, filter);
|
|
103
|
+
}
|
|
85
104
|
destroy() {
|
|
86
105
|
if (this.initialized) {
|
|
87
106
|
if (this.session !== null) {
|
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,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAO,IAAI,GAAG,CAAC;AAC9D;;ADVA;;;;;AAmBO,MAAM;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AAS,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,OAAO,MAAc,EAAE,MAAc,EAAU;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;IACrC;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 BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\n\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 complete_filter(filter: string): { err: string; fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n err: out.err,\n fields: vectorToArray(out.fields),\n };\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 follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\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 type: \"proto\" | \"url\" | \"framenum\" | \"\";\n url?: string;\n fnum?: 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 follow: Vector<Vector<string>>\n}\n\nexport interface CompleteField {\n field: string;\n type: string;\n name: string;\n}\n\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FollowPayload {\n number: number;\n server: number;\n data: string;\n}\n\nexport interface Follow {\n shost: string;\n sport: string;\n sbytes: number;\n chost: string;\n cport: string;\n cbytes: number;\n payloads: Vector<FollowPayload>;\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 follow(follow: string, filter: string): Follow;\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 completeFilter(filter: string): { err: string; fields: Vector<CompleteField> };\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,20 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
|
|
|
37
39
|
*/ test_filter(filter) {
|
|
38
40
|
return this.lib.checkFilter(filter);
|
|
39
41
|
}
|
|
42
|
+
complete_filter(filter) {
|
|
43
|
+
const out = this.lib.completeFilter(filter);
|
|
44
|
+
return {
|
|
45
|
+
err: out.err,
|
|
46
|
+
fields: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(out.fields)
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
reload_lua_plugins() {
|
|
50
|
+
this.lib.reloadLuaPlugins();
|
|
51
|
+
}
|
|
52
|
+
add_plugin(name, data, opts = {}) {
|
|
53
|
+
const path = this.pluginsDir + "/" + name;
|
|
54
|
+
this.lib.FS.writeFile(path, data, opts);
|
|
55
|
+
}
|
|
40
56
|
/**
|
|
41
57
|
* Load a packet trace file for analysis.
|
|
42
58
|
*
|
|
@@ -64,6 +80,9 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
|
|
|
64
80
|
*/ frame(num) {
|
|
65
81
|
return this.session.getFrame(num);
|
|
66
82
|
}
|
|
83
|
+
follow(follow, filter) {
|
|
84
|
+
return this.session.follow(follow, filter);
|
|
85
|
+
}
|
|
67
86
|
destroy() {
|
|
68
87
|
if (this.initialized) {
|
|
69
88
|
if (this.session !== null) {
|
package/dist/module.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;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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":"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;;;;;AAmBO,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,I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,OAAO,MAAc,EAAE,MAAc,EAAU;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;IACrC;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 BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\n\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 complete_filter(filter: string): { err: string; fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n err: out.err,\n fields: vectorToArray(out.fields),\n };\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 follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\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 type: \"proto\" | \"url\" | \"framenum\" | \"\";\n url?: string;\n fnum?: 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 follow: Vector<Vector<string>>\n}\n\nexport interface CompleteField {\n field: string;\n type: string;\n name: string;\n}\n\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FollowPayload {\n number: number;\n server: number;\n data: string;\n}\n\nexport interface Follow {\n shost: string;\n sport: string;\n sbytes: number;\n chost: string;\n cport: string;\n cbytes: number;\n payloads: Vector<FollowPayload>;\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 follow(follow: string, filter: string): Follow;\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 completeFilter(filter: string): { err: string; fields: Vector<CompleteField> };\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;
|
|
@@ -26,6 +28,9 @@ export interface ProtoTree {
|
|
|
26
28
|
start: number;
|
|
27
29
|
length: number;
|
|
28
30
|
data_source_idx: number;
|
|
31
|
+
type: "proto" | "url" | "framenum" | "";
|
|
32
|
+
url?: string;
|
|
33
|
+
fnum?: number;
|
|
29
34
|
tree: Vector<ProtoTree>;
|
|
30
35
|
}
|
|
31
36
|
export interface Frame {
|
|
@@ -33,11 +38,31 @@ export interface Frame {
|
|
|
33
38
|
comments: Vector<string>;
|
|
34
39
|
data_sources: Vector<DataSource>;
|
|
35
40
|
tree: Vector<ProtoTree>;
|
|
41
|
+
follow: Vector<Vector<string>>;
|
|
42
|
+
}
|
|
43
|
+
export interface CompleteField {
|
|
44
|
+
field: string;
|
|
45
|
+
type: string;
|
|
46
|
+
name: string;
|
|
36
47
|
}
|
|
37
48
|
export interface FramesResponse {
|
|
38
49
|
frames: Vector<FrameMeta>;
|
|
39
50
|
matched: number;
|
|
40
51
|
}
|
|
52
|
+
export interface FollowPayload {
|
|
53
|
+
number: number;
|
|
54
|
+
server: number;
|
|
55
|
+
data: string;
|
|
56
|
+
}
|
|
57
|
+
export interface Follow {
|
|
58
|
+
shost: string;
|
|
59
|
+
sport: string;
|
|
60
|
+
sbytes: number;
|
|
61
|
+
chost: string;
|
|
62
|
+
cport: string;
|
|
63
|
+
cbytes: number;
|
|
64
|
+
payloads: Vector<FollowPayload>;
|
|
65
|
+
}
|
|
41
66
|
export interface FrameMeta {
|
|
42
67
|
number: number;
|
|
43
68
|
comments: boolean;
|
|
@@ -87,6 +112,7 @@ export interface DissectSession {
|
|
|
87
112
|
* @param number Frame number
|
|
88
113
|
*/
|
|
89
114
|
getFrame(number: number): Frame;
|
|
115
|
+
follow(follow: string, filter: string): Follow;
|
|
90
116
|
}
|
|
91
117
|
export interface DissectSessionConstructable {
|
|
92
118
|
new (path: string): DissectSession;
|
|
@@ -152,10 +178,20 @@ export interface WiregasmLib extends EmscriptenModule {
|
|
|
152
178
|
* @returns Path of the directory
|
|
153
179
|
*/
|
|
154
180
|
getUploadDirectory(): string;
|
|
181
|
+
/**
|
|
182
|
+
* Returns the directory where plugins are stored
|
|
183
|
+
*
|
|
184
|
+
* @returns Path of the plugins directory
|
|
185
|
+
*/
|
|
186
|
+
getPluginsDirectory(): string;
|
|
155
187
|
/**
|
|
156
188
|
* Initialize the library, load preferences and register dissectors
|
|
157
189
|
*/
|
|
158
190
|
init(): boolean;
|
|
191
|
+
/**
|
|
192
|
+
* Reload lua plugins
|
|
193
|
+
*/
|
|
194
|
+
reloadLuaPlugins(): boolean;
|
|
159
195
|
/**
|
|
160
196
|
* Clean up any memory associated with the lib
|
|
161
197
|
*/
|
|
@@ -166,6 +202,10 @@ export interface WiregasmLib extends EmscriptenModule {
|
|
|
166
202
|
* @param filter A display filter expression
|
|
167
203
|
*/
|
|
168
204
|
checkFilter(filter: string): CheckFilterResponse;
|
|
205
|
+
completeFilter(filter: string): {
|
|
206
|
+
err: string;
|
|
207
|
+
fields: Vector<CompleteField>;
|
|
208
|
+
};
|
|
169
209
|
/**
|
|
170
210
|
* Returns the column headers
|
|
171
211
|
*/
|
|
@@ -180,6 +220,7 @@ export interface WiregasmLib extends EmscriptenModule {
|
|
|
180
220
|
upload(file_name: string, data_ptr: number, length: number): string;
|
|
181
221
|
}
|
|
182
222
|
export type WiregasmLoader = (overrides: WiregasmLibOverrides) => Promise<WiregasmLib>;
|
|
223
|
+
export type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;
|
|
183
224
|
/**
|
|
184
225
|
* Converts a Vector to a JS array
|
|
185
226
|
*
|
|
@@ -195,6 +236,7 @@ export class Wiregasm {
|
|
|
195
236
|
initialized: boolean;
|
|
196
237
|
session: DissectSession | null;
|
|
197
238
|
uploadDir: string;
|
|
239
|
+
pluginsDir: string;
|
|
198
240
|
constructor();
|
|
199
241
|
/**
|
|
200
242
|
* Initialize the wrapper and the Wiregasm module
|
|
@@ -202,13 +244,19 @@ export class Wiregasm {
|
|
|
202
244
|
* @param loader Loader function for the Emscripten module
|
|
203
245
|
* @param overrides Overrides
|
|
204
246
|
*/
|
|
205
|
-
init(loader: WiregasmLoader, overrides?: WiregasmLibOverrides): Promise<void>;
|
|
247
|
+
init(loader: WiregasmLoader, overrides?: WiregasmLibOverrides, beforeInit?: BeforeInitCallback): Promise<void>;
|
|
206
248
|
/**
|
|
207
249
|
* Check the validity of a filter expression.
|
|
208
250
|
*
|
|
209
251
|
* @param filter A display filter expression
|
|
210
252
|
*/
|
|
211
253
|
test_filter(filter: string): CheckFilterResponse;
|
|
254
|
+
complete_filter(filter: string): {
|
|
255
|
+
err: string;
|
|
256
|
+
fields: CompleteField[];
|
|
257
|
+
};
|
|
258
|
+
reload_lua_plugins(): void;
|
|
259
|
+
add_plugin(name: string, data: string | ArrayBufferView, opts?: object): void;
|
|
212
260
|
/**
|
|
213
261
|
* Load a packet trace file for analysis.
|
|
214
262
|
*
|
|
@@ -229,6 +277,7 @@ export class Wiregasm {
|
|
|
229
277
|
* @param number Frame number
|
|
230
278
|
*/
|
|
231
279
|
frame(num: number): Frame;
|
|
280
|
+
follow(follow: string, filter: string): Follow;
|
|
232
281
|
destroy(): void;
|
|
233
282
|
/**
|
|
234
283
|
* Returns the column headers
|
package/dist/types.d.ts.map
CHANGED
|
@@ -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,CAAC;
|
|
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,CAAC;IAChC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,OAAE;IACvC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,OAAE;CACpC;AAED;IACE,MAAM,EAAE,eAAe,CAAC;CACzB;AAED;IACE,EAAE,EAAE,oBAAoB,CAAC;IACzB,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAED,wBAAwB,CAAC;IACvB,IAAI,IAAI,MAAM,CAAC;IACf,G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pD;ACMD;;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;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,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,aAAa,EAAE,CAAA;KAAE;IAQzE,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,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAI9C,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 BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\n\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 complete_filter(filter: string): { err: string; fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n err: out.err,\n fields: vectorToArray(out.fields),\n };\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 follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\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"}
|