Giter VIP home page Giter VIP logo

javascript-window-listener-library's Introduction

javascript逆向开发基础组件: window监听器

一、 简介

用于监听window的变化,目前只有新增全局变量监控,最初是为了用在javascript hook库中实现对window变量的proxy功能。

二、Example

(async () => {

    const monitor = new WindowMonitor();
    // 在window新增变量时会触发此处传入的Listener函数,Listener函数可以有多个 
    await monitor.addWindowListener(key => {
        console.log(new Date(), key);
    });
    // 启动监控器,其实就是个while循环不断的检查window上是否有新增变量 
    await monitor.startWindowMonitor();

})();

const chars = "ABCDEFGHJKMNPQRSTWXYZ"

function randomString(length) {
    length = length || 100;
    const charArray = [];
    for (let i = 0; i < length; i++) {
        charArray.push(chars.charAt(Math.floor(Math.random() * chars.length)));
    }
    return charArray.join("");
}

function genGlobalVars() {
    window[randomString(40)] = randomString(6);
    setTimeout(genGlobalVars, Math.random() * 10)
}

setTimeout(() => {
    genGlobalVars();
}, Math.random() * 10)

三、原理

其实原理简单粗暴,就是每隔一段时间遍历window对其所有属性做一个快照,然后前后快照做diff,就能够找出来新增的变量或者删除的变量,对于第一个快照会认为是初始化,这样就能够把默认的属性给识别出来不触发新增事件。

javascript-window-listener-library's People

Contributors

cc11001100 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

javascript-window-listener-library's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.