// function w(e, t) { // e || Ge("Assertion failed: " + t) // } // function Ge(t) { // h.onAbort && h.onAbort(t), // t = void 0 !== t ? (r(t), // y(t), // JSON.stringify(t)) : "", // v = !0, // 0; // var o = "abort(" + t + ") at " + P(); // throw $e && $e.forEach(function(e) { // o = e(o, t) // }), // o // return t // } function w(e, t) { return e } function u(e, t, o, i, n) { var r, a, s = (w(a = h["_" + (r = e)], "Cannot call unknown function " + r + ", make sure it is exported"), a), c = [], d = 0; if (w("array" !== t, 'Return type should not be "array".'), i) for (var l = 0; l < i.length; l++) { var u = x[o[l]]; u ? (0 === d && (d = je()), c[l] = u(i[l])) : c[l] = i[l] } var f, p = s.apply(null, c); return f = p, p = "string" === t ? T(f) : "boolean" === t ? Boolean(f) : f, 0 !== d && He(d), p }
const fs = require('fs'); var wasm_data = fs.readFileSync('./ckey.wasm') var buffer = new Uint8Array(wasm_data); var wasmobject = new WebAssembly.Instance(new WebAssembly.Module(buffer));
报错:WebAssembly.Instance(): Imports argument must be present and must be an object
1 2 3
var wasm_env = { }; var wasmobject = new WebAssembly.Instance(new WebAssembly.Module(buffer), wasm_env);
报错:Import #0 module="env" error: module is not an object or function
重点关注445: function(Ke, e, t)的return WebAssembly.instantiate(e, c)
1 2 3 4 5 6 7 8 9 10 11 12
var s, c = { global: null, env: null, asm2wasm: g, parent: h }; var g = { "f64-rem": function(e, t) { return e % t }, debugger: function() {} };
1 2 3 4 5 6 7 8 9 10 11 12
// 由于h的实现太过复杂,目前只用{}替代 var wasm_env = { global: {}, env: {}, asm2wasm: { "f64-rem": function(e, t) { return e % t }, debugger: function() {} }, parent: {} };
报错:Import #0 module="env" function="enlargeMemory" error: function import requires a callable。在h.asmLibraryArg中查看环境变量信息,由于Ge函数只校验参数抛错,所以直接用空函数代替
1 2 3 4 5 6 7
enlargeMemory: K function K() { G() } function G() { Ge("Cannot enlarge memory arrays. Either (1) compile with -s TOTAL_MEMORY=X with X higher than the current value " + Q + ", (2) compile with -s ALLOW_MEMORY_GROWTH=1 which allows increasing the size at runtime, or (3) if you want malloc to return NULL (0) instead of this abort, compile with -s ABORTING_MALLOC=0 ") }
添加环境变量中的env参数enlargeMemory
1 2 3 4 5 6 7 8 9 10 11 12 13 14
var fun_ = function () { }; var wasm_env = { global: {}, env: { enlargeMemory: fun_, }, asm2wasm: { "f64-rem": function(e, t) { return e % t }, debugger: function() {} }, parent: {} };
报错:Import #1 module="env" function="getTotalMemory" error: function import requires a callable,以上同理,以空函数代替
_get_unicode_str: function () { function a(e) { return e ? 48 < e.length ? e.substr(0, 48) : e : "" } var e = function () { var e = document.URL , t = window.navigator.userAgent.toLowerCase() , o = ""; 0 < document.referrer.length && (o = document.referrer); try { 0 == o.length && 0 < opener.location.href.length && (o = opener.location.href) } catch (e) { } var i = window.navigator.appCodeName , n = window.navigator.appName , r = window.navigator.platform , e = a(e) , o = a(o); return e + "|" + (t = a(t)) + "|" + o + "|" + i + "|" + n + "|" + r }() , t = q(e) + 1, o =Ve(t);// 5250872; //_malloc(t); console.log('---',t, o) return S(e, o, t + 1), o },
报错:Import #21 module="env" function="memoryBase" error: global import must be a number or WebAssembly.Global object
报错:Import #22 module="env" function="tableBase" error: global import must be a number or WebAssembly.Global object
1 2
memoryBase: 1024, tableBase: 0,
报错:Import #23 module="env" function="DYNAMICTOP_PTR" error: global import must be a number or WebAssembly.Global object
报错:Import #24 module="env" function="tempDoublePtr" error: global import must be a number or WebAssembly.Global object
报错:Import #25 module="env" function="STACKTOP" error: global import must be a number or WebAssembly.Global object
报错:Import #26 module="env" function="STACK_MAX" error: global import must be a number or WebAssembly.Global object
// h["_" + (r = e)] = wasm._getckey // je = wasm.stackSave // He = wasm.stackRestore // Fe = wasm.stackAlloc // Ve = wasm._malloc 修改_get_unicode_str中的Ve function _getckey() { return wasmobject.exports._getckey.apply(null, arguments) } function stackSave() { return wasmobject.exports.stackSave.apply(null, arguments) } function stackRestore() { return wasmobject.exports.stackRestore.apply(null, arguments) } function stackAlloc() { return wasmobject.exports.stackAlloc.apply(null, arguments) } function _malloc() { return wasmobject.exports._malloc.apply(null, arguments) }
// 函数引用完成n函数 function S(e, t, o) { // o(a, b, c) return w("number" == typeof o, "stringToUTF8(str, outPtr, maxBytesToWrite) is missing the third parameter that specifies the length of the output buffer!"), E(e, C, t, o) } function T(e, t) { if (0 === t || !e) return ""; for (var o, i = 0, n = 0; w(e + n < Q), i |= o = C[e + n >> 0], (0 != o || t) && (n++, !t || n != t); ) ; t = t || n; var r = ""; if (i < 128) { for (var a; 0 < t; ) a = String.fromCharCode.apply(String, C.subarray(e, e + Math.min(t, 1024))), r = r ? r + a : a, e += 1024, t -= 1024; return r } return _(C, e) } var l = { stackSave: function() { stackSave() }, stackRestore: function() { stackRestore() }, arrayToC: function(e) { var t, o, i = stackAlloc(e.length); // Fe(e.length); return o = i, w(0 <= (t = e).length, "writeArrayToMemory array must have a length (should be an array or typed array)"), R.set(t, o), i }, stringToC: function(e) { var t, o = 0; return null != e && 0 !== e && (t = 1 + (e.length << 2), S(e, o = stackAlloc(t), t)), //Fe(e.length); o } } var x = { string: l.stringToC, array: l.arrayToC } function n(...args) { var e = "getckey" var t = "string" var o = ["number", "string", "string", "string", "string", "number"] var i = args var n = undefined var r, a, s = (w(a = _getckey, "Cannot call unknown function " + r + ", make sure it is exported"), a), c = [], d = 0; // var r = "getckey", a = _getckey, s = _getckey, c = [], d = 0; // if (w("array" !== t, 'Return type should not be "array".'), // i) for (var l = 0; l < i.length; l++) { var u = x[o[l]]; console.log("uuuu",u) u ? (0 === d && (d = stackSave()), // je() c[l] = u(i[l])) : c[l] = i[l] } var f, p = s.apply(null, c); return f = p, p = "string" === t ? T(f) : "boolean" === t ? Boolean(f) : f, 0 !== d && stackRestore(d), // He(d) p }
报错:TypeError: Cannot set property '7984' of undefined 说明在内存操作的时候有部分变量我们没有注意到,回到445: function(Ke, e, t)中,抽出部分值操作
1 2 3 4 5 6 7 8
function X() { R = new Int8Array(k), O = new Int16Array(k), I = new Int32Array(k), C = new Uint8Array(k), M = new Uint32Array(k) } X()
报错:document is not defined,window is not defined,Cannot read property 'userAgent' of undefined…
1 2 3 4 5 6 7 8 9 10 11 12 13
var document = { URL: "", referrer: "" } var window = { document: document, navigator: { userAgent: "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36", appCodeName: "Mozilla", appName: "Netscape", platform: "Win32" }, };
node ckey_blog.js
主动调用
由于公众号和正常腾讯视频中的部分参数不一致,修改function m(e)
1 2 3 4 5 6 7
function getCKey(plateform,appVer,vid) { // var t = n ? (e.encryptVer = "9.1", // n(e.platform, e.appVer, e.vids || e.vid, "", e.guid, e.tm)) : (e.encryptVer = "8.1", // a(e.vids || e.vid, e.tm, e.appVer, e.guid, e.platform)); var t = n(plateform, appVer, vid, "", createGUID(), Date.parse(new Date()).toString().substr(0, 10)) return t }