Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@webassemblyjs/wasm-parser

Package Overview
Dependencies
Maintainers
1
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@webassemblyjs/wasm-parser - npm Package Compare versions

Comparing version 1.2.2 to 1.2.3

94

lib/decoder.js

@@ -10,2 +10,4 @@ "use strict";

var _leb = require("@webassemblyjs/leb128");
function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }

@@ -29,14 +31,6 @@

var _require2 = require("@webassemblyjs/helper-leb128"),
decodeInt32 = _require2.decodeInt32,
decodeUInt32 = _require2.decodeUInt32,
MAX_NUMBER_OF_BYTE_U32 = _require2.MAX_NUMBER_OF_BYTE_U32,
decodeInt64 = _require2.decodeInt64,
decodeUInt64 = _require2.decodeUInt64,
MAX_NUMBER_OF_BYTE_U64 = _require2.MAX_NUMBER_OF_BYTE_U64;
var ieee754 = require("./ieee754");
var _require3 = require("./utf8"),
utf8ArrayToStr = _require3.utf8ArrayToStr;
var _require2 = require("./utf8"),
utf8ArrayToStr = _require2.utf8ArrayToStr;
/**

@@ -75,16 +69,3 @@ * FIXME(sven): we can't do that because number > 2**53 will fail here

var buf = new Uint8Array(ab);
var inc = {};
function getUniqueName() {
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "temp";
if (!inc.hasOwnProperty(prefix)) {
inc[prefix] = 0;
} else {
inc[prefix] = inc[prefix] + 1;
}
return prefix + "_" + inc[prefix];
}
var getUniqueName = t.getUniqueNameGenerator();
var offset = 0;

@@ -207,5 +188,5 @@

function readU32() {
var bytes = readBytes(MAX_NUMBER_OF_BYTE_U32);
var bytes = readBytes(_leb.MAX_NUMBER_OF_BYTE_U32);
var buffer = Buffer.from(bytes);
return decodeUInt32(buffer);
return (0, _leb.decodeUInt32)(buffer);
}

@@ -218,5 +199,5 @@ /**

function read32() {
var bytes = readBytes(MAX_NUMBER_OF_BYTE_U32);
var bytes = readBytes(_leb.MAX_NUMBER_OF_BYTE_U32);
var buffer = Buffer.from(bytes);
return decodeInt32(buffer);
return (0, _leb.decodeInt32)(buffer);
}

@@ -229,11 +210,11 @@ /**

function read64() {
var bytes = readBytes(MAX_NUMBER_OF_BYTE_U64);
var bytes = readBytes(_leb.MAX_NUMBER_OF_BYTE_U64);
var buffer = Buffer.from(bytes);
return decodeInt64(buffer);
return (0, _leb.decodeInt64)(buffer);
}
function readU64() {
var bytes = readBytes(MAX_NUMBER_OF_BYTE_U64);
var bytes = readBytes(_leb.MAX_NUMBER_OF_BYTE_U64);
var buffer = Buffer.from(bytes);
return decodeUInt64(buffer);
return (0, _leb.decodeUInt64)(buffer);
}

@@ -429,5 +410,6 @@

throw new _errors.CompileError("function signature not found (".concat(typeindex, ")"));
}
} // preserve anonymous, a name might be resolved later
var id = t.identifier(getUniqueName("func"));
var id = t.withRaw(t.identifier(getUniqueName("func")), "");
state.functionsInModule.push({

@@ -476,3 +458,4 @@ id: id,

id = func.id;
id = t.cloneNode(func.id);
id = t.withRaw(id, String(index));
signature = func.signature;

@@ -493,2 +476,3 @@ } else if (exportTypes[typeIndex] === "Table") {

id = t.identifier(getUniqueName("memory"));
id = t.withRaw(id, ""); // preserve anonymous
}

@@ -606,4 +590,5 @@

var instr = [];
parseInstructionBlock(instr);
var label = t.identifier(getUniqueName("loop"));
parseInstructionBlock(instr); // preserve anonymous
var label = t.withRaw(t.identifier(getUniqueName("loop")), "");
var loopNode = t.loopInstruction(label, blocktype, instr);

@@ -627,4 +612,5 @@ code.push(loopNode);

var alternate = []; // FIXME(sven): where is that stored?
// preserve anonymous
var testIndex = t.identifier(getUniqueName("ifindex"));
var testIndex = t.withRaw(t.identifier(getUniqueName("ifindex")), "");
var testInstrs = [];

@@ -646,8 +632,7 @@ var ifNode = t.ifInstruction(testIndex, _blocktype, testInstrs, consequentInstr, alternate);

var _instr = [];
parseInstructionBlock(_instr);
parseInstructionBlock(_instr); // preserve anonymous
var _label = t.identifier(getUniqueName()); // FIXME(sven): result type is ignored?
var _label = t.withRaw(t.identifier(getUniqueName("block")), "");
var blockNode = t.blockInstruction(_label, _instr);
var blockNode = t.blockInstruction(_label, _instr, _blocktype2);
code.push(blockNode);

@@ -663,2 +648,19 @@ instructionAlreadyCreated = true;

instructionAlreadyCreated = true;
} else if (instruction.name === "call_indirect") {
var indexU32 = readU32();
var typeindex = indexU32.value;
eatBytes(indexU32.nextIndex);
dump([typeindex], "type index");
var signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new _errors.CompileError("call_indirect signature not found (".concat(typeindex, ")"));
}
var _callNode = t.callIndirectInstruction(signature.params, signature.result, []);
eatBytes(1); // 0x00 - reserved byte
code.push(_callNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "br_table") {

@@ -670,3 +672,3 @@ var indicesu32 = readU32();

for (var i = 0; i < indices; i++) {
for (var i = 0; i <= indices; i++) {
var _indexu = readU32();

@@ -677,8 +679,4 @@

dump([_index], "index");
args.push(t.numberLiteral(_indexu.value.toString(), "f64"));
}
var labelIndexu32 = readU32();
var labelIndex = labelIndexu32.value;
eatBytes(labelIndexu32.nextIndex);
dump([labelIndex], "label index");
} else if (instructionByte >= 0x28 && instructionByte <= 0x40) {

@@ -685,0 +683,0 @@ /**

@@ -8,4 +8,2 @@ "use strict";

var _ast = require("@webassemblyjs/ast");
var decoder = _interopRequireWildcard(require("./decoder"));

@@ -15,2 +13,4 @@

var t = require("@webassemblyjs/ast");
var defaultDecoderOpts = {

@@ -21,7 +21,8 @@ dump: false,

ignoreCustomNameSection: false
};
}; // traverses the AST, locating function name metadata, which is then
// used to update index-based identifiers with function names
function restoreNames(ast) {
var functionNames = [];
(0, _ast.traverse)(ast, {
t.traverse(ast, {
FunctionNameMetadata: function FunctionNameMetadata(_ref) {

@@ -40,3 +41,3 @@ var node = _ref.node;

(0, _ast.traverse)(ast, {
t.traverse(ast, {
Func: function (_Func) {

@@ -63,4 +64,57 @@ function Func(_x) {

if (functionName) {
nodeName.value = functionName.name;
nodeName.value = functionName.name; // $FlowIgnore
delete nodeName.raw;
}
}),
// Also update the reference in the export
ModuleExport: function (_ModuleExport) {
function ModuleExport(_x2) {
return _ModuleExport.apply(this, arguments);
}
ModuleExport.toString = function () {
return _ModuleExport.toString();
};
return ModuleExport;
}(function (_ref3) {
var node = _ref3.node;
if (node.descr.type === "Func") {
// $FlowIgnore
var nodeName = node.descr.id;
var indexBasedFunctionName = nodeName.value;
var index = Number(indexBasedFunctionName.replace("func_", ""));
var functionName = functionNames.find(function (f) {
return f.index === index;
});
if (functionName) {
nodeName.value = functionName.name;
}
}
}),
CallInstruction: function (_CallInstruction) {
function CallInstruction(_x3) {
return _CallInstruction.apply(this, arguments);
}
CallInstruction.toString = function () {
return _CallInstruction.toString();
};
return CallInstruction;
}(function (nodePath) {
var node = nodePath.node;
var index = node.index.value;
var functionName = functionNames.find(function (f) {
return f.index === index;
});
if (functionName) {
node.index = t.identifier(functionName.name); // $FlowIgnore
delete node.raw;
}
})

@@ -67,0 +121,0 @@ });

{
"name": "@webassemblyjs/wasm-parser",
"version": "1.2.2",
"version": "1.2.3",
"keywords": [

@@ -19,7 +19,7 @@ "webassembly",

"dependencies": {
"@webassemblyjs/ast": "1.2.2",
"@webassemblyjs/helper-leb128": "1.2.2",
"@webassemblyjs/helper-wasm-bytecode": "1.2.2",
"@webassemblyjs/wasm-parser": "1.2.2",
"webassemblyjs": "1.2.2"
"@webassemblyjs/ast": "1.2.3",
"@webassemblyjs/helper-wasm-bytecode": "1.2.3",
"@webassemblyjs/leb128": "1.2.3",
"@webassemblyjs/wasm-parser": "1.2.3",
"webassemblyjs": "1.2.3"
},

@@ -32,3 +32,7 @@ "repository": {

"access": "public"
},
"devDependencies": {
"@webassemblyjs/wast-parser": "1.2.3",
"wabt": "^1.0.0"
}
}
// @flow
import { CompileError } from "webassemblyjs/lib/errors";
import {
decodeInt32,
decodeUInt32,
MAX_NUMBER_OF_BYTE_U32,
decodeInt64,
decodeUInt64,
MAX_NUMBER_OF_BYTE_U64
} from "@webassemblyjs/leb128";
const t = require("@webassemblyjs/ast");

@@ -20,12 +30,2 @@ const {

const {
decodeInt32,
decodeUInt32,
MAX_NUMBER_OF_BYTE_U32,
decodeInt64,
decodeUInt64,
MAX_NUMBER_OF_BYTE_U64
} = require("@webassemblyjs/helper-leb128");
const ieee754 = require("./ieee754");

@@ -66,13 +66,4 @@ const { utf8ArrayToStr } = require("./utf8");

const inc = {};
const getUniqueName = t.getUniqueNameGenerator();
function getUniqueName(prefix: string = "temp"): string {
if (!inc.hasOwnProperty(prefix)) {
inc[prefix] = 0;
} else {
inc[prefix] = inc[prefix] + 1;
}
return prefix + "_" + inc[prefix];
}
let offset = 0;

@@ -468,3 +459,4 @@

const id = t.identifier(getUniqueName("func"));
// preserve anonymous, a name might be resolved later
const id = t.withRaw(t.identifier(getUniqueName("func")), "");

@@ -522,3 +514,5 @@ state.functionsInModule.push({

id = func.id;
id = t.cloneNode(func.id);
id = t.withRaw(id, String(index));
signature = func.signature;

@@ -541,2 +535,3 @@ } else if (exportTypes[typeIndex] === "Table") {

id = t.identifier(getUniqueName("memory"));
id = t.withRaw(id, ""); // preserve anonymous
}

@@ -680,3 +675,4 @@

const label = t.identifier(getUniqueName("loop"));
// preserve anonymous
const label = t.withRaw(t.identifier(getUniqueName("loop")), "");
const loopNode = t.loopInstruction(label, blocktype, instr);

@@ -707,3 +703,4 @@

// FIXME(sven): where is that stored?
const testIndex = t.identifier(getUniqueName("ifindex"));
// preserve anonymous
const testIndex = t.withRaw(t.identifier(getUniqueName("ifindex")), "");
const testInstrs = [];

@@ -738,6 +735,6 @@

const label = t.identifier(getUniqueName());
// preserve anonymous
const label = t.withRaw(t.identifier(getUniqueName("block")), "");
// FIXME(sven): result type is ignored?
const blockNode = t.blockInstruction(label, instr);
const blockNode = t.blockInstruction(label, instr, blocktype);

@@ -757,2 +754,27 @@ code.push(blockNode);

instructionAlreadyCreated = true;
} else if (instruction.name === "call_indirect") {
const indexU32 = readU32();
const typeindex = indexU32.value;
eatBytes(indexU32.nextIndex);
dump([typeindex], "type index");
const signature = state.typesInModule[typeindex];
if (typeof signature === "undefined") {
throw new CompileError(
`call_indirect signature not found (${typeindex})`
);
}
const callNode = t.callIndirectInstruction(
signature.params,
signature.result,
[]
);
eatBytes(1); // 0x00 - reserved byte
code.push(callNode);
instructionAlreadyCreated = true;
} else if (instruction.name === "br_table") {

@@ -765,3 +787,3 @@ const indicesu32 = readU32();

for (let i = 0; i < indices; i++) {
for (let i = 0; i <= indices; i++) {
const indexu32 = readU32();

@@ -772,9 +794,5 @@ const index = indexu32.value;

dump([index], "index");
args.push(t.numberLiteral(indexu32.value.toString(), "f64"));
}
const labelIndexu32 = readU32();
const labelIndex = labelIndexu32.value;
eatBytes(labelIndexu32.nextIndex);
dump([labelIndex], "label index");
} else if (instructionByte >= 0x28 && instructionByte <= 0x40) {

@@ -781,0 +799,0 @@ /**

// @flow
import { traverse } from "@webassemblyjs/ast";
const t = require("@webassemblyjs/ast");
import * as decoder from "./decoder";

@@ -12,6 +12,8 @@

// traverses the AST, locating function name metadata, which is then
// used to update index-based identifiers with function names
function restoreNames(ast) {
const functionNames = [];
traverse(ast, {
t.traverse(ast, {
FunctionNameMetadata({ node }) {

@@ -29,3 +31,3 @@ functionNames.push({

traverse(ast, {
t.traverse(ast, {
Func({ node }: NodePath<Func>) {

@@ -39,3 +41,33 @@ // $FlowIgnore

nodeName.value = functionName.name;
// $FlowIgnore
delete nodeName.raw;
}
},
// Also update the reference in the export
ModuleExport({ node }: NodePath<ModuleExport>) {
if (node.descr.type === "Func") {
// $FlowIgnore
const nodeName: Identifier = node.descr.id;
const indexBasedFunctionName = nodeName.value;
const index = Number(indexBasedFunctionName.replace("func_", ""));
const functionName = functionNames.find(f => f.index === index);
if (functionName) {
nodeName.value = functionName.name;
}
}
},
CallInstruction(nodePath: NodePath<CallInstruction>) {
const node = nodePath.node;
const index = node.index.value;
const functionName = functionNames.find(f => f.index === index);
if (functionName) {
node.index = t.identifier(functionName.name);
// $FlowIgnore
delete node.raw;
}
}

@@ -42,0 +74,0 @@ });

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc