@goodtools/wiregasm 1.7.0 → 1.8.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/dist/main.js +25 -1
- package/dist/main.js.map +1 -1
- package/dist/module.js +25 -1
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +17 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/wiregasm.data.gz +0 -0
- package/dist/wiregasm.js +6 -0
- package/dist/wiregasm.wasm +0 -0
- package/dist/wiregasm.wasm.gz +0 -0
- package/package.json +1 -1
package/dist/main.js
CHANGED
|
@@ -78,6 +78,16 @@ function $9ba0f9a5c47c04f2$export$a6506e3cba6c4388(code) {
|
|
|
78
78
|
const $882b6d93070905b3$var$ALLOWED_TAP_KEYS = new Set(Array.from({
|
|
79
79
|
length: 15
|
|
80
80
|
}, (_, i)=>`tap${i}`));
|
|
81
|
+
const $882b6d93070905b3$var$ALLOWED_GRAPH_KEYS = new Set([
|
|
82
|
+
"filter",
|
|
83
|
+
"interval",
|
|
84
|
+
...Array.from({
|
|
85
|
+
length: 9
|
|
86
|
+
}, (_, i)=>`graph${i}`),
|
|
87
|
+
...Array.from({
|
|
88
|
+
length: 9
|
|
89
|
+
}, (_, i)=>`filter${i}`)
|
|
90
|
+
]);
|
|
81
91
|
class $882b6d93070905b3$export$c4e6ddb7806910b1 {
|
|
82
92
|
constructor(){
|
|
83
93
|
this.initialized = false;
|
|
@@ -135,7 +145,7 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
|
|
|
135
145
|
// Validate keys.
|
|
136
146
|
if (!("tap0" in taps)) throw new Error("tap0 is mandatory.");
|
|
137
147
|
if (!Object.keys(taps).every((k)=>$882b6d93070905b3$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);
|
|
138
|
-
const args = new this.lib.
|
|
148
|
+
const args = new this.lib.MapInput();
|
|
139
149
|
Object.entries(taps).forEach(([k, v])=>args.set(k, v));
|
|
140
150
|
const response = this.session.tap(args);
|
|
141
151
|
return {
|
|
@@ -168,6 +178,20 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
|
|
|
168
178
|
download(token) {
|
|
169
179
|
return this.session.download(token);
|
|
170
180
|
}
|
|
181
|
+
iograph(input) {
|
|
182
|
+
// Validate keys.
|
|
183
|
+
if (!("graph0" in input)) throw new Error("graph0 is mandatory.");
|
|
184
|
+
if (!Object.keys(input).every((k)=>$882b6d93070905b3$var$ALLOWED_GRAPH_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($882b6d93070905b3$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
|
|
185
|
+
const args = new this.lib.MapInput();
|
|
186
|
+
Object.entries(input).forEach(([k, v])=>args.set(k, v));
|
|
187
|
+
const out = this.session.iograph(args);
|
|
188
|
+
return {
|
|
189
|
+
...out,
|
|
190
|
+
iograph: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(out.iograph).map((t)=>({
|
|
191
|
+
items: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(t.items)
|
|
192
|
+
}))
|
|
193
|
+
};
|
|
194
|
+
}
|
|
171
195
|
reload_lua_plugins() {
|
|
172
196
|
this.lib.reloadLuaPlugins();
|
|
173
197
|
}
|
package/dist/main.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IA+BO;UAAK,aAAa;IAAb,cAAA,cACV,kBAAA,KAAA;IADU,cAAA,cAEV,0BAAA,KAAA;IAFU,cAAA,cAGV,4BAAA,KAAA;IAHU,cAAA,cAIV,wBAAA,KAAA;GAJU,8CAAA;IAOL;UAAK,QAAQ;IAAR,SAAA,SACV,eAAA,KAAA;IADU,SAAA,SAEV,eAAA,KAAA;IAFU,SAAA,SAGV,eAAA,KAAA;IAHU,SAAA,SAIV,iBAAA,KAAA;IAJU,SAAA,SAKV,gBAAA,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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;IAGA,UAAU,GAAQ,EAAkC;QAClD,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;IAEA,YAAY,GAAQ,EAA0B;QAC5C,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapInput,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n\nconst ALLOWED_TAP_KEYS = new Set(Array.from({ length: 15 }, (_, i) => `tap${i}`));\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 list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\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): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: TapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\")\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.TapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n }\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\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\n is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\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 enum PrefSetResult {\n PREFS_SET_OK, // succeeded\n PREFS_SET_SYNTAX_ERR, // syntax error in string\n PREFS_SET_NO_SUCH_PREF, // no such preference\n PREFS_SET_OBSOLETE, // preference used to exist but no longer does\n}\n\nexport enum PrefType {\n PREF_UINT = 1 << 0,\n PREF_BOOL = 1 << 1,\n PREF_ENUM = 1 << 2,\n PREF_STRING = 1 << 3,\n PREF_RANGE = 1 << 4,\n PREF_STATIC_TEXT = 1 << 5,\n PREF_UAT = 1 << 6,\n PREF_SAVE_FILENAME = 1 << 7,\n PREF_COLOR = 1 << 8, // These are only supported for \"internal\" (non-protocol)\n PREF_CUSTOM = 1 << 9, // use and not as a generic protocol preference\n PREF_OBSOLETE = 1 << 10,\n PREF_DIRNAME = 1 << 11,\n PREF_DECODE_AS_UINT = 1 << 12, // These are only supported for \"internal\" (non-protocol)\n PREF_DECODE_AS_RANGE = 1 << 13, // use and not as a generic protocol preference\n PREF_OPEN_FILENAME = 1 << 14,\n PREF_PASSWORD = 1 << 15, // like string, but never saved to prefs file\n}\n\nexport interface PrefModule {\n name: string;\n title: string;\n description: string;\n use_gui: boolean;\n submodules: Vector<PrefModule>;\n}\n\nexport interface PrefSetResponse {\n code: PrefSetResult;\n error: string;\n}\n\nexport interface PrefResponse {\n code: number;\n data: Pref;\n}\n\nexport interface Pref {\n name: string;\n title: string;\n description: string;\n\n type: PrefType;\n uint_value: number;\n uint_base_value: number;\n bool_value: boolean;\n string_value: string;\n range_value: 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\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}\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 Download {\n file: string;\n mime: string;\n data: string;\n}\n\nexport interface DownloadResponse {\n error: string;\n download: Download;\n}\n\nexport type TapInput = Record<string, string>;\n\ninterface ExportObject {\n hostname: string;\n pkt: number;\n type: string;\n filename: string;\n _download: string;\n len: number;\n}\n\n\nexport interface Conversation {\n saddr: string;\n daddr: string;\n sport: string;\n dport: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n start: number;\n stop: number;\n filter: string;\n}\n\nexport interface Host {\n host: string;\n port: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n filter: string;\n}\n\nexport interface TapResponseBase {\n type: string;\n tap: string;\n proto: string;\n}\n\nexport interface TapExportObjectResponse extends TapResponseBase {\n objects: Vector<ExportObject>;\n}\n\nexport interface TapConvResponse extends TapResponseBase {\n geoip: boolean;\n convs: Vector<Conversation>;\n hosts: Vector<Host>;\n}\n\nexport type TapResponse = TapExportObjectResponse | TapConvResponse;\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 tap(taps: Map<string, string>): {\n taps: Vector<TapResponse>;\n error: string;\n };\n\n download(token: string): DownloadResponse;\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 TapInput: MapConstructor;\n TapExportObject: () => TapExportObjectResponse;\n TapConvResponse: () => TapConvResponse;\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 * List all the preference modules\n * @returns List of preference modules\n */\n listModules(): Vector<PrefModule>;\n\n /**\n * List all the preferences for a given module\n *\n * @param module Preference module\n */\n listPreferences(module: string): Vector<Pref>;\n\n /**\n * Apply preferences\n */\n applyPreferences(): void;\n\n /**\n * Set a preference\n *\n * @param module Preference module\n * @param key Preference key\n * @param value Preference value\n */\n setPref(module: string, key: string, value: string): PrefSetResponse;\n\n /**\n * Get a preference\n *\n * @param module Preference module\n * @param key Preference key\n */\n getPref(module: string, key: string): PrefResponse;\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): { fields: Vector<CompleteField> };\n\n download(token: string): Download;\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","import { PrefSetResult, 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\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IA+BO;UAAK,aAAa;IAAb,cAAA,cACV,kBAAA,KAAA;IADU,cAAA,cAEV,0BAAA,KAAA;IAFU,cAAA,cAGV,4BAAA,KAAA;IAHU,cAAA,cAIV,wBAAA,KAAA;GAJU,8CAAA;IAOL;UAAK,QAAQ;IAAR,SAAA,SACV,eAAA,KAAA;IADU,SAAA,SAEV,eAAA,KAAA;IAFU,SAAA,SAGV,eAAA,KAAA;IAHU,SAAA,SAIV,iBAAA,KAAA;IAJU,SAAA,SAKV,gBAAA,MAAA;IALU,SAAA,SAMV,sBAAA,MAAA;IANU,SAAA,SAOV,cAAA,MAAA;IAPU,SAAA,SAQV,wBAAA,OAAA;IARU,SAAA,SASV,gBAAA,OAAA;IATU,SAAA,SAUV,iBAAA,OAAA;IAVU,SAAA,SAWV,mBAAA,QAAA;IAXU,SAAA,SAYV,kBAAA,QAAA;IAZU,SAAA,SAaV,yBAAA,QAAA;IAbU,SAAA,SAcV,0BAAA,QAAA;IAdU,SAAA,SAeV,wBAAA,SAAA;IAfU,SAAA,SAgBV,mBAAA,SAAA;GAhBU,8CAAA;;ADtCZ;;;;;AEAA;AAQO,SAAS,0CAAiB,GAAc,EAAO;IACpD,OAAO,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAO,IAAI,GAAG,CAA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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;IAEA,UAAU,GAAQ,EAAkC;QAClD,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;IAEA,YAAY,GAAQ,EAA0B;QAC5C,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n MapInput,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\nconst ALLOWED_TAP_KEYS = new Set(\n Array.from({ length: 15 }, (_, i) => `tap${i}`)\n);\n\nconst ALLOWED_GRAPH_KEYS = new Set(\n [\n \"filter\", \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\n ]\n);\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 list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\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): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: MapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\");\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.MapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n };\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\n }\n\n iograph(input: MapInput) {\n // Validate keys.\n if (!(\"graph0\" in input)) {\n throw new Error(\"graph0 is mandatory.\");\n }\n if (!Object.keys(input).every((k) => ALLOWED_GRAPH_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Allowed keys are: ${Array.from(ALLOWED_GRAPH_KEYS).join(\", \")}.`);\n }\n\n const args = new this.lib.MapInput();\n Object.entries(input).forEach(([k, v]) => args.set(k, v));\n\n const out = this.session.iograph(args);\n return {\n ...out,\n iograph: vectorToArray(out.iograph).map((t) => ({\n items: vectorToArray(t.items),\n })),\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 is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\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 enum PrefSetResult {\n PREFS_SET_OK, // succeeded\n PREFS_SET_SYNTAX_ERR, // syntax error in string\n PREFS_SET_NO_SUCH_PREF, // no such preference\n PREFS_SET_OBSOLETE, // preference used to exist but no longer does\n}\n\nexport enum PrefType {\n PREF_UINT = 1 << 0,\n PREF_BOOL = 1 << 1,\n PREF_ENUM = 1 << 2,\n PREF_STRING = 1 << 3,\n PREF_RANGE = 1 << 4,\n PREF_STATIC_TEXT = 1 << 5,\n PREF_UAT = 1 << 6,\n PREF_SAVE_FILENAME = 1 << 7,\n PREF_COLOR = 1 << 8, // These are only supported for \"internal\" (non-protocol)\n PREF_CUSTOM = 1 << 9, // use and not as a generic protocol preference\n PREF_OBSOLETE = 1 << 10,\n PREF_DIRNAME = 1 << 11,\n PREF_DECODE_AS_UINT = 1 << 12, // These are only supported for \"internal\" (non-protocol)\n PREF_DECODE_AS_RANGE = 1 << 13, // use and not as a generic protocol preference\n PREF_OPEN_FILENAME = 1 << 14,\n PREF_PASSWORD = 1 << 15, // like string, but never saved to prefs file\n}\n\nexport interface PrefModule {\n name: string;\n title: string;\n description: string;\n use_gui: boolean;\n submodules: Vector<PrefModule>;\n}\n\nexport interface PrefSetResponse {\n code: PrefSetResult;\n error: string;\n}\n\nexport interface PrefResponse {\n code: number;\n data: Pref;\n}\n\nexport interface Pref {\n name: string;\n title: string;\n description: string;\n\n type: PrefType;\n uint_value: number;\n uint_base_value: number;\n bool_value: boolean;\n string_value: string;\n range_value: 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\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}\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 Download {\n file: string;\n mime: string;\n data: string;\n}\n\nexport interface DownloadResponse {\n error: string;\n download: Download;\n}\n\nexport type MapInput = Record<string, string>;\n\ninterface ExportObject {\n hostname: string;\n pkt: number;\n type: string;\n filename: string;\n _download: string;\n len: number;\n}\n\nexport interface Conversation {\n saddr: string;\n daddr: string;\n sport: string;\n dport: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n start: number;\n stop: number;\n filter: string;\n}\n\nexport interface Host {\n host: string;\n port: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n filter: string;\n}\n\nexport interface TapResponseBase {\n type: string;\n tap: string;\n proto: string;\n}\n\nexport interface TapExportObjectResponse extends TapResponseBase {\n objects: Vector<ExportObject>;\n}\n\nexport interface TapConvResponse extends TapResponseBase {\n geoip: boolean;\n convs: Vector<Conversation>;\n hosts: Vector<Host>;\n}\n\nexport type TapResponse = TapExportObjectResponse | TapConvResponse;\n\n\nexport interface IoGraphResult {\n error: string;\n iograph: Vector<IoGraph>;\n}\n\nexport interface IoGraph {\n items: Vector<number>;\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 tap(taps: Map<string, string>): {\n taps: Vector<TapResponse>;\n error: string;\n };\n\n iograph(input: Map<string, string>): IoGraphResult;\n\n download(token: string): DownloadResponse;\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 MapInput: MapConstructor;\n TapExportObject: () => TapExportObjectResponse;\n TapConvResponse: () => TapConvResponse;\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 * List all the preference modules\n * @returns List of preference modules\n */\n listModules(): Vector<PrefModule>;\n\n /**\n * List all the preferences for a given module\n *\n * @param module Preference module\n */\n listPreferences(module: string): Vector<Pref>;\n\n /**\n * Apply preferences\n */\n applyPreferences(): void;\n\n /**\n * Set a preference\n *\n * @param module Preference module\n * @param key Preference key\n * @param value Preference value\n */\n setPref(module: string, key: string, value: string): PrefSetResponse;\n\n /**\n * Get a preference\n *\n * @param module Preference module\n * @param key Preference key\n */\n getPref(module: string, key: string): PrefResponse;\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): { fields: Vector<CompleteField> };\n\n download(token: string): Download;\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","import { PrefSetResult, 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\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
|
package/dist/module.js
CHANGED
|
@@ -60,6 +60,16 @@ function $fab42eb3dee39b5b$export$a6506e3cba6c4388(code) {
|
|
|
60
60
|
const $149c1bd638913645$var$ALLOWED_TAP_KEYS = new Set(Array.from({
|
|
61
61
|
length: 15
|
|
62
62
|
}, (_, i)=>`tap${i}`));
|
|
63
|
+
const $149c1bd638913645$var$ALLOWED_GRAPH_KEYS = new Set([
|
|
64
|
+
"filter",
|
|
65
|
+
"interval",
|
|
66
|
+
...Array.from({
|
|
67
|
+
length: 9
|
|
68
|
+
}, (_, i)=>`graph${i}`),
|
|
69
|
+
...Array.from({
|
|
70
|
+
length: 9
|
|
71
|
+
}, (_, i)=>`filter${i}`)
|
|
72
|
+
]);
|
|
63
73
|
class $149c1bd638913645$export$c4e6ddb7806910b1 {
|
|
64
74
|
constructor(){
|
|
65
75
|
this.initialized = false;
|
|
@@ -117,7 +127,7 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
|
|
|
117
127
|
// Validate keys.
|
|
118
128
|
if (!("tap0" in taps)) throw new Error("tap0 is mandatory.");
|
|
119
129
|
if (!Object.keys(taps).every((k)=>$149c1bd638913645$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);
|
|
120
|
-
const args = new this.lib.
|
|
130
|
+
const args = new this.lib.MapInput();
|
|
121
131
|
Object.entries(taps).forEach(([k, v])=>args.set(k, v));
|
|
122
132
|
const response = this.session.tap(args);
|
|
123
133
|
return {
|
|
@@ -150,6 +160,20 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
|
|
|
150
160
|
download(token) {
|
|
151
161
|
return this.session.download(token);
|
|
152
162
|
}
|
|
163
|
+
iograph(input) {
|
|
164
|
+
// Validate keys.
|
|
165
|
+
if (!("graph0" in input)) throw new Error("graph0 is mandatory.");
|
|
166
|
+
if (!Object.keys(input).every((k)=>$149c1bd638913645$var$ALLOWED_GRAPH_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($149c1bd638913645$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
|
|
167
|
+
const args = new this.lib.MapInput();
|
|
168
|
+
Object.entries(input).forEach(([k, v])=>args.set(k, v));
|
|
169
|
+
const out = this.session.iograph(args);
|
|
170
|
+
return {
|
|
171
|
+
...out,
|
|
172
|
+
iograph: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(out.iograph).map((t)=>({
|
|
173
|
+
items: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(t.items)
|
|
174
|
+
}))
|
|
175
|
+
};
|
|
176
|
+
}
|
|
153
177
|
reload_lua_plugins() {
|
|
154
178
|
this.lib.reloadLuaPlugins();
|
|
155
179
|
}
|
package/dist/module.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;ACAA,IA+BO;UAAK,aAAa;IAAb,cAAA,cACV,kBAAA,KAAA;IADU,cAAA,cAEV,0BAAA,KAAA;IAFU,cAAA,cAGV,4BAAA,KAAA;IAHU,cAAA,cAIV,wBAAA,KAAA;GAJU,8CAAA;IAOL;UAAK,QAAQ;IAAR,SAAA,SACV,eAAA,KAAA;IADU,SAAA,SAEV,eAAA,KAAA;IAFU,SAAA,SAGV,eAAA,KAAA;IAHU,SAAA,SAIV,iBAAA,KAAA;IAJU,SAAA,SAKV,gBAAA,MAAA;IALU,SAAA,SAMV,sBAAA,MAAA;IANU,SAAA,SAOV,cAAA,MAAA;IAPU,SAAA,SAQV,wBAAA,OAAA;IARU,SAAA,SASV,gBAAA,OAAA;IATU,SAAA,SAUV,iBAAA,OAAA;IAVU,SAAA,SAWV,mBAAA,QAAA;IAXU,SAAA,SAYV,kBAAA,QAAA;IAZU,SAAA,SAaV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AA,GAAA,yCAAY,EAAE;IACvB;IAGA,UAAU,GAAQ,EAAkC;QAClD,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;IAEA,YAAY,GAAQ,EAA0B;QAC5C,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapInput,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n\nconst ALLOWED_TAP_KEYS = new Set(Array.from({ length: 15 }, (_, i) => `tap${i}`));\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 list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\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): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: TapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\")\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.TapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n }\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\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\n is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\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 enum PrefSetResult {\n PREFS_SET_OK, // succeeded\n PREFS_SET_SYNTAX_ERR, // syntax error in string\n PREFS_SET_NO_SUCH_PREF, // no such preference\n PREFS_SET_OBSOLETE, // preference used to exist but no longer does\n}\n\nexport enum PrefType {\n PREF_UINT = 1 << 0,\n PREF_BOOL = 1 << 1,\n PREF_ENUM = 1 << 2,\n PREF_STRING = 1 << 3,\n PREF_RANGE = 1 << 4,\n PREF_STATIC_TEXT = 1 << 5,\n PREF_UAT = 1 << 6,\n PREF_SAVE_FILENAME = 1 << 7,\n PREF_COLOR = 1 << 8, // These are only supported for \"internal\" (non-protocol)\n PREF_CUSTOM = 1 << 9, // use and not as a generic protocol preference\n PREF_OBSOLETE = 1 << 10,\n PREF_DIRNAME = 1 << 11,\n PREF_DECODE_AS_UINT = 1 << 12, // These are only supported for \"internal\" (non-protocol)\n PREF_DECODE_AS_RANGE = 1 << 13, // use and not as a generic protocol preference\n PREF_OPEN_FILENAME = 1 << 14,\n PREF_PASSWORD = 1 << 15, // like string, but never saved to prefs file\n}\n\nexport interface PrefModule {\n name: string;\n title: string;\n description: string;\n use_gui: boolean;\n submodules: Vector<PrefModule>;\n}\n\nexport interface PrefSetResponse {\n code: PrefSetResult;\n error: string;\n}\n\nexport interface PrefResponse {\n code: number;\n data: Pref;\n}\n\nexport interface Pref {\n name: string;\n title: string;\n description: string;\n\n type: PrefType;\n uint_value: number;\n uint_base_value: number;\n bool_value: boolean;\n string_value: string;\n range_value: 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\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}\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 Download {\n file: string;\n mime: string;\n data: string;\n}\n\nexport interface DownloadResponse {\n error: string;\n download: Download;\n}\n\nexport type TapInput = Record<string, string>;\n\ninterface ExportObject {\n hostname: string;\n pkt: number;\n type: string;\n filename: string;\n _download: string;\n len: number;\n}\n\n\nexport interface Conversation {\n saddr: string;\n daddr: string;\n sport: string;\n dport: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n start: number;\n stop: number;\n filter: string;\n}\n\nexport interface Host {\n host: string;\n port: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n filter: string;\n}\n\nexport interface TapResponseBase {\n type: string;\n tap: string;\n proto: string;\n}\n\nexport interface TapExportObjectResponse extends TapResponseBase {\n objects: Vector<ExportObject>;\n}\n\nexport interface TapConvResponse extends TapResponseBase {\n geoip: boolean;\n convs: Vector<Conversation>;\n hosts: Vector<Host>;\n}\n\nexport type TapResponse = TapExportObjectResponse | TapConvResponse;\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 tap(taps: Map<string, string>): {\n taps: Vector<TapResponse>;\n error: string;\n };\n\n download(token: string): DownloadResponse;\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 TapInput: MapConstructor;\n TapExportObject: () => TapExportObjectResponse;\n TapConvResponse: () => TapConvResponse;\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 * List all the preference modules\n * @returns List of preference modules\n */\n listModules(): Vector<PrefModule>;\n\n /**\n * List all the preferences for a given module\n *\n * @param module Preference module\n */\n listPreferences(module: string): Vector<Pref>;\n\n /**\n * Apply preferences\n */\n applyPreferences(): void;\n\n /**\n * Set a preference\n *\n * @param module Preference module\n * @param key Preference key\n * @param value Preference value\n */\n setPref(module: string, key: string, value: string): PrefSetResponse;\n\n /**\n * Get a preference\n *\n * @param module Preference module\n * @param key Preference key\n */\n getPref(module: string, key: string): PrefResponse;\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): { fields: Vector<CompleteField> };\n\n download(token: string): Download;\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","import { PrefSetResult, 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\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;ACAA,IA+BO;UAAK,aAAa;IAAb,cAAA,cACV,kBAAA,KAAA;IADU,cAAA,cAEV,0BAAA,KAAA;IAFU,cAAA,cAGV,4BAAA,KAAA;IAHU,cAAA,cAIV,wBAAA,KAAA;GAJU,8CAAA;IAOL;UAAK,QAAQ;IAAR,SAAA,SACV,eAAA,KAAA;IADU,SAAA,SAEV,eAAA,KAAA;IAFU,SAAA,SAGV,eAAA,KAAA;IAHU,SAAA,SAIV,iBAAA,KAAA;IAJU,SAAA,SAKV,gBAAA,MAAA;IALU,SAAA,SAMV,sBAAA,MAAA;IANU,SAAA,SAOV,cAAA,MAAA;IAPU,SAAA,SAQV,wBAAA,OAAA;IARU,SAAA,SASV,gBAAA,OAAA;IATU,SAAA,SAUV,iBAAA,OAAA;IAVU,SAAA,SAWV,mBAAA,QAAA;IAXU,SAAA,SAYV,kBAAA,QAAA;IAZU,SAAA,SAaV,yBAAA,QAAA;IAbU,SAAA,SAcV,0BAAA,QAAA;IAdU,SAAA,SAeV,wBAAA,SAAA;IAfU,SAAA,SAgBV,mBAAA,SAAA;GAhBU,8CAAA;;ADtCZ;;;;;AEAA;AAQO,SAAS,0CAAiB,GAAc,EAAO;IACpD,OAAO,IAAI,MAAM,IAAI,IAAI,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,KAAO,IAAI,GAAG,CAAC;AAC9D;AAEO,SAAS,0CAAyB,IAAY,EAAU;IAC7D,OAAQ;QACN,KAAK,CAAA,GAAA,yCAAa,AAAD,EAAE,oBAAoB;YACrC,OAAO;QACT,KAAK,CAAA,GAAA,yCAAa,AAAD,EAAE,sBAAsB;YACvC,OAAO;QACT,KAAK,CAAA,GAAA,yCAAa,AAAD,EAAE,kBAAkB;YACnC,OAAO;QACT;YACE,OA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C,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;IAEA,UAAU,GAAQ,EAAkC;QAClD,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;IAEA,YAAY,GAAQ,EAA0B;QAC5C,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n MapInput,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\nconst ALLOWED_TAP_KEYS = new Set(\n Array.from({ length: 15 }, (_, i) => `tap${i}`)\n);\n\nconst ALLOWED_GRAPH_KEYS = new Set(\n [\n \"filter\", \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\n ]\n);\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 list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\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): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: MapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\");\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.MapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n };\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\n }\n\n iograph(input: MapInput) {\n // Validate keys.\n if (!(\"graph0\" in input)) {\n throw new Error(\"graph0 is mandatory.\");\n }\n if (!Object.keys(input).every((k) => ALLOWED_GRAPH_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Allowed keys are: ${Array.from(ALLOWED_GRAPH_KEYS).join(\", \")}.`);\n }\n\n const args = new this.lib.MapInput();\n Object.entries(input).forEach(([k, v]) => args.set(k, v));\n\n const out = this.session.iograph(args);\n return {\n ...out,\n iograph: vectorToArray(out.iograph).map((t) => ({\n items: vectorToArray(t.items),\n })),\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 is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\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 enum PrefSetResult {\n PREFS_SET_OK, // succeeded\n PREFS_SET_SYNTAX_ERR, // syntax error in string\n PREFS_SET_NO_SUCH_PREF, // no such preference\n PREFS_SET_OBSOLETE, // preference used to exist but no longer does\n}\n\nexport enum PrefType {\n PREF_UINT = 1 << 0,\n PREF_BOOL = 1 << 1,\n PREF_ENUM = 1 << 2,\n PREF_STRING = 1 << 3,\n PREF_RANGE = 1 << 4,\n PREF_STATIC_TEXT = 1 << 5,\n PREF_UAT = 1 << 6,\n PREF_SAVE_FILENAME = 1 << 7,\n PREF_COLOR = 1 << 8, // These are only supported for \"internal\" (non-protocol)\n PREF_CUSTOM = 1 << 9, // use and not as a generic protocol preference\n PREF_OBSOLETE = 1 << 10,\n PREF_DIRNAME = 1 << 11,\n PREF_DECODE_AS_UINT = 1 << 12, // These are only supported for \"internal\" (non-protocol)\n PREF_DECODE_AS_RANGE = 1 << 13, // use and not as a generic protocol preference\n PREF_OPEN_FILENAME = 1 << 14,\n PREF_PASSWORD = 1 << 15, // like string, but never saved to prefs file\n}\n\nexport interface PrefModule {\n name: string;\n title: string;\n description: string;\n use_gui: boolean;\n submodules: Vector<PrefModule>;\n}\n\nexport interface PrefSetResponse {\n code: PrefSetResult;\n error: string;\n}\n\nexport interface PrefResponse {\n code: number;\n data: Pref;\n}\n\nexport interface Pref {\n name: string;\n title: string;\n description: string;\n\n type: PrefType;\n uint_value: number;\n uint_base_value: number;\n bool_value: boolean;\n string_value: string;\n range_value: 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\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}\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 Download {\n file: string;\n mime: string;\n data: string;\n}\n\nexport interface DownloadResponse {\n error: string;\n download: Download;\n}\n\nexport type MapInput = Record<string, string>;\n\ninterface ExportObject {\n hostname: string;\n pkt: number;\n type: string;\n filename: string;\n _download: string;\n len: number;\n}\n\nexport interface Conversation {\n saddr: string;\n daddr: string;\n sport: string;\n dport: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n start: number;\n stop: number;\n filter: string;\n}\n\nexport interface Host {\n host: string;\n port: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n filter: string;\n}\n\nexport interface TapResponseBase {\n type: string;\n tap: string;\n proto: string;\n}\n\nexport interface TapExportObjectResponse extends TapResponseBase {\n objects: Vector<ExportObject>;\n}\n\nexport interface TapConvResponse extends TapResponseBase {\n geoip: boolean;\n convs: Vector<Conversation>;\n hosts: Vector<Host>;\n}\n\nexport type TapResponse = TapExportObjectResponse | TapConvResponse;\n\n\nexport interface IoGraphResult {\n error: string;\n iograph: Vector<IoGraph>;\n}\n\nexport interface IoGraph {\n items: Vector<number>;\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 tap(taps: Map<string, string>): {\n taps: Vector<TapResponse>;\n error: string;\n };\n\n iograph(input: Map<string, string>): IoGraphResult;\n\n download(token: string): DownloadResponse;\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 MapInput: MapConstructor;\n TapExportObject: () => TapExportObjectResponse;\n TapConvResponse: () => TapConvResponse;\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 * List all the preference modules\n * @returns List of preference modules\n */\n listModules(): Vector<PrefModule>;\n\n /**\n * List all the preferences for a given module\n *\n * @param module Preference module\n */\n listPreferences(module: string): Vector<Pref>;\n\n /**\n * Apply preferences\n */\n applyPreferences(): void;\n\n /**\n * Set a preference\n *\n * @param module Preference module\n * @param key Preference key\n * @param value Preference value\n */\n setPref(module: string, key: string, value: string): PrefSetResponse;\n\n /**\n * Get a preference\n *\n * @param module Preference module\n * @param key Preference key\n */\n getPref(module: string, key: string): PrefResponse;\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): { fields: Vector<CompleteField> };\n\n download(token: string): Download;\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","import { PrefSetResult, 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\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
|
package/dist/types.d.ts
CHANGED
|
@@ -146,7 +146,7 @@ export interface DownloadResponse {
|
|
|
146
146
|
error: string;
|
|
147
147
|
download: Download;
|
|
148
148
|
}
|
|
149
|
-
export type
|
|
149
|
+
export type MapInput = Record<string, string>;
|
|
150
150
|
interface ExportObject {
|
|
151
151
|
hostname: string;
|
|
152
152
|
pkt: number;
|
|
@@ -191,6 +191,13 @@ export interface TapConvResponse extends TapResponseBase {
|
|
|
191
191
|
hosts: Vector<Host>;
|
|
192
192
|
}
|
|
193
193
|
export type TapResponse = TapExportObjectResponse | TapConvResponse;
|
|
194
|
+
export interface IoGraphResult {
|
|
195
|
+
error: string;
|
|
196
|
+
iograph: Vector<IoGraph>;
|
|
197
|
+
}
|
|
198
|
+
export interface IoGraph {
|
|
199
|
+
items: Vector<number>;
|
|
200
|
+
}
|
|
194
201
|
export interface DissectSession {
|
|
195
202
|
/**
|
|
196
203
|
* Free up any memory used by the session
|
|
@@ -221,6 +228,7 @@ export interface DissectSession {
|
|
|
221
228
|
taps: Vector<TapResponse>;
|
|
222
229
|
error: string;
|
|
223
230
|
};
|
|
231
|
+
iograph(input: Map<string, string>): IoGraphResult;
|
|
224
232
|
download(token: string): DownloadResponse;
|
|
225
233
|
}
|
|
226
234
|
export interface DissectSessionConstructable {
|
|
@@ -281,7 +289,7 @@ export interface WiregasmLibOverrides {
|
|
|
281
289
|
}
|
|
282
290
|
export interface WiregasmLib extends EmscriptenModule {
|
|
283
291
|
DissectSession: DissectSessionConstructable;
|
|
284
|
-
|
|
292
|
+
MapInput: MapConstructor;
|
|
285
293
|
TapExportObject: () => TapExportObjectResponse;
|
|
286
294
|
TapConvResponse: () => TapConvResponse;
|
|
287
295
|
/**
|
|
@@ -402,11 +410,17 @@ export class Wiregasm {
|
|
|
402
410
|
complete_filter(filter: string): {
|
|
403
411
|
fields: CompleteField[];
|
|
404
412
|
};
|
|
405
|
-
tap(taps:
|
|
413
|
+
tap(taps: MapInput): {
|
|
406
414
|
error: string;
|
|
407
415
|
taps: any[];
|
|
408
416
|
};
|
|
409
417
|
download(token: string): DownloadResponse;
|
|
418
|
+
iograph(input: MapInput): {
|
|
419
|
+
iograph: {
|
|
420
|
+
items: number[];
|
|
421
|
+
}[];
|
|
422
|
+
error: string;
|
|
423
|
+
};
|
|
410
424
|
reload_lua_plugins(): void;
|
|
411
425
|
add_plugin(name: string, data: string | ArrayBufferView, opts?: object): void;
|
|
412
426
|
/**
|
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;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,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;CACvB;AAED;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;IACE,YAAY,IAAA;IACZ,oBAAoB,IAAA;IACpB,sBAAsB,IAAA;IACtB,kBAAkB,IAAA;CACnB;AAED;IACE,SAAS,IAAS;IAClB,SAAS,IAAS;IAClB,SAAS,IAAS;IAClB,WAAW,IAAS;IACpB,UAAU,KAAS;IACnB,gBAAgB,KAAS;IACzB,QAAQ,KAAS;IACjB,kBAAkB,MAAS;IAC3B,UAAU,MAAS;IACn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,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;IAQnB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,uBAAuB;IAInD,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,eAAe;CAG9C","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 DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapInput,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n\nconst ALLOWED_TAP_KEYS = new Set(Array.from({ length: 15 }, (_, i) => `tap${i}`));\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 list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\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): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: TapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\")\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.TapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n }\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\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\n is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils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,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;IAOnB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,uBAAuB;IAInD,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,eAAe;CAG9C","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 DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n MapInput,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\nconst ALLOWED_TAP_KEYS = new Set(\n Array.from({ length: 15 }, (_, i) => `tap${i}`)\n);\n\nconst ALLOWED_GRAPH_KEYS = new Set(\n [\n \"filter\", \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\n ]\n);\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 list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\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): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: MapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\");\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.MapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n };\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\n }\n\n iograph(input: MapInput) {\n // Validate keys.\n if (!(\"graph0\" in input)) {\n throw new Error(\"graph0 is mandatory.\");\n }\n if (!Object.keys(input).every((k) => ALLOWED_GRAPH_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Allowed keys are: ${Array.from(ALLOWED_GRAPH_KEYS).join(\", \")}.`);\n }\n\n const args = new this.lib.MapInput();\n Object.entries(input).forEach(([k, v]) => args.set(k, v));\n\n const out = this.session.iograph(args);\n return {\n ...out,\n iograph: vectorToArray(out.iograph).map((t) => ({\n items: vectorToArray(t.items),\n })),\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 is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
package/dist/wiregasm.data.gz
CHANGED
|
Binary file
|
package/dist/wiregasm.js
CHANGED
|
@@ -9044,6 +9044,12 @@ var dynCall_dii = Module["dynCall_dii"] = createExportWrapper("dynCall_dii");
|
|
|
9044
9044
|
/** @type {function(...*):?} */
|
|
9045
9045
|
var dynCall_viid = Module["dynCall_viid"] = createExportWrapper("dynCall_viid");
|
|
9046
9046
|
/** @type {function(...*):?} */
|
|
9047
|
+
var dynCall_viif = Module["dynCall_viif"] = createExportWrapper("dynCall_viif");
|
|
9048
|
+
/** @type {function(...*):?} */
|
|
9049
|
+
var dynCall_viiif = Module["dynCall_viiif"] = createExportWrapper("dynCall_viiif");
|
|
9050
|
+
/** @type {function(...*):?} */
|
|
9051
|
+
var dynCall_iiiif = Module["dynCall_iiiif"] = createExportWrapper("dynCall_iiiif");
|
|
9052
|
+
/** @type {function(...*):?} */
|
|
9047
9053
|
var dynCall_iiiiiii = Module["dynCall_iiiiiii"] = createExportWrapper("dynCall_iiiiiii");
|
|
9048
9054
|
/** @type {function(...*):?} */
|
|
9049
9055
|
var dynCall_vid = Module["dynCall_vid"] = createExportWrapper("dynCall_vid");
|
package/dist/wiregasm.wasm
CHANGED
|
Binary file
|
package/dist/wiregasm.wasm.gz
CHANGED
|
Binary file
|