Aloha せかい - wasm
type: channel
link: https://blog.2cn.in/index.php/tag/wasm/
items: Wasm reverse engineering script kit

Wasm reverse engineering script kit
type: item
date: 2024-06-03T10:15:42+08:00
description: memories = [wasmMemory] //TODO: change it to real memory address // the real memory pointer can be found by searching "new WebAssembly.Memory", the result value is the memory address base pointer viewDWORD = (addr) =>{ addr = addr.value !== undefined ? addr.value : addr; const arr = new Uint32Array(memories[0].buffer.slice(addr, addr + 16)); return arr; }; viewChar = (addr, size = 16) =>{ addr = addr.value !== undefined ? addr.value : addr; const arr = new Uint8Array(memories[0].buffer.slice(addr, addr + size)); return String.fromCharCode.apply(null, arr); }; viewHEX = (addr, size = 16) =>{ addr = addr.value !== undefined ? addr.value : addr; const arr = new Uint8Array(memories[0].buffer.slice(addr, addr + size)); return (Array.from(arr, x =>x.toString(16).padStart(2, '0')).join(' ')); }; viewHexCode = (addr, size = 16) =>{ addr = addr.value !== undefined ? addr.value : addr; const arr = new Uint8Array(memories[0].buffer.slice(addr, addr + size)); return (Array.from(arr, x =>'0x' + x.toString(16).padStart(2, '0')).join(', ')); }; dumpMemory = (addr, size = 16) =>{ addr = addr.value !== undefined ? addr.value : addr; const arr = new Uint8Array(memories[0].buffer.slice(addr, addr + size)); return arr; }; viewString = (addr, size = 16) =>{ addr = addr.value !== undefined ? addr.value : addr; const arr = new Uint8Array(memories[0].buffer.slice(addr, addr + size)); let max = size; for (let i = 0; i < size; i++) { if (arr[i] === 0) { max = i; break; } } return String.fromCharCode.apply(null, arr.slice(0, max)); }; viewStrings = (...addrs) =>{ addrs.forEach(addr=>{ console.log(addr, viewString(addr)) }) }; search = function(stirng) { const m = new Uint8Array(memories[0].buffer); // vid=35402, 9AAizQZJ // vid=20268, a3fMpSkB const k = Array.from(stirng, x =>x.charCodeAt()); const match = (j) =>{ return k.every((b, i) =>m[i + j] === b); }; const max = Math.min(10_000_000, m.byteLength || m.length); for (let i = 0; i < max; i++) { if (match(i)) { console.info(i); } } console.…