@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 1.31 kB
JavaScript
import*as Common from"../../core/common/common.js";import*as WasmParser from"../../third_party/wasmparser/wasmparser.js";export function dissambleWASM(e,s){try{const t=Common.Base64.decode(e.content);let r=new WasmParser.WasmParser.BinaryReader;r.setData(t,0,t.byteLength);const a=new WasmParser.WasmDis.DevToolsNameGenerator;a.read(r);const o=new Uint8Array(t);r=new WasmParser.WasmParser.BinaryReader;const n=new WasmParser.WasmDis.WasmDisassembler;n.addOffsets=!0,n.exportMetadata=a.getExportMetadata(),n.nameResolver=a.getNameResolver();const m=[],i=[],f=[];let c=131072,l=new Uint8Array(c),p=0,d=0;for(let e=0;e<o.length;){c>o.length-e&&(c=o.length-e);const t=p+c;if(l.byteLength<t){const e=new Uint8Array(t);e.set(l),l=e}for(;p<t;)l[p++]=o[e++];r.setData(l.buffer,0,t,e===o.length);const a=n.disassembleChunk(r,d),h=n.getResult();for(const e of h.lines)m.push(e);for(const e of h.offsets)i.push(e);for(const e of h.functionBodyOffsets)f.push(e);if(a)break;if(0===r.position){p=t;continue}const g=r.data.subarray(r.position,r.length);p=g.length,l.set(g),d+=r.position;s({event:"progress",params:{percentage:Math.floor(d/o.length*100)}})}s({event:"progress",params:{percentage:100}}),s({method:"disassemble",result:{lines:m,offsets:i,functionBodyOffsets:f}})}catch(e){s({method:"disassemble",error:e})}}