1
0
mirror of https://github.com/Big1moster/catvm.git synced 2025-04-15 15:56:10 +08:00
catvm/CatVm2/tools/vm_safefunction.js
Big1moster d843fcb236 dsf
2023-02-06 11:36:48 +08:00

32 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 主要用来保护伪造的函数,使其更难被识别
// 主要用来保护伪造的函数,让其更难识破
;
(() => {
'use strict';
// 取原型链上的toString
const $toString = Function.toString;
// 取方法名 reload
const myFunction_toString_symbol = Symbol('('.concat('', ')_', (Math.random() + '').toString(36)));
const myToString = function () {
return typeof this == 'function' && this[myFunction_toString_symbol] || $toString.call(this);
};
function set_native(func, key, value) {
Object.defineProperty(func, key, {
"enumerable": false, // 不可枚举
"configurable": true, // 可配置
"writable": true, // 可写
"value": value
})
}
delete Function.prototype['toString'];// 删除原型链上的toString
set_native(Function.prototype, "toString", myToString); // 自定义一个getter方法其实就是一个hook
//套个娃保护一下我们定义的toString避免js对toString再次toStringlocation.reload.toString.toString() 否则就暴露了
set_native(Function.prototype.toString, myFunction_toString_symbol, "function toString() { [native code] }");
this.catvm.safefunction = (func) => {
set_native(func, myFunction_toString_symbol, `function ${myFunction_toString_symbol,func.name || ''}() { [native code] }`);
}; //导出函数到globalThis更改原型上的toSting为自己的toString。这个方法相当于过掉func的toString检测点
}).call(this);