首页 > 其他分享 >一键脱环境

一键脱环境

时间:2023-07-06 23:23:35浏览次数:33  
标签:function code jsCode name 一键 ObjEct 环境 value

 

 

 

 

function deEnvironment_defineHeader_function_proto(ObjEct){ //第一步 定义头部函数,并关联上级原型链
    ObjEct.name = ObjEct.constructor.name;
    let jsCode = "";
    try {
        new ObjEct()
        jsCode += `${ObjEct.name} = function ${ObjEct.name}(){
            debugger;\r\n};` + "\r\n";
    }catch (e){
        jsCode += `${ObjEct.name} = function ${ObjEct.name}(){
            plugin.throwError(${e.constructor.name},'${e.message}');\r\n};` + "\r\n"
    }
    jsCode += `plugin.func_set_native(${ObjEct.name})` + "\r\n";
    jsCode += `plugin.rename(${ObjEct.name}.prototype, "${ObjEct.name}")` + "\r\n";
    if (ObjEct.__proto__.name != "Object" && ObjEct.__proto__.name != ""){
        jsCode += `Object.setPrototypeOf(${ObjEct.name}.prototype,${ObjEct.__proto__.name}.prototype)` + "\r\n";
    }

    return jsCode;
}

function deEnvironment_Shelling_proto(ObjEct,myThis){ //第二步 脱取原型链属性
    let jsCode = "";
    let temp = myThis;
    let isSos;
    try {
        while (true){
            temp = temp.__proto__;
            if(temp.constructor.name === ObjEct.name){
                isSos = true;
                break;
            }
        }
    }catch (e) {
        console.error(`未找到该对象${myThis.constructor.name}上的原型${ObjEct.name}`)
    }

    if (isSos){
        function getCode(OwnPropertyName,OwnPropertyDescriptor){
            function getValueOrGetSet(functionName){
                let jsCodeTemp = "";

                if(OwnPropertyDescriptor.value == undefined){
                    if(value === "" || value === undefined || value === "''"){
                        jsCodeTemp = `plugin.defineProperty(${ObjEct.name}.prototype,'${OwnPropertyName}',undefined,${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable},function (){ debugger; },function (value){ debugger; });plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].get,'get ${OwnPropertyName}');plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].set,'set ${OwnPropertyName}');`
                    }else {
                        jsCodeTemp = `plugin.defineProperty(${ObjEct.name}.prototype,'${OwnPropertyName}',undefined,${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable},function (){ debugger; },function (value){ debugger; });plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].get,'get ${OwnPropertyName}');plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${ObjEct.name}.prototype)['${OwnPropertyName}'].set,'set ${OwnPropertyName}');`
                    }
                }else {
                    jsCodeTemp = `plugin.defineProperty(${ObjEct.name}.prototype,'${OwnPropertyName}',${value},${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable});`
                    if (functionName){
                        jsCodeTemp += `plugin.func_set_native(${ObjEct.name}.prototype.${functionName});`;
                    }
                }
                return jsCodeTemp;
            }
            let code = "";
            let value = myThis[OwnPropertyName];
            switch (typeof value){
                case "string":
                    value = `'${value}'`;
                    code = getValueOrGetSet();
                    break;
                case "number":
                    code = getValueOrGetSet();
                    break;
                case "function":
                    const functionName = value.name;
                    value = `function ${functionName}(){ debugger; }`
                    code = getValueOrGetSet(functionName);
                    break;
                case "object":
                    // if(value instanceof Array){
                    //     value = "[]";
                    // }else if(value == null){
                    //     value = "null"
                    // }else {
                    //     value = "{}";
                    // }
                    value = "(function(){debugger;})()";
                    code = getValueOrGetSet();
                    break;
                case "boolean":
                    code = getValueOrGetSet();
                    break;
                case "undefined":
                    value = `undefined`;
                    code = getValueOrGetSet();
                    break;
                default:
                    debugger;
            }
            return code;
        }
        let OwnPropertyNames = Object.getOwnPropertyNames(temp);
        let OwnPropertyDescriptors = Object.getOwnPropertyDescriptors(temp);
        OwnPropertyNames.forEach((key) =>{
            if (key !== "constructor" && key !== "arguments" && key !== "caller" && key !== "length" && key !== "name"){
                jsCode += getCode(key,OwnPropertyDescriptors[key]) + "\r\n";
            }
        })
    }

    return jsCode;
}

