首页 > 其他分享 >some proxy demo

some proxy demo

时间:2023-07-17 12:34:24浏览次数:28  
标签:return target demo some propKey proxy WatchName console result

 

 

let rawindexof = String.prototype.indexOf
String.prototype.indexOf = function (str) {
    var res = rawindexof.call(this, str)
    console.log(`[String] "${this}" is indexof "${str}", res is ${res}`)
    return res
}
let mydocument = {
    "head": {},
    "documentElement": {
        "getAttribute": function () {
        }
    },
    "readyState": "complete",
    "addEventListener": function () {
    },
    "createElement": function () {
        return {}
    },
    "getElementsByTagName": function (str) {
        console.log(str)
        if (str === "meta") {
            let metaRes = []
            metaRes["meta-pro"] = {
                "content": {
                    "length": 6
                }
            }
            return metaRes
        }
    }
}
let mynavigator = {
    userAgent: "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36",
    platform: "Linux x86_64",
    appCodeName: "Mozilla",
    languages: ["en-US", "en"],
    cookieEnabled: true,
    webdriver: false,
};
let mysrceen = {
    height: 852,
    width: 1918,
    colorDepth: 24,
};
let mylocation = {
    "protocol": "https:",
    "href": "http://www.dtasecurity.cn/flightlist",
    "pathname": "/flightlist",
    "host": "www.dtasecurity.cn",
    "hostname": "www.dtasecurity.cn",
}
let mywindow = {
    XMLHttpRequest: function () {
    },
    sessionStorage: {},
    localStorage: {},
    navigator: mynavigator,
    scrollTo: function () {
    },
    addEventListener: function () {
    },
    attachEvent: function () {
    },
    screen: mysrceen,
    location: mylocation,
    chrome: {},
    document: mydocument,
};

let Image = function () {
};
let rawstringify = JSON.stringify;
JSON.stringify = function (Object) {
    if ((Object?.value ?? Object) === global) {
        return "global"
    } else {
        return rawstringify(Object)
    }
}

function checkproxy() {
    //Object.keys(window)
    window.a = {
        "b": {
            "c": {
                "d": 123
            }
        }
    }
    window.a.b.c.d = 456
    window.a.b
    // window.btoa("123")
    // window.atob.name
    "c" in window.a
    delete window.a.b
    Object.defineProperty(window, "b", {
        value: "bbb"
    })
    Object.getOwnPropertyDescriptor(window, "b")
    Object.getPrototypeOf(window)
    Object.setPrototypeOf(window, {"dta": "dta"})
    // for (let windowKey in window) {
    //     windowKey
    // }
    Object.preventExtensions(window)
    Object.isExtensible(window)
}

function getMethodHandler(WatchName) {
    let methodhandler = {
        apply(target, thisArg, argArray) {
            let result = Reflect.apply(target, thisArg, argArray)
            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)
            console.log(`[${WatchName}] construct function name is [${target.name}], argArray is [${argArray}], result is [${JSON.stringify(result)}].`)
            return result;
        }
    }
    return methodhandler
}

function getObjhandler(WatchName) {
    let handler = {
        get(target, propKey, receiver) {
            let result = Reflect.get(target, propKey, receiver)
            if (result instanceof Object) {
                if (typeof result === "function") {
                    console.log(`[${WatchName}] getting propKey is [${propKey}] , it is function`)
                    //return new Proxy(result,getMethodHandler(WatchName))
                } else {
                    console.log(`[${WatchName}] getting propKey is [${propKey}], result is [${JSON.stringify(result)}]`);
                }
                return new Proxy(result, getObjhandler(`${WatchName}.${propKey}`))
            }
            console.log(`[${WatchName}] getting propKey is [${propKey?.description ?? propKey}], result is [${result}]`);
            return result;
        },
        set(target, propKey, value, receiver) {
            if (value instanceof Object) {
                console.log(`[${WatchName}] setting propKey is [${propKey}], value is [${JSON.stringify(value)}]`);
            } else {
                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);
            console.log(`[${WatchName}] has propKey [${propKey}], result is [${result}]`)
            return result;
        },
        deleteProperty(target, propKey) {
            var result = Reflect.deleteProperty(target, propKey);
            console.log(`[${WatchName}] delete propKey [${propKey}], result is [${result}]`)
            return result;
        },
        getOwnPropertyDescriptor(target, propKey) {
            var result = Reflect.getOwnPropertyDescriptor(target, propKey);
            console.log(`[${WatchName}] getOwnPropertyDescriptor  propKey [${propKey}] result is [${JSON.stringify(result)}]`)
            return result;
        },
        defineProperty(target, propKey, attributes) {
            var result = Reflect.defineProperty(target, propKey, attributes);
            console.log(`[${WatchName}] defineProperty propKey [${propKey}] attributes is [${JSON.stringify(attributes)}], result is [${result}]`)
            return result
        },
        getPrototypeOf(target) {
            var result = Reflect.getPrototypeOf(target)
            console.log(`[${WatchName}] getPrototypeOf result is [${JSON.stringify(result)}]`)
            return result;
        },
        setPrototypeOf(target, proto) {
            console.log(`[${WatchName}] setPrototypeOf proto is [${JSON.stringify(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)}]`)
            return result
        },
        apply(target, thisArg, argArray) {
            let result = Reflect.apply(target, thisArg, argArray)
            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)
            console.log(`[${WatchName}] construct function name is [${target.name}], argArray is [${argArray}], result is [${JSON.stringify(result)}].`)
            return result;
        }
    }
    return handler;
}

