hook:
在不动函数的前提下,进行一些操作.用一个变量去接收函数,重写原函数,返回原先的执行方法.
function a(){
return arguments[0]
}
_a = a
a = function(){
console.log(arguments[1])
return _a.apply(this,arguments)
}
重写与hook:
前者是改变原函数的逻辑,让功能发生变化,后者是在不改变函数功能的前提加入一些东西.
debugger:
1.关键词debugger;比较熟悉
2.eval(‘debugger’)原理与上相似,在虚拟机里执行debugger方法
相当于是执行字符串里面的js代码,可操作空间大
eval('a'+'b'+'c')//返回值为debugger
3.Function(‘debugger’)()
三者可以结合
1.定时器不断间隔创造宏任务队列
setInterval('debuggger', x)
Never pause here,在定时器启动前重写setInterval,autoresponse
setInterval = function(){}
2.html页面产生,自动生成几千个script标签,里面是debugger;
autoresponse
3.循环
for (let i=0;i<=5000;i++){
Function('debugger')() // 原型链 获取Function
eval('debugger')
debugger;
}
Never pause here比较吃性能
autoresponse
干掉进入循环的函数
4.添加sccript标签,插入debugger
cont = document.body
var newScript = document.createElement('script');
newScript.type = 'text/javascript';
newScript.innerHTML = 'debugger';
cont.appendChild(newScript);
关于解决方法:
1优先看Never pause here
2尝试重写调用函数
3autoresponse overrids替换
eval不涉及this指向的问题
python与js代码进行交互
- py-mini-racer
先实例化,然后用eval方式将js代码编译进去,.call的方式去调用里面的函数.
from py_mini_racer import MiniRacer
ctx = MiniRacer()
ctx.eval(js_code)
result = ctx.call('b', x)
print(result)
- Pyexecjs
import execjs
ctx = execjs.compile(js_code)
result = ctx.call('b', xxx)
print(result)
- os.popen
不能调函数,不能传参
能收到异步内容,控制台有console.log,通道就能接收到
import os
js_code = js_code.replace('// ', '')
print(js_code)
with os.popen('node -e console.log(global)') as p:
print(p._stream.buffer.read().decode('utf-8'))
4.subprocess同三
import subprocess
result = subprocess.check_output(['node','-e', js_code])
print(result)
传参用replace js_code.replace(’ ',‘xxx’)
异步可以用subprocess
(new Promise((f)=>{f()})).then(()=>{
a = 1000;
// console.log(a);
global.result = a;
}
)
import subprocess
result = subprocess.check_output(['node', '-e', js_code.replace('//', '')])
print(result)