js逆向-使用pywasm调用wasm二进制文件的函数

实例来源 猿人学第15题
talk is cheap show you the code
js_code = '''
function fn() {
    var fetch = require("node-fetch");
    m = fetch('match/match15/main.wasm').then(response => response.arrayBuffer()
    ).then(bytes => WebAssembly.instantiate(bytes)).then(results => {
            instance = results.instance;
            # 关键点 **********************************************************
            q = instance.exports.encode;
            m = function () {
                t1 = parseInt(Date.parse(new Date()) / 1000 / 2);
                t2 = parseInt(Date.parse(new Date()) / 1000 / 2 - Math.floor(Math.random() * (50) + 1));
                return q(t1, t2).toString() + '|' + t1 + '|' + t2;
            }();
            return m;

        }
    )
    return m
}
'''
import math
import random
import time
import pywasm

def main():
    t = int(time.time())
    t1 = int(t / 2)
    t2 = int(t / 2 - math.floor(random.random() * 50 + 1))
    vm = pywasm.load("./main.wasm")
    # 关键点 **********************************************************
    result = vm.exec("encode", [t1, t2])
    print(result)
    return result

if __name__ == "__main__":
    main()

推荐阅读更多精彩内容