const navigator = new Proxy(Object.create(mynavigator), getObjhandler("navigator"));
const screen = new Proxy(Object.create(mysrceen), getObjhandler("screen"));
const location = new Proxy(mylocation, getObjhandler("location"));
const document = new Proxy(mydocument, getObjhandler("document"));
const window = new Proxy(Object.assign(global, mywindow), getObjhandler("window"));

checkproxy()
module.exports = {
    window,
    navigator,
    screen,
    location,
    String,
    Image,
    document
}

 

标签:return,target,demo,some,propKey,proxy,WatchName,console,result
From: https://www.cnblogs.com/angdh/p/17559764.html

相关文章

  • requests.exceptions.ProxyError问题解决方法
    出现这个问题是因为你系统上在使用代理,然后你的代理又是规则匹配的。https://stackoverflow.com/questions/36906985/switch-off-proxy-in-requests-library3种解决方法:headers={"User-Agent":"Mozilla/5.0(WindowsNT10.0;Win64;x64;rv:109.0)Gecko/20100101Fi......
  • Ant design的Table组件报错TypeError: rawData.some is not a function
    [(54条消息)Antdesign的Table组件报错TypeError:rawData.someisnotafunction_清颖~的博客-CSDN博客](https://blog.csdn.net/aaqingying/article/details/118971186)React的组件库,AntDesign之Table系列问题解决。这个问题其实很简单,但也很常见呢~看了网上的其他博文,说不......
  • 如何解决error: failed to push some refs to
    出现错误的主要原因是gitee(github)中的README.md文件不在本地代码目录中此时我们要执行gitpull--rebaseoriginmaster命令README.md拉到本地,然后执行gitpushoriginmaster ......
  • sparksql数据倾斜demo
    SparkSQL数据倾斜简介在大数据处理中,数据倾斜是一个常见的问题。当数据在分布式计算中不均匀地分布在不同的节点上时,就会出现数据倾斜。数据倾斜会导致计算节点的负载不平衡,导致部分节点的计算速度变慢,从而影响整个作业的执行效率。SparkSQL是ApacheSpark提供的用于处理结构化......
  • dotnet 连接使用ef orm连接sqlite数据库的小demo
    EF6SQLiteTutorial/Program.csusingEF6SQLiteTutorial.Data;usingMicrosoft.EntityFrameworkCore;varbuilder=WebApplication.CreateBuilder(args);//Addservicestothecontainer.builder.Services.AddControllers();//LearnmoreaboutconfiguringSwag......
  • 创建Spring Boot+Spring MVC+Mybatis Demo项目
    参考资料IDEA搭建Springboot+SpringMVC+Mybatis+Mysql(详细、易懂)创建项目创建多个目录把application.properties改成yml格式并补充配置mysql中创建数据库和表createdatabasedb1;usedb1;createtable`user`( `id`INTUNSIGNEDAUTO_INCREMENT, `name`VARCHAR(......
  • 133.什么是Proxy
    133.什么是Proxy?Proxy用于修改某些操作的默认行为,等同于在语言层面做出修改,所以属于一种“元编程”,即对编程语言进行编程。Proxy可以理解成,在目标对象之前架设一层“拦截”,外界对该对象的访问,都必须先通过这层拦截,因此提供了一种机制,可以对外界的访问进行过滤和改写。Prox......
  • Envoy Proxy负载均衡介绍
    负载均衡是devops工程师的常用术语。当大量流量进入您的系统时,您需要找到一种方法来扩展系统,以便它能够正确处理它。一种解决方案是提高正在运行的单个节点的性能。另一种解决方案是添加更多节点并在这些节点之间分配工作。拥有多个节点还有另一个附加优势是高可用性。负载均......
  • flink demo
    1.搭建测试环境安装1.1下载并启动docker-compose容器#该DockerCompose中包含的容器有:#DataGen:数据生成器。容器启动后会自动开始生成用户行为数据,并发送到Kafka集群中。默认每秒生成1000条数据,持续生成约3小时。也可以更改docker-compose.yml中datagen的spee......
  • 六月学习之Haproxy高级功能(自定义HTTP报文)
    6、Haproxy高级功能6.8、自定义HTTP报文6.8.1、reqaddreqadd<string>[{if|unless}<crond>]在请求报文中添加指定首部实现原理:client-->haproxy-->reqadd(添加header)-->web1、在frontend中使用reqadd,将发往后端集群的请求中添加一个headercat/etc/haproxy/haproxy.cfgf......