Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
const filename = process.argv[2];
if (typeof filename === "undefined") {
throw new Error("Missing file");
}
const decoderOpts = {
ignoreCodeSection: true,
ignoreDataSection: true
};
// $FlowIgnore: this is correct but not correctly documented
const buff = toArrayBuffer(readFileSync(filename, null));
const ast = decode(buff, decoderOpts);
let found = false;
traverse(ast, {
ProducersSectionMetadata({ node }) {
node.producers.forEach(entry => {
entry.forEach(producer => {
console.log(producer.name, producer.version);
});
});
found = true;
}
});
if (found === false) {
if (e === "\\") {
// Start espace sequence
const byte = chars[i + 1] + chars[i + 2];
const hexInNumber = parseInt(byte, 16);
out.push(hexInNumber);
i = i + 2;
} else {
// ASCII
const hexInNumber = Number(chars[i].charCodeAt(0));
out.push(hexInNumber);
}
}
decode(out);
}
parse(binary, state) {
// flag it as ESM
state.module.buildMeta.exportsType = "namespace";
// parse it
const program = decode(binary, decoderOpts);
const module = program.body[0];
const moduleContext = moduleContextFromModuleAST(module);
// extract imports and exports
const exports = (state.module.buildMeta.providedExports = []);
const jsIncompatibleExports = (state.module.buildMeta.jsIncompatibleExports = []);
const importedGlobals = [];
t.traverse(module, {
ModuleExport({ node }) {
const descriptor = node.descr;
if (descriptor.exportType === "Func") {
const funcidx = descriptor.id.value;
generate(module, dependencyTemplates, runtimeTemplate, type) {
let bin = module.originalSource().source();
const initFuncId = t.identifier(
Array.isArray(module.usedExports)
? Template.numberToIdentifer(module.usedExports.length)
: "__webpack_init__"
);
// parse it
const ast = decode(bin, {
ignoreDataSection: true,
ignoreCodeSection: true,
ignoreCustomNameSection: true
});
const moduleContext = moduleContextFromModuleAST(ast.body[0]);
const importedGlobals = getImportedGlobals(ast);
const countImportedFunc = getCountImportedFunc(ast);
const startAtFuncOffset = moduleContext.getStart();
const nextFuncIndex = getNextFuncIndex(ast, countImportedFunc);
const nextTypeIndex = getNextTypeIndex(ast);
const usedDependencyMap = getUsedDependencyMap(
module,
this.options.mangleImports
if (e === "\\") {
// Start espace sequence
const byte = chars[i + 1] + chars[i + 2];
const hexInNumber = parseInt(byte, 16);
out.push(hexInNumber);
i = i + 2;
} else {
// ASCII
const hexInNumber = Number(chars[i].charCodeAt(0));
out.push(hexInNumber);
}
}
decode(out);
}
export function edit(ab: ArrayBuffer, visitors: Object): ArrayBuffer {
ab = preprocess(ab);
const ast = decode(ab);
return editWithAST(ast, ab, visitors);
}
export function shrinkPaddedLEB128(uint8Buffer: Uint8Array): Uint8Array {
try {
const ast = decode(uint8Buffer.buffer, decoderOpts);
return makeShrinkPaddedLEB128(ast, uint8Buffer);
} catch (e) {
throw new OptimizerError("shrinkPaddedLEB128", e);
}
}
exports.parseMetadata = (buffer) => {
let importTableName
let mainFnFound
const operations = []
const ast = decode(buffer, { dump: false, ignoreCodeSection: true })
traverse(ast, {
ModuleExport (path) {
const fn = path.node.name
if (fn === 'main') {
mainFnFound = true
} else if (!['memory', '__wbindgen_malloc', '__wbindgen_realloc', '__wbindgen_free', '__rustc_debug_gdb_scripts_section__', '__wbg_function_table'].includes(fn)) {
operations.push(fn)
}
},
ModuleImport (path) {
if (!importTableName) {
importTableName = path.node.module
} else if (importTableName !== path.node.module) {
if (path.node.module !== 'metering') {
throw new Error('Invalid Rust wasm_bindgen WASM module: inconsistent import module name.')
}
#!/usr/bin/env node
const { readFileSync } = require("fs");
const { decode } = require("@webassemblyjs/wasm-parser");
const { print } = require("@webassemblyjs/wast-printer");
function toArrayBuffer(buf) {
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
}
const filename = process.argv[2];
const buff = toArrayBuffer(readFileSync(filename, null));
const ast = decode(buff);
const wast = print(ast);
process.stdout.write(wast);