Home
Docs
GitHub
Pricing
Blog
Log In

Run Sandworm Audit for your App

Get started

@webassemblyjs/wasm-edit 1.11.3

> Rewrite a WASM binary
Package summary
Share
0
issues
0
licenses
Package created
5 Mar 2018
Version published
2 Jul 2022
Maintainers
1
Total deps
0
Direct deps
0
License
MIT
Error Generating Report

Frequently Asked Questions

What does @webassemblyjs/wasm-edit do?

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.

How do you use @webassemblyjs/wasm-edit?

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)))
]);

Where are the @webassemblyjs/wasm-edit docs?

For detailed documentation on using @webassemblyjs/wasm-edit, you can refer to the README file in the webassemblyjs GitHub repository.