@webassemblyjs/wasm-edit

1.14.1 • Public • Published

@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.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.14.114,083,248latest

Version History

VersionDownloads (Last 7 Days)Published
1.14.114,083,248
1.13.2562
1.13.13,661
1.12.13,564,844
1.11.61,927,772
1.11.5141,879
1.11.33
1.11.12,693,082
1.11.0184,537
1.10.13
1.10.03
1.9.130,170
1.9.03,742,042
1.8.5802,727
1.8.46
1.8.35,884
1.8.2894
1.8.13
1.8.03
1.7.11141,807
1.7.106,981
1.7.924
1.7.815,460
1.7.73
1.7.644,976
1.7.53
1.7.43
1.7.33
1.7.23
1.7.2-13
1.7.2-02
1.7.13
1.7.02
1.7.0-32
1.7.0-22
1.7.0-12
1.6.13
1.7.1-02
1.7.0-02
1.6.03
1.5.1336,701
1.5.1213,628
1.5.113
1.5.10950
1.5.93,782
1.5.82,059
1.5.73
1.5.63
1.5.53
1.5.43
1.5.33
1.5.23
1.5.13
1.5.03
1.4.322,627
1.4.21,943
1.4.13
1.4.03
1.3.33
1.3.23
1.3.1693
1.3.0395
1.2.83
1.2.73
1.2.63
1.2.53
1.2.43
1.2.33
1.2.23
1.2.13
1.2.02
1.1.2-y.102
1.1.2-y.92
1.1.2-y.82
1.1.2-y.72
1.1.2-y.62
1.1.2-y.52
1.1.2-y.42
1.1.2-y.32
1.1.2-y.22
1.1.2-y.12
1.1.2-y.02
1.1.13
1.1.02

Package Sidebar

Install

npm i @webassemblyjs/wasm-edit

Weekly Downloads

27,473,482

Version

1.14.1

License

MIT

Unpacked Size

34.6 kB

Total Files

7

Last publish

Collaborators

  • xtuc