Socket
Socket
Sign inDemoInstall

@webassemblyjs/helper-wasm-section

Package Overview
Dependencies
12
Maintainers
1
Versions
81
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @webassemblyjs/helper-wasm-section


Version published
Weekly downloads
23M
increased by2.73%
Maintainers
1
Install size
527 kB
Created
Weekly downloads
 

Package description

What is @webassemblyjs/helper-wasm-section?

The @webassemblyjs/helper-wasm-section package is part of the WebAssemblyJS project and provides utility functions for manipulating sections in WebAssembly (Wasm) binary files. It allows developers to parse, add, or modify sections within a Wasm binary, which can be useful for tasks such as Wasm optimization, analysis, or transformation.

What are @webassemblyjs/helper-wasm-section's main functionalities?

Parsing a Wasm section

This feature allows you to parse a specific section of a WebAssembly binary. The code sample demonstrates how to use the `getSectionMetadata` function to retrieve metadata for the 'type' section of a Wasm binary.

const { decode } = require('@webassemblyjs/wasm-parser');
const { getSectionMetadata } = require('@webassemblyjs/helper-wasm-section');

const wasmBuffer = ...; // A buffer containing the Wasm binary
const ast = decode(wasmBuffer);
const typeSectionMetadata = getSectionMetadata(ast, 'type');

Adding a new Wasm section

This feature allows you to add a new section to a WebAssembly binary. The code sample shows how to use the `addSection` function to add a new section to the AST of a Wasm binary and then encode it back into a binary format.

const { addSection } = require('@webassemblyjs/helper-wasm-section');
const { encode } = require('@webassemblyjs/wasm-gen');

const ast = ...; // The AST of a Wasm binary
const newSection = ...; // The new section to add
addSection(ast, newSection);
const newWasmBuffer = encode(ast);

Modifying an existing Wasm section

This feature allows you to modify the content of an existing section in a WebAssembly binary. The code sample illustrates how to use the `editSection` function to change the content of the 'code' section in the AST and then encode the modified AST back into a binary.

const { editSection } = require('@webassemblyjs/helper-wasm-section');
const { encode } = require('@webassemblyjs/wasm-gen');

const ast = ...; // The AST of a Wasm binary
const sectionName = 'code';
const newContent = ...; // The new content for the section
editSection(ast, sectionName, newContent);
const newWasmBuffer = encode(ast);

Other packages similar to @webassemblyjs/helper-wasm-section

FAQs

Last updated on 13 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc