@webassemblyjs/wasm-edit
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
@webassemblyjs/ast | 1.11.1 | 35.54 kB | MIT | prod | |
@webassemblyjs/helper-buffer | 1.11.1 | 2.42 kB | MIT | prod | |
@webassemblyjs/helper-wasm-bytecode | 1.11.1 | 4.36 kB | MIT | prod | |
@webassemblyjs/helper-wasm-section | 1.11.1 | 3.82 kB | MIT | prod | |
@webassemblyjs/wasm-gen | 1.11.1 | 4.08 kB | MIT | prod | |
@webassemblyjs/wasm-opt | 1.11.1 | 2.64 kB | MIT | prod | |
@webassemblyjs/wasm-parser | 1.11.1 | 22.69 kB | MIT | prod | |
@webassemblyjs/wast-printer | 1.11.1 | 4.73 kB | MIT | prod |
The @webassemblyjs/wasm-edit
npm package is a JavaScript utility for rewriting WASM binaries. It allows you to perform operations such as replace, update, insert, and remove an Abstract Syntax Tree (AST) node within the binary in-place.
To use @webassemblyjs/wasm-edit
, you first need to install it in your project using the following command:
yarn add @webassemblyjs/wasm-edit
Post installation, you import the required function (edit
or add
) from the package and pass in the appropriate parameters.
Example code usage to Update:
import { edit } from "@webassemblyjs/wasm-edit";
const binary = [/*...*/]; // WASM binary data
const visitors = {
ModuleImport({ node }) {
node.module = "foo";
node.name = "bar";
}
};
const newBinary = edit(binary, visitors);
Example code usage to Replace:
import { edit } from "@webassemblyjs/wasm-edit";
const binary = [/*...*/]; // WASM binary data
const visitors = {
Instr(path) {
const newNode = t.callInstruction(t.indexLiteral(0));
path.replaceWith(newNode);
}
};
const newBinary = edit(binary, visitors);
Example code usage to Remove:
import { edit } from "@webassemblyjs/wasm-edit";
const binary = [/*...*/]; // WASM binary data
const visitors = {
ModuleExport({ node }) {
path.remove()
}
};
const newBinary = edit(binary, visitors);
Example code usage to Insert:
import { add } from "@webassemblyjs/wasm-edit";
const binary = [/*...*/]; // WASM binary data
const newBinary = add(actualBinary, [
t.moduleImport("env", "mem", t.memory(t.limit(1)))
]);
For detailed documentation on using @webassemblyjs/wasm-edit
, you can refer to the README file in the webassemblyjs GitHub repository.