@goodtools/wiregasm 1.9.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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,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,GA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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 ...Array.from({ length: 15 }, (_, i) => `filter${i}`),\n]);\n\nconst ALLOWED_GRAPH_KEYS = new Set([\n \"filter\",\n \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\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\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n if (!this.lib.init()) {\n throw new Error(\"Failed to initialize Wiregasm\");\n }\n\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_GRAPH_KEYS\n ).join(\", \")}.`\n );\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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_GRAPH_KEYS\n ).join(\", \")}.`\n );\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\n conv_id: number;\n start_abs_time: number;\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\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 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 version of the library\n *\n * @returns Version string\n */\n wiresharkVersion(): string;\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":";;;;;;;;;;;;;;;;;;;;;AAAA,4CAA4C;;;;;ACA5C,4CAA4C;AAC5C,IAiCO;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,SAg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AuB;IACvD;IAEA;;;;;;GAMC,GACD,oBAAoB,SAAiB,EAAE,OAAgB,EAAW;QAChE,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,WAAW;IACjD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["// SPDX-License-Identifier: GPL-2.0-or-later\nimport {\n type BeforeInitCallback,\n type CheckFilterResponse,\n type CompleteField,\n type DissectSession,\n type DownloadResponse,\n type Follow,\n type Frame,\n type FramesResponse,\n type IoGraphResult,\n type HeuristicInfo,\n type LoadResponse,\n type MapInput,\n type Pref,\n type PrefModule,\n PrefSetResult,\n type ProtocolInfo,\n type TapConvResponse,\n type TapExportObjectResponse,\n type TapResponse,\n type Vector,\n type WiregasmLib,\n type WiregasmLibOverrides,\n type WiregasmLoader,\n} from \"./types\";\nimport { free, preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\nconst ALLOWED_TAP_KEYS = new Set([\n ...Array.from({ length: 15 }, (_, i) => `tap${i}`),\n ...Array.from({ length: 15 }, (_, i) => `filter${i}`),\n]);\n\nconst ALLOWED_GRAPH_KEYS = new Set([\n \"filter\",\n \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\n]);\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n // Set by init(); using the wrapper before init() is a programming error.\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 = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n if (!this.lib.init()) {\n throw new Error(\"Failed to initialize Wiregasm\");\n }\n\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n this.initialized = true;\n }\n\n listModules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n listPrefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n applyPrefs() {\n this.lib.applyPreferences();\n }\n\n setPref(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 getPref(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 testFilter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n completeFilter(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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_TAP_KEYS\n ).join(\", \")}.`\n );\n }\n\n const session = this.loadedSession();\n const args = new this.lib.MapInput();\n for (const [k, v] of Object.entries(taps)) {\n args.set(k, v);\n }\n\n let response: ReturnType<DissectSession[\"tap\"]>;\n try {\n response = session.tap(args);\n } finally {\n free(args);\n }\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n // biome-ignore lint/suspicious/noExplicitAny: keeps the public return type of tap() unchanged\n let res: any;\n if (this.isConvTap(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.isEoTap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n };\n } else {\n free(tap);\n throw new Error(\"Unknown tap result\");\n }\n free(tap);\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.loadedSession().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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_GRAPH_KEYS\n ).join(\", \")}.`\n );\n }\n\n const session = this.loadedSession();\n const args = new this.lib.MapInput();\n for (const [k, v] of Object.entries(input)) {\n args.set(k, v);\n }\n\n let out: IoGraphResult;\n try {\n out = session.iograph(args);\n } finally {\n free(args);\n }\n return {\n ...out,\n iograph: vectorToArray(out.iograph).map((t) => ({\n items: vectorToArray(t.items),\n })),\n };\n }\n\n reloadLuaPlugins() {\n this.lib.reloadLuaPlugins();\n }\n\n addPlugin(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 const response = this.session.load();\n if (response.code !== 0) {\n // Don't keep a session for a file that failed to open.\n this.session.delete();\n this.session = null;\n }\n return response;\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.loadedSession().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.loadedSession().getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.loadedSession().follow(follow, filter);\n }\n\n private loadedSession(): DissectSession {\n if (this.session === null) {\n throw new Error(\"No capture file loaded, call load() first.\");\n }\n return this.session;\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 isEoTap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n isConvTap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n\n // Protocol enable/disable methods\n\n /**\n * List all registered protocols\n *\n * @returns Array of all protocols with their enabled state\n */\n listProtocols(): ProtocolInfo[] {\n return vectorToArray(this.lib.listProtocols());\n }\n\n /**\n * Enable or disable a protocol by its ID\n *\n * @param protoId Protocol ID\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabled(protoId: number, enabled: boolean): boolean {\n return this.lib.setProtocolEnabled(protoId, enabled);\n }\n\n /**\n * Enable or disable a protocol by its filter name\n *\n * @param protoName Protocol filter name (e.g., \"tcp\", \"udp\")\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabledByName(protoName: string, enabled: boolean): boolean {\n return this.lib.setProtocolEnabledByName(protoName, enabled);\n }\n\n // Heuristic dissector enable/disable methods\n\n /**\n * List all registered heuristic dissectors\n *\n * @returns Array of all heuristic dissectors with their enabled state\n */\n listHeuristicDissectors(): HeuristicInfo[] {\n return vectorToArray(this.lib.listHeuristicDissectors());\n }\n\n /**\n * Enable or disable a heuristic dissector by its unique short name\n *\n * @param shortName Unique short name of the heuristic dissector (e.g., \"mac_nr_udp\")\n * @param enabled Whether to enable or disable the heuristic\n * @returns true if successful, false otherwise\n */\n setHeuristicEnabled(shortName: string, enabled: boolean): boolean {\n return this.lib.setHeuristicEnabled(shortName, enabled);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","// SPDX-License-Identifier: GPL-2.0-or-later\nexport 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): void;\n mkdir(path: string, mode?: number): void;\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 /** Frees the vector on the wasm heap (embind handle). */\n delete(): void;\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 PREF_PROTO_TCP_SNDAMB_ENUM = 1 << 16,\n PREF_DISSECTOR = 1 << 17, // like string, but with dissector name syntax check\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\n conv_id: number;\n start_abs_time: number;\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\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 IoGraphResult {\n error: string;\n iograph: Vector<IoGraph>;\n}\n\nexport interface IoGraph {\n items: Vector<number>;\n}\n\nexport interface ProtocolInfo {\n id: number;\n name: string;\n long_name: string;\n enabled: boolean;\n enabled_by_default: boolean;\n can_toggle: boolean;\n}\n\nexport interface HeuristicInfo {\n short_name: string;\n display_name: string;\n list_name: string;\n protocol_name: string;\n protocol_id: number; // protocol ID this heuristic belongs to (-1 if none)\n enabled: boolean;\n enabled_by_default: boolean;\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 version of the library\n *\n * @returns Version string\n */\n wiresharkVersion(): string;\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 // Protocol enable/disable functions\n\n /**\n * List all registered protocols\n *\n * @returns List of all protocols with their enabled state\n */\n listProtocols(): Vector<ProtocolInfo>;\n\n /**\n * Enable or disable a protocol by its ID\n *\n * @param protoId Protocol ID\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabled(protoId: number, enabled: boolean): boolean;\n\n /**\n * Enable or disable a protocol by its filter name\n *\n * @param protoName Protocol filter name (e.g., \"tcp\", \"udp\")\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabledByName(protoName: string, enabled: boolean): boolean;\n\n // Heuristic dissector enable/disable functions\n\n /**\n * List all registered heuristic dissectors\n *\n * @returns List of all heuristic dissectors with their enabled state\n */\n listHeuristicDissectors(): Vector<HeuristicInfo>;\n\n /**\n * Enable or disable a heuristic dissector by its unique short name\n *\n * @param shortName Unique short name of the heuristic dissector (e.g., \"mac_nr_udp\")\n * @param enabled Whether to enable or disable the heuristic\n * @returns true if successful, false otherwise\n */\n setHeuristicEnabled(shortName: string, enabled: boolean): boolean;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n","// SPDX-License-Identifier: GPL-2.0-or-later\nimport { PrefSetResult, type Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array and frees the Vector\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n try {\n return Array.from({ length: vec.size() }, (_, i) => vec.get(i));\n } finally {\n // the elements are copied out; free the vector on the wasm heap\n vec.delete();\n }\n}\n\n/**\n * Frees an embind object (class instance, vector or map) on the wasm heap.\n */\nexport function free(handle: unknown): void {\n (handle as { delete(): void }).delete();\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","sourceRoot":"../"}
package/dist/module.js CHANGED
@@ -1,18 +1,20 @@
1
1
  function $parcel$export(e, n, v, s) {
2
2
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
3
3
  }
4
- var $81c1b644006d48ec$exports = {};
4
+ // SPDX-License-Identifier: GPL-2.0-or-later
5
+ var $922ca3010d5b156c$exports = {};
5
6
 
6
- $parcel$export($81c1b644006d48ec$exports, "PrefSetResult", () => $81c1b644006d48ec$export$9511720e10589113);
7
- $parcel$export($81c1b644006d48ec$exports, "PrefType", () => $81c1b644006d48ec$export$eeff8db21dc74b3d);
8
- let $81c1b644006d48ec$export$9511720e10589113;
7
+ $parcel$export($922ca3010d5b156c$exports, "PrefSetResult", () => $922ca3010d5b156c$export$9511720e10589113);
8
+ $parcel$export($922ca3010d5b156c$exports, "PrefType", () => $922ca3010d5b156c$export$eeff8db21dc74b3d);
9
+ // SPDX-License-Identifier: GPL-2.0-or-later
10
+ let $922ca3010d5b156c$export$9511720e10589113;
9
11
  (function(PrefSetResult) {
10
12
  PrefSetResult[PrefSetResult["PREFS_SET_OK"] = 0] = "PREFS_SET_OK";
11
13
  PrefSetResult[PrefSetResult["PREFS_SET_SYNTAX_ERR"] = 1] = "PREFS_SET_SYNTAX_ERR";
12
14
  PrefSetResult[PrefSetResult["PREFS_SET_NO_SUCH_PREF"] = 2] = "PREFS_SET_NO_SUCH_PREF";
13
15
  PrefSetResult[PrefSetResult["PREFS_SET_OBSOLETE"] = 3] = "PREFS_SET_OBSOLETE";
14
- })($81c1b644006d48ec$export$9511720e10589113 || ($81c1b644006d48ec$export$9511720e10589113 = {}));
15
- let $81c1b644006d48ec$export$eeff8db21dc74b3d;
16
+ })($922ca3010d5b156c$export$9511720e10589113 || ($922ca3010d5b156c$export$9511720e10589113 = {}));
17
+ let $922ca3010d5b156c$export$eeff8db21dc74b3d;
16
18
  (function(PrefType) {
17
19
  PrefType[PrefType["PREF_UINT"] = 1] = "PREF_UINT";
18
20
  PrefType[PrefType["PREF_BOOL"] = 2] = "PREF_BOOL";
@@ -30,24 +32,38 @@ let $81c1b644006d48ec$export$eeff8db21dc74b3d;
30
32
  PrefType[PrefType["PREF_DECODE_AS_RANGE"] = 8192] = "PREF_DECODE_AS_RANGE";
31
33
  PrefType[PrefType["PREF_OPEN_FILENAME"] = 16384] = "PREF_OPEN_FILENAME";
32
34
  PrefType[PrefType["PREF_PASSWORD"] = 32768] = "PREF_PASSWORD";
33
- })($81c1b644006d48ec$export$eeff8db21dc74b3d || ($81c1b644006d48ec$export$eeff8db21dc74b3d = {}));
35
+ PrefType[PrefType["PREF_PROTO_TCP_SNDAMB_ENUM"] = 65536] = "PREF_PROTO_TCP_SNDAMB_ENUM";
36
+ PrefType[PrefType["PREF_DISSECTOR"] = 131072] = "PREF_DISSECTOR";
37
+ })($922ca3010d5b156c$export$eeff8db21dc74b3d || ($922ca3010d5b156c$export$eeff8db21dc74b3d = {}));
34
38
 
