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

131 天前
 sbmzhcn
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');

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

1579 次点击
所在节点    程序员
4 条回复
yyf1234
131 天前
wasm 这玩意逆向只能靠动态调试,一步步跟逻辑。光代码段是分析不出来的
misdake
131 天前
给这么多都是胶水代码,没有实现。有效信息只有 4 个输入和 1 个输出,全靠蒙。
我猜就是这几个属性拼属性名然后排序拼接,过一遍 sha256 。可以调试进 wasm 找找常量字符串,看看属性名叫什么。
janemon
130 天前
先把 wasm 字节码捞出来然后反编译一下看看,你这都是外围胶水代码,没什么用
weixiangzhe
129 天前
wasm 当黑盒用不行吗

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1004818

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX