collab/polyglot-riscv-arm
what if the same machine code was valid riscv and arm asm
git clone https://git.julia.blue/collab/polyglot-riscv-arm
885cc4e
main
1'use strict' ; 2 3var _documentCurrentScript = typeof document !== 'undefined' ?document . currentScript :null ; 4var capstone$1 = (() => { 5var _scriptDir = ( typeof document === 'undefined' ?require ( 'u' + 'rl' ). pathToFileURL ( __filename ). href :( _documentCurrentScript && _documentCurrentScript . src || new URL ( 'index.cjs' , document . baseURI ). href )); 6return async function ( moduleArg = {}) { 7var Module = moduleArg ; 8var readyPromiseResolve , readyPromiseReject ; 9Module [ "ready" ] = new Promise (( resolve , reject ) => { 10readyPromiseResolve = resolve ; 11readyPromiseReject = reject ; 12}); 13var moduleOverrides = Object . assign ({}, Module ); 14var ENVIRONMENT_IS_WEB = typeof window == "object" ; 15var ENVIRONMENT_IS_WORKER = typeof importScripts == "function" ; 16var ENVIRONMENT_IS_NODE = typeof process == "object" && typeof process . versions == "object" && typeof process . versions . node == "string" ; 17var scriptDirectory = "" ; 18function locateFile ( path ) { 19if ( Module [ "locateFile" ]) { 20return Module [ "locateFile" ]( path , scriptDirectory ); 21} 22return scriptDirectory + path ; 23} 24var read_ , readAsync , readBinary ; 25if ( ENVIRONMENT_IS_NODE ) { 26const { createRequire :createRequire } = await import ( 'module' ); 27/** @suppress {duplicate} */ var require$1 = createRequire (( typeof document === 'undefined' ?require ( 'u' + 'rl' ). pathToFileURL ( __filename ). href :( _documentCurrentScript && _documentCurrentScript . src || new URL ( 'index.cjs' , document . baseURI ). href ))); 28var fs = require$1 ( "fs" ); 29var nodePath = require$1 ( "path" ); 30if ( ENVIRONMENT_IS_WORKER ) { 31scriptDirectory = nodePath . dirname ( scriptDirectory ) + "/" ; 32} else { 33scriptDirectory = require$1 ( "url" ). fileURLToPath ( new URL ( "./" , ( typeof document === 'undefined' ?require ( 'u' + 'rl' ). pathToFileURL ( __filename ). href :( _documentCurrentScript && _documentCurrentScript . src || new URL ( 'index.cjs' , document . baseURI ). href )))); 34} 35read_ = ( filename , binary ) => { 36filename = isFileURI ( filename ) ?new URL ( filename ) :nodePath . normalize ( filename ); 37return fs . readFileSync ( filename , binary ?undefined :"utf8" ); 38}; 39readBinary = ( filename ) => { 40var ret = read_ ( filename , true ); 41if ( ! ret . buffer ) { 42ret = new Uint8Array ( ret ); 43} 44return ret ; 45}; 46readAsync = ( filename , onload , onerror , binary = true ) => { 47filename = isFileURI ( filename ) ?new URL ( filename ) :nodePath . normalize ( filename ); 48fs . readFile ( filename , binary ?undefined :"utf8" , ( err , data ) => { 49if ( err ) onerror ( err ); 50else onload ( binary ?data . buffer :data ); 51}); 52}; 53if ( ! Module [ "thisProgram" ] && process . argv . length > 1 ) { 54process . argv [ 1 ]. replace ( / \\ / g , "/" ); 55} 56process . argv . slice ( 2 ); 57Module [ "inspect" ] = () => "[Emscripten Module object]" ; 58} else if ( ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER ) { 59if ( ENVIRONMENT_IS_WORKER ) { 60scriptDirectory = self . location . href ; 61} else if ( typeof document != "undefined" && document . currentScript ) { 62scriptDirectory = document . currentScript . src ; 63} 64if ( _scriptDir ) { 65scriptDirectory = _scriptDir ; 66} 67if ( scriptDirectory . indexOf ( "blob:" ) !== 0 ) { 68scriptDirectory = scriptDirectory . substr ( 0 , scriptDirectory . replace ( / [ ?# ] . */ , "" ). lastIndexOf ( "/" ) + 1 ); 69} else { 70scriptDirectory = "" ; 71} 72{ 73read_ = ( url ) => { 74var xhr = new XMLHttpRequest ; 75xhr . open ( "GET" , url , false ); 76xhr . send ( null ); 77return xhr . responseText ; 78}; 79if ( ENVIRONMENT_IS_WORKER ) { 80readBinary = ( url ) => { 81var xhr = new XMLHttpRequest ; 82xhr . open ( "GET" , url , false ); 83xhr . responseType = "arraybuffer" ; 84xhr . send ( null ); 85return new Uint8Array ( /** @type { !ArrayBuffer } */ xhr . response ); 86}; 87} 88readAsync = ( url , onload , onerror ) => { 89var xhr = new XMLHttpRequest ; 90xhr . open ( "GET" , url , true ); 91xhr . responseType = "arraybuffer" ; 92xhr . onload = () => { 93if ( xhr . status == 200 || xhr . status == 0 && xhr . response ) { 94onload ( xhr . response ); 95return ; 96} 97onerror (); 98}; 99xhr . onerror = onerror ; 100xhr . send ( null ); 101}; 102} 103} else ; 104Module [ "print" ] || console . log . bind ( console ); 105var err = Module [ "printErr" ] || console . error . bind ( console ); 106Object . assign ( Module , moduleOverrides ); 107moduleOverrides = null ; 108if ( Module [ "arguments" ]) Module [ "arguments" ]; 109if ( Module [ "thisProgram" ]) Module [ "thisProgram" ]; 110if ( Module [ "quit" ]) Module [ "quit" ]; 111var wasmBinary ; 112if ( Module [ "wasmBinary" ]) wasmBinary = Module [ "wasmBinary" ]; 113Module [ "noExitRuntime" ] || true ; 114if ( typeof WebAssembly != "object" ) { 115abort ( "no native wasm support detected" ); 116} 117var wasmMemory ; 118var ABORT = false ; 119var /** @type { !Int8Array } */ HEAP8 , /** @type { !Uint8Array } */ HEAPU8 , /** @type { !Int16Array } */ HEAP16 , /** @type { !Int32Array } */ HEAP32 , /** @type { !Uint32Array } */ HEAPU32 , /** @type { !Float32Array } */ HEAPF32 , /* BigInt64Array type is not correctly defined in closure 120/** not-@type {!BigInt64Array} */ HEAP64 , /** @type { !Float64Array } */ HEAPF64 ; 121function updateMemoryViews () { 122var b = wasmMemory . buffer ; 123Module [ "HEAP8" ] = HEAP8 = new Int8Array ( b ); 124Module [ "HEAP16" ] = HEAP16 = new Int16Array ( b ); 125Module [ "HEAPU8" ] = HEAPU8 = new Uint8Array ( b ); 126Module [ "HEAPU16" ] = new Uint16Array ( b ); 127Module [ "HEAP32" ] = HEAP32 = new Int32Array ( b ); 128Module [ "HEAPU32" ] = HEAPU32 = new Uint32Array ( b ); 129Module [ "HEAPF32" ] = HEAPF32 = new Float32Array ( b ); 130Module [ "HEAPF64" ] = HEAPF64 = new Float64Array ( b ); 131Module [ "HEAP64" ] = HEAP64 = new BigInt64Array ( b ); 132Module [ "HEAPU64" ] = new BigUint64Array ( b ); 133} 134var __ATPRERUN__ = []; 135var __ATINIT__ = []; 136var __ATPOSTRUN__ = []; 137function preRun () { 138if ( Module [ "preRun" ]) { 139if ( typeof Module [ "preRun" ] == "function" ) Module [ "preRun" ] = [ 140Module [ "preRun" ] 141]; 142while ( Module [ "preRun" ]. length ){ 143addOnPreRun ( Module [ "preRun" ]. shift ()); 144} 145} 146callRuntimeCallbacks ( __ATPRERUN__ ); 147} 148function initRuntime () { 149callRuntimeCallbacks ( __ATINIT__ ); 150} 151function postRun () { 152if ( Module [ "postRun" ]) { 153if ( typeof Module [ "postRun" ] == "function" ) Module [ "postRun" ] = [ 154Module [ "postRun" ] 155]; 156while ( Module [ "postRun" ]. length ){ 157addOnPostRun ( Module [ "postRun" ]. shift ()); 158} 159} 160callRuntimeCallbacks ( __ATPOSTRUN__ ); 161} 162function addOnPreRun ( cb ) { 163__ATPRERUN__ . unshift ( cb ); 164} 165function addOnInit ( cb ) { 166__ATINIT__ . unshift ( cb ); 167} 168function addOnPostRun ( cb ) { 169__ATPOSTRUN__ . unshift ( cb ); 170} 171var runDependencies = 0 ; 172var dependenciesFulfilled = null ; 173function addRunDependency ( id ) { 174runDependencies ++ ; 175if ( Module [ "monitorRunDependencies" ]) { 176Module [ "monitorRunDependencies" ]( runDependencies ); 177} 178} 179function removeRunDependency ( id ) { 180runDependencies -- ; 181if ( Module [ "monitorRunDependencies" ]) { 182Module [ "monitorRunDependencies" ]( runDependencies ); 183} 184if ( runDependencies == 0 ) { 185if ( dependenciesFulfilled ) { 186var callback = dependenciesFulfilled ; 187dependenciesFulfilled = null ; 188callback (); 189} 190} 191} 192/** @param { string|number= } what */ function abort ( what ) { 193if ( Module [ "onAbort" ]) { 194Module [ "onAbort" ]( what ); 195} 196what = "Aborted(" + what + ")" ; 197err ( what ); 198ABORT = true ; 199what += ". Build with -sASSERTIONS for more info." ; 200/** @suppress {checkTypes} */ var e = new WebAssembly . RuntimeError ( what ); 201readyPromiseReject ( e ); 202throw e ; 203} 204var dataURIPrefix = "data:application/octet-stream;base64," ; 205function isDataURI ( filename ) { 206return filename . startsWith ( dataURIPrefix ); 207} 208function isFileURI ( filename ) { 209return filename . startsWith ( "file://" ); 210} 211var wasmBinaryFile ; 212if ( Module [ "locateFile" ]) { 213wasmBinaryFile = "capstone.wasm" ; 214if ( ! isDataURI ( wasmBinaryFile )) { 215wasmBinaryFile = locateFile ( wasmBinaryFile ); 216} 217} else { 218wasmBinaryFile = new URL ( "capstone.wasm" , ( typeof document === 'undefined' ?require ( 'u' + 'rl' ). pathToFileURL ( __filename ). href :( _documentCurrentScript && _documentCurrentScript . src || new URL ( 'index.cjs' , document . baseURI ). href ))). href ; 219} 220function getBinarySync ( file ) { 221if ( file == wasmBinaryFile && wasmBinary ) { 222return new Uint8Array ( wasmBinary ); 223} 224if ( readBinary ) { 225return readBinary ( file ); 226} 227throw "both async and sync fetching of the wasm failed" ; 228} 229function getBinaryPromise ( binaryFile ) { 230if ( ! wasmBinary && ( ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER )) { 231if ( typeof fetch == "function" && ! isFileURI ( binaryFile )) { 232return fetch ( binaryFile , { 233credentials :"same-origin" 234}). then (( response ) => { 235if ( ! response [ "ok" ]) { 236throw "failed to load wasm binary file at '" + binaryFile + "'" ; 237} 238return response [ "arrayBuffer" ](); 239}). catch (() => getBinarySync ( binaryFile )); 240} else if ( readAsync ) { 241return new Promise (( resolve , reject ) => { 242readAsync ( binaryFile , ( response ) => resolve ( new Uint8Array ( /** @type { !ArrayBuffer } */ response )), reject ); 243}); 244} 245} 246return Promise . resolve (). then (() => getBinarySync ( binaryFile )); 247} 248function instantiateArrayBuffer ( binaryFile , imports , receiver ) { 249return getBinaryPromise ( binaryFile ). then (( binary ) => WebAssembly . instantiate ( binary , imports )). then (( instance ) => instance ). then ( receiver , ( reason ) => { 250err ( `failed to asynchronously prepare wasm: ${ reason } ` ); 251abort ( reason ); 252}); 253} 254function instantiateAsync ( binary , binaryFile , imports , callback ) { 255if ( ! binary && typeof WebAssembly . instantiateStreaming == "function" && ! isDataURI ( binaryFile ) && ! isFileURI ( binaryFile ) && ! ENVIRONMENT_IS_NODE && typeof fetch == "function" ) { 256return fetch ( binaryFile , { 257credentials :"same-origin" 258}). then (( response ) => { 259/** @suppress {checkTypes} */ var result = WebAssembly . instantiateStreaming ( response , imports ); 260return result . then ( callback , function ( reason ) { 261err ( `wasm streaming compile failed: ${ reason } ` ); 262err ( "falling back to ArrayBuffer instantiation" ); 263return instantiateArrayBuffer ( binaryFile , imports , callback ); 264}); 265}); 266} 267return instantiateArrayBuffer ( binaryFile , imports , callback ); 268} 269function createWasm () { 270var info = { 271"a" :wasmImports 272}; 273/** @param { WebAssembly.Module= } module*/ function receiveInstance ( instance , module ) { 274wasmExports = instance . exports ; 275wasmMemory = wasmExports [ "c" ]; 276updateMemoryViews (); 277addOnInit ( wasmExports [ "d" ]); 278removeRunDependency (); 279return wasmExports ; 280} 281addRunDependency (); 282function receiveInstantiationResult ( result ) { 283receiveInstance ( result [ "instance" ]); 284} 285if ( Module [ "instantiateWasm" ]) { 286try { 287return Module [ "instantiateWasm" ]( info , receiveInstance ); 288} catch ( e ) { 289err ( `Module.instantiateWasm callback failed with error: ${ e } ` ); 290readyPromiseReject ( e ); 291} 292} 293instantiateAsync ( wasmBinary , wasmBinaryFile , info , receiveInstantiationResult ). catch ( readyPromiseReject ); 294return {}; 295} 296var callRuntimeCallbacks = ( callbacks ) => { 297while ( callbacks . length > 0 ){ 298callbacks . shift ()( Module ); 299} 300}; 301/** 302* @param { number } ptr 303* @param { string } type 304*/ function getValue ( ptr , type = "i8" ) { 305if ( type . endsWith ( "*" )) type = "*" ; 306switch ( type ){ 307case "i1" : 308return HEAP8 [ ptr >> 0 ]; 309case "i8" : 310return HEAP8 [ ptr >> 0 ]; 311case "i16" : 312return HEAP16 [ ptr >> 1 ]; 313case "i32" : 314return HEAP32 [ ptr >> 2 ]; 315case "i64" : 316return HEAP64 [ ptr >> 3 ]; 317case "float" : 318return HEAPF32 [ ptr >> 2 ]; 319case "double" : 320return HEAPF64 [ ptr >> 3 ]; 321case "*" : 322return HEAPU32 [ ptr >> 2 ]; 323default : 324abort ( `invalid type for getValue: ${ type } ` ); 325} 326} 327var _emscripten_memcpy_js = ( dest , src , num ) => HEAPU8 . copyWithin ( dest , src , src + num ); 328var abortOnCannotGrowMemory = ( requestedSize ) => { 329abort ( "OOM" ); 330}; 331var _emscripten_resize_heap = ( requestedSize ) => { 332HEAPU8 . length ; 333abortOnCannotGrowMemory (); 334}; 335var getCFunc = ( ident ) => { 336var func = Module [ "_" + ident ]; 337return func ; 338}; 339var writeArrayToMemory = ( array , buffer ) => { 340HEAP8 . set ( array , buffer ); 341}; 342var lengthBytesUTF8 = ( str ) => { 343var len = 0 ; 344for ( var i = 0 ; i < str . length ; ++ i ){ 345var c = str . charCodeAt ( i ); 346if ( c <= 127 ) { 347len ++ ; 348} else if ( c <= 2047 ) { 349len += 2 ; 350} else if ( c >= 55296 && c <= 57343 ) { 351len += 4 ; 352++ i ; 353} else { 354len += 3 ; 355} 356} 357return len ; 358}; 359var stringToUTF8Array = ( str , heap , outIdx , maxBytesToWrite ) => { 360if ( ! ( maxBytesToWrite > 0 )) return 0 ; 361var startIdx = outIdx ; 362var endIdx = outIdx + maxBytesToWrite - 1 ; 363for ( var i = 0 ; i < str . length ; ++ i ){ 364var u = str . charCodeAt ( i ); 365if ( u >= 55296 && u <= 57343 ) { 366var u1 = str . charCodeAt ( ++ i ); 367u = 65536 + (( u & 1023 ) << 10 ) | u1 & 1023 ; 368} 369if ( u <= 127 ) { 370if ( outIdx >= endIdx ) break ; 371heap [ outIdx ++ ] = u ; 372} else if ( u <= 2047 ) { 373if ( outIdx + 1 >= endIdx ) break ; 374heap [ outIdx ++ ] = 192 | u >> 6 ; 375heap [ outIdx ++ ] = 128 | u & 63 ; 376} else if ( u <= 65535 ) { 377if ( outIdx + 2 >= endIdx ) break ; 378heap [ outIdx ++ ] = 224 | u >> 12 ; 379heap [ outIdx ++ ] = 128 | u >> 6 & 63 ; 380heap [ outIdx ++ ] = 128 | u & 63 ; 381} else { 382if ( outIdx + 3 >= endIdx ) break ; 383heap [ outIdx ++ ] = 240 | u >> 18 ; 384heap [ outIdx ++ ] = 128 | u >> 12 & 63 ; 385heap [ outIdx ++ ] = 128 | u >> 6 & 63 ; 386heap [ outIdx ++ ] = 128 | u & 63 ; 387} 388} 389heap [ outIdx ] = 0 ; 390return outIdx - startIdx ; 391}; 392var stringToUTF8 = ( str , outPtr , maxBytesToWrite ) => stringToUTF8Array ( str , HEAPU8 , outPtr , maxBytesToWrite ); 393var stringToUTF8OnStack = ( str ) => { 394var size = lengthBytesUTF8 ( str ) + 1 ; 395var ret = stackAlloc ( size ); 396stringToUTF8 ( str , ret , size ); 397return ret ; 398}; 399var UTF8Decoder = typeof TextDecoder != "undefined" ?new TextDecoder ( "utf8" ) :undefined ; 400/** 401* Given a pointer 'idx' to a null-terminated UTF8-encoded string in the given 402* array that contains uint8 values, returns a copy of that string as a 403* Javascript String object. 404* heapOrArray is either a regular array, or a JavaScript typed array view. 405* @param { number } idx 406* @param { number= } maxBytesToRead 407* @return { string } 408*/ var UTF8ArrayToString = ( heapOrArray , idx , maxBytesToRead ) => { 409var endIdx = idx + maxBytesToRead ; 410var endPtr = idx ; 411while ( heapOrArray [ endPtr ] && ! ( endPtr >= endIdx )) ++ endPtr ; 412if ( endPtr - idx > 16 && heapOrArray . buffer && UTF8Decoder ) { 413return UTF8Decoder . decode ( heapOrArray . subarray ( idx , endPtr )); 414} 415var str = "" ; 416while ( idx < endPtr ){ 417var u0 = heapOrArray [ idx ++ ]; 418if ( ! ( u0 & 128 )) { 419str += String . fromCharCode ( u0 ); 420continue ; 421} 422var u1 = heapOrArray [ idx ++ ] & 63 ; 423if (( u0 & 224 ) == 192 ) { 424str += String . fromCharCode (( u0 & 31 ) << 6 | u1 ); 425continue ; 426} 427var u2 = heapOrArray [ idx ++ ] & 63 ; 428if (( u0 & 240 ) == 224 ) { 429u0 = ( u0 & 15 ) << 12 | u1 << 6 | u2 ; 430} else { 431u0 = ( u0 & 7 ) << 18 | u1 << 12 | u2 << 6 | heapOrArray [ idx ++ ] & 63 ; 432} 433if ( u0 < 65536 ) { 434str += String . fromCharCode ( u0 ); 435} else { 436var ch = u0 - 65536 ; 437str += String . fromCharCode ( 55296 | ch >> 10 , 56320 | ch & 1023 ); 438} 439} 440return str ; 441}; 442/** 443* Given a pointer 'ptr' to a null-terminated UTF8-encoded string in the 444* emscripten HEAP, returns a copy of that string as a Javascript String object. 445* 446* @param { number } ptr 447* @param { number= } maxBytesToRead - An optional length that specifies the 448* maximum number of bytes to read. You can omit this parameter to scan the 449* string until the first 0 byte. If maxBytesToRead is passed, and the string 450* at [ptr, ptr+maxBytesToReadr[ contains a null byte in the middle, then the 451* string will cut short at that byte index (i.e. maxBytesToRead will not 452* produce a string of exact length [ptr, ptr+maxBytesToRead[) N.B. mixing 453* frequent uses of UTF8ToString() with and without maxBytesToRead may throw 454* JS JIT optimizations off, so it is worth to consider consistently using one 455* @return { string } 456*/ var UTF8ToString = ( ptr , maxBytesToRead ) => ptr ?UTF8ArrayToString ( HEAPU8 , ptr , maxBytesToRead ) :"" ; 457/** 458* @param { string|null= } returnType 459* @param { Array= } argTypes 460* @param { Arguments|Array= } args 461* @param { Object= } opts 462*/ var ccall = ( ident , returnType , argTypes , args , opts ) => { 463var toC = { 464"string" :( str ) => { 465var ret = 0 ; 466if ( str !== null && str !== undefined && str !== 0 ) { 467ret = stringToUTF8OnStack ( str ); 468} 469return ret ; 470}, 471"array" :( arr ) => { 472var ret = stackAlloc ( arr . length ); 473writeArrayToMemory ( arr , ret ); 474return ret ; 475} 476}; 477function convertReturnValue ( ret ) { 478if ( returnType === "string" ) { 479return UTF8ToString ( ret ); 480} 481if ( returnType === "boolean" ) return Boolean ( ret ); 482return ret ; 483} 484var func = getCFunc ( ident ); 485var cArgs = []; 486var stack = 0 ; 487if ( args ) { 488for ( var i = 0 ; i < args . length ; i ++ ){ 489var converter = toC [ argTypes [ i ]]; 490if ( converter ) { 491if ( stack === 0 ) stack = stackSave (); 492cArgs [ i ] = converter ( args [ i ]); 493} else { 494cArgs [ i ] = args [ i ]; 495} 496} 497} 498var ret = func . apply ( null , cArgs ); 499function onDone ( ret ) { 500if ( stack !== 0 ) stackRestore ( stack ); 501return convertReturnValue ( ret ); 502} 503ret = onDone ( ret ); 504return ret ; 505}; 506/** 507* @param { string= } returnType 508* @param { Array= } argTypes 509* @param { Object= } opts 510*/ var cwrap = ( ident , returnType , argTypes , opts ) => { 511var numericArgs = ! argTypes || argTypes . every (( type ) => type === "number" || type === "boolean" ); 512var numericRet = returnType !== "string" ; 513if ( numericRet && numericArgs && ! opts ) { 514return getCFunc ( ident ); 515} 516return function () { 517return ccall ( ident , returnType , argTypes , arguments ); 518}; 519}; 520var wasmImports = { 521/** @export */ b :_emscripten_memcpy_js , 522/** @export */ a :_emscripten_resize_heap 523}; 524var wasmExports = createWasm (); 525Module [ "_cs_version" ] = ( a0 , a1 ) => ( Module [ "_cs_version" ] = wasmExports [ "e" ])( a0 , a1 ); 526Module [ "_cs_support" ] = ( a0 ) => ( Module [ "_cs_support" ] = wasmExports [ "f" ])( a0 ); 527Module [ "_cs_errno" ] = ( a0 ) => ( Module [ "_cs_errno" ] = wasmExports [ "g" ])( a0 ); 528Module [ "_cs_strerror" ] = ( a0 ) => ( Module [ "_cs_strerror" ] = wasmExports [ "h" ])( a0 ); 529Module [ "_cs_open" ] = ( a0 , a1 , a2 ) => ( Module [ "_cs_open" ] = wasmExports [ "i" ])( a0 , a1 , a2 ); 530Module [ "_cs_close" ] = ( a0 ) => ( Module [ "_cs_close" ] = wasmExports [ "j" ])( a0 ); 531Module [ "_cs_option" ] = ( a0 , a1 , a2 ) => ( Module [ "_cs_option" ] = wasmExports [ "k" ])( a0 , a1 , a2 ); 532Module [ "_cs_disasm" ] = ( a0 , a1 , a2 , a3 , a4 , a5 ) => ( Module [ "_cs_disasm" ] = wasmExports [ "l" ])( a0 , a1 , a2 , a3 , a4 , a5 ); 533Module [ "_cs_free" ] = ( a0 , a1 ) => ( Module [ "_cs_free" ] = wasmExports [ "m" ])( a0 , a1 ); 534Module [ "_cs_malloc" ] = ( a0 ) => ( Module [ "_cs_malloc" ] = wasmExports [ "n" ])( a0 ); 535Module [ "_cs_reg_name" ] = ( a0 , a1 ) => ( Module [ "_cs_reg_name" ] = wasmExports [ "o" ])( a0 , a1 ); 536Module [ "_cs_insn_name" ] = ( a0 , a1 ) => ( Module [ "_cs_insn_name" ] = wasmExports [ "p" ])( a0 , a1 ); 537Module [ "_cs_group_name" ] = ( a0 , a1 ) => ( Module [ "_cs_group_name" ] = wasmExports [ "q" ])( a0 , a1 ); 538Module [ "_cs_insn_group" ] = ( a0 , a1 , a2 ) => ( Module [ "_cs_insn_group" ] = wasmExports [ "r" ])( a0 , a1 , a2 ); 539Module [ "_cs_reg_read" ] = ( a0 , a1 , a2 ) => ( Module [ "_cs_reg_read" ] = wasmExports [ "s" ])( a0 , a1 , a2 ); 540Module [ "_cs_reg_write" ] = ( a0 , a1 , a2 ) => ( Module [ "_cs_reg_write" ] = wasmExports [ "t" ])( a0 , a1 , a2 ); 541Module [ "_cs_op_count" ] = ( a0 , a1 , a2 ) => ( Module [ "_cs_op_count" ] = wasmExports [ "u" ])( a0 , a1 , a2 ); 542Module [ "_cs_op_index" ] = ( a0 , a1 , a2 , a3 ) => ( Module [ "_cs_op_index" ] = wasmExports [ "v" ])( a0 , a1 , a2 , a3 ); 543Module [ "_cs_regs_access" ] = ( a0 , a1 , a2 , a3 , a4 , a5 ) => ( Module [ "_cs_regs_access" ] = wasmExports [ "w" ])( a0 , a1 , a2 , a3 , a4 , a5 ); 544Module [ "_malloc" ] = ( a0 ) => ( Module [ "_malloc" ] = wasmExports [ "x" ])( a0 ); 545Module [ "_free" ] = ( a0 ) => ( Module [ "_free" ] = wasmExports [ "y" ])( a0 ); 546var stackSave = () => ( stackSave = wasmExports [ "z" ])(); 547var stackRestore = ( a0 ) => ( stackRestore = wasmExports [ "A" ])( a0 ); 548var stackAlloc = ( a0 ) => ( stackAlloc = wasmExports [ "B" ])( a0 ); 549Module [ "ccall" ] = ccall ; 550Module [ "cwrap" ] = cwrap ; 551Module [ "getValue" ] = getValue ; 552Module [ "UTF8ToString" ] = UTF8ToString ; 553var calledRun ; 554dependenciesFulfilled = function runCaller () { 555if ( ! calledRun ) run (); 556if ( ! calledRun ) dependenciesFulfilled = runCaller ; 557}; 558function run () { 559if ( runDependencies > 0 ) { 560return ; 561} 562preRun (); 563if ( runDependencies > 0 ) { 564return ; 565} 566function doRun () { 567if ( calledRun ) return ; 568calledRun = true ; 569Module [ "calledRun" ] = true ; 570if ( ABORT ) return ; 571initRuntime (); 572readyPromiseResolve ( Module ); 573if ( Module [ "onRuntimeInitialized" ]) Module [ "onRuntimeInitialized" ](); 574postRun (); 575} 576if ( Module [ "setStatus" ]) { 577Module [ "setStatus" ]( "Running..." ); 578setTimeout ( function () { 579setTimeout ( function () { 580Module [ "setStatus" ]( "" ); 581}, 1 ); 582doRun (); 583}, 1 ); 584} else { 585doRun (); 586} 587} 588if ( Module [ "preInit" ]) { 589if ( typeof Module [ "preInit" ] == "function" ) Module [ "preInit" ] = [ 590Module [ "preInit" ] 591]; 592while ( Module [ "preInit" ]. length > 0 ){ 593Module [ "preInit" ]. pop ()(); 594} 595} 596run (); 597return moduleArg . ready ; 598}; 599})(); 600 601// AUTO-GENERATED FILE, DO NOT EDIT 602/* eslint-disable */ const CS_API_MAJOR = 5 ; 603const CS_API_MINOR = 0 ; 604const CS_ARCH_ARM = 0 ; 605const CS_ARCH_ARM64 = 1 ; 606const CS_ARCH_MIPS = 2 ; 607const CS_ARCH_X86 = 3 ; 608const CS_ARCH_PPC = 4 ; 609const CS_ARCH_SPARC = 5 ; 610const CS_ARCH_SYSZ = 6 ; 611const CS_ARCH_XCORE = 7 ; 612const CS_ARCH_M68K = 8 ; 613const CS_ARCH_TMS320C64X = 9 ; 614const CS_ARCH_M680X = 10 ; 615const CS_ARCH_MAX = 11 ; 616const CS_ARCH_ALL = 0xFFFF ; 617const CS_MODE_LITTLE_ENDIAN = 0 ; 618const CS_MODE_ARM = 0 ; 619const CS_MODE_16 = 1 << 1 ; 620const CS_MODE_32 = 1 << 2 ; 621const CS_MODE_64 = 1 << 3 ; 622const CS_MODE_THUMB = 1 << 4 ; 623const CS_MODE_MCLASS = 1 << 5 ; 624const CS_MODE_V8 = 1 << 6 ; 625const CS_MODE_MICRO = 1 << 4 ; 626const CS_MODE_MIPS3 = 1 << 5 ; 627const CS_MODE_MIPS32R6 = 1 << 6 ; 628const CS_MODE_MIPS2 = 1 << 7 ; 629const CS_MODE_BIG_ENDIAN = 1 << 31 ; 630const CS_MODE_V9 = 1 << 4 ; 631const CS_MODE_MIPS32 = CS_MODE_32 ; 632const CS_MODE_MIPS64 = CS_MODE_64 ; 633const CS_MODE_QPX = 1 << 4 ; 634const CS_MODE_M680X_6301 = 1 << 1 ; 635const CS_MODE_M680X_6309 = 1 << 2 ; 636const CS_MODE_M680X_6800 = 1 << 3 ; 637const CS_MODE_M680X_6801 = 1 << 4 ; 638const CS_MODE_M680X_6805 = 1 << 5 ; 639const CS_MODE_M680X_6808 = 1 << 6 ; 640const CS_MODE_M680X_6809 = 1 << 7 ; 641const CS_MODE_M680X_6811 = 1 << 8 ; 642const CS_MODE_M680X_CPU12 = 1 << 9 ; 643const CS_MODE_M680X_HCS08 = 1 << 10 ; 644const CS_ERR_OK = 0 ; 645const CS_ERR_MEM = 1 ; 646const CS_ERR_ARCH = 2 ; 647const CS_ERR_HANDLE = 3 ; 648const CS_ERR_CSH = 4 ; 649const CS_ERR_MODE = 5 ; 650const CS_ERR_OPTION = 6 ; 651const CS_ERR_DETAIL = 7 ; 652const CS_ERR_MEMSETUP = 8 ; 653const CS_ERR_VERSION = 9 ; 654const CS_ERR_DIET = 10 ; 655const CS_ERR_SKIPDATA = 11 ; 656const CS_ERR_X86_ATT = 12 ; 657const CS_ERR_X86_INTEL = 13 ; 658const CS_OPT_SYNTAX = 1 ; 659const CS_OPT_DETAIL = 2 ; 660const CS_OPT_MODE = 3 ; 661const CS_OPT_OFF = 0 ; 662const CS_OPT_SYNTAX_INTEL = 1 ; 663const CS_OPT_SYNTAX_ATT = 2 ; 664const CS_OPT_ON = 3 ; 665const CS_OPT_SYNTAX_NOREGNAME = 3 ; 666const CS_OP_INVALID = 0 ; 667const CS_OP_REG = 1 ; 668const CS_OP_IMM = 2 ; 669const CS_OP_MEM = 3 ; 670const CS_OP_FP = 4 ; 671const CS_AC_INVALID = 0 ; 672const CS_AC_READ = 1 << 0 ; 673const CS_AC_WRITE = 1 << 1 ; 674const CS_GRP_INVALID = 0 ; 675const CS_GRP_JUMP = 1 ; 676const CS_GRP_CALL = 2 ; 677const CS_GRP_RET = 3 ; 678const CS_GRP_INT = 4 ; 679const CS_GRP_IRET = 5 ; 680const CS_GRP_PRIVILEGE = 6 ; 681const CS_SUPPORT_DIET = CS_ARCH_ALL + 1 ; 682const CS_SUPPORT_X86_REDUCE = CS_ARCH_ALL + 2 ; 683 684var _const = /*#__PURE__*/ Object . freeze ({ 685__proto__ :null , 686CS_AC_INVALID :CS_AC_INVALID , 687CS_AC_READ :CS_AC_READ , 688CS_AC_WRITE :CS_AC_WRITE , 689CS_API_MAJOR :CS_API_MAJOR , 690CS_API_MINOR :CS_API_MINOR , 691CS_ARCH_ALL :CS_ARCH_ALL , 692CS_ARCH_ARM :CS_ARCH_ARM , 693CS_ARCH_ARM64 :CS_ARCH_ARM64 , 694CS_ARCH_M680X :CS_ARCH_M680X , 695CS_ARCH_M68K :CS_ARCH_M68K , 696CS_ARCH_MAX :CS_ARCH_MAX , 697CS_ARCH_MIPS :CS_ARCH_MIPS , 698CS_ARCH_PPC :CS_ARCH_PPC , 699CS_ARCH_SPARC :CS_ARCH_SPARC , 700CS_ARCH_SYSZ :CS_ARCH_SYSZ , 701CS_ARCH_TMS320C64X :CS_ARCH_TMS320C64X , 702CS_ARCH_X86 :CS_ARCH_X86 , 703CS_ARCH_XCORE :CS_ARCH_XCORE , 704CS_ERR_ARCH :CS_ERR_ARCH , 705CS_ERR_CSH :CS_ERR_CSH , 706CS_ERR_DETAIL :CS_ERR_DETAIL , 707CS_ERR_DIET :CS_ERR_DIET , 708CS_ERR_HANDLE :CS_ERR_HANDLE , 709CS_ERR_MEM :CS_ERR_MEM , 710CS_ERR_MEMSETUP :CS_ERR_MEMSETUP , 711CS_ERR_MODE :CS_ERR_MODE , 712CS_ERR_OK :CS_ERR_OK , 713CS_ERR_OPTION :CS_ERR_OPTION , 714CS_ERR_SKIPDATA :CS_ERR_SKIPDATA , 715CS_ERR_VERSION :CS_ERR_VERSION , 716CS_ERR_X86_ATT :CS_ERR_X86_ATT , 717CS_ERR_X86_INTEL :CS_ERR_X86_INTEL , 718CS_GRP_CALL :CS_GRP_CALL , 719CS_GRP_INT :CS_GRP_INT , 720CS_GRP_INVALID :CS_GRP_INVALID , 721CS_GRP_IRET :CS_GRP_IRET , 722CS_GRP_JUMP :CS_GRP_JUMP , 723CS_GRP_PRIVILEGE :CS_GRP_PRIVILEGE , 724CS_GRP_RET :CS_GRP_RET , 725CS_MODE_16 :CS_MODE_16 , 726CS_MODE_32 :CS_MODE_32 , 727CS_MODE_64 :CS_MODE_64 , 728CS_MODE_ARM :CS_MODE_ARM , 729CS_MODE_BIG_ENDIAN :CS_MODE_BIG_ENDIAN , 730CS_MODE_LITTLE_ENDIAN :CS_MODE_LITTLE_ENDIAN , 731CS_MODE_M680X_6301 :CS_MODE_M680X_6301 , 732CS_MODE_M680X_6309 :CS_MODE_M680X_6309 , 733CS_MODE_M680X_6800 :CS_MODE_M680X_6800 , 734CS_MODE_M680X_6801 :CS_MODE_M680X_6801 , 735CS_MODE_M680X_6805 :CS_MODE_M680X_6805 , 736CS_MODE_M680X_6808 :CS_MODE_M680X_6808 , 737CS_MODE_M680X_6809 :CS_MODE_M680X_6809 , 738CS_MODE_M680X_6811 :CS_MODE_M680X_6811 , 739CS_MODE_M680X_CPU12 :CS_MODE_M680X_CPU12 , 740CS_MODE_M680X_HCS08 :CS_MODE_M680X_HCS08 , 741CS_MODE_MCLASS :CS_MODE_MCLASS , 742CS_MODE_MICRO :CS_MODE_MICRO , 743CS_MODE_MIPS2 :CS_MODE_MIPS2 , 744CS_MODE_MIPS3 :CS_MODE_MIPS3 , 745CS_MODE_MIPS32 :CS_MODE_MIPS32 , 746CS_MODE_MIPS32R6 :CS_MODE_MIPS32R6 , 747CS_MODE_MIPS64 :CS_MODE_MIPS64 , 748CS_MODE_QPX :CS_MODE_QPX , 749CS_MODE_THUMB :CS_MODE_THUMB , 750CS_MODE_V8 :CS_MODE_V8 , 751CS_MODE_V9 :CS_MODE_V9 , 752CS_OPT_DETAIL :CS_OPT_DETAIL , 753CS_OPT_MODE :CS_OPT_MODE , 754CS_OPT_OFF :CS_OPT_OFF , 755CS_OPT_ON :CS_OPT_ON , 756CS_OPT_SYNTAX :CS_OPT_SYNTAX , 757CS_OPT_SYNTAX_ATT :CS_OPT_SYNTAX_ATT , 758CS_OPT_SYNTAX_INTEL :CS_OPT_SYNTAX_INTEL , 759CS_OPT_SYNTAX_NOREGNAME :CS_OPT_SYNTAX_NOREGNAME , 760CS_OP_FP :CS_OP_FP , 761CS_OP_IMM :CS_OP_IMM , 762CS_OP_INVALID :CS_OP_INVALID , 763CS_OP_MEM :CS_OP_MEM , 764CS_OP_REG :CS_OP_REG , 765CS_SUPPORT_DIET :CS_SUPPORT_DIET , 766CS_SUPPORT_X86_REDUCE :CS_SUPPORT_X86_REDUCE 767}); 768 769const POINTER_SIZE = 4 ; 770function defineMethods ( obj ) { 771return obj ; 772} 773function getNativeTypeSize ( type ) { 774switch ( type ){ 775case '*' : 776return POINTER_SIZE ; 777case 'i1' : 778case 'i8' : 779return 1 ; 780case 'i16' : 781return 2 ; 782case 'i32' : 783return 4 ; 784case 'i64' : 785return 8 ; 786case 'float' : 787return 4 ; 788case 'double' : 789return 8 ; 790default : 791{ 792throw new Error ( `Unsupported type: ${ type } ` ); 793} 794} 795} 796function getFieldSize ( field ) { 797if ( field . type === 'string' || field . type === 'bytes' ) { 798return field . size ; 799} 800return getNativeTypeSize ( field . type ); 801} 802function getStructFieldPadding ( offset , size ) { 803const remainder = offset % size ; 804if ( remainder ) { 805return size - remainder ; 806} 807return 0 ; 808} 809function sizeOfStruct ( fields ) { 810return fields . reduce (( acc , field ) => { 811const size = getFieldSize ( field ); 812const padding = field . type === 'string' || field . type === 'bytes' ?0 :getStructFieldPadding ( acc , size ); 813return acc + padding + size ; 814}, 0 ); 815} 816function readStruct ( module , ptr , fields ) { 817let offset = 0 ; 818return fields . reduce (( obj , field ) => { 819let value ; 820let size ; 821if ( field . type === 'string' ) { 822size = field . size ; 823value = module . UTF8ToString ( ptr + offset , size ); 824} else if ( field . type === 'bytes' ) { 825size = field . size ; 826value = module . HEAPU8 . slice ( ptr + offset , ptr + offset + size ); 827} else { 828size = getNativeTypeSize ( field . type ); 829offset += getStructFieldPadding ( offset , size ); 830value = module . getValue ( ptr + offset , field . type ); 831} 832offset += size ; 833if ( field . name ) { 834return { 835 ...obj , 836[ field . name ] :value 837}; 838} 839return obj ; 840}, {}); 841} 842 843const METHODS_TYPES = defineMethods ({ 844cs_open :{ 845returnType :'number' , 846argTypes :[ 847'number' , 848'number' , 849'number' 850] 851}, 852cs_disasm :{ 853returnType :'number' , 854argTypes :[ 855'number' , 856'array' , 857'number' , 858'number' , 859'number' , 860'number' 861] 862}, 863cs_free :{ 864returnType :null , 865argTypes :[ 866'number' , 867'number' 868] 869}, 870cs_close :{ 871returnType :'number' , 872argTypes :[ 873'number' 874] 875}, 876cs_option :{ 877returnType :'number' , 878argTypes :[ 879'number' , 880'number' , 881'number' 882] 883}, 884cs_reg_name :{ 885returnType :'string' , 886argTypes :[ 887'number' , 888'number' 889] 890}, 891cs_op_count :{ 892returnType :'number' , 893argTypes :[ 894'number' , 895'number' , 896'number' 897] 898}, 899cs_op_index :{ 900returnType :'number' , 901argTypes :[ 902'number' , 903'number' , 904'number' , 905'number' 906] 907}, 908cs_insn_name :{ 909returnType :'string' , 910argTypes :[ 911'number' , 912'number' 913] 914}, 915cs_group_name :{ 916returnType :'string' , 917argTypes :[ 918'number' , 919'number' 920] 921}, 922cs_insn_group :{ 923returnType :'boolean' , 924argTypes :[ 925'number' , 926'number' , 927'number' 928] 929}, 930cs_reg_read :{ 931returnType :'boolean' , 932argTypes :[ 933'number' , 934'number' , 935'number' 936] 937}, 938cs_reg_write :{ 939returnType :'boolean' , 940argTypes :[ 941'number' , 942'number' , 943'number' 944] 945}, 946cs_errno :{ 947returnType :'number' , 948argTypes :[ 949'number' 950] 951}, 952cs_version :{ 953returnType :'number' , 954argTypes :[ 955'number' , 956'number' 957] 958}, 959cs_support :{ 960returnType :'boolean' , 961argTypes :[ 962'number' 963] 964}, 965cs_strerror :{ 966returnType :'string' , 967argTypes :[ 968'number' 969] 970}, 971cs_regs_access :{ 972returnType :'number' , 973argTypes :[ 974'number' , 975'number' , 976'number' , 977'number' , 978'number' , 979'number' 980] 981}, 982malloc :{ 983returnType :'number' , 984argTypes :[ 985'number' 986] 987}, 988free :{ 989returnType :null , 990argTypes :[ 991'number' 992] 993} 994}); 995let capstone ; 996const INSN_FIELDS = [ 997{ 998name :'id' , 999type :'i32' 1000}, 1001{ 1002name :'address' , 1003type :'i64' 1004}, 1005{ 1006name :'size' , 1007type :'i16' 1008}, 1009{ 1010name :'bytes' , 1011type :'bytes' , 1012size :24 1013}, 1014{ 1015name :'mnemonic' , 1016type :'string' , 1017size :32 1018}, 1019{ 1020name :'opStr' , 1021type :'string' , 1022size :160 1023}, 1024{ 1025// detail pointer 1026type :'i32' 1027} 1028]; 1029const INSN_SIZE = sizeOfStruct ( INSN_FIELDS ); 1030class Capstone { 1031get handle () { 1032return capstone . getValue ( this . handle_ptr , '*' ); 1033} 1034setOption ( opt , value ) { 1035return Capstone . call ( 'cs_option' , this . handle , opt , value ); 1036} 1037close () { 1038const ret = Capstone . call ( 'cs_close' , this . handle_ptr ); 1039if ( ret !== CS_ERR_OK ) { 1040throw new Error ( `Failed to close capstone: ${ Capstone . strError ( ret )} ` ); 1041} 1042this . handle_ptr = null ; 1043} 1044static readInsn ( insnPtr ) { 1045const insn = readStruct ( capstone , insnPtr , INSN_FIELDS ); 1046insn . bytes = insn . bytes . subarray ( 0 , insn . size ); 1047return insn ; 1048} 1049disasm ( data , options = {}) { 1050const { address= 0 , count :maxCount = 0 } = options ; 1051const insnPtrPtr = Capstone . call ( 'malloc' , POINTER_SIZE ); 1052const count = Capstone . call ( 'cs_disasm' , this . handle , data , data . length , BigInt ( address ), maxCount , insnPtrPtr ); 1053if ( count === 0 ) { 1054Capstone . call ( 'free' , insnPtrPtr ); 1055throw new Error ( `Failed to disassemble, error: ${ Capstone . strError ( this . errNo ())} ` ); 1056} 1057const insnPtr = capstone . getValue ( insnPtrPtr , '*' ); 1058const instructions = []; 1059for ( let i = 0 ; i < count ; i ++ ){ 1060const insn = Capstone . readInsn ( insnPtr + i * INSN_SIZE ); 1061if ( insn . address <= Number . MAX_SAFE_INTEGER ) { 1062insn . address = Number ( insn . address ); 1063} 1064instructions . push ( insn ); 1065} 1066Capstone . call ( 'cs_free' , insnPtr , count ); 1067Capstone . call ( 'free' , insnPtrPtr ); 1068return instructions ; 1069} 1070getRegName ( id ) { 1071return Capstone . call ( 'cs_reg_name' , this . handle , id ); 1072} 1073getInsnName ( id ) { 1074return Capstone . call ( 'cs_insn_name' , this . handle , id ); 1075} 1076getGroupName ( id ) { 1077return Capstone . call ( 'cs_group_name' , this . handle , id ); 1078} 1079errNo () { 1080return Capstone . call ( 'cs_errno' , this . handle ); 1081} 1082static call ( name , ...args ) { 1083const methodType = METHODS_TYPES [ name ]; 1084return capstone . ccall ( name , methodType . returnType , methodType . argTypes , args ); 1085} 1086static version () { 1087const int = this . call ( 'cs_version' ); 1088/* eslint-disable no-bitwise */ return { 1089major :int >> 8 , 1090minor :int & 0xff 1091}; 1092/* eslint-enable no-bitwise */ } 1093static support ( query ) { 1094return this . call ( 'cs_support' , query ); 1095} 1096static strError ( errNo ) { 1097return this . call ( 'cs_strerror' , errNo ); 1098} 1099constructor ( arch , mode ){ 1100this . arch = arch ; 1101this . mode = mode ; 1102this . handle_ptr = Capstone . call ( 'malloc' , POINTER_SIZE ); 1103const ret = Capstone . call ( 'cs_open' , arch , mode , this . handle_ptr ); 1104if ( ret !== CS_ERR_OK ) { 1105throw new Error ( `Failed to initialize capstone: ${ Capstone . strError ( ret )} ` ); 1106} 1107} 1108} 1109async function factory ( args ) { 1110if ( capstone ) { 1111return ; 1112} 1113capstone = await capstone$1 ( args ); 1114} 1115 1116exports . Capstone = Capstone ; 1117exports . Const = _const ; 1118exports . loadCapstone = factory ;