@goodtools/wiregasm 1.6.1 → 1.7.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 CHANGED
@@ -75,6 +75,9 @@ function $9ba0f9a5c47c04f2$export$a6506e3cba6c4388(code) {
75
75
 
76
76
 
77
77
 
78
+ const $882b6d93070905b3$var$ALLOWED_TAP_KEYS = new Set(Array.from({
79
+ length: 15
80
+ }, (_, i)=>`tap${i}`));
78
81
  class $882b6d93070905b3$export$c4e6ddb7806910b1 {
79
82
  constructor(){
80
83
  this.initialized = false;
@@ -125,10 +128,46 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
125
128
  complete_filter(filter) {
126
129
  const out = this.lib.completeFilter(filter);
127
130
  return {
128
- err: out.err,
129
131
  fields: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(out.fields)
130
132
  };
131
133
  }
134
+ tap(taps) {
135
+ // Validate keys.
136
+ if (!("tap0" in taps)) throw new Error("tap0 is mandatory.");
137
+ if (!Object.keys(taps).every((k)=>$882b6d93070905b3$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);
138
+ const args = new this.lib.TapInput();
139
+ Object.entries(taps).forEach(([k, v])=>args.set(k, v));
140
+ const response = this.session.tap(args);
141
+ return {
142
+ error: response.error,
143
+ taps: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(response.taps).map((tap)=>{
144
+ let res;
145
+ if (this.is_conv_tap(tap)) res = {
146
+ proto: tap.proto,
147
+ tap: tap.tap,
148
+ type: tap.type,
149
+ geoip: tap.geoip,
150
+ convs: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(tap.convs),
151
+ hosts: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(tap.hosts)
152
+ };
153
+ else if (this.is_eo_tap(tap)) res = {
154
+ proto: tap.proto,
155
+ tap: tap.tap,
156
+ type: tap.type,
157
+ objects: (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(tap.objects)
158
+ };
159
+ else {
160
+ tap.delete();
161
+ throw new Error("Unknown tap result");
162
+ }
163
+ tap.delete();
164
+ return res;
165
+ })
166
+ };
167
+ }
168
+ download(token) {
169
+ return this.session.download(token);
170
+ }
132
171
  reload_lua_plugins() {
133
172
  this.lib.reloadLuaPlugins();
134
173
  }
@@ -183,6 +222,12 @@ class $882b6d93070905b3$export$c4e6ddb7806910b1 {
183
222
  // convert it from a vector to array
184
223
  return (0, $9ba0f9a5c47c04f2$export$4b978bcb0889dc66)(vec);
185
224
  }
225
+ is_eo_tap(tap) {
226
+ return tap instanceof this.lib.TapExportObject;
227
+ }
228
+ is_conv_tap(tap) {
229
+ return tap instanceof this.lib.TapConvResponse;
230
+ }
186
231
  }
187
232
  $parcel$exportWildcard(module.exports, $faefaad95e5fcca0$exports);
188
233
  $parcel$exportWildcard(module.exports, $9ba0f9a5c47c04f2$exports);
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,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ilterResponse,\n CompleteField,\n DissectSession,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n 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): { err: string; fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n err: out.err,\n fields: vectorToArray(out.fields),\n };\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","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\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FollowPayload {\n number: number;\n server: number;\n data: string;\n}\n\nexport interface Follow {\n shost: string;\n sport: string;\n sbytes: number;\n chost: string;\n cport: string;\n cbytes: number;\n payloads: Vector<FollowPayload>;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\n\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n\n follow(follow: string, filter: string): Follow;\n}\n\nexport interface DissectSessionConstructable {\n new(path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Returns the directory where plugins are stored\n *\n * @returns Path of the plugins directory\n */\n getPluginsDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * List all the preference modules\n \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): { err: string; fields: Vector<CompleteField> };\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n","import { PrefSetResult, Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACAA,IA+BO;UAAK,aAAa;IAAb,cAAA,cACV,kBAAA,KAAA;IADU,cAAA,cAEV,0BAAA,KAAA;IAFU,cAAA,cAGV,4BAAA,KAAA;IAHU,cAAA,cAIV,wBAAA,KAAA;GAJU,8CAAA;IAOL;UAAK,QAAQ;IAAR,SAAA,SACV,eAAA,KAAA;IADU,SAAA,SAEV,eAAA,KAAA;IAFU,SAAA,SAGV,eAAA,KAAA;IAHU,SAAA,SAIV,iBAAA,KAAA;IAJU,SAAA,SAKV,gBAAA,MAAA;IALU,SAAA,SAMV,sBAAA,MAAA;IANU,SAAA,SAOV,cAAA,MAAA;IAPU,SAAA,SAQV,wBAAA,OAAA;IARU,SAAA,SASV,gBAAA,OAAA;IATU,SAAA,SAUV,iBAAA,OAAA;IAVU,SAAA,SAWV,mBAAA,QAAA;IAXU,SAAA,SAYV,k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AE/B,oCAAoC;QACpC,OAAO,CAAA,GAAA,yCAAY,EAAE;IACvB;IAGA,UAAU,GAAQ,EAAkC;QAClD,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;IAEA,YAAY,GAAQ,EAA0B;QAC5C,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapInput,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n\nconst ALLOWED_TAP_KEYS = new Set(Array.from({ length: 15 }, (_, i) => `tap${i}`));\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n complete_filter(filter: string): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: TapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\")\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.TapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n }\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n\n\n is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","export interface EmscriptenFileSystem {\n writeFile(\n path: string,\n data: string | ArrayBufferView,\n opts?: { flags?: string | undefined }\n ): void;\n readdir(path: string): string[];\n mkdirTree(path: string, mode?: number);\n mkdir(path: string, mode?: number);\n}\n\nexport interface EmscriptenHeap {\n buffer: ArrayBufferLike;\n}\n\nexport interface EmscriptenModule {\n FS: EmscriptenFileSystem;\n HEAPU8: EmscriptenHeap;\n _malloc(size: number): number;\n}\n\nexport interface Vector<T> {\n size(): number;\n get(index: number): T;\n}\n\nexport interface DataSource {\n name: string;\n data: string;\n}\n\nexport enum PrefSetResult {\n PREFS_SET_OK, // succeeded\n PREFS_SET_SYNTAX_ERR, // syntax error in string\n PREFS_SET_NO_SUCH_PREF, // no such preference\n PREFS_SET_OBSOLETE, // preference used to exist but no longer does\n}\n\nexport enum PrefType {\n PREF_UINT = 1 << 0,\n PREF_BOOL = 1 << 1,\n PREF_ENUM = 1 << 2,\n PREF_STRING = 1 << 3,\n PREF_RANGE = 1 << 4,\n PREF_STATIC_TEXT = 1 << 5,\n PREF_UAT = 1 << 6,\n PREF_SAVE_FILENAME = 1 << 7,\n PREF_COLOR = 1 << 8, // These are only supported for \"internal\" (non-protocol)\n PREF_CUSTOM = 1 << 9, // use and not as a generic protocol preference\n PREF_OBSOLETE = 1 << 10,\n PREF_DIRNAME = 1 << 11,\n PREF_DECODE_AS_UINT = 1 << 12, // These are only supported for \"internal\" (non-protocol)\n PREF_DECODE_AS_RANGE = 1 << 13, // use and not as a generic protocol preference\n PREF_OPEN_FILENAME = 1 << 14,\n PREF_PASSWORD = 1 << 15, // like string, but never saved to prefs file\n}\n\nexport interface PrefModule {\n name: string;\n title: string;\n description: string;\n use_gui: boolean;\n submodules: Vector<PrefModule>;\n}\n\nexport interface PrefSetResponse {\n code: PrefSetResult;\n error: string;\n}\n\nexport interface PrefResponse {\n code: number;\n data: Pref;\n}\n\nexport interface Pref {\n name: string;\n title: string;\n description: string;\n\n type: PrefType;\n uint_value: number;\n uint_base_value: number;\n bool_value: boolean;\n string_value: string;\n range_value: string;\n}\n\nexport interface ProtoTree {\n label: string;\n filter: string;\n start: number;\n length: number;\n data_source_idx: number;\n type: \"proto\" | \"url\" | \"framenum\" | \"\";\n url?: string;\n fnum?: number;\n tree: Vector<ProtoTree>;\n}\n\nexport interface Frame {\n number: number;\n comments: Vector<string>;\n data_sources: Vector<DataSource>;\n tree: Vector<ProtoTree>;\n follow: Vector<Vector<string>>\n}\n\nexport interface CompleteField {\n field: string;\n type: string;\n name: string;\n}\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FollowPayload {\n number: number;\n server: number;\n data: string;\n}\n\nexport interface Follow {\n shost: string;\n sport: string;\n sbytes: number;\n chost: string;\n cport: string;\n cbytes: number;\n payloads: Vector<FollowPayload>;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface Download {\n file: string;\n mime: string;\n data: string;\n}\n\nexport interface DownloadResponse {\n error: string;\n download: Download;\n}\n\nexport type TapInput = Record<string, string>;\n\ninterface ExportObject {\n hostname: string;\n pkt: number;\n type: string;\n filename: string;\n _download: string;\n len: number;\n}\n\n\nexport interface Conversation {\n saddr: string;\n daddr: string;\n sport: string;\n dport: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n start: number;\n stop: number;\n filter: string;\n}\n\nexport interface Host {\n host: string;\n port: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n filter: string;\n}\n\nexport interface TapResponseBase {\n type: string;\n tap: string;\n proto: string;\n}\n\nexport interface TapExportObjectResponse extends TapResponseBase {\n objects: Vector<ExportObject>;\n}\n\nexport interface TapConvResponse extends TapResponseBase {\n geoip: boolean;\n convs: Vector<Conversation>;\n hosts: Vector<Host>;\n}\n\nexport type TapResponse = TapExportObjectResponse | TapConvResponse;\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n\n follow(follow: string, filter: string): Follow;\n\n tap(taps: Map<string, string>): {\n taps: Vector<TapResponse>;\n error: string;\n };\n\n download(token: string): DownloadResponse;\n}\n\nexport interface DissectSessionConstructable {\n new(path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n TapInput: MapConstructor;\n TapExportObject: () => TapExportObjectResponse;\n TapConvResponse: () => TapConvResponse;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Returns the directory where plugins are stored\n *\n * @returns Path of the plugins directory\n */\n getPluginsDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * List all the preference modules\n * @returns List of preference modules\n */\n listModules(): Vector<PrefModule>;\n\n /**\n * List all the preferences for a given module\n *\n * @param module Preference module\n */\n listPreferences(module: string): Vector<Pref>;\n\n /**\n * Apply preferences\n */\n applyPreferences(): void;\n\n /**\n * Set a preference\n *\n * @param module Preference module\n * @param key Preference key\n * @param value Preference value\n */\n setPref(module: string, key: string, value: string): PrefSetResponse;\n\n /**\n * Get a preference\n *\n * @param module Preference module\n * @param key Preference key\n */\n getPref(module: string, key: string): PrefResponse;\n\n /**\n * Reload lua plugins\n */\n reloadLuaPlugins(): boolean;\n\n /**\n * Clean up any memory associated with the lib\n */\n destroy(): void;\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n checkFilter(filter: string): CheckFilterResponse;\n\n completeFilter(filter: string): { fields: Vector<CompleteField> };\n\n download(token: string): Download;\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n","import { PrefSetResult, Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -57,6 +57,9 @@ function $fab42eb3dee39b5b$export$a6506e3cba6c4388(code) {
57
57
 
58
58
 
59
59
 
60
+ const $149c1bd638913645$var$ALLOWED_TAP_KEYS = new Set(Array.from({
61
+ length: 15
62
+ }, (_, i)=>`tap${i}`));
60
63
  class $149c1bd638913645$export$c4e6ddb7806910b1 {
61
64
  constructor(){
62
65
  this.initialized = false;
@@ -107,10 +110,46 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
107
110
  complete_filter(filter) {
108
111
  const out = this.lib.completeFilter(filter);
109
112
  return {
110
- err: out.err,
111
113
  fields: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(out.fields)
112
114
  };
113
115
  }
116
+ tap(taps) {
117
+ // Validate keys.
118
+ if (!("tap0" in taps)) throw new Error("tap0 is mandatory.");
119
+ if (!Object.keys(taps).every((k)=>$149c1bd638913645$var$ALLOWED_TAP_KEYS.has(k))) throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);
120
+ const args = new this.lib.TapInput();
121
+ Object.entries(taps).forEach(([k, v])=>args.set(k, v));
122
+ const response = this.session.tap(args);
123
+ return {
124
+ error: response.error,
125
+ taps: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(response.taps).map((tap)=>{
126
+ let res;
127
+ if (this.is_conv_tap(tap)) res = {
128
+ proto: tap.proto,
129
+ tap: tap.tap,
130
+ type: tap.type,
131
+ geoip: tap.geoip,
132
+ convs: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(tap.convs),
133
+ hosts: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(tap.hosts)
134
+ };
135
+ else if (this.is_eo_tap(tap)) res = {
136
+ proto: tap.proto,
137
+ tap: tap.tap,
138
+ type: tap.type,
139
+ objects: (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(tap.objects)
140
+ };
141
+ else {
142
+ tap.delete();
143
+ throw new Error("Unknown tap result");
144
+ }
145
+ tap.delete();
146
+ return res;
147
+ })
148
+ };
149
+ }
150
+ download(token) {
151
+ return this.session.download(token);
152
+ }
114
153
  reload_lua_plugins() {
115
154
  this.lib.reloadLuaPlugins();
116
155
  }
@@ -165,6 +204,12 @@ class $149c1bd638913645$export$c4e6ddb7806910b1 {
165
204
  // convert it from a vector to array
166
205
  return (0, $fab42eb3dee39b5b$export$4b978bcb0889dc66)(vec);
167
206
  }
207
+ is_eo_tap(tap) {
208
+ return tap instanceof this.lib.TapExportObject;
209
+ }
210
+ is_conv_tap(tap) {
211
+ return tap instanceof this.lib.TapConvResponse;
212
+ }
168
213
  }
169
214
 
170
215
 
@@ -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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,IAAI,IAAI,EACtB,IAAI,CAAC,OAAO,CAAC,MAAM;QAGrB,MAAM,OAAO,IAAI,CAAC,SAAS,GAAG,MAAM;QACpC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,SAAS,CAAC,MAAM,MAAM;QAElC,IAAI,CAAC,OAAO,GAAG,IAAI,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC;QAE3C,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI;IAC1B;IAEA;;;;;;GAMC,GACD,OAAO,MAAc,EAAE,OAAO,CAAC,EAAE,QAAQ,CAAC,EAAkB;QAC1D,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,QAAQ,MAAM;IAC9C;IAEA;;;;GAIC,GACD,MAAM,GAAW,EAAS;QACxB,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC/B;IAEA,OAAO,MAAc,EAAE,MAAc,EAAU;QAC7C,OAAO,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ;IACrC;IAEA,UAAU;QACR,IAAI,IAAI,CAAC,WAAW,EAAE;YACpB,IAAI,IAAI,CAAC,OAAO,KAAK,IAAI,EAAE;gBACzB,IAAI,CAAC,OAAO,CAAC,MAAM;gBACnB,IAAI,CAAC,OAAO,GAAG,IAAI;YACrB,CAAC;YAED,IAAI,CAAC,GAAG,CAAC,OAAO;YAChB,IAAI,CAAC,WAAW,GAAG,KAAK;QAC1B,CAAC;IACH;IAEA;;GAEC,GACD,UAAoB;QAClB,MAAM,MAAM,IAAI,CAAC,GAAG,CAAC,UAAU;QAE/B,oCAAoC;QACpC,OAAO,CAAA,GAAA,yCAAY,EAAE;IACvB;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n 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): { err: string; fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n err: out.err,\n fields: vectorToArray(out.fields),\n };\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","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\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FollowPayload {\n number: number;\n server: number;\n data: string;\n}\n\nexport interface Follow {\n shost: string;\n sport: string;\n sbytes: number;\n chost: string;\n cport: string;\n cbytes: number;\n payloads: Vector<FollowPayload>;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\n\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n\n follow(follow: string, filter: string): Follow;\n}\n\nexport interface DissectSessionConstructable {\n new(path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Returns the directory where plugins are stored\n *\n * @returns Path of the plugins directory\n */\n getPluginsDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * List all the preference modules\n \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): { err: string; fields: Vector<CompleteField> };\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n","import { PrefSetResult, Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;ACAA,IA+BO;UAAK,aAAa;IAAb,cAAA,cACV,kBAAA,KAAA;IADU,cAAA,cAEV,0BAAA,KAAA;IAFU,cAAA,cAGV,4BAAA,KAAA;IAHU,cAAA,cAIV,wBAAA,KAAA;GAJU,8CAAA;IAOL;UAAK,QAAQ;IAAR,SAAA,SACV,eAAA,KAAA;IADU,SAAA,SAEV,eAAA,KAAA;IAFU,SAAA,SAGV,eAAA,KAAA;IAHU,SAAA,SAIV,iBAAA,KAAA;IAJU,SAAA,SAKV,gBAAA,MAAA;IALU,SAAA,SAMV,sBAAA,MAAA;IANU,SAAA,SAOV,cAAA,MAAA;IAPU,SAAA,SAQV,wBAAA,OAAA;IARU,SAAA,SASV,gBAAA,OAAA;IATU,SAAA,SAUV,iBAAA,OAAA;IAVU,SAAA,SAWV,mBAAA,QAAA;IAXU,SAAA,SAYV,kBAAA,QAAA;IAZU,SAAA,SAaV,yBAAA,QAAA;IAbU,SAAA,SAcV,0BAAA,QAAA;IAdU,SAAA,SAeV,wBAAA,SAAA;IAfU,SAAA,SAgBV,mBAAA,SAAA;GAhBU,8C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Y,GAAQ,EAA0B;QAC5C,OAAO,eAAe,IAAI,CAAC,GAAG,CAAC,eAAe;IAChD;AACF","sources":["src/index.ts","src/types.ts","src/utils.ts"],"sourcesContent":["import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapInput,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n\nconst ALLOWED_TAP_KEYS = new Set(Array.from({ length: 15 }, (_, i) => `tap${i}`));\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n complete_filter(filter: string): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: TapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\")\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.TapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n }\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n\n\n is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n","export interface EmscriptenFileSystem {\n writeFile(\n path: string,\n data: string | ArrayBufferView,\n opts?: { flags?: string | undefined }\n ): void;\n readdir(path: string): string[];\n mkdirTree(path: string, mode?: number);\n mkdir(path: string, mode?: number);\n}\n\nexport interface EmscriptenHeap {\n buffer: ArrayBufferLike;\n}\n\nexport interface EmscriptenModule {\n FS: EmscriptenFileSystem;\n HEAPU8: EmscriptenHeap;\n _malloc(size: number): number;\n}\n\nexport interface Vector<T> {\n size(): number;\n get(index: number): T;\n}\n\nexport interface DataSource {\n name: string;\n data: string;\n}\n\nexport enum PrefSetResult {\n PREFS_SET_OK, // succeeded\n PREFS_SET_SYNTAX_ERR, // syntax error in string\n PREFS_SET_NO_SUCH_PREF, // no such preference\n PREFS_SET_OBSOLETE, // preference used to exist but no longer does\n}\n\nexport enum PrefType {\n PREF_UINT = 1 << 0,\n PREF_BOOL = 1 << 1,\n PREF_ENUM = 1 << 2,\n PREF_STRING = 1 << 3,\n PREF_RANGE = 1 << 4,\n PREF_STATIC_TEXT = 1 << 5,\n PREF_UAT = 1 << 6,\n PREF_SAVE_FILENAME = 1 << 7,\n PREF_COLOR = 1 << 8, // These are only supported for \"internal\" (non-protocol)\n PREF_CUSTOM = 1 << 9, // use and not as a generic protocol preference\n PREF_OBSOLETE = 1 << 10,\n PREF_DIRNAME = 1 << 11,\n PREF_DECODE_AS_UINT = 1 << 12, // These are only supported for \"internal\" (non-protocol)\n PREF_DECODE_AS_RANGE = 1 << 13, // use and not as a generic protocol preference\n PREF_OPEN_FILENAME = 1 << 14,\n PREF_PASSWORD = 1 << 15, // like string, but never saved to prefs file\n}\n\nexport interface PrefModule {\n name: string;\n title: string;\n description: string;\n use_gui: boolean;\n submodules: Vector<PrefModule>;\n}\n\nexport interface PrefSetResponse {\n code: PrefSetResult;\n error: string;\n}\n\nexport interface PrefResponse {\n code: number;\n data: Pref;\n}\n\nexport interface Pref {\n name: string;\n title: string;\n description: string;\n\n type: PrefType;\n uint_value: number;\n uint_base_value: number;\n bool_value: boolean;\n string_value: string;\n range_value: string;\n}\n\nexport interface ProtoTree {\n label: string;\n filter: string;\n start: number;\n length: number;\n data_source_idx: number;\n type: \"proto\" | \"url\" | \"framenum\" | \"\";\n url?: string;\n fnum?: number;\n tree: Vector<ProtoTree>;\n}\n\nexport interface Frame {\n number: number;\n comments: Vector<string>;\n data_sources: Vector<DataSource>;\n tree: Vector<ProtoTree>;\n follow: Vector<Vector<string>>\n}\n\nexport interface CompleteField {\n field: string;\n type: string;\n name: string;\n}\n\nexport interface FramesResponse {\n frames: Vector<FrameMeta>;\n matched: number;\n}\n\nexport interface FollowPayload {\n number: number;\n server: number;\n data: string;\n}\n\nexport interface Follow {\n shost: string;\n sport: string;\n sbytes: number;\n chost: string;\n cport: string;\n cbytes: number;\n payloads: Vector<FollowPayload>;\n}\n\nexport interface FrameMeta {\n number: number;\n comments: boolean;\n ignored: boolean;\n marked: boolean;\n bg: number;\n fg: number;\n columns: Vector<string>;\n}\nexport interface LoadSummary {\n filename: string;\n file_type: string;\n file_length: number;\n file_encap_type: string;\n packet_count: number;\n start_time: number;\n stop_time: number;\n elapsed_time: number;\n}\n\nexport interface LoadResponse {\n code: number;\n error: string;\n summary: LoadSummary;\n}\n\nexport interface Download {\n file: string;\n mime: string;\n data: string;\n}\n\nexport interface DownloadResponse {\n error: string;\n download: Download;\n}\n\nexport type TapInput = Record<string, string>;\n\ninterface ExportObject {\n hostname: string;\n pkt: number;\n type: string;\n filename: string;\n _download: string;\n len: number;\n}\n\n\nexport interface Conversation {\n saddr: string;\n daddr: string;\n sport: string;\n dport: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n start: number;\n stop: number;\n filter: string;\n}\n\nexport interface Host {\n host: string;\n port: string;\n txf: number;\n txb: number;\n rxf: number;\n rxb: number;\n filter: string;\n}\n\nexport interface TapResponseBase {\n type: string;\n tap: string;\n proto: string;\n}\n\nexport interface TapExportObjectResponse extends TapResponseBase {\n objects: Vector<ExportObject>;\n}\n\nexport interface TapConvResponse extends TapResponseBase {\n geoip: boolean;\n convs: Vector<Conversation>;\n hosts: Vector<Host>;\n}\n\nexport type TapResponse = TapExportObjectResponse | TapConvResponse;\n\nexport interface DissectSession {\n /**\n * Free up any memory used by the session\n */\n delete(): void;\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(): LoadResponse;\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n getFrames(filter: string, skip: number, limit: number): FramesResponse;\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n getFrame(number: number): Frame;\n\n follow(follow: string, filter: string): Follow;\n\n tap(taps: Map<string, string>): {\n taps: Vector<TapResponse>;\n error: string;\n };\n\n download(token: string): DownloadResponse;\n}\n\nexport interface DissectSessionConstructable {\n new(path: string): DissectSession;\n}\n\nexport interface CheckFilterResponse {\n ok: boolean;\n error: string;\n}\n\nexport interface WiregasmLibOverrides {\n /**\n * If set, this method will be called when the runtime needs to load a file,\n * such as a .wasm WebAssembly file, .mem memory init file, or a file generated\n * by the file packager. The function receives the relative path to the file as\n * configured in build process and a prefix (path to the main JavaScript file’s\n * directory), and should return the actual URL.\n *\n * This lets you host file packages or the .mem file etc. on a different location\n * than the directory of the JavaScript file (which is the default expectation),\n * for example if you want to host them on a CDN.\n *\n * @param path Path of the requested file.\n * @param prefix Prefix of the requested path. May be empty.\n *\n * @returns Path to the requested file.\n */\n locateFile?(path: string, prefix: string): string;\n\n /**\n * Called when something is printed to standard error (stderr)\n *\n * @param error Error content\n */\n printErr?(error: string): void;\n\n /**\n * Called when something is printed to standard output (stdout)\n *\n * @param message Message content\n */\n print?(message: string): void;\n\n /**\n * Called from within the Wiregasm Library to notify\n * about any status updates.\n *\n * @param type Type of the status\n * @param message Message content\n */\n handleStatus?(type: number, message: string): void;\n\n /**\n * If you can fetch the binary yourself, you can set it\n */\n wasmBinary?: ArrayBuffer;\n\n /**\n * If you want to manually manage the download of .data file packages for\n * custom caching, progress reporting and error handling behavior,\n * you can implement this override.\n */\n getPreloadedPackage?(name: string, size: number): ArrayBuffer;\n}\n\nexport interface WiregasmLib extends EmscriptenModule {\n DissectSession: DissectSessionConstructable;\n\n TapInput: MapConstructor;\n TapExportObject: () => TapExportObjectResponse;\n TapConvResponse: () => TapConvResponse;\n\n /**\n * Returns the directory where files are uploaded\n *\n * @returns Path of the directory\n */\n getUploadDirectory(): string;\n\n /**\n * Returns the directory where plugins are stored\n *\n * @returns Path of the plugins directory\n */\n getPluginsDirectory(): string;\n\n /**\n * Initialize the library, load preferences and register dissectors\n */\n init(): boolean;\n\n /**\n * List all the preference modules\n * @returns List of preference modules\n */\n listModules(): Vector<PrefModule>;\n\n /**\n * List all the preferences for a given module\n *\n * @param module Preference module\n */\n listPreferences(module: string): Vector<Pref>;\n\n /**\n * Apply preferences\n */\n applyPreferences(): void;\n\n /**\n * Set a preference\n *\n * @param module Preference module\n * @param key Preference key\n * @param value Preference value\n */\n setPref(module: string, key: string, value: string): PrefSetResponse;\n\n /**\n * Get a preference\n *\n * @param module Preference module\n * @param key Preference key\n */\n getPref(module: string, key: string): PrefResponse;\n\n /**\n * Reload lua plugins\n */\n reloadLuaPlugins(): boolean;\n\n /**\n * Clean up any memory associated with the lib\n */\n destroy(): void;\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n checkFilter(filter: string): CheckFilterResponse;\n\n completeFilter(filter: string): { fields: Vector<CompleteField> };\n\n download(token: string): Download;\n /**\n * Returns the column headers\n */\n getColumns(): Vector<string>;\n\n /**\n * Creates a new file in the upload directory with the supplied data\n *\n * @param file_name Name of the file\n * @param data_ptr Pointer to the data\n * @param length Length of the data\n */\n upload(file_name: string, data_ptr: number, length: number): string;\n}\n\nexport type WiregasmLoader = (\n overrides: WiregasmLibOverrides\n) => Promise<WiregasmLib>;\n\nexport type BeforeInitCallback = (lib: WiregasmLib) => Promise<void>;\n","import { PrefSetResult, Vector } from \"./types\";\n\n/**\n * Converts a Vector to a JS array\n *\n * @param vec Vector\n * @returns JS array of the Vector contents\n */\nexport function vectorToArray<T>(vec: Vector<T>): T[] {\n return new Array(vec.size()).fill(0).map((_, id) => vec.get(id));\n}\n\nexport function preferenceSetCodeToError(code: number): string {\n switch (code) {\n case PrefSetResult.PREFS_SET_SYNTAX_ERR:\n return \"Syntax error in string\";\n case PrefSetResult.PREFS_SET_NO_SUCH_PREF:\n return \"No such preference\";\n case PrefSetResult.PREFS_SET_OBSOLETE:\n return \"Preference used to exist but no longer does\";\n default:\n return \"Unknown error\";\n }\n}\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -137,6 +137,60 @@ export interface LoadResponse {
137
137
  error: string;
138
138
  summary: LoadSummary;
139
139
  }
140
+ export interface Download {
141
+ file: string;
142
+ mime: string;
143
+ data: string;
144
+ }
145
+ export interface DownloadResponse {
146
+ error: string;
147
+ download: Download;
148
+ }
149
+ export type TapInput = Record<string, string>;
150
+ interface ExportObject {
151
+ hostname: string;
152
+ pkt: number;
153
+ type: string;
154
+ filename: string;
155
+ _download: string;
156
+ len: number;
157
+ }
158
+ export interface Conversation {
159
+ saddr: string;
160
+ daddr: string;
161
+ sport: string;
162
+ dport: string;
163
+ txf: number;
164
+ txb: number;
165
+ rxf: number;
166
+ rxb: number;
167
+ start: number;
168
+ stop: number;
169
+ filter: string;
170
+ }
171
+ export interface Host {
172
+ host: string;
173
+ port: string;
174
+ txf: number;
175
+ txb: number;
176
+ rxf: number;
177
+ rxb: number;
178
+ filter: string;
179
+ }
180
+ export interface TapResponseBase {
181
+ type: string;
182
+ tap: string;
183
+ proto: string;
184
+ }
185
+ export interface TapExportObjectResponse extends TapResponseBase {
186
+ objects: Vector<ExportObject>;
187
+ }
188
+ export interface TapConvResponse extends TapResponseBase {
189
+ geoip: boolean;
190
+ convs: Vector<Conversation>;
191
+ hosts: Vector<Host>;
192
+ }
193
+ export type TapResponse = TapExportObjectResponse | TapConvResponse;
140
194
  export interface DissectSession {
141
195
  /**
142
196
  * Free up any memory used by the session
@@ -163,6 +217,11 @@ export interface DissectSession {
163
217
  */
164
218
  getFrame(number: number): Frame;
165
219
  follow(follow: string, filter: string): Follow;
220
+ tap(taps: Map<string, string>): {
221
+ taps: Vector<TapResponse>;
222
+ error: string;
223
+ };
224
+ download(token: string): DownloadResponse;
166
225
  }
167
226
  export interface DissectSessionConstructable {
168
227
  new (path: string): DissectSession;
@@ -222,6 +281,9 @@ export interface WiregasmLibOverrides {
222
281
  }
223
282
  export interface WiregasmLib extends EmscriptenModule {
224
283
  DissectSession: DissectSessionConstructable;
284
+ TapInput: MapConstructor;
285
+ TapExportObject: () => TapExportObjectResponse;
286
+ TapConvResponse: () => TapConvResponse;
225
287
  /**
226
288
  * Returns the directory where files are uploaded
227
289
  *
@@ -240,7 +302,6 @@ export interface WiregasmLib extends EmscriptenModule {
240
302
  init(): boolean;
241
303
  /**
242
304
  * List all the preference modules
243
-
244
305
  * @returns List of preference modules
245
306
  */
246
307
  listModules(): Vector<PrefModule>;
@@ -284,9 +345,9 @@ export interface WiregasmLib extends EmscriptenModule {
284
345
  */
285
346
  checkFilter(filter: string): CheckFilterResponse;
286
347
  completeFilter(filter: string): {
287
- err: string;
288
348
  fields: Vector<CompleteField>;
289
349
  };
350
+ download(token: string): Download;
290
351
  /**
291
352
  * Returns the column headers
292
353
  */
@@ -339,9 +400,13 @@ export class Wiregasm {
339
400
  */
340
401
  test_filter(filter: string): CheckFilterResponse;
341
402
  complete_filter(filter: string): {
342
- err: string;
343
403
  fields: CompleteField[];
344
404
  };
405
+ tap(taps: TapInput): {
406
+ error: string;
407
+ taps: any[];
408
+ };
409
+ download(token: string): DownloadResponse;
345
410
  reload_lua_plugins(): void;
346
411
  add_plugin(name: string, data: string | ArrayBufferView, opts?: object): void;
347
412
  /**
@@ -370,6 +435,8 @@ export class Wiregasm {
370
435
  * Returns the column headers
371
436
  */
372
437
  columns(): string[];
438
+ is_eo_tap(tap: any): tap is TapExportObjectResponse;
439
+ is_conv_tap(tap: any): tap is TapConvResponse;
373
440
  }
374
441
 
375
442
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"mappings":"AAAA;IACE,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GACpC,IAAI,CAAC;IACR,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAA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QAAC,MAAM,EAAE,aAAa,EAAE,CAAA;KAAE;IAQzE,kBAAkB;IAIlB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,IAAI,GAAE,MAAW;IAK1E;;;;OAIG;IACH,IAAI,CACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,GAAE,MAAW,GAChB,YAAY;IAaf;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,SAAI,EAAE,KAAK,SAAI,GAAG,cAAc;IAI3D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIzB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAI9C,OAAO;IAYP;;OAEG;IACH,OAAO,IAAI,MAAM,EAAE;CAMpB","sources":["src/src/types.ts","src/src/utils.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,"import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader,\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n 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): { err: string; fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n err: out.err,\n fields: vectorToArray(out.fields),\n };\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n"],"names":[],"version":3,"file":"types.d.ts.map"}
1
+ {"mappings":"AAAA;IACE,SAAS,CACP,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;KAAE,GACpC,IAAI,CAAC;IACR,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,OAAE;IACvC,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,OAAE;CACpC;AAED;IACE,MAAM,EAAE,eAAe,CAAC;CACzB;AAED;IACE,EAAE,EAAE,oBAAoB,CAAC;IACzB,MAAM,EAAE,cAAc,CAAC;IACvB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;CAC/B;AAED,wBAAwB,CAAC;IACvB,IAAI,IAAI,MAAM,CAAC;IACf,GAAG,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,CAAC;CACvB;AAED;IACE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACd;AAED;IACE,YAAY,IAAA;IACZ,oBAAoB,IAAA;IACpB,sBAAs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ClB,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAIzC,kBAAkB;IAIlB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,eAAe,EAAE,IAAI,GAAE,MAAW;IAK1E;;;;OAIG;IACH,IAAI,CACF,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,GAAG,eAAe,EAC9B,IAAI,GAAE,MAAW,GAChB,YAAY;IAaf;;;;;;OAMG;IACH,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,SAAI,EAAE,KAAK,SAAI,GAAG,cAAc;IAI3D;;;;OAIG;IACH,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK;IAIzB,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM;IAI9C,OAAO;IAYP;;OAEG;IACH,OAAO,IAAI,MAAM,EAAE;IAQnB,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,uBAAuB;IAInD,WAAW,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,eAAe;CAG9C","sources":["src/src/types.ts","src/src/utils.ts","src/src/index.ts","src/index.ts"],"sourcesContent":[null,null,null,"import {\n BeforeInitCallback,\n CheckFilterResponse,\n CompleteField,\n DissectSession,\n DownloadResponse,\n Follow,\n Frame,\n FramesResponse,\n LoadResponse,\n Pref,\n PrefModule,\n PrefSetResult,\n TapConvResponse,\n TapExportObjectResponse,\n TapInput,\n TapResponse,\n Vector,\n WiregasmLib,\n WiregasmLibOverrides,\n WiregasmLoader\n} from \"./types\";\n\nimport { preferenceSetCodeToError, vectorToArray } from \"./utils\";\n\n\nconst ALLOWED_TAP_KEYS = new Set(Array.from({ length: 15 }, (_, i) => `tap${i}`));\n\n/**\n * Wraps the WiregasmLib lib functionality and manages a single DissectSession\n */\nexport class Wiregasm {\n lib: WiregasmLib;\n initialized: boolean;\n session: DissectSession | null;\n uploadDir: string;\n pluginsDir: string;\n\n constructor() {\n this.initialized = false;\n this.session = null;\n }\n\n /**\n * Initialize the wrapper and the Wiregasm module\n *\n * @param loader Loader function for the Emscripten module\n * @param overrides Overrides\n */\n async init(\n loader: WiregasmLoader,\n overrides: WiregasmLibOverrides = {},\n beforeInit: BeforeInitCallback = null\n ) {\n if (this.initialized) {\n return;\n }\n\n this.lib = await loader(overrides);\n this.uploadDir = this.lib.getUploadDirectory();\n this.pluginsDir = this.lib.getPluginsDirectory();\n\n if (beforeInit !== null) {\n await beforeInit(this.lib);\n }\n\n this.lib.init();\n this.initialized = true;\n }\n\n list_modules(): Vector<PrefModule> {\n return this.lib.listModules();\n }\n\n list_prefs(module: string): Vector<Pref> {\n return this.lib.listPreferences(module);\n }\n\n apply_prefs() {\n this.lib.applyPreferences();\n }\n\n set_pref(module: string, key: string, value: string) {\n const ret = this.lib.setPref(module, key, value);\n\n if (ret.code != PrefSetResult.PREFS_SET_OK) {\n const message =\n ret.error != \"\" ? ret.error : preferenceSetCodeToError(ret.code);\n throw new Error(\n `Failed to set preference (${module}.${key}): ${message}`\n );\n }\n }\n\n get_pref(module: string, key: string): Pref {\n const response = this.lib.getPref(module, key);\n if (response.code != 0) {\n throw new Error(`Failed to get preference (${module}.${key})`);\n }\n return response.data;\n }\n\n /**\n * Check the validity of a filter expression.\n *\n * @param filter A display filter expression\n */\n test_filter(filter: string): CheckFilterResponse {\n return this.lib.checkFilter(filter);\n }\n\n complete_filter(filter: string): { fields: CompleteField[] } {\n const out = this.lib.completeFilter(filter);\n return {\n fields: vectorToArray(out.fields),\n };\n }\n\n tap(taps: TapInput) {\n // Validate keys.\n if (!(\"tap0\" in taps)) {\n throw new Error(\"tap0 is mandatory.\")\n }\n if (!Object.keys(taps).every((k) => ALLOWED_TAP_KEYS.has(k))) {\n throw new Error(`Invalid arguments. Only tap0..tap15 keys are allowed.`);\n }\n\n const args = new this.lib.TapInput();\n Object.entries(taps).forEach(([k, v]) => args.set(k, v));\n\n const response = this.session.tap(args);\n return {\n error: response.error,\n taps: vectorToArray(response.taps).map((tap) => {\n let res;\n if (this.is_conv_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n geoip: tap.geoip,\n convs: vectorToArray(tap.convs),\n hosts: vectorToArray(tap.hosts),\n };\n } else if (this.is_eo_tap(tap)) {\n res = {\n proto: tap.proto,\n tap: tap.tap,\n type: tap.type,\n objects: vectorToArray(tap.objects),\n }\n } else {\n (tap as { delete: () => void }).delete();\n throw new Error(\"Unknown tap result\");\n }\n (tap as TapResponse & { delete: () => void }).delete();\n return res;\n }),\n };\n }\n\n download(token: string): DownloadResponse {\n return this.session.download(token);\n }\n\n reload_lua_plugins() {\n this.lib.reloadLuaPlugins();\n }\n\n add_plugin(name: string, data: string | ArrayBufferView, opts: object = {}) {\n const path = this.pluginsDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n }\n\n /**\n * Load a packet trace file for analysis.\n *\n * @returns Response containing the status and summary\n */\n load(\n name: string,\n data: string | ArrayBufferView,\n opts: object = {}\n ): LoadResponse {\n if (this.session != null) {\n this.session.delete();\n }\n\n const path = this.uploadDir + \"/\" + name;\n this.lib.FS.writeFile(path, data, opts);\n\n this.session = new this.lib.DissectSession(path);\n\n return this.session.load();\n }\n\n /**\n * Get Packet List information for a range of packets.\n *\n * @param filter Output those frames that pass this filter expression\n * @param skip Skip N frames\n * @param limit Limit the output to N frames\n */\n frames(filter: string, skip = 0, limit = 0): FramesResponse {\n return this.session.getFrames(filter, skip, limit);\n }\n\n /**\n * Get full information about a frame including the protocol tree.\n *\n * @param number Frame number\n */\n frame(num: number): Frame {\n return this.session.getFrame(num);\n }\n\n follow(follow: string, filter: string): Follow {\n return this.session.follow(follow, filter);\n }\n\n destroy() {\n if (this.initialized) {\n if (this.session !== null) {\n this.session.delete();\n this.session = null;\n }\n\n this.lib.destroy();\n this.initialized = false;\n }\n }\n\n /**\n * Returns the column headers\n */\n columns(): string[] {\n const vec = this.lib.getColumns();\n\n // convert it from a vector to array\n return vectorToArray(vec);\n }\n\n\n is_eo_tap(tap: any): tap is TapExportObjectResponse {\n return tap instanceof this.lib.TapExportObject;\n }\n\n is_conv_tap(tap: any): tap is TapConvResponse {\n return tap instanceof this.lib.TapConvResponse;\n }\n}\n\nexport * from \"./types\";\nexport * from \"./utils\";\n"],"names":[],"version":3,"file":"types.d.ts.map"}
Binary file
package/dist/wiregasm.js CHANGED
@@ -6655,6 +6655,96 @@ function unexportedRuntimeSymbol(sym) {
6655
6655
  });
6656
6656
  }
6657
6657
 
6658
+
6659
+
6660
+
6661
+
6662
+
6663
+
6664
+
6665
+ function validateThis(this_, classType, humanName) {
6666
+ if (!(this_ instanceof Object)) {
6667
+ throwBindingError(humanName + ' with invalid "this": ' + this_);
6668
+ }
6669
+ if (!(this_ instanceof classType.registeredClass.constructor)) {
6670
+ throwBindingError(humanName + ' incompatible with "this" of type ' + this_.constructor.name);
6671
+ }
6672
+ if (!this_.$$.ptr) {
6673
+ throwBindingError('cannot call emscripten binding method ' + humanName + ' on deleted object');
6674
+ }
6675
+
6676
+ // todo: kill this
6677
+ return upcastPointer(this_.$$.ptr,
6678
+ this_.$$.ptrType.registeredClass,
6679
+ classType.registeredClass);
6680
+ }
6681
+ function __embind_register_class_property(classType,
6682
+ fieldName,
6683
+ getterReturnType,
6684
+ getterSignature,
6685
+ getter,
6686
+ getterContext,
6687
+ setterArgumentType,
6688
+ setterSignature,
6689
+ setter,
6690
+ setterContext) {
6691
+ fieldName = readLatin1String(fieldName);
6692
+ getter = embind__requireFunction(getterSignature, getter);
6693
+
6694
+ whenDependentTypesAreResolved([], [classType], function(classType) {
6695
+ classType = classType[0];
6696
+ var humanName = classType.name + '.' + fieldName;
6697
+ var desc = {
6698
+ get: function() {
6699
+ throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [getterReturnType, setterArgumentType]);
6700
+ },
6701
+ enumerable: true,
6702
+ configurable: true
6703
+ };
6704
+ if (setter) {
6705
+ desc.set = () => {
6706
+ throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [getterReturnType, setterArgumentType]);
6707
+ };
6708
+ } else {
6709
+ desc.set = (v) => {
6710
+ throwBindingError(humanName + ' is a read-only property');
6711
+ };
6712
+ }
6713
+
6714
+ Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
6715
+
6716
+ whenDependentTypesAreResolved(
6717
+ [],
6718
+ (setter ? [getterReturnType, setterArgumentType] : [getterReturnType]),
6719
+ function(types) {
6720
+ var getterReturnType = types[0];
6721
+ var desc = {
6722
+ get: function() {
6723
+ var ptr = validateThis(this, classType, humanName + ' getter');
6724
+ return getterReturnType['fromWireType'](getter(getterContext, ptr));
6725
+ },
6726
+ enumerable: true
6727
+ };
6728
+
6729
+ if (setter) {
6730
+ setter = embind__requireFunction(setterSignature, setter);
6731
+ var setterArgumentType = types[1];
6732
+ desc.set = function(v) {
6733
+ var ptr = validateThis(this, classType, humanName + ' setter');
6734
+ var destructors = [];
6735
+ setter(setterContext, ptr, setterArgumentType['toWireType'](destructors, v));
6736
+ runDestructors(destructors);
6737
+ };
6738
+ }
6739
+
6740
+ Object.defineProperty(classType.registeredClass.instancePrototype, fieldName, desc);
6741
+ return [];
6742
+ });
6743
+
6744
+ return [];
6745
+ });
6746
+ }
6747
+
6658
6748
  var emval_free_list = [];
6659
6749
 
6660
6750
  var emval_handle_array = [{},{value:undefined},{value:null},{value:true},{value:false}];
@@ -6914,6 +7004,45 @@ function unexportedRuntimeSymbol(sym) {
6914
7004
 
6915
7005
 
6916
7006
 
7007
+ function __embind_register_smart_ptr(rawType,
7008
+ rawPointeeType,
7009
+ name,
7010
+ sharingPolicy,
7011
+ getPointeeSignature,
7012
+ rawGetPointee,
7013
+ constructorSignature,
7014
+ rawConstructor,
7015
+ shareSignature,
7016
+ rawShare,
7017
+ destructorSignature,
7018
+ rawDestructor) {
7019
+ name = readLatin1String(name);
7020
+ rawGetPointee = embind__requireFunction(getPointeeSignature, rawGetPointee);
7021
+ rawConstructor = embind__requireFunction(constructorSignature, rawConstructor);
7022
+ rawShare = embind__requireFunction(shareSignature, rawShare);
7023
+ rawDestructor = embind__requireFunction(destructorSignature, rawDestructor);
7024
+
7025
+ whenDependentTypesAreResolved([rawType], [rawPointeeType], function(pointeeType) {
7026
+ pointeeType = pointeeType[0];
7027
+
7028
+ var registeredPointer = new RegisteredPointer(name,
7029
+ pointeeType.registeredClass,
7030
+ false,
7031
+ false,
7032
+ // smart pointer properties
7033
+ true,
7034
+ pointeeType,
7035
+ sharingPolicy,
7036
+ rawGetPointee,
7037
+ rawConstructor,
7038
+ rawShare,
7039
+ rawDestructor);
7040
+ return [registeredPointer];
7041
+ });
7042
+ }
7043
+
7044
+
7045
+
6917
7046
 
6918
7047
  function __embind_register_std_string(rawType, name) {
6919
7048
  name = readLatin1String(name);
@@ -7269,14 +7398,6 @@ function unexportedRuntimeSymbol(sym) {
7269
7398
 
7270
7399
  function __emscripten_throw_longjmp() { throw Infinity; }
7271
7400
 
7272
-
7273
- function __emval_incref(handle) {
7274
- if (handle > 4) {
7275
- emval_handle_array[handle].refcount += 1;
7276
- }
7277
- }
7278
-
7279
-
7280
7401
 
7281
7402
 
7282
7403
  function requireRegisteredType(rawType, humanName) {
@@ -7286,6 +7407,38 @@ function unexportedRuntimeSymbol(sym) {
7286
7407
  }
7287
7408
  return impl;
7288
7409
  }
7410
+ function emval_lookupTypes(argCount, argTypes) {
7411
+ var a = new Array(argCount);
7412
+ for (var i = 0; i < argCount; ++i) {
7413
+ a[i] = requireRegisteredType(HEAPU32[(((argTypes)+(i * 4))>>2)],
7414
+ "parameter " + i);
7415
+ }
7416
+ return a;
7417
+ }
7418
+
7419
+ function __emval_call(handle, argCount, argTypes, argv) {
7420
+ handle = Emval.toValue(handle);
7421
+ var types = emval_lookupTypes(argCount, argTypes);
7422
+
7423
+ var args = new Array(argCount);
7424
+ for (var i = 0; i < argCount; ++i) {
7425
+ var type = types[i];
7426
+ args[i] = type['readValueFromPointer'](argv);
7427
+ argv += type['argPackAdvance'];
7428
+ }
7429
+
7430
+ var rv = handle.apply(undefined, args);
7431
+ return Emval.toHandle(rv);
7432
+ }
7433
+
7434
+
7435
+ function __emval_incref(handle) {
7436
+ if (handle > 4) {
7437
+ emval_handle_array[handle].refcount += 1;
7438
+ }
7439
+ }
7440
+
7441
+
7289
7442
  function __emval_take_value(type, arg) {
7290
7443
  type = requireRegisteredType(type, '_emval_take_value');
7291
7444
  var v = type['readValueFromPointer'](arg);
@@ -8722,11 +8875,13 @@ var wasmImports = {
8722
8875
  "_embind_register_class": __embind_register_class,
8723
8876
  "_embind_register_class_constructor": __embind_register_class_constructor,
8724
8877
  "_embind_register_class_function": __embind_register_class_function,
8878
+ "_embind_register_class_property": __embind_register_class_property,
8725
8879
  "_embind_register_emval": __embind_register_emval,
8726
8880
  "_embind_register_float": __embind_register_float,
8727
8881
  "_embind_register_function": __embind_register_function,
8728
8882
  "_embind_register_integer": __embind_register_integer,
8729
8883
  "_embind_register_memory_view": __embind_register_memory_view,
8884
+ "_embind_register_smart_ptr": __embind_register_smart_ptr,
8730
8885
  "_embind_register_std_string": __embind_register_std_string,
8731
8886
  "_embind_register_std_wstring": __embind_register_std_wstring,
8732
8887
  "_embind_register_value_object": __embind_register_value_object,
@@ -8734,6 +8889,7 @@ var wasmImports = {
8734
8889
  "_embind_register_void": __embind_register_void,
8735
8890
  "_emscripten_get_now_is_monotonic": __emscripten_get_now_is_monotonic,
8736
8891
  "_emscripten_throw_longjmp": __emscripten_throw_longjmp,
8892
+ "_emval_call": __emval_call,
8737
8893
  "_emval_decref": __emval_decref,
8738
8894
  "_emval_incref": __emval_incref,
8739
8895
  "_emval_take_value": __emval_take_value,
@@ -9423,11 +9579,9 @@ var missingLibrarySymbols = [
9423
9579
  'registerInheritedInstance',
9424
9580
  'unregisterInheritedInstance',
9425
9581
  'enumReadValueFromPointer',
9426
- 'validateThis',
9427
9582
  'getStringOrSymbol',
9428
9583
  'craftEmvalAllocator',
9429
9584
  'emval_get_global',
9430
- 'emval_lookupTypes',
9431
9585
  'emval_allocateDestructors',
9432
9586
  'emval_addMethodCaller',
9433
9587
  ];
@@ -9619,6 +9773,7 @@ var unexportedSymbols = [
9619
9773
  'shallowCopyInternalPointer',
9620
9774
  'downcastPointer',
9621
9775
  'upcastPointer',
9776
+ 'validateThis',
9622
9777
  'char_0',
9623
9778
  'char_9',
9624
9779
  'makeLegalFunctionName',
@@ -9630,6 +9785,7 @@ var unexportedSymbols = [
9630
9785
  'get_first_emval',
9631
9786
  'Emval',
9632
9787
  'emval_newers',
9788
+ 'emval_lookupTypes',
9633
9789
  'emval_methodCallers',
9634
9790
  'emval_registeredMethods',
9635
9791
  ];
Binary file
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodtools/wiregasm",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "Packet Analyzer powered by Wireshark compiled for WebAssembly",
5
5
  "source": "src/index.ts",
6
6
  "main": "dist/main.js",