核心代码就两处
拦截关于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 }); });
本地代理服务拿到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 })
然后你懂得...
1 CodeXx 2024-03-19 17:08:19 +08:00 dd |
![]() | 2 pancrasxox 2024-03-19 19:07:12 +08:00 via Android 不懂 这个有啥用 |
3 LICC168 2024-03-19 19:13:39 +08:00 dd |
![]() | 4 notot 2024-03-19 19:27:36 +08:00 js rpc |
5 airzhao 2024-03-19 20:36:32 +08:00 dd |
6 boris1993Jr 2024-03-19 21:12:05 +08:00 via iPhone dd if=/dev/null of=/dev/sda |
![]() | 7 loveqianool 2024-03-19 21:39:31 +08:00 via Android 有快手的吗 |
![]() | 8 fbzl 2024-03-19 21:50:21 +08:00 via iPhone js 文件会变动,要定期适配 |
![]() | 9 0x0x 2024-03-19 23:29:13 +08:00 via iPhone dd |
![]() | 10 doanything 2024-03-20 08:16:16 +08:00 via iPhone dd |
11 whoami9426 2024-03-20 08:35:43 +08:00 hook 网页直播的 websocket |
![]() | 13 huyiwei OP github 懒得上了,很烂的代码,大神略过。 蓝奏地址 https://vsay.lanzoul.com/b02fym2lc 密码:7ar3 |
![]() | 14 huyiwei OP |
![]() | 15 huyiwei OP @loveqianool 快手同理呀 |
16 EmpCold 2024-03-20 13:28:05 +08:00 |
17 dylan593 2024-03-20 14:33:54 +08:00 谢谢楼主分享 |
![]() | 18 yuanchao 2024-03-20 16:22:18 +08:00 这个可以干啥,没看懂使用场景 |
![]() | 19 bkmi 2024-03-20 17:36:00 +08:00 via Android 发个 gist 呗 |