35
39
 
36
- var $fab42eb3dee39b5b$exports = {};
40
+ var $06475149eda1d309$exports = {};
37
41
 
38
- $parcel$export($fab42eb3dee39b5b$exports, "vectorToArray", () => $fab42eb3dee39b5b$export$4b978bcb0889dc66);
39
- $parcel$export($fab42eb3dee39b5b$exports, "preferenceSetCodeToError", () => $fab42eb3dee39b5b$export$a6506e3cba6c4388);
42
+ $parcel$export($06475149eda1d309$exports, "vectorToArray", () => $06475149eda1d309$export$4b978bcb0889dc66);
43
+ $parcel$export($06475149eda1d309$exports, "free", () => $06475149eda1d309$export$13e2de3c33d99539);
44
+ $parcel$export($06475149eda1d309$exports, "preferenceSetCodeToError", () => $06475149eda1d309$export$a6506e3cba6c4388);
45
+ // SPDX-License-Identifier: GPL-2.0-or-later
40
46
 
41
- function $fab42eb3dee39b5b$export$4b978bcb0889dc66(vec) {
42
- return new Array(vec.size()).fill(0).map((_, id)=>vec.get(id));
47
+ function $06475149eda1d309$export$4b978bcb0889dc66(vec) {
48
+ try {
49
+ return Array.from({
50
+ length: vec.size()
51
+ }, (_, i)=>vec.get(i));
52
+ } finally{
53
+ // the elements are copied out; free the vector on the wasm heap
54
+ vec.delete();
55
+ }
56
+ }
57
+ function $06475149eda1d309$export$13e2de3c33d99539(handle) {
58
+ handle.delete();
43
59
  }
44
- function $fab42eb3dee39b5b$export$a6506e3cba6c4388(code) {
60
+ function $06475149eda1d309$export$a6506e3cba6c4388(code) {
45
61
  switch(code){
46
- case (0, $81c1b644006d48ec$export$9511720e10589113).PREFS_SET_SYNTAX_ERR:
62
+ case (0, $922ca3010d5b156c$export$9511720e10589113).PREFS_SET_SYNTAX_ERR:
47
63
  return "Syntax error in string";
48
- case (0, $81c1b644006d48ec$export$9511720e10589113).PREFS_SET_NO_SUCH_PREF:
64
+ case (0, $922ca3010d5b156c$export$9511720e10589113).PREFS_SET_NO_SUCH_PREF:
49
65
  return "No such preference";
50
- case (0, $81c1b644006d48ec$export$9511720e10589113).PREFS_SET_OBSOLETE:
66
+ case (0, $922ca3010d5b156c$export$9511720e10589113).PREFS_SET_OBSOLETE:
51
67
  return "Preference used to exist but no longer does";
52
68
  default:
53
69
  return "Unknown error";
@@ -57,7 +73,7 @@ function $fab42eb3dee39b5b$export$a6506e3cba6c4388(code) {
57
73
 
58
74
 
59
75
 
60
- const $149c1bd638913645$var$ALLOWED_TAP_KEYS = new Set([
76
+ const $f9eab8d5ad8ec090$var$ALLOWED_TAP_KEYS = new Set([
61
77
  ...Array.from({
62
78
  length: 15
63
79
  }, (_, i)=>`tap${i}`),
@@ -65,7 +81,7 @@ const $149c1bd638913645$var$ALLOWED_TAP_KEYS = new Set([
65
81
  length: 15
66
82
  }, (_, i)=>`filter${i}`)
67
83
  ]);
68
- const $149c1bd638913645$var$ALLOWED_GRAPH_KEYS = new Set([
84
+ const $f9eab8d5ad8ec090$var$ALLOWED_GRAPH_KEYS = new Set([
69
85
  "filter",
70
86
  "interval",
71
87
  ...Array.from({
@@ -75,7 +91,7 @@ const $149c1bd638913645$var$ALLOWED_GRAPH_KEYS = new Set([
75
91
  length: 9
76
92
  }, (_, i)=>`filter${i}`)
77
93
  ]);
78
- class $149c1bd638913645$export$c4e6ddb7806910b1 {
94
+ class $f9eab8d5ad8ec090$export$c4e6ddb7806910b1 {
79
95
  constructor(){
80
96
  this.initialized = false;
81
97
  this.session = null;
@@ -94,96 +110,109 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
94
110
  this.pluginsDir = this.lib.getPluginsDirectory();
95
111
  this.initialized = true;
96
112
  }
97
- list_modules() {
113
+ listModules() {
98
114
  return this.lib.listModules();
99
115
  }
100
- list_prefs(module) {
116
+ listPrefs(module) {
101
117
  return this.lib.listPreferences(module);
102
118
  }
103
- apply_prefs() {
119
+ applyPrefs() {
104
120
  this.lib.applyPreferences();
105
121
  }
106
- set_pref(module, key, value) {
122
+ setPref(module, key, value) {
107
123
  const ret = this.lib.setPref(module, key, value);
108
- if (ret.code != (0, $81c1b644006d48ec$export$9511720e10589113).PREFS_SET_OK) {
109
- const message = ret.error != "" ? ret.error : (0, $fab42eb3dee39b5b$export$a6506e3cba6c4388)(ret.code);
124
+ if (ret.code !== (0, $922ca3010d5b156c$export$9511720e10589113).PREFS_SET_OK) {
125
+ const message = ret.error !== "" ? ret.error : (0, $06475149eda1d309$export$a6506e3cba6c4388)(ret.code);
110
126
  throw new Error(`Failed to set preference (${module}.${key}): ${message}`);
111
127
  }
112
128
  }
113
- get_pref(module, key) {
129
+ getPref(module, key) {
114
130
  const response = this.lib.getPref(module, key);
115
- if (response.code != 0) throw new Error(`Failed to get preference (${module}.${key})`);
131
+ if (response.code !== 0) throw new Error(`Failed to get preference (${module}.${key})`);
116
132
  return response.data;
117
133
  }
118
134
  /**
119
135
  * Check the validity of a filter expression.
120
136
  *
121
137
  * @param filter A display filter expression
122
- */ test_filter(filter) {
138
+ */ testFilter(filter) {
123
139
  return this.lib.checkFilter(filter);
124
140
  }
125
- complete_filter(filter) {
141
+ completeFilter(filter) {
126
142
  const out = this.lib.completeFilter(filter);
127
143
  return {
128
- fields: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(out.fields)
144
+ fields: (0, $06475149eda1d309$export$4b978bcb0889dc66)(out.fields)
129
145
  };
130
146
  }
131
147
  tap(taps) {
132
148
  // Validate keys.
133
149
  if (!("tap0" in taps)) throw new Error("tap0 is mandatory.");
134
- if (!Object.keys(taps).every((k)=>$149c1bd638913645$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($149c1bd638913645$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
150
+ if (!Object.keys(taps).every((k)=>$f9eab8d5ad8ec090$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($f9eab8d5ad8ec090$var$ALLOWED_TAP_KEYS).join(", ")}.`);
151
+ const session = this.loadedSession();
135
152
  const args = new this.lib.MapInput();
136
- Object.entries(taps).forEach(([k, v])=>args.set(k, v));
137
- const response = this.session.tap(args);
153
+ for (const [k, v] of Object.entries(taps))args.set(k, v);
154
+ let response;
155
+ try {
156
+ response = session.tap(args);
157
+ } finally{
158
+ (0, $06475149eda1d309$export$13e2de3c33d99539)(args);
159
+ }
138
160
  return {
139
161
  error: response.error,
140
- taps: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(response.taps).map((tap)=>{
162
+ taps: (0, $06475149eda1d309$export$4b978bcb0889dc66)(response.taps).map((tap)=>{
163
+ // biome-ignore lint/suspicious/noExplicitAny: keeps the public return type of tap() unchanged
141
164
  let res;
142
- if (this.is_conv_tap(tap)) res = {
165
+ if (this.isConvTap(tap)) res = {
143
166
  proto: tap.proto,
144
167
  tap: tap.tap,
145
168
  type: tap.type,
146
169
  geoip: tap.geoip,
147
- convs: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(tap.convs),
148
- hosts: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(tap.hosts)
170
+ convs: (0, $06475149eda1d309$export$4b978bcb0889dc66)(tap.convs),
171
+ hosts: (0, $06475149eda1d309$export$4b978bcb0889dc66)(tap.hosts)
149
172
  };
150
- else if (this.is_eo_tap(tap)) res = {
173
+ else if (this.isEoTap(tap)) res = {
151
174
  proto: tap.proto,
152
175
  tap: tap.tap,
153
176
  type: tap.type,
154
- objects: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(tap.objects)
177
+ objects: (0, $06475149eda1d309$export$4b978bcb0889dc66)(tap.objects)
155
178
  };
156
179
  else {
157
- tap.delete();
180
+ (0, $06475149eda1d309$export$13e2de3c33d99539)(tap);
158
181
  throw new Error("Unknown tap result");
159
182
  }
160
- tap.delete();
183
+ (0, $06475149eda1d309$export$13e2de3c33d99539)(tap);
161
184
  return res;
162
185
  })
163
186
  };
164
187
  }
165
188
  download(token) {
166
- return this.session.download(token);
189
+ return this.loadedSession().download(token);
167
190
  }
168
191
  iograph(input) {
169
192
  // Validate keys.
170
193
  if (!("graph0" in input)) throw new Error("graph0 is mandatory.");
171
- 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(", ")}.`);
194
+ if (!Object.keys(input).every((k)=>$f9eab8d5ad8ec090$var$ALLOWED_GRAPH_KEYS.has(k))) throw new Error(`Invalid arguments. Allowed keys are: ${Array.from($f9eab8d5ad8ec090$var$ALLOWED_GRAPH_KEYS).join(", ")}.`);
195
+ const session = this.loadedSession();
172
196
  const args = new this.lib.MapInput();
173
- Object.entries(input).forEach(([k, v])=>args.set(k, v));
174
- const out = this.session.iograph(args);
197
+ for (const [k, v] of Object.entries(input))args.set(k, v);
198
+ let out;
199
+ try {
200
+ out = session.iograph(args);
201
+ } finally{
202
+ (0, $06475149eda1d309$export$13e2de3c33d99539)(args);
203
+ }
175
204
  return {
176
205
  ...out,
177
- iograph: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(out.iograph).map((t)=>({
178
- items: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(t.items)
206
+ iograph: (0, $06475149eda1d309$export$4b978bcb0889dc66)(out.iograph).map((t)=>({
207
+ items: (0, $06475149eda1d309$export$4b978bcb0889dc66)(t.items)
179
208
  }))
180
209
  };
181
210
  }
182
- reload_lua_plugins() {
211
+ reloadLuaPlugins() {
183
212
  this.lib.reloadLuaPlugins();
184
213
  }
185
- add_plugin(name, data, opts = {}) {
186
- const path = this.pluginsDir + "/" + name;
214
+ addPlugin(name, data, opts = {}) {
215
+ const path = `${this.pluginsDir}/${name}`;
187
216
  this.lib.FS.writeFile(path, data, opts);
188
217
  }
189
218
  /**
@@ -192,10 +221,16 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
192
221
  * @returns Response containing the status and summary
193
222
  */ load(name, data, opts = {}) {
194
223
  if (this.session != null) this.session.delete();
195
- const path = this.uploadDir + "/" + name;
224
+ const path = `${this.uploadDir}/${name}`;
196
225
  this.lib.FS.writeFile(path, data, opts);
197
226
  this.session = new this.lib.DissectSession(path);
198
- return this.session.load();
227
+ const response = this.session.load();
228
+ if (response.code !== 0) {
229
+ // Don't keep a session for a file that failed to open.
230
+ this.session.delete();
231
+ this.session = null;
232
+ }
233
+ return response;
199
234
  }
200
235
  /**
201
236
  * Get Packet List information for a range of packets.
@@ -204,17 +239,21 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
204
239
  * @param skip Skip N frames
205
240
  * @param limit Limit the output to N frames
206
241
  */ frames(filter, skip = 0, limit = 0) {
207
- return this.session.getFrames(filter, skip, limit);
242
+ return this.loadedSession().getFrames(filter, skip, limit);
208
243
  }
209
244
  /**
210
245
  * Get full information about a frame including the protocol tree.
211
246
  *
212
247
  * @param number Frame number
213
248
  */ frame(num) {
214
- return this.session.getFrame(num);
249
+ return this.loadedSession().getFrame(num);
215
250
  }
216
251
  follow(follow, filter) {
217
- return this.session.follow(follow, filter);
252
+ return this.loadedSession().follow(follow, filter);
253
+ }
254
+ loadedSession() {
255
+ if (this.session === null) throw new Error("No capture file loaded, call load() first.");
256
+ return this.session;
218
257
  }
219
258
  destroy() {
220
259
  if (this.initialized) {
@@ -231,16 +270,59 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
231
270
  */ columns() {
232
271
  const vec = this.lib.getColumns();
233
272
  // convert it from a vector to array
234
- return (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(vec);
273
+ return (0, $06475149eda1d309$export$4b978bcb0889dc66)(vec);
235
274
  }
236
- is_eo_tap(tap) {
275
+ isEoTap(tap) {
237
276
  return tap instanceof this.lib.TapExportObject;
238
277
  }
239
- is_conv_tap(tap) {
278
+ isConvTap(tap) {
240
279
  return tap instanceof this.lib.TapConvResponse;
241
280
  }
281
+ // Protocol enable/disable methods
282
+ /**
283
+ * List all registered protocols
284
+ *
285
+ * @returns Array of all protocols with their enabled state
286
+ */ listProtocols() {
287
+ return (0, $06475149eda1d309$export$4b978bcb0889dc66)(this.lib.listProtocols());
288
+ }
289
+ /**
290
+ * Enable or disable a protocol by its ID
291
+ *
292
+ * @param protoId Protocol ID
293
+ * @param enabled Whether to enable or disable the protocol
294
+ * @returns true if successful, false otherwise
295
+ */ setProtocolEnabled(protoId, enabled) {
296
+ return this.lib.setProtocolEnabled(protoId, enabled);
297
+ }
298
+ /**
299
+ * Enable or disable a protocol by its filter name
300
+ *
301
+ * @param protoName Protocol filter name (e.g., "tcp", "udp")
302
+ * @param enabled Whether to enable or disable the protocol
303
+ * @returns true if successful, false otherwise
304
+ */ setProtocolEnabledByName(protoName, enabled) {
305
+ return this.lib.setProtocolEnabledByName(protoName, enabled);
306
+ }
307
+ // Heuristic dissector enable/disable methods
308
+ /**
309
+ * List all registered heuristic dissectors
310
+ *
311
+ * @returns Array of all heuristic dissectors with their enabled state
312
+ */ listHeuristicDissectors() {
313
+ return (0, $06475149eda1d309$export$4b978bcb0889dc66)(this.lib.listHeuristicDissectors());
314
+ }
315
+ /**
316
+ * Enable or disable a heuristic dissector by its unique short name
317
+ *
318
+ * @param shortName Unique short name of the heuristic dissector (e.g., "mac_nr_udp")
319
+ * @param enabled Whether to enable or disable the heuristic
320
+ * @returns true if successful, false otherwise
321
+ */ setHeuristicEnabled(shortName, enabled) {
322
+ return this.lib.setHeuristicEnabled(shortName, enabled);
323
+ }
242
324
  }
243
325
 
244
326
 
245
- export {$149c1bd638913645$export$c4e6ddb7806910b1 as Wiregasm, $81c1b644006d48ec$export$9511720e10589113 as PrefSetResult, $81c1b644006d48ec$export$eeff8db21dc74b3d as PrefType, $fab42eb3dee39b5b$export$4b978bcb0889dc66 as vectorToArray, $fab42eb3dee39b5b$export$a6506e3cba6c4388 as preferenceSetCodeToError};
327
+ export {$f9eab8d5ad8ec090$export$c4e6ddb7806910b1 as Wiregasm, $922ca3010d5b156c$export$9511720e10589113 as PrefSetResult, $922ca3010d5b156c$export$eeff8db21dc74b3d as PrefType, $06475149eda1d309$export$4b978bcb0889dc66 as vectorToArray, $06475149eda1d309$export$13e2de3c33d99539 as free, $06475149eda1d309$export$a6506e3cba6c4388 as preferenceSetCodeToError};
246
328
  //# sourceMappingURL=module.js.map
@@ -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,yBAAA,QAAA;IAbU,SAAA,SAcV,0BAAA,QAAA;IAdU,SAAA,SAeV,wBAAA,SAAA;IAfU,SAAA,SAgBV,mBAAA,SAAA;GA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;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 ...Array.from({ length: 15 }, (_, i) => `filter${i}`),\n]);\n\nconst ALLOWED_GRAPH_KEYS = new Set([\n \"filter\",\n \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\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\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n if (!this.lib.init()) {\n throw new Error(\"Failed to initialize Wiregasm\");\n }\n\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_GRAPH_KEYS\n ).join(\", \")}.`\n );\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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_GRAPH_KEYS\n ).join(\", \")}.`\n );\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\n conv_id: number;\n start_abs_time: number;\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\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 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 version of the library\n *\n * @returns Version string\n */\n wiresharkVersion(): string;\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":";;;AAAA,4CAA4C;;;;;ACA5C,4CAA4C;AAC5C,IAiCO;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;IA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AEA;;;;;;GAMC,GACD,mBAAmB,OAAe,EAAE,OAAgB,EAAW;QAC7D,OAAO,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,SAAS;IAC9C;IAEA;;;;;;GAMC,GACD,yBAAyB,SAAiB,EAAE,OAAgB,EAAW;QACrE,OAAO,IAAI,CAAC,GAAG,CAAC,wBAAwB,CAAC,WAAW;IACtD;IAEA,6CAA6C;IAE7C;;;;GAIC,GACD,0BAA2C;QACzC,OAAO,CAAA,GAAA,yCAAY,EAAE,IAAI,CAAC,GAAG,CAAC,uBAAuB;IACvD;IAEA;;;;;;GAMC,GACD,oBAAoB,SAAiB,EAAE,OAAgB,EAAW;QAChE,OAAO,IAAI,CAAC,GAAG,CAAC,mBAAmB,CAAC,WAAW;IACjD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["// SPDX-License-Identifier: GPL-2.0-or-later\nimport {\n type BeforeInitCallback,\n type CheckFilterResponse,\n type CompleteField,\n type DissectSession,\n type DownloadResponse,\n type Follow,\n type Frame,\n type FramesResponse,\n type IoGraphResult,\n type HeuristicInfo,\n type LoadResponse,\n type MapInput,\n type Pref,\n type PrefModule,\n PrefSetResult,\n type ProtocolInfo,\n type TapConvResponse,\n type TapExportObjectResponse,\n type TapResponse,\n type Vector,\n type WiregasmLib,\n type WiregasmLibOverrides,\n type WiregasmLoader,\n} from \"./types\";\nimport { free, preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\nconst ALLOWED_TAP_KEYS = new Set([\n ...Array.from({ length: 15 }, (_, i) => `tap${i}`),\n ...Array.from({ length: 15 }, (_, i) => `filter${i}`),\n]);\n\nconst ALLOWED_GRAPH_KEYS = new Set([\n \"filter\",\n \"interval\",\n ...Array.from({ length: 9 }, (_, i) => `graph${i}`),\n ...Array.from({ length: 9 }, (_, i) => `filter${i}`),\n]);\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n // Set by init(); using the wrapper before init() is a programming error.\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 = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n if (!this.lib.init()) {\n throw new Error(\"Failed to initialize Wiregasm\");\n }\n\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n this.initialized = true;\n }\n\n listModules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n listPrefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n applyPrefs() {\n this.lib.applyPreferences();\n }\n\n setPref(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 getPref(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 testFilter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n completeFilter(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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_TAP_KEYS\n ).join(\", \")}.`\n );\n }\n\n const session = this.loadedSession();\n const args = new this.lib.MapInput();\n for (const [k, v] of Object.entries(taps)) {\n args.set(k, v);\n }\n\n let response: ReturnType<DissectSession[\"tap\"]>;\n try {\n response = session.tap(args);\n } finally {\n free(args);\n }\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n // biome-ignore lint/suspicious/noExplicitAny: keeps the public return type of tap() unchanged\n let res: any;\n if (this.isConvTap(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.isEoTap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n };\n } else {\n free(tap);\n throw new Error(\"Unknown tap result\");\n }\n free(tap);\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.loadedSession().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(\n `Invalid arguments. Allowed keys are: ${Array.from(\n ALLOWED_GRAPH_KEYS\n ).join(\", \")}.`\n );\n }\n\n const session = this.loadedSession();\n const args = new this.lib.MapInput();\n for (const [k, v] of Object.entries(input)) {\n args.set(k, v);\n }\n\n let out: IoGraphResult;\n try {\n out = session.iograph(args);\n } finally {\n free(args);\n }\n return {\n ...out,\n iograph: vectorToArray(out.iograph).map((t) => ({\n items: vectorToArray(t.items),\n })),\n };\n }\n\n reloadLuaPlugins() {\n this.lib.reloadLuaPlugins();\n }\n\n addPlugin(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 const response = this.session.load();\n if (response.code !== 0) {\n // Don't keep a session for a file that failed to open.\n this.session.delete();\n this.session = null;\n }\n return response;\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.loadedSession().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.loadedSession().getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.loadedSession().follow(follow, filter);\n }\n\n private loadedSession(): DissectSession {\n if (this.session === null) {\n throw new Error(\"No capture file loaded, call load() first.\");\n }\n return this.session;\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 isEoTap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n isConvTap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n\n // Protocol enable/disable methods\n\n /**\n * List all registered protocols\n *\n * @returns Array of all protocols with their enabled state\n */\n listProtocols(): ProtocolInfo[] {\n return vectorToArray(this.lib.listProtocols());\n }\n\n /**\n * Enable or disable a protocol by its ID\n *\n * @param protoId Protocol ID\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabled(protoId: number, enabled: boolean): boolean {\n return this.lib.setProtocolEnabled(protoId, enabled);\n }\n\n /**\n * Enable or disable a protocol by its filter name\n *\n * @param protoName Protocol filter name (e.g., \"tcp\", \"udp\")\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabledByName(protoName: string, enabled: boolean): boolean {\n return this.lib.setProtocolEnabledByName(protoName, enabled);\n }\n\n // Heuristic dissector enable/disable methods\n\n /**\n * List all registered heuristic dissectors\n *\n * @returns Array of all heuristic dissectors with their enabled state\n */\n listHeuristicDissectors(): HeuristicInfo[] {\n return vectorToArray(this.lib.listHeuristicDissectors());\n }\n\n /**\n * Enable or disable a heuristic dissector by its unique short name\n *\n * @param shortName Unique short name of the heuristic dissector (e.g., \"mac_nr_udp\")\n * @param enabled Whether to enable or disable the heuristic\n * @returns true if successful, false otherwise\n */\n setHeuristicEnabled(shortName: string, enabled: boolean): boolean {\n return this.lib.setHeuristicEnabled(shortName, enabled);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","// SPDX-License-Identifier: GPL-2.0-or-later\nexport 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): void;\n mkdir(path: string, mode?: number): void;\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 /** Frees the vector on the wasm heap (embind handle). */\n delete(): void;\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 PREF_PROTO_TCP_SNDAMB_ENUM = 1 << 16,\n PREF_DISSECTOR = 1 << 17, // like string, but with dissector name syntax check\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\n conv_id: number;\n start_abs_time: number;\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 tx_bytes_total: number;\n tx_frames_total: number;\n rx_bytes_total: number;\n rx_frames_total: number;\n filtered: boolean;\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 IoGraphResult {\n error: string;\n iograph: Vector<IoGraph>;\n}\n\nexport interface IoGraph {\n items: Vector<number>;\n}\n\nexport interface ProtocolInfo {\n id: number;\n name: string;\n long_name: string;\n enabled: boolean;\n enabled_by_default: boolean;\n can_toggle: boolean;\n}\n\nexport interface HeuristicInfo {\n short_name: string;\n display_name: string;\n list_name: string;\n protocol_name: string;\n protocol_id: number; // protocol ID this heuristic belongs to (-1 if none)\n enabled: boolean;\n enabled_by_default: boolean;\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 version of the library\n *\n * @returns Version string\n */\n wiresharkVersion(): string;\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 // Protocol enable/disable functions\n\n /**\n * List all registered protocols\n *\n * @returns List of all protocols with their enabled state\n */\n listProtocols(): Vector<ProtocolInfo>;\n\n /**\n * Enable or disable a protocol by its ID\n *\n * @param protoId Protocol ID\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabled(protoId: number, enabled: boolean): boolean;\n\n /**\n * Enable or disable a protocol by its filter name\n *\n * @param protoName Protocol filter name (e.g., \"tcp\", \"udp\")\n * @param enabled Whether to enable or disable the protocol\n * @returns true if successful, false otherwise\n */\n setProtocolEnabledByName(protoName: string, enabled: boolean): boolean;\n\n // Heuristic dissector enable/disable functions\n\n /**\n * List all registered heuristic dissectors\n *\n * @returns List of all heuristic dissectors with their enabled state\n */\n listHeuristicDissectors(): Vector<HeuristicInfo>;\n\n /**\n * Enable or disable a heuristic dissector by its unique short name\n *\n * @param shortName Unique short name of the heuristic dissector (e.g., \"mac_nr_udp\")\n * @param enabled Whether to enable or disable the heuristic\n * @returns true if successful, false otherwise\n */\n setHeuristicEnabled(shortName: string, enabled: boolean): boolean;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n","// SPDX-License-Identifier: GPL-2.0-or-later\nimport { PrefSetResult, type Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array and frees the Vector\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n try {\n return Array.from({ length: vec.size() }, (_, i) => vec.get(i));\n } finally {\n // the elements are copied out; free the vector on the wasm heap\n vec.delete();\n }\n}\n\n/**\n * Frees an embind object (class instance, vector or map) on the wasm heap.\n */\nexport function free(handle: unknown): void {\n (handle as { delete(): void }).delete();\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","sourceRoot":"../"}