frameassembly-wasm 1.4.6 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,18 +1,39 @@
1
- # FrameAssembly WebAssembly Compiler (`frameassembly-wasm` v1.4.6)
1
+ # FrameAssembly WebAssembly Compiler (`frameassembly-wasm` v1.5.1)
2
2
 
3
- High-performance WebAssembly compiler, frame inspector, and UTF-16 IDE diagnostics for **FrameAssembly (`.fasm`)** — the **Packets as Code** domain-specific language for compiling `.fasm` code into deterministic `.pcapng` packet captures across 81 L2–L7 protocols for pentesting labs, testing firewall rules, simulating SNMPv1/v2c/v3 traps, and validating network monitoring and cybersecurity solutions in browser applications, web cyber ranges, and Node.js test suites. *(Note: FrameAssembly is a network protocol DSL, not x86 Flat Assembler).*
3
+ [![Website & Playground](https://img.shields.io/badge/web%20app-frameassembly.ai.studio-0ea5e9.svg)](https://frameassembly.ai.studio/)
4
+ [![NPM](https://img.shields.io/npm/v/frameassembly-wasm.svg)](https://www.npmjs.com/package/frameassembly-wasm)
5
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/SteveWinschel/FrameAssembly/blob/main/LICENSE)
6
+
7
+ [**Try in Browser (`frameassembly.ai.studio`)**](https://frameassembly.ai.studio/) • [**Installation**](#installation) • [**Vite, React & Next.js**](#initialization-vite-react-nextjs--google-ai-studio) • [**TypeScript API**](#typescript-api-reference)
8
+
9
+ WebAssembly compiler, `.pcap`/`.pcapng`-to-`.fasm` decompiler, frame inspector, and UTF-16 IDE diagnostics for **FrameAssembly (`.fasm`)** — compiling `.fasm` code into `.pcapng` packet captures and decompiling existing captures back into `.fasm` code across 81 L2–L7 protocols in browser applications, web cyber ranges, and Node.js test suites. Powers the official FrameAssembly interactive browser playground at [**frameassembly.ai.studio**](https://frameassembly.ai.studio/). *(Note: FrameAssembly is a network protocol DSL, not x86 Flat Assembler).*
4
10
 
5
11
  ---
6
12
 
7
- ## Client-Side `.fasm` to `.pcapng` Compilation in the Browser & Node.js
13
+ ## Client-Side `.fasm` to `.pcapng` Compilation & PCAP Decompilation in the Browser & Node.js
14
+
15
+ `frameassembly-wasm` compiles the FrameAssembly Rust engine to WebAssembly, turning `.fasm` code into `.pcapng` byte streams, decompiling binary `.pcap` and `.pcapng` captures into `.fasm` code via `reversePcap(pcapBytes)`, and emitting real-time Monaco/CodeMirror syntax diagnostics directly in the browser or Node.js without a backend server:
8
16
 
9
- `frameassembly-wasm` compiles the complete FrameAssembly Rust engine directly to WebAssembly, turning `.fasm` code into nanosecond-precision `.pcapng` byte streams and real-time Monaco/CodeMirror syntax diagnostics entirely in the browser or Node.js—with no backend packet-crafting server, root privileges (`CAP_NET_RAW`), Python `Scapy` runtime, manual `text2pcap` hex offsets, or native `libpcap` dependencies required:
17
+ ```frameassembly
18
+ host client { ip 192.168.1.10 mac 00:11:22:33:44:55 }
19
+ host server { ip 8.8.8.8 mac aa:bb:cc:dd:ee:ff }
20
+
21
+ flow dns_query(c, s) {
22
+ c -> s dns query txid 0x1234 qname "example.com" qtype "A" wait 1ms
23
+ c <- s dns response txid 0x1234 qname "example.com" qtype "A" rdata 93.184.216.34 wait 1ms
24
+ }
25
+
26
+ compile {
27
+ dns_query(client, server)
28
+ }
29
+ ```
10
30
 
11
31
  ```ts
12
32
  import init, {
13
33
  compile_fasm_to_pcapng,
14
34
  validate_fasm,
15
35
  inspect_fasm,
36
+ reversePcap,
16
37
  } from "frameassembly-wasm";
17
38
 
18
39
  // Initialize WASM module once at startup
@@ -23,7 +44,7 @@ host server { ip 8.8.8.8 mac aa:bb:cc:dd:ee:ff }
23
44
 
24
45
  flow dns_query(c, s) {
25
46
  c -> s dns query txid 0x1234 qname "example.com" qtype "A" wait 1ms
26
- c <- s dns response txid 0x1234 qname "example.com" qtype "A" rdata "93.184.216.34" wait 1ms
47
+ c <- s dns response txid 0x1234 qname "example.com" qtype "A" rdata 93.184.216.34 wait 1ms
27
48
  }
28
49
 
29
50
  compile {
@@ -41,6 +62,10 @@ if (diagnostics.length === 0) {
41
62
  const pcapngBytes = compile_fasm_to_pcapng(source);
42
63
  const blob = new Blob([pcapngBytes], { type: "application/vnd.tcpdump.pcap" });
43
64
  console.log(`Generated PCAPNG: ${blob.size} bytes`);
65
+
66
+ // 4. Decompile binary PCAP/PCAPNG bytes back into canonical .fasm code
67
+ const reversed = reversePcap(pcapngBytes);
68
+ console.log(`Reversed ${reversed.packetCount} frames across ${reversed.hostCount} hosts:\n${reversed.fasm}`);
44
69
  }
45
70
  ```
46
71
 
@@ -64,10 +89,11 @@ npm install frameassembly-wasm
64
89
  validate_fasm,
65
90
  inspect_fasm,
66
91
  compile_fasm_to_pcapng,
67
- } from "https://cdn.jsdelivr.net/npm/frameassembly-wasm@1.4.6/frameassembly_wasm.js";
92
+ reversePcap,
93
+ } from "https://cdn.jsdelivr.net/npm/frameassembly-wasm@1.5.1/frameassembly_wasm.js";
68
94
 
69
95
  await init();
70
- console.log("FrameAssembly WebAssembly engine loaded successfully.");
96
+ console.log("FrameAssembly WebAssembly engine v1.5.1 loaded successfully.");
71
97
  </script>
72
98
  ```
73
99
 
@@ -82,8 +108,10 @@ import init, {
82
108
  validate_fasm,
83
109
  inspect_fasm,
84
110
  compile_fasm_to_pcapng,
111
+ reversePcap,
85
112
  type IdeDiagnostic,
86
113
  type PacketPreview,
114
+ type ReversePcapResult,
87
115
  } from "frameassembly-wasm";
88
116
  import wasmUrl from "frameassembly-wasm/frameassembly_wasm_bg.wasm?url";
89
117
 
@@ -95,7 +123,7 @@ await init({ module_or_path: wasmUrl });
95
123
 
96
124
  ## API Reference
97
125
 
98
- ### `validate_fasm(source: string): IdeDiagnostic[]`
126
+ ### `validate_fasm(source: string): IdeDiagnostic[]` / `validateFasm(source: string): IdeDiagnostic[]`
99
127
  Parses and validates `.fasm` source code, returning zero-based UTF-16 line and column spans ready for Monaco Editor or CodeMirror 6 diagnostic markers. Returns an empty array `[]` when the source compiles cleanly.
100
128
 
101
129
  ```ts
@@ -114,22 +142,36 @@ Compiles `.fasm` source code into an array of packet inspection summaries, inclu
114
142
 
115
143
  ```ts
116
144
  interface PacketPreview {
117
- index: number; // 0-based frame index
145
+ index: number; // 1-based frame index
118
146
  timestamp_ms: number; // Relative timestamp in milliseconds
119
147
  length: number; // Total packet length in bytes
120
148
  hex: string; // Space-separated lowercase hex byte dump
121
149
  }
122
150
  ```
123
151
 
124
- ### `compile_fasm_to_pcapng(source: string): Uint8Array`
152
+ ### `compile_fasm_to_pcapng(source: string): Uint8Array` / `compileFasm(source: string): Uint8Array`
125
153
  Compiles `.fasm` source code into a binary `Uint8Array` containing a valid, standards-compliant PCAPNG byte stream with nanosecond timestamp precision (`IfTsResol = 9`). Throws a JavaScript `Error` with rich diagnostic context if compilation fails.
126
154
 
155
+ ### `reversePcap(pcap_bytes: Uint8Array): ReverseJsResult`
156
+ Decompiles an in-memory `.pcap` or `.pcapng` byte array (`Uint8Array`) across all 81 native Layer 2 through Layer 7 protocols into canonical lowercase `.fasm` code (`host` declarations and an inline `compile` block), returning summary statistics (`packetCount`, `hostCount`). Throws a structured error object (`{ success: false, error, message }`) if `pcap_bytes` is not a valid packet capture.
157
+
158
+ ```ts
159
+ interface ReversePcapResult {
160
+ success: boolean; // true when decompilation succeeds
161
+ fasm: string; // Canonical lowercase .fasm source code
162
+ packetCount: number; // Total number of reversed packets
163
+ hostCount: number; // Total number of host_N declarations emitted
164
+ }
165
+
166
+ type ReverseJsResult = ReversePcapResult;
167
+ ```
168
+
127
169
  ---
128
170
 
129
171
  ## Complete Browser Playground & Download Example
130
172
 
131
173
  ```ts
132
- import init, { compile_fasm_to_pcapng, validate_fasm } from "frameassembly-wasm";
174
+ import init, { compile_fasm_to_pcapng, reversePcap, validate_fasm } from "frameassembly-wasm";
133
175
 
134
176
  export async function downloadCapture(fasmCode: string, filename = "capture.pcapng") {
135
177
  await init();
@@ -151,6 +193,13 @@ export async function downloadCapture(fasmCode: string, filename = "capture.pcap
151
193
  document.body.removeChild(a);
152
194
  URL.revokeObjectURL(url);
153
195
  }
196
+
197
+ export async function importCaptureFile(file: File): Promise<string> {
198
+ await init();
199
+ const bytes = new Uint8Array(await file.arrayBuffer());
200
+ const result = reversePcap(bytes);
201
+ return result.fasm;
202
+ }
154
203
  ```
155
204
 
156
205
  ---
@@ -158,14 +207,14 @@ export async function downloadCapture(fasmCode: string, filename = "capture.pcap
158
207
  ## Features & Engine Capabilities
159
208
 
160
209
  - **Zero Server Dependencies**: Executes 100% locally in WebAssembly inside Chrome, Firefox, Safari, Edge, Web Workers, and Node.js.
161
- - **81 Native Protocols**: Complete coverage across L2–L7 (Ethernet, 802.1Q VLAN, QinQ, MPLS, ARP, IPv4/IPv6, ICMP, TCP, UDP, SCTP, SNMPv1/v2c/v3 USM, DNS, DHCP, HTTP, TLS, Modbus, DNP3, and more).
162
- - **Nanosecond Fidelity**: Compiles deterministic PCAPNG captures with nanosecond-resolution Section and Interface Description Blocks (`IfTsResol(9)`).
163
- - **Sub-Millisecond Compilation**: Small to medium captures compile in `< 5ms`, making real-time live typing diagnostics instantaneous in web editors.
210
+ - **81 Native Protocols (Forward & Reverse)**: Complete compilation and `.pcap`/`.pcapng` decompilation coverage across L2–L7 (Ethernet, 802.1Q VLAN, QinQ, MPLS, ARP, IPv4/IPv6, ICMP, TCP, UDP, SCTP, SNMPv1/v2c/v3 USM, DNS, DHCP, HTTP, TLS, Modbus, DNP3, and more), including pure Layer-2 MAC-only switch topologies and inline `compile` statements.
211
+ - **Nanosecond Fidelity**: Compiles and reverses deterministic PCAP/PCAPNG captures with nanosecond-resolution Section and Interface Description Blocks (`IfTsResol(9)`).
212
+ - **Sub-Millisecond Compilation**: Small to medium captures compile and decompile in `< 5ms`, making real-time live typing diagnostics and drag-and-drop PCAP import instantaneous in web editors.
164
213
 
165
214
  ---
166
215
 
167
216
  ## Disambiguation: FrameAssembly vs. Flat Assembler
168
217
 
169
- **FrameAssembly** (`.fasm`, media type `text/vnd.frameassembly`) is a domain-specific network protocol specification language for synthesizing deterministic `.pcap` and `.pcapng` packet captures. It is completely unrelated to x86 Flat Assembler (`fasm.net`) and SymbiFlow / F4PGA FPGA bitstream FASM tools.
218
+ **FrameAssembly** (`.fasm`, media type `text/vnd.frameassembly`) is a domain-specific network protocol specification language for synthesizing and decompiling deterministic `.pcap` and `.pcapng` packet captures. It is completely unrelated to x86 Flat Assembler (`fasm.net`) and SymbiFlow / F4PGA FPGA bitstream FASM tools.
170
219
 
171
- Full documentation, grammar specifications, and 2,611 verified examples: https://github.com/SteveWinschel/FrameAssembly
220
+ Full documentation, interactive browser playground ([https://frameassembly.ai.studio/](https://frameassembly.ai.studio/)), grammar specifications, and 2,611 verified examples: https://github.com/SteveWinschel/FrameAssembly
@@ -17,10 +17,30 @@ export interface PacketPreview {
17
17
  hex: string;
18
18
  }
19
19
 
20
+ export interface ReversePcapResult {
21
+ success: boolean;
22
+ fasm: string;
23
+ packetCount: number;
24
+ hostCount: number;
25
+ }
26
+
27
+ export type ReverseJsResult = ReversePcapResult;
28
+
29
+ export interface ReversePcapError {
30
+ success: boolean;
31
+ error: string;
32
+ message: string;
33
+ }
34
+
20
35
 
21
36
 
22
37
  /**
23
- * Compiles .fasm source into a standards-compliant PCAPNG byte array (JS Uint8Array).
38
+ * Compiles `.fasm` source into a standards-compliant PCAPNG byte array (`compileFasm` alias).
39
+ */
40
+ export function compileFasm(source: string): Uint8Array;
41
+
42
+ /**
43
+ * Compiles `.fasm` source into a standards-compliant PCAPNG byte array (JS `Uint8Array`).
24
44
  */
25
45
  export function compile_fasm_to_pcapng(source: string): Uint8Array;
26
46
 
@@ -30,7 +50,22 @@ export function compile_fasm_to_pcapng(source: string): Uint8Array;
30
50
  export function inspect_fasm(source: string): PacketPreview[];
31
51
 
32
52
  /**
33
- * Validates .fasm source and returns UTF-16 line/column diagnostics for Monaco/CodeMirror.
53
+ * Decompiles an in-memory `.pcap` or `.pcapng` capture (`Uint8Array`) into canonical `.fasm`
54
+ * source code and summary counts (`{ success: true, fasm, packetCount, hostCount }`).
55
+ *
56
+ * # Errors
57
+ * Returns a structured `JsValue` error object (`{ success: false, error, message }`) if
58
+ * `pcap_bytes` is not a valid `.pcap` or `.pcapng` capture.
59
+ */
60
+ export function reversePcap(pcap_bytes: Uint8Array | number[]): ReversePcapResult;
61
+
62
+ /**
63
+ * Validates `.fasm` source and returns UTF-16 line/column diagnostics (`validateFasm` alias).
64
+ */
65
+ export function validateFasm(source: string): IdeDiagnostic[];
66
+
67
+ /**
68
+ * Validates `.fasm` source and returns UTF-16 line/column diagnostics for Monaco/CodeMirror.
34
69
  */
35
70
  export function validate_fasm(source: string): IdeDiagnostic[];
36
71
 
@@ -38,8 +73,11 @@ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembl
38
73
 
39
74
  export interface InitOutput {
40
75
  readonly memory: WebAssembly.Memory;
76
+ readonly compileFasm: (a: number, b: number) => [number, number, number, number];
41
77
  readonly compile_fasm_to_pcapng: (a: number, b: number) => [number, number, number, number];
42
78
  readonly inspect_fasm: (a: number, b: number) => [number, number, number];
79
+ readonly reversePcap: (a: number, b: number) => [number, number, number];
80
+ readonly validateFasm: (a: number, b: number) => [number, number, number];
43
81
  readonly validate_fasm: (a: number, b: number) => [number, number, number];
44
82
  readonly __wbindgen_malloc: (a: number, b: number) => number;
45
83
  readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
@@ -1,7 +1,24 @@
1
1
  /* @ts-self-types="./frameassembly_wasm.d.ts" */
2
2
 
3
3
  /**
4
- * Compiles .fasm source into a standards-compliant PCAPNG byte array (JS Uint8Array).
4
+ * Compiles `.fasm` source into a standards-compliant PCAPNG byte array (`compileFasm` alias).
5
+ * @param {string} source
6
+ * @returns {Uint8Array}
7
+ */
8
+ export function compileFasm(source) {
9
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
10
+ const len0 = WASM_VECTOR_LEN;
11
+ const ret = wasm.compileFasm(ptr0, len0);
12
+ if (ret[3]) {
13
+ throw takeFromExternrefTable0(ret[2]);
14
+ }
15
+ var v2 = getArrayU8FromWasm0(ret[0], ret[1]).slice();
16
+ wasm.__wbindgen_free(ret[0], ret[1] * 1, 1);
17
+ return v2;
18
+ }
19
+
20
+ /**
21
+ * Compiles `.fasm` source into a standards-compliant PCAPNG byte array (JS `Uint8Array`).
5
22
  * @param {string} source
6
23
  * @returns {Uint8Array}
7
24
  */
@@ -33,7 +50,42 @@ export function inspect_fasm(source) {
33
50
  }
34
51
 
35
52
  /**
36
- * Validates .fasm source and returns UTF-16 line/column diagnostics for Monaco/CodeMirror.
53
+ * Decompiles an in-memory `.pcap` or `.pcapng` capture (`Uint8Array`) into canonical `.fasm`
54
+ * source code and summary counts (`{ success: true, fasm, packetCount, hostCount }`).
55
+ *
56
+ * # Errors
57
+ * Returns a structured `JsValue` error object (`{ success: false, error, message }`) if
58
+ * `pcap_bytes` is not a valid `.pcap` or `.pcapng` capture.
59
+ * @param {Uint8Array | number[]} pcap_bytes
60
+ * @returns {ReversePcapResult}
61
+ */
62
+ export function reversePcap(pcap_bytes) {
63
+ const ptr0 = passArray8ToWasm0(pcap_bytes, wasm.__wbindgen_malloc);
64
+ const len0 = WASM_VECTOR_LEN;
65
+ const ret = wasm.reversePcap(ptr0, len0);
66
+ if (ret[2]) {
67
+ throw takeFromExternrefTable0(ret[1]);
68
+ }
69
+ return takeFromExternrefTable0(ret[0]);
70
+ }
71
+
72
+ /**
73
+ * Validates `.fasm` source and returns UTF-16 line/column diagnostics (`validateFasm` alias).
74
+ * @param {string} source
75
+ * @returns {IdeDiagnostic[]}
76
+ */
77
+ export function validateFasm(source) {
78
+ const ptr0 = passStringToWasm0(source, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
79
+ const len0 = WASM_VECTOR_LEN;
80
+ const ret = wasm.validateFasm(ptr0, len0);
81
+ if (ret[2]) {
82
+ throw takeFromExternrefTable0(ret[1]);
83
+ }
84
+ return takeFromExternrefTable0(ret[0]);
85
+ }
86
+
87
+ /**
88
+ * Validates `.fasm` source and returns UTF-16 line/column diagnostics for Monaco/CodeMirror.
37
89
  * @param {string} source
38
90
  * @returns {IdeDiagnostic[]}
39
91
  */
@@ -133,6 +185,13 @@ function getUint8ArrayMemory0() {
133
185
  return cachedUint8ArrayMemory0;
134
186
  }
135
187
 
188
+ function passArray8ToWasm0(arg, malloc) {
189
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
190
+ getUint8ArrayMemory0().set(arg, ptr / 1);
191
+ WASM_VECTOR_LEN = arg.length;
192
+ return ptr;
193
+ }
194
+
136
195
  function passStringToWasm0(arg, malloc, realloc) {
137
196
  if (realloc === undefined) {
138
197
  const buf = cachedTextEncoder.encode(arg);
Binary file
package/package.json CHANGED
@@ -4,8 +4,8 @@
4
4
  "collaborators": [
5
5
  "Steve Winschel"
6
6
  ],
7
- "description": "WebAssembly compiler, packet inspector, and IDE diagnostics for the FrameAssembly (.fasm) network packet synthesis DSL",
8
- "version": "1.4.6",
7
+ "description": "WebAssembly compiler, PCAP/PCAPNG decompiler, packet inspector, and IDE diagnostics for the FrameAssembly (.fasm) network packet synthesis DSL",
8
+ "version": "1.5.1",
9
9
  "license": "MIT",
10
10
  "repository": {
11
11
  "type": "git",
@@ -17,7 +17,7 @@
17
17
  "frameassembly_wasm.d.ts"
18
18
  ],
19
19
  "main": "frameassembly_wasm.js",
20
- "homepage": "https://github.com/SteveWinschel/FrameAssembly",
20
+ "homepage": "https://frameassembly.ai.studio/",
21
21
  "types": "frameassembly_wasm.d.ts",
22
22
  "sideEffects": [
23
23
  "./snippets/*"