Js逆向 -- 避免toString检测

!function(){
    const MyGetOwnPropertySymbols = Object.getOwnPropertySymbols;

    Object.getOwnPropertySymbols = function getOwnPropertySymbols(){
        const result = MyGetOwnPropertySymbols.apply(this,arguments);
        for(let i = 0;i < result.length;i++){
            if(result[i].toString().indexOf("myToString") != -1) return [];
        };
        return result;
    };

    const $toString = Function.toString;
    //为什么这里要随机,因为如果说不随机,那么就是固定检测特征,如果说目标代码检测了,你就G
    const myFunction_toString_symbol = Symbol('myToString('.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
        })
    }
    //先删除所有函数的toString方法
    delete Function.prototype.toString
    //在重定义一个所有函数公用的toString方法
    set_native(Function.prototype, "toString", myToString);
    set_native(Function.prototype.toString, myFunction_toString_symbol, "function toString() { [native code] }")
    set_native(Object.getOwnPropertySymbols, myFunction_toString_symbol, `function getOwnPropertySymbols() { [native code] }`)
    global.func_set_native = (func) => {
        set_native(func, myFunction_toString_symbol, `function ${func.name || '

你可能感兴趣的:(Js逆向 -- 避免toString检测)