mirror of
https://github.com/Big1moster/catvm.git
synced 2025-04-15 15:56:10 +08:00
32 lines
1.5 KiB
JavaScript
32 lines
1.5 KiB
JavaScript
// 主要用来保护伪造的函数,使其更难被识别
|
||
|
||
// 主要用来保护伪造的函数,让其更难识破
|
||
;
|
||
(() => {
|
||
'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再次toString,如:location.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);
|