Sha256: b91753384cafcdec8a430ca7b1f6870b649eb91380653a01350f2260c484a911

Contents?: true

Size: 1.33 KB

Versions: 28

Compression:

Stored size: 1.33 KB

Contents

# @webassemblyjs/wasm-edit

> Rewrite a WASM binary

Replace in-place an AST node in the binary.

## Installation

```sh
yarn add @webassemblyjs/wasm-edit
```

## Usage

Update:

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

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

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

const newBinary = edit(binary, visitors);
```

Replace:

```js
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:

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

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

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

const newBinary = edit(binary, visitors);
```

Insert:

```js
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:

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

Note that the AST will be updated in-place.

Version data entries

28 entries across 27 versions & 9 rubygems

Version Path
optimacms-0.1.61 spec/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.18.0 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.18.2 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.16.1 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.15.2 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.18.4 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.18.1 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.12.7.pre.puma.pre.3 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.14.0 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
disco_app-0.13.6.pre.puma.pre.3 test/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
tang-0.2.1 spec/tang_app/node_modules/@webassemblyjs/wasm-edit/README.md
groonga-client-model-6.0.0 test/apps/rails6.1.3/node_modules/@webassemblyjs/wasm-edit/README.md
groonga-client-model-6.0.0 test/apps/rails6.0.3.5/node_modules/@webassemblyjs/wasm-edit/README.md
ruby2js-4.0.4 lib/tasks/testrails/node_modules/@webassemblyjs/wasm-edit/README.md
ruby2js-4.0.3 lib/tasks/testrails/node_modules/@webassemblyjs/wasm-edit/README.md
tang-0.2.0 spec/tang_app/node_modules/@webassemblyjs/wasm-edit/README.md
tang-0.1.0 spec/tang_app/node_modules/@webassemblyjs/wasm-edit/README.md
tang-0.0.9 spec/tang_app/node_modules/@webassemblyjs/wasm-edit/README.md
enju_library-0.3.8 spec/dummy/node_modules/@webassemblyjs/wasm-edit/README.md
jester-data-8.0.0 node_modules/@webassemblyjs/wasm-edit/README.md