V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
爱意满满的作品展示区。
huyiwei
V2EX  ›  分享创造

理论永远不会失效的抖音直播间消息获取工具[狗头]需要的朋友 dd

  •  1
     
  •   huyiwei · 39 天前 · 1779 次点击
    这是一个创建于 39 天前的主题,其中的信息可能已经有所发展或是发生改变。

    原理就是 hook web 网页 js 哈哈哈

    第 1 条附言  ·  38 天前

    核心代码就两处

    main.js

    拦截关于websocket的js文件把请求转给本地代理服务器

    // 拦截请求
    this.webContents.session.webRequest.onBeforeRequest((details, callback) => {
    
        // 在这里进行请求处理,例如修改请求 URL、添加请求头等
        if (
            /^https:\/\/.+?webcast\/douyin_live\/\d+.+\.js$/.test(details.url)
        ) {
            callback({ redirectURL: `http://localhost:${replaceWsPort}/${details.url}` });
            return
        }
        
        // 继续请求
        callback({ cancel: false });
    });
    

    replaceWs.js

    本地代理服务拿到js文件,对js文件修改加hook

    // http拿到js文件内容
    return fetch(url).then(res => res.text()).then(text => {
        // 是否有ws字样
        if (!text.includes('new WebSocket')) return text
        // 开始替换数据
        // 替换onError
        text = text.replaceAll(/(\{.+?\("socket error",(.+?)\),)/g, '$1typeof window.emitClose == \'function\' && window.emitClose(\'error\',$2),')
        // 替换onClose
        text = text.replace(/(\{.+?\("socket closed",(.+?)\),)/, '$1typeof window.emitClose == \'function\' && window.emitClose(\'close\',$2),')
        // 替换onOpen td("socket established"),
        text = text.replace(/(\{.+?\("socket established"\),)/, '$1typeof window.emitOpen == \'function\' && window.emitOpen(),')
        // 替换onMessage ;eu || tM("no payload can be decoded, maybe cannot find idl", eo);
        text = text.replace(/;([a-zA-Z]+)?\|\|.+?\("no payload can be decoded, maybe cannot find idl",[a-zA-Z]+\);/, ';if(typeof window.emitMessage == \'function\'){window.emitMessage($1);}return {method:\'\'};')
        // 替换stop函数
        // text = text.replace(/\{[a-zA-Z]+?\("socket terminating"\),/, '{return;')
        text = text.replaceAll(/stop\(\)\s*\{/g, 'stop(){return;')
        // 替换 "visible"
        text = text.replaceAll(/"visible"/g, '"_visible_"')
        // 替换暂停 pause() {
        text = text.replaceAll(/pause\(\)\s*\{/g, 'pause() {return;')
        return text
    })
    

    然后你懂得...

    第 2 条附言  ·  38 天前
    github 懒得上了,很烂的代码,大神略过。 蓝奏地址 https://vsay.lanzoul.com/b02fym2lc
    密码:7ar3
    19 条回复    2024-03-20 17:36:00 +08:00
    CodeXx
        1
    CodeXx  
       39 天前
    dd
    pancrasxox
        2
    pancrasxox  
       39 天前 via Android
    不懂 这个有啥用😵‍💫
    LICC168
        3
    LICC168  
       39 天前
    dd
    notot
        4
    notot  
       39 天前
    js rpc
    airzhao
        5
    airzhao  
       39 天前
    dd
    boris1993Jr
        6
    boris1993Jr  
       39 天前 via iPhone
    dd if=/dev/null of=/dev/sda
    loveqianool
        7
    loveqianool  
       39 天前 via Android
    有快手的吗
    fbzl
        8
    fbzl  
       39 天前 via iPhone
    js 文件会变动,要定期适配
    ck19920702
        9
    ck19920702  
       39 天前 via iPhone
    dd
    doanything
        10
    doanything  
       38 天前 via iPhone
    dd
    whoami9426
        11
    whoami9426  
       38 天前
    hook 网页直播的 websocket
    huyiwei
        12
    huyiwei  
    OP
       38 天前
    @fbzl 不需要,基本不用改代码,自动适配
    huyiwei
        13
    huyiwei  
    OP
       38 天前
    github 懒得上了,很烂的代码,大神略过。 蓝奏地址 https://vsay.lanzoul.com/b02fym2lc
    密码:7ar3
    huyiwei
        14
    huyiwei  
    OP
       38 天前
    huyiwei
        15
    huyiwei  
    OP
       38 天前 via Android
    @loveqianool 快手同理呀
    EmpCold
        16
    EmpCold  
       38 天前
    先顶后看。
    dylan593
        17
    dylan593  
       38 天前
    谢谢楼主分享
    yuanchao
        18
    yuanchao  
       38 天前
    这个可以干啥,没看懂使用场景
    bkmi
        19
    bkmi  
       38 天前 via Android
    发个 gist 呗
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   880 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 131ms · UTC 20:13 · PVG 04:13 · LAX 13:13 · JFK 16:13
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.