
核心代码就两处
拦截关于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 Mar 19, 2024 dd |
2 pancrasxox Mar 19, 2024 via Android 不懂 这个有啥用 |
3 LICC168 Mar 19, 2024 dd |
4 notot Mar 19, 2024 js rpc |
5 airzhao Mar 19, 2024 dd |
6 boris1993Jr Mar 19, 2024 via iPhone dd if=/dev/null of=/dev/sda |
7 loveqianool Mar 19, 2024 via Android 有快手的吗 |
8 fbzl Mar 19, 2024 via iPhone js 文件会变动,要定期适配 |
9 0x0x Mar 19, 2024 via iPhone dd |
10 doanything Mar 20, 2024 via iPhone dd |
11 whoami9426 Mar 20, 2024 hook 网页直播的 websocket |
13 huyiwei OP github 懒得上了,很烂的代码,大神略过。 蓝奏地址 https://vsay.lanzoul.com/b02fym2lc 密码:7ar3 |
14 huyiwei OP |
15 huyiwei OP @loveqianool 快手同理呀 |
16 EmpCold Mar 20, 2024 |
17 dylan593 Mar 20, 2024 谢谢楼主分享 |
18 getcodex Mar 20, 2024 这个可以干啥,没看懂使用场景 |
19 bkmi Mar 20, 2024 via Android 发个 gist 呗 |