HOOK脚本

(function() {
    'use strict';
    var xzz = {}
    !(function()  {
    'use strict';
    const $toString = Function.toString;
    const myFunction_toString_symbol = Symbol('('.concat('', ')_', (Math.random() + '').toString(36)));
    const myToString = function toString() {
        return typeof this == 'function' && this[myFunction_toString_symbol] || $toString.call(this);
    };
    function set_native(func,key,value) {
         try {
                Object.defineProperty(func, key, {
                    "enumerable": false,
                    "configurable": true,
                    "writable": true,
                    "value": value
                })
            } catch (e) {
                console.log("保护函数出错 => ", e)
                debugger
            }
    };
   // delete Function.prototype['toString'];
    set_native(Function.prototype,"toString",myToString);
    set_native(Function.prototype.toString,myFunction_toString_symbol,"function toString() { [native code] }")
    this.functionprotect = (func,func_name,type) => {
        set_native(func, myFunction_toString_symbol ,`function ${func_name || ''}() { [native code] }`);
    };
}).call(xzz);
    console.clear = function () {};
    xzz.functionprotect(console.clear,'clear');
    xzz.hook_env_name = ['window','document'];
    xzz.hook_env_blacklist = [];
    xzz.hook_env = [];;
    xzz.hook_env[0] = window;
    xzz.hook_env[1] = document;


    for (let l=0;l<xzz.hook_env_name.length;l++) {
        xzz[xzz.hook_env_name[l] + '_hook'] = []
        for (let func_name in xzz.hook_env[l]) {
            if (typeof xzz.hook_env[l][func_name] == 'function')  xzz[xzz.hook_env_name[l] + '_hook'].push(func_name)
        }
        for (let ll=0;ll< xzz[xzz.hook_env_name[l] + '_hook'].length;ll++) {
            if ( xzz[xzz.hook_env_name[l] + '_hook'][ll] == 'eval') continue;
            if ( xzz[xzz.hook_env_name[l] + '_hook'][ll] == 'assign') continue;
           xzz.hook_env[l][xzz[xzz.hook_env_name[l] + '_hook'][ll]] =  function(hook_func) {
                return function() {
                    let ret = hook_func.apply(this, arguments);
                    let time = new Date();
                    try {
                        console.log('[*] '+xzz.hook_env[l]+'->'+(this.__proto__ + '')+'hooked function-->'+hook_func.name+',arg:',arguments)
                    } catch (e) {
                        console.log('[*] '+xzz.hook_env[l]+'hooked function-->'+hook_func.name+',arg:',arguments)
                    }
                    console.log('[*] cookie:',document.cookie)
                    debugger
                    return ret;
                };
            }(xzz.hook_env[l][xzz[xzz.hook_env_name[l] + '_hook'][ll]]);
            xzz.functionprotect(xzz.hook_env[l][xzz[xzz.hook_env_name[l] + '_hook'][ll]],xzz[xzz.hook_env_name[l] + '_hook'][0]);
        }
    }

   xzz.cookie_ = '';
    Object.defineProperty(document, 'cookie', {
    //hook set方法也就是赋值的方法
    //当前也可以hook get方法
     set: function(val) {

            //这样就可以快速给下面这个代码行下断点
            //从而快速定位设置cookie的代码
         debugger
         console.log('[*]  Hook捕获到cookie设置->', val);
         xzz.cookie_ = val;
         return val;
     },

     get: function(val) {
            //这样就可以快速给下面这个代码行下断点
            //从而快速定位设置cookie的代码
          //  console.log('[*] Hook捕获到cookie获取->', val);
            return xzz.cookie_;
         }
    });
    xzz.proxy = function (obj, objname, type) {
    function isSymbol(value) {
        const type = typeof value
        return type === 'symbol' || type === 'object'
    }

    function isSymbol2(value) {
        const type = typeof value
        return type == 'symbol' || (type === 'object' && value != null && Object.prototype.toString.call(value) == '[object Symbol]')
    }

    function getMethodHandler(WatchName) {
        let methodhandler = {
            apply(target, thisArg, argArray) {
                let result = Reflect.apply(target, thisArg, argArray)
                if (isSymbol(result)) {
                    console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray.toString().slice(0, 60)}]`)
                } else {
                    if (argArray+''.length > 60) {
                        console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [function], result is [${result}].`)
                    }else{
                    console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray.toString().slice(0, 60)}], result is [${result}].`)
                    }


                }
                return result
            },
            construct(target, argArray, newTarget) {
                var result = Reflect.construct(target, argArray, newTarget)
                if (isSymbol(result)) {

                    console.log(`[${WatchName}] construct function name is [${target.name}], argArray is [${argArray.toString().slice(0, 60)}]`)
                } else {
                    if (argArray+''.length > 60) {
                        console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [function], result is [${result}].`)
                    }else{
                    console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray.toString().slice(0, 60)}], result is [${result}].`)
                    }
                    //
                }
                return result;
            }
        }
        return methodhandler
    }

    function getObjhandler(WatchName) {
        let handler = {
            get(target, propKey, receiver) {
                // if (propKey === "constructor"){
                //     debugger;
                // }
                if (propKey == 'length') {
                    xzzvm.memory.debuger.run('Proxy')
                }


                let result = Reflect.get(target, propKey, receiver)
                if (result instanceof Object && propKey !== 'cbb_id') {
                    if (typeof result === "function") {
                        if (isSymbol(propKey)) {
                            console.log(`[${WatchName}] getting propKey is [symbol] , it is function`)

                        } else {
                            // if (propKey !== 'cbb_id') {
                                console.log(`[${WatchName}] getting propKey is [${propKey}] , it is function`)
                            // }

                        }
                        return new Proxy(result, getMethodHandler(WatchName))
                    } else {
                        if (isSymbol(propKey)) {
                            console.log(`[${WatchName}] getting propKey is [msybol], result is [${(result)}]`);

                        } else {
                            // if (propKey !== 'cbb_id') {
                                console.log(`[${WatchName}] getting propKey is [${propKey}], result is [${(result)}]`);
                            // }

                        }
                    }
                    let paic = ["Function", "Array"]
                    if (paic.indexOf(propKey) != -1 || paic.indexOf(target) != -1 || isSymbol2(propKey)) {
                        return result

                    }
                    return new Proxy(result, getObjhandler(`${WatchName}.${propKey}`))
                    // return result
                }
                if (isSymbol(result)) {
                    // if (propKey !== 'cbb_id') {
                        console.log(`[${WatchName}] getting propKey is [${propKey?.description ?? propKey}]`)
                    // }

                } else {
                    // if (propKey !== 'cbb_id') {

                        console.log(`[${WatchName}] getting propKey is [${propKey?.description ?? propKey}], result is [${result}]`);
                    // }

                }
                return result;
            },
            set(target, propKey, value, receiver) {
                if (propKey === "innerHTML"){
                    debugger;
                }

                if (value instanceof Object) {
                    if (typeof value === "function") {
                        if (isSymbol(WatchName)) {
                            // if (propKey !== 'cbb_id') {
                                console.log(`[symbolName] setting propKey is [${propKey}] , it is function`)
                            // }

                        } else {
                            if (isSymbol(propKey)) {
                                console.log(`[${WatchName}] setting propKey is [symbolpropKey] , it is function`)

                            } else {
                                // if (propKey !== 'cbb_id') {
                                    console.log(`[${WatchName}] setting propKey is [${propKey}] , it is function`)
                                // }

                            }

                        }
                    } else if (isSymbol(value)) {
                        // if (propKey !== 'cbb_id') {
                            console.log(`[${WatchName}] setting propKey is [${propKey}]`)
                        // }
                    } else {
                        // if (propKey !== 'cbb_id') {
                            console.log(`[${WatchName}] setting propKey is [${propKey}], value is [${(value)}]`);
                        // }
                    }
                } else {
                    if (isSymbol(value)) {
                        // if (propKey !== 'cbb_id') {
                            console.log(`[${WatchName}] setting propKey is [${propKey}]`);
                        // }
                    } else {
                        // if (propKey !== 'cbb_id') {
                            console.log(`[${WatchName}] setting propKey is [${propKey}], value is [${value}]`);
                        // }
                    }
                }
                return Reflect.set(target, propKey, value, receiver);
            },
            has(target, propKey) {
                var result = Reflect.has(target, propKey);
                if (isSymbol(result)) {
                    // if (propKey !== 'cbb_id') {
                        console.log(`[${WatchName}] has propKey [${propKey}]`)
                    // }
                } else {
                    // if (propKey !== 'cbb_id') {
                        console.log(`[${WatchName}] has propKey [${propKey}], result is [${result}]`)
                    // }
                }
                return result;
            },
            deleteProperty(target, propKey) {
                if (propKey === "__fycb"){
                    return true
                }
                var result = Reflect.deleteProperty(target, propKey);
                if (isSymbol(result)) {
                    // if (propKey !== 'cbb_id') {
                        console.log(`[${WatchName}] delete propKey [${propKey}]`)
                    // }

                } else {
                    // if (propKey !== 'cbb_id') {
                        console.log(`[${WatchName}] delete propKey [${propKey}], result is [${result}]`)
                    // }

                }

                return result;
            },
            getOwnPropertyDescriptor(target, propKey) {
                var result = Reflect.getOwnPropertyDescriptor(target, propKey);
                if (isSymbol(result)) {
                    if (isSymbol2(propKey)) {
                        console.log(`[${WatchName}] getOwnPropertyDescriptor  propKey [symbol] result is [${(result)}]`)
                    } else {
                        // if (propKey !== 'cbb_id') {
                            if ('_$It' == ''+propKey){
                                eval('debu'+'gger')
                            // }
                            console.log(`[${WatchName}] getOwnPropertyDescriptor  propKey [${propKey}] result is [${(result)}]`)
                        }
                    }
                } else {
                    if (isSymbol(propKey)) {
                        console.log(`[${WatchName}] getOwnPropertyDescriptor  propKey `)
                    } else {
                        // if (propKey !== 'cbb_id') {
                            console.log(`[${WatchName}] getOwnPropertyDescriptor  propKey [${propKey}]`)
                        // }
                    }
                }
                return result;
            },
            defineProperty(target, propKey, attributes) {
                var result = Reflect.defineProperty(target, propKey, attributes);
                if (isSymbol(result)) {
                    // if (propKey !== 'cbb_id') {
                        console.log(`[${WatchName}] defineProperty propKey [${propKey}] attributes is [${(attributes)}], result is [${result}]`)
                    // }
                } else {
                    if (isSymbol(propKey)) {
                        console.log(`[${WatchName}] defineProperty propKey [symbolpropKey] attributes is [${(attributes)}]`)
                    } else {
                        // if (propKey !== 'cbb_id') {
                            console.log(`[${WatchName}] defineProperty propKey [${propKey}] attributes is [${(attributes)}]`)
                        // }
                    }
                }
                return result
            },
            getPrototypeOf(target) {
                var result = Reflect.getPrototypeOf(target)
                if (isSymbol(result)) {
                    console.log(`[${WatchName}] getPrototypeOf result is [${(result)}]`)

                } else {
                    console.log(`[${WatchName}] getPrototypeOf `)
                }
                return result;
            },
            setPrototypeOf(target, proto) {
                console.log(`[${WatchName}] setPrototypeOf proto is [${(proto)}]`)
                return Reflect.setPrototypeOf(target, proto);
            },
            preventExtensions(target) {
                console.log(`[${WatchName}] preventExtensions`)
                return Reflect.preventExtensions(target);
            },
            isExtensible(target) {
                var result = Reflect.isExtensible(target)
                console.log(`[${WatchName}] isExtensible, result is [${result}]`)
                return result;
            },
            ownKeys(target) {
                var result = Reflect.ownKeys(target)
                console.log(`[${WatchName}] invoke ownkeys, result is [${(JSON.stringify(result))}]`)
                if (typeof result === typeof []) {
                    let fo = result.indexOf("globalMy")
                    if (fo !== -1){
                        result.splice(fo,1)
                    }
                }

                return result
            },
            apply(target, thisArg, argArray) {
                let result = Reflect.apply(target, thisArg, argArray)
                if (isSymbol(result)) {
                    console.log(`[${WatchName}] apply function name is [${target.name}]`)

                } else {
                    if (argArray+''.length > 60) {
                        console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [function], result is [${result}].`)
                    }else{
                    console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray}], result is [${result}].`)
                    }

                }
                return result
            },

            construct(target, argArray, newTarget) {
                var result = Reflect.construct(target, argArray, newTarget)
                if (isSymbol(result)) {
                    console.log(`[${WatchName}] construct function name is [${target.name}]`)
                } else {
                    if (argArray+''.length > 60) {
                       console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [function], result is [${result}].`)
                    }else{
                    console.log(`[${WatchName}] apply function name is [${target.name}], argArray is [${argArray.slice(0, 60)}], result is [${result}].`)
                    }
                    //
                }
                return result;
            }
        }
        return handler;
    }

    if (type === "method") {
        return new Proxy(obj, getMethodHandler(objname));
    }
    return new Proxy(obj, getObjhandler(objname));
}

    localStorage = xzz.proxy(localStorage,'localStorage')

})();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值