zoukankan      html  css  js  c++  java
  • 浏览器无环境调试

    1. 安装

    /*
        注意: 如何安装不了,cmd窗口以管理员身份运行
        npm install node-inspect -g  // 浏览器无环境配置
        cd 某个目录,安装 npm install vm2 -g //获取纯净v8环境,-g 全局安装
    */

    2. 调试程序目录结构

     3. 添加配置

     

     

     4. 点击debugger--> 配置好的(浏览器无环境)进入debugger

     5. 打开任意浏览器(此处以google浏览器为例) 按 F12进入调试模式

     

    本地代码加载到了浏览器中,可以在浏览器中进行调试了。

    6.代码

    index.js

    var fs =require('fs');
    /*
        注意: 如何安装不了,cmd窗口以管理员身份运行
        npm install node-inspect -g  // 浏览器无环境配置
        npm install vm2 -g 
    */
    const { VM,VMScript} = require('vm2');
    const vm =new VM();// V8创建
    file=`${__dirname}\\code.js`
    w_file=`${__dirname}\\window.js`
    var code =fs.readFileSync(w_file,"utf-8")+fs.readFileSync(file,"utf-8");
    var script = new VMScript(code,`${__dirname}\\正在调试.js`)
    debugger
    vm.run(script);
    debugger
    index.js

    code.js

    console.log("you!")
    debugger

    window.js

    window=this;
    // 重新定义对象的名字,此处给window对象重新定义名字
    Object.defineProperties(window,{
        [Symbol.toStringTag]:{
            value:"window",
            configurable:true
        }
    
    })
    // 封装
    function vmProxy(o) {
    
        return new Proxy(o,{
    
            set(obj,prop,value){
                // obj 哪个对象,prop哪个个对象的属性,该属性的值
                console.log("set=>",obj,prop,value)
                // 把原对象赋值回去
                return Reflect.set(...arguments)
            },
            get(obj,prop,recevier){
                console.log("get=>",obj,prop,recevier)
                return obj[prop];
            }
        
        });
    };
    
    // 主要用来保护伪造的函数,让其更难被识破
    
    
    
    /*
    Object.defineProperty(window,"zhiyuan",{
    
        set:function (val) {
            console.log("zhiyuan",val)
            
        },
        get:function () {
            return this.zhuyuan
        }
    
    }); 
    */
    
    window= vmProxy(window)
    // 后代理的检测不到先代理的
    window.zhiyuan="12345";
    window.aaa= window.zhiyuan;
    /*
     创建对象:
        1. {}
        2. function window(){};new window;
        3. Object.create({})
        4. class window()
    
    */
    navigator=class navigator{}
    navigator=vmProxy(navigator)
    document=class document{}
    document=vmProxy(document)
    location=class location{}
    
    // toString 方法会调用这个
    location.reload=function reload() {
        
    }
    location =vmProxy(location)
    window.js

    lauch.json

    {
        // 使用 IntelliSense 了解相关属性。 
        // 悬停以查看现有属性的描述。
        // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
        "version": "0.2.0",
        "configurations": [
    
            {
                "name": "浏览器无环境",
                "program": "${workspaceFolder}\\src\\index.js",
                "request": "launch",
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "runtimeExecutable": "node-inspect",
                "type": "pwa-node"
            },
        
    
            {
                "name": "Launch Program",
                "program": "${workspaceFolder}\\src\\index.js",
                "request": "launch",
                "skipFiles": [
                    "<node_internals>/**"
                ],
                "type": "pwa-node"
            },
           
        ]
    }
    lauch.json
  • 相关阅读:
    298. Binary Tree Longest Consecutive Sequence
    117. Populating Next Right Pointers in Each Node II
    116. Populating Next Right Pointers in Each Node
    163. Missing Ranges
    336. Palindrome Pairs
    727. Minimum Window Subsequence
    211. Add and Search Word
    年底购物狂欢,移动支付安全不容忽视
    成为程序员前需要做的10件事
    全球首推iOS应用防破解技术!
  • 原文地址:https://www.cnblogs.com/knighterrant/p/15704145.html
Copyright © 2011-2022 走看看