function deEnvironment_main_proto(ObjEct,myThis){
    let jsCode = "";
    jsCode += deEnvironment_defineHeader_function_proto(ObjEct) + "\r\n"; //第一步 定义头部函数,并关联上级原型链
    jsCode += deEnvironment_Shelling_proto(ObjEct,myThis) + "\r\n"; //第二步 脱取原型链属性
    return jsCode;
}

function deEnvironment_defineHeader_function(myThis,name){
    let jsCode = "";
    jsCode += `${name} = {};` + "\r\n";


    if (myThis.constructor.name != "" && myThis.constructor.name != "Object"){
        jsCode += `Object.setPrototypeOf(${name}, ${myThis.constructor.name}.prototype);` + "\r\n";
    }

    return jsCode;
}

function deEnvironment_Shelling(myThis,name){
    let jsCode = "";
    function getCode(OwnPropertyName,OwnPropertyDescriptor){
        function getValueOrGetSet(functionName){
            let jsCodeTemp = "";
            if(OwnPropertyDescriptor.value == undefined){
                jsCodeTemp = `plugin.defineProperty(${name},'${OwnPropertyName}',undefined,${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable},function (){ debugger; },function (){ debugger; });plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${name})['${OwnPropertyName}'].get,'get ${OwnPropertyName}');plugin.func_set_native_Div(Object.getOwnPropertyDescriptors(${name})['${OwnPropertyName}'].set,'set ${OwnPropertyName}');`
            }else {
                jsCodeTemp = `plugin.defineProperty(${name},'${OwnPropertyName}',${value},${OwnPropertyDescriptor.configurable},${OwnPropertyDescriptor.enumerable},${OwnPropertyDescriptor.writable});`
                if (functionName){
                    jsCodeTemp += `plugin.func_set_native(${name}.${functionName});`;
                }
            }
            return jsCodeTemp;
        }
        let code = "";
        let value = myThis[OwnPropertyName];
        switch (typeof value){
            case "string":
                value = `'${value}'`;
                code = getValueOrGetSet();
                break;
            case "number":
                code = getValueOrGetSet();
                break;
            case "function":
                const functionName = value.name;
                value = `function ${functionName}(){ debugger; }`
                code = getValueOrGetSet(functionName);
                break;
            case "object":
                // if(value instanceof Array){
                //     value = "[]";
                // }else if(value == null){
                //     value = "null"
                // }else {
                //     value = "{}";
                // }
                value = "(function(){debugger;})()";

                code = getValueOrGetSet();
                break;
            case "boolean":
                code = getValueOrGetSet();
                break;
            case "undefined":
                value = `undefined`;
                code = getValueOrGetSet();
                break;
            default:
                debugger;
        }
        return code;
    }
    let OwnPropertyNames = Object.getOwnPropertyNames(myThis);
    let OwnPropertyDescriptors = Object.getOwnPropertyDescriptors(myThis);
    OwnPropertyNames.forEach((key) =>{
        if (key !== "constructor" && key !== "arguments" && key !== "caller" && key !== "length" && key !== "name"){
            if (key,OwnPropertyDescriptors[key] == undefined) {
                return;
            }
            jsCode += getCode(key,OwnPropertyDescriptors[key]) + "\r\n";
        }
    })

    return jsCode;

}

function deEnvironment_main(myThis,name){
    let jsCode = "";
    jsCode += deEnvironment_defineHeader_function(myThis,name) + "\r\n"; //第一步 定义头部函数,并关联上级原型链
    jsCode += deEnvironment_Shelling(myThis,name) + "\r\n"; //第二步 脱取对象属性
    return jsCode;
}

let code = '';

// code = deEnvironment_main(document.body.style,"CSSStyleDeclaration");

code = deEnvironment_main_proto(HTMLDivElement,document.createElement("div"));

copy(code)

console.log(code)

 

标签:function,code,jsCode,name,一键,ObjEct,环境,value
From: https://www.cnblogs.com/angdh/p/17533603.html

相关文章

  • TypeScript基本介绍与开发环境
    TypeScript基本介绍与开发环境TypeScript官网TypeScript简介TypeScript是JavaScript的超集它对JS进行了扩展,向JS中引入了类型的概念,并添加了许多新的特性TS代码需要通过编译器编译为JS,然后再交由JS解析器执行TS完全兼容JS,换言之,任何的JS代码都可以直接当成JS使用相较于J......
  • 将PYTHON包环境从一个电脑拷贝到另外一个电脑
    将PYTHON包环境从一个电脑拷贝到另外一个电脑1、在当前电脑复制D:\ProgramFiles\Python\Python311\Lib中的所有文件生成myrequirement.txt文件pipfreeze>myrequirement.txtmyrequirement.txt文件如下:colorama==0.4.6constantly==15.1.0cpca==0.5.5cryptography=......
  • 学会使用 Postman 环境变量,让接口测试更加高效
    在 Postman 中,用Environments来管理环境变量。我们在开发的过程中,往往会用到多个环境:开发环境,测试环境,UAT环境,生产环境等。我们要调用不同环境的API时,只需切换Postman的Environment即可。下面,我们来具体说下Postman环境变量的使用方法。知识扩展:Postman环境设置介绍......
  • anconda配置tensorflow环境
    一、anconda的安装1.进入Anaconda官网并按照电脑配置选择合适的安装包Anaconda官网:https://www.anaconda.com/点击进入不同的三个版本,分别是windows,mac,linux根据自己的电脑配置下载对应的安装包点击next点击Iagree同意协议默认上面的选择,点击next安装位置可以......
  • mac安装php单点调试环境
    页面预览和抓包方式sudophp-fpmsudokillallphp-fpm开启/usr/local/etc/nginx/nginxnginx-squit运行Charles就行 单点调试环境方式:配置apache运行的目录,然后+phpStorm的xdebug就行,postman发请求带xdebug生成的keysudoapachectlstart浏览器debug打开,phpStorm配......
  • mac spark+hive+hadoop 数据分析环境搭建(单机简版)
    apache产品下载地址:http://archive.apache.org/dist/mysql5.6brew方式安装配置:Icon mysql做为元数据存储使用。[email protected] 配置mysqlhome:exportMYSQL_HOME=/usr/local/opt/[email protected]启动mysql:$MYSQL_HOME/bin/mysql.serverstart$M......
  • 1.Vue3 配置开发-测试环境
    1、根目录新建.env.testing、.env.donline文件2、package.json=》scripts中配置"start":"vue-cli-serviceserve--modetesting","start-o":"vue-cli-serviceserve--modedonline"3、vue.config.jsconstBundleAnalyzerPlugin=require(&......
  • gitlab+jenkins+pycharm持续集成环境搭建
    接口自动化虚拟机登录:root   sq若gitlab的容器打不开,关闭防火墙gitlab登录:http://192.168.31.128:9001/projects/new#blank_projectrooti3213941 Git:分布式版本控制系统本地仓库:是在开发人员自己电脑上的git仓库远程仓库:是在远程服务器上的git仓库Clone:克隆,就是将......
  • pycharm虚拟环境创建
    python+django+3.2版本1.先创建纯净的项目+虚拟环境(代码+环境放在,.venv).venv隐藏文件夹可能会出现一个问题每次pip都需要-targrt指定到.venv/Lib/site-packages目录下很麻烦那可以直接venv 2.创建一个py文件,随便安装一个包试试3.Pycharme终端执行pipinstalldjango==3.2......
  • 使用parcel搭建three.js开发环境
    目录1、安装2、项目设置3、打包脚本为了方便模块化进行three.js项目的学习和开发,又不用学习太多的配置,增加学习成本,所以就使用Parcel这个web应用打包工具。Parcel官网:https://v2.parceljs.cn/getting-started/webapp/1、安装​在开始之前,您需要安装Node和npm,并为您......