@webassemblyjs/wasm-edit
> Rewrite a WASM binary
Last updated 5 years ago by xtuc .
MIT · Repository · Bugs · Original npm
$ cnpm install @webassemblyjs/wasm-edit 
SYNC missed versions from official npm registry.

@webassemblyjs/wasm-edit

Rewrite a WASM binary

Replace in-place an AST node in the binary.

Installation

yarn add @webassemblyjs/wasm-edit

Usage

Update:

import { edit } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const visitors = {
  ModuleImport({ node }) {
    node.module = "foo";
    node.name = "bar";
  }
};

const newBinary = edit(binary, visitors);

Replace:

import { edit } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const visitors = {
  Instr(path) {
    const newNode = t.callInstruction(t.indexLiteral(0));
    path.replaceWith(newNode);
  }
};

const newBinary = edit(binary, visitors);

Remove:

import { edit } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const visitors = {
  ModuleExport({ node }) {
    path.remove()
  }
};

const newBinary = edit(binary, visitors);

Insert:

import { add } from "@webassemblyjs/wasm-edit";

const binary = [/*...*/];

const newBinary = add(actualBinary, [
  t.moduleImport("env", "mem", t.memory(t.limit(1)))
]);

Providing the AST

Providing an AST allows you to handle the decoding yourself, here is the API:

addWithAST(Program, ArrayBuffer, Array<Node>): ArrayBuffer;
editWithAST(Program, ArrayBuffer, visitors): ArrayBuffer;

Note that the AST will be updated in-place.

Current Tags

  • 1.11.6                                ...           latest (2 years ago)

11 Versions

  • 1.11.6                                ...           2 years ago
  • 1.11.3                                ...           3 years ago
  • 1.11.1                                ...           4 years ago
  • 1.11.0                                ...           5 years ago
  • 1.9.1                                ...           5 years ago
  • 1.5.13                                ...           7 years ago
  • 1.5.12                                ...           7 years ago
  • 1.7.11                                ...           7 years ago
  • 1.7.6                                ...           7 years ago
  • 1.8.5                                ...           7 years ago
  • 1.9.0                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dev Dependencies (1)
Dependents (0)
None

Copyright 2013 - present © cnpmjs.org