3回答

0收藏

关于js变量赋值时怎么被hook到

问答交流 问答交流 1936 人阅读 | 3 人回复 | 2020-07-11


var a = 'hello';

怎么做到当一个变量(不确定变量名时)被赋值为 'hello' 时 被hook到呢 ?备注:不能用下面的hook方式,因为假设的前提是不知道变量名

Object.defineProperty(window, 'a', {

set:function(x){

if (x == 'hello'){

debugger;

};

return x;

}

})










目前想到的只能下面这种形式的赋值能够被hook到,但实际中很少有这种赋值方式:

var a = new String('hello');

相关的hook函数

myString = String;

String = function(value){

if (value == 'hello'){

debugger;

};

console.log(value);

return myString(value);

}




求大佬解答
分享到:
回复

使用道具 举报

回答|共 3 个

mengtao

发表于 2020-7-24 17:49:56 | 显示全部楼层

我的回复呢?
回复

使用道具 举报

mengtao

发表于 2020-7-24 17:50:23 | 显示全部楼层

JS防注入删掉了?
回复

使用道具 举报

mengtao

发表于 2020-7-24 17:51:02 | 显示全部楼层

// ==UserScript==
// @name         参数破解
// @namespace    http://*
// @version      0.1
// @description  try to take over the world!
// @author       Mengtao
// @match        https://*
// @grant        none
// ==/UserScript==

var code = function(){
     var open = window.XMLHttpRequest.prototype.open;

     window.XMLHttpRequest.prototype.open = function open(method, url, async){
         if (url.indexOf("MmEwMD")>-1){
             debugger;
         }
         if (url.indexOf("sensor_data")>-1){
             debugger;
         }
         return open.apply(this, arguments);
     };
}

var script = document.createElement('script');
script.textContent = '(' + code + ')()';
(document.head||document.documentElement).appendChild(script);
script.parentNode.removeChild(script);
回复

使用道具 举报