debugger,python与js代码交互

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代码进行交互

  1. 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)
  1. Pyexecjs
import execjs

ctx = execjs.compile(js_code)
result = ctx.call('b', xxx)
print(result)
  1. 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)

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值