V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sbmzhcn
V2EX  ›  程序员

一段 WebAssembly 生成的 js 代码能否看出逆向代码是什么

  •  
  •   sbmzhcn · 118 天前 · 1552 次点击
    这是一个创建于 118 天前的主题,其中的信息可能已经有所发展或是发生改变。
    h = function (e, t, n, l) {
        let s,
            a;
        try {
            let d = r.__wbindgen_add_to_stack_pointer(- 16),
                u = passStringToWasm0(e, r.__wbindgen_malloc, r.__wbindgen_realloc),
                h = F,
                g = passStringToWasm0(t, r.__wbindgen_malloc, r.__wbindgen_realloc),
                m = F,
                f = passStringToWasm0(n, r.__wbindgen_malloc, r.__wbindgen_realloc),
                x = F,
                p = passStringToWasm0(l, r.__wbindgen_malloc, r.__wbindgen_realloc),
                v = F;
            r.sign(d, u, h, g, m, f, x, p, v);
            var o,
                i = getInt32Memory0()[d / 4 + 0],
                c = getInt32Memory0()[d / 4 + 1];
            return s = i,
            a = c,
            o = i >>> 0,
            W.decode(getUint8Memory0().subarray(o, o + c))
        } finally {
            r.__wbindgen_add_to_stack_pointer(16),
            r.__wbindgen_free(s, a, 1)
        }
    }(i, d, u, e)
    
    

    i = "6b3aebd9-af68-4c12-b349-38c68cb94924" //每次随机一个
    d = "1704012139" //当前时间戳
    u = "d192de21a79b50e44b7774c7887e2f465bb7e197" //一个固定值
    e = "hello" // 变化的字符串

    h 的最张结果应该是( sign 值):
    "5b81e04144091fdcd8af6ec04931f08bf6ccea3b6136a141daa439274b2b6449"

    更多附加信息

    let F = 0, Q = null;
    function getUint8Memory0() {
        return (null === Q || 0 === Q.byteLength) && (Q = new Uint8Array(r.memory.buffer)),
        Q
    }
    let q = "undefined" != typeof TextEncoder ? new TextEncoder("utf-8") : {
        encode: ()=>{
            throw Error("TextEncoder not available")
        }
    }
        , G = "function" == typeof q.encodeInto ? function(e, t) {
        return q.encodeInto(e, t)
    }
    : function(e, t) {
        let n = q.encode(e);
        return t.set(n),
        {
            read: e.length,
            written: n.length
        }
    };
    function passStringToWasm0(e, t, n) {
        if (void 0 === n) {
            let n = q.encode(e)
              , r = t(n.length, 1) >>> 0;
            return getUint8Memory0().subarray(r, r + n.length).set(n),
            F = n.length,
            r
        }
        let r = e.length
          , l = t(r, 1) >>> 0
          , s = getUint8Memory0()
          , a = 0;
        for (; a < r; a++) {
            let t = e.charCodeAt(a);
            if (t > 127)
                break;
            s[l + a] = t
        }
        if (a !== r) {
            0 !== a && (e = e.slice(a)),
            l = n(l, r, r = a + 3 * e.length, 1) >>> 0;
            let t = getUint8Memory0().subarray(l + a, l + r)
              , s = G(e, t);
            a += s.written
        }
        return F = a,
        l
    }
    let O = null;
    function getInt32Memory0() {
        return (null === O || 0 === O.byteLength) && (O = new Int32Array(r.memory.buffer)),
        O
    }
    
    let W = "undefined" != typeof TextDecoder ? new TextDecoder("utf-8",{
        ignoreBOM: !0,
        fatal: !0
    }) : {
        decode: ()=>{
            throw Error("TextDecoder not available")
        }
    };
    

    猜测可能是 crypto.createHash('sha256').update(data).digest('hex');

    但试了都不对,有没有人能帮忙解决下,谢谢!

    4 条回复    2024-01-02 10:32:46 +08:00
    yyf1234
        1
    yyf1234  
       118 天前 via iPhone
    wasm 这玩意逆向只能靠动态调试,一步步跟逻辑。光代码段是分析不出来的
    misdake
        2
    misdake  
       118 天前
    给这么多都是胶水代码,没有实现。有效信息只有 4 个输入和 1 个输出,全靠蒙。
    我猜就是这几个属性拼属性名然后排序拼接,过一遍 sha256 。可以调试进 wasm 找找常量字符串,看看属性名叫什么。
    janemon
        3
    janemon  
       117 天前 via iPhone
    先把 wasm 字节码捞出来然后反编译一下看看,你这都是外围胶水代码,没什么用
    weixiangzhe
        4
    weixiangzhe  
       116 天前
    wasm 当黑盒用不行吗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2871 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 14:50 · PVG 22:50 · LAX 07:50 · JFK 10:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.