v0.1.0
No files matched your search
@@ -1,2 +1,4 @@
|
|||||||
.DS_Store
|
.DS_Store
|
||||||
relay/mobile.aar
|
relay/mobile.aar
|
||||||
|
relay/relay-*
|
||||||
|
prebuilts/
|
||||||
@@ -1,13 +1,16 @@
|
|||||||
# Whitelist Bypass
|
# Whitelist Bypass
|
||||||
|
|
||||||
Tunnels internet traffic through VK call DataChannels to bypass government whitelist censorship.
|
Tunnels internet traffic through video calling platforms (VK Call, Yandex Telemost) to bypass government whitelist censorship.
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
VK calls use WebRTC with an SFU (Selective Forwarding Unit). The SFU forwards all SCTP data channels between participants without inspecting them. This tool creates a custom DataChannel (id:2) alongside VK's built-in animoji channel (id:1) and uses it as a bidirectional data pipe.
|
Video calling platforms use WebRTC with an SFU (Selective Forwarding Unit). The SFU forwards SCTP data channels between participants without inspecting them. This tool creates a DataChannel alongside the call's built-in channels and uses it as a bidirectional data pipe.
|
||||||
|
|
||||||
|
- **VK Call**: Uses negotiated DataChannel id:2 (alongside VK's animoji channel id:1)
|
||||||
|
- **Telemost**: Uses non-negotiated DataChannel labeled "sharing" (matching real screen sharing traffic), with SDP renegotiation via signaling WebSocket
|
||||||
|
|
||||||
```
|
```
|
||||||
Joiner (censored) Creator (free internet)
|
Joiner (censored, Android) Creator (free internet, desktop)
|
||||||
|
|
||||||
All apps
|
All apps
|
||||||
|
|
|
|
||||||
@@ -19,9 +22,9 @@ SOCKS5 proxy (Go, :1080)
|
|||||||
|
|
|
|
||||||
WebSocket (:9000)
|
WebSocket (:9000)
|
||||||
|
|
|
|
||||||
WebView (VK call) Browser (VK call)
|
WebView (call page) Electron (call page)
|
||||||
| |
|
| |
|
||||||
DataChannel id:2 <--- VK SFU ---> DataChannel id:2
|
DataChannel <------- SFU -------> DataChannel
|
||||||
|
|
|
|
||||||
WebSocket (:9000)
|
WebSocket (:9000)
|
||||||
|
|
|
|
||||||
@@ -30,70 +33,90 @@ DataChannel id:2 <--- VK SFU ---> DataChannel id:2
|
|||||||
Internet
|
Internet
|
||||||
```
|
```
|
||||||
|
|
||||||
Traffic goes through VK's TURN servers (155.212.x.x:19302) which are whitelisted. To the network firewall it looks like a normal VK call.
|
Traffic goes through the platform's TURN servers which are whitelisted. To the network firewall it looks like a normal video call.
|
||||||
|
|
||||||
## Components
|
## Components
|
||||||
|
|
||||||
- `hook.js` - Injected into VK call page on both sides. Hooks RTCPeerConnection, creates tunnel DataChannel, bridges to local WebSocket.
|
- `hooks/` - JavaScript hooks injected into call pages. Separate hooks per platform and role:
|
||||||
- `relay/` - Go binary and gomobile library. SOCKS5 proxy + WebSocket server + tun2socks.
|
- `joiner-vk.js`, `creator-vk.js` - VK Call hooks
|
||||||
- `app/` - Android app. WebView + VpnService + Go relay (.aar).
|
- `joiner-telemost.js`, `creator-telemost.js` - Telemost hooks
|
||||||
|
- Hooks intercept RTCPeerConnection, create tunnel DataChannel, bridge to local WebSocket
|
||||||
|
- Telemost hooks include fake media (camera/mic), message chunking (994B payload, 1000B total), and SDP renegotiation
|
||||||
|
- `relay/` - Go relay binary and gomobile library
|
||||||
|
- SOCKS5 proxy with TCP CONNECT and UDP ASSOCIATE
|
||||||
|
- WebSocket server for browser-relay communication
|
||||||
|
- tun2socks (Android only, via build tags)
|
||||||
|
- Binary framing protocol: `[4B connID][1B msgType][payload]`
|
||||||
|
- `android-app/` - Android joiner app
|
||||||
|
- WebView loading call page with hook injection
|
||||||
|
- VpnService capturing all device traffic
|
||||||
|
- Go relay as .aar library (gomobile)
|
||||||
|
- `creator-app/` - Electron desktop creator app
|
||||||
|
- Webview with persistent session for login retention
|
||||||
|
- CSP header stripping for localhost WebSocket access
|
||||||
|
- Auto-permission granting (camera/mic)
|
||||||
|
- Go relay spawned as child process
|
||||||
|
- Log panels for relay and hook output
|
||||||
|
|
||||||
|
## Prebuilt binaries
|
||||||
|
|
||||||
|
Run `./build-creator.sh` and `./build-app.sh` to produce binaries in `prebuilts/`:
|
||||||
|
|
||||||
|
| File | Platform |
|
||||||
|
|---|---|
|
||||||
|
| `WhitelistBypass Creator-*-arm64.dmg` | macOS |
|
||||||
|
| `WhitelistBypass Creator-*-x64.exe` | Windows x64 |
|
||||||
|
| `WhitelistBypass Creator-*-ia32.exe` | Windows x86 |
|
||||||
|
| `WhitelistBypass Creator-*.AppImage` | Linux x64 |
|
||||||
|
| `whitelist-bypass.apk` | Android |
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
### Creator side (free internet, PC)
|
### Creator side (free internet, desktop)
|
||||||
|
|
||||||
1. Build the relay:
|
Install and run the Electron app from `prebuilts/`. It bundles the Go relay automatically.
|
||||||
```
|
|
||||||
cd relay
|
|
||||||
go build -o relay .
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Start it:
|
1. Open the app
|
||||||
```
|
2. Click "VK Call" or "Telemost"
|
||||||
./relay --mode creator
|
3. Log in, create a call
|
||||||
```
|
4. Copy the join link, send it to the joiner
|
||||||
|
|
||||||
3. Open Chrome, go to Sources -> Snippets, create snippet with contents of `hook.js`, run it.
|
|
||||||
|
|
||||||
4. Create a VK call, copy the join link, send it to the joiner.
|
|
||||||
|
|
||||||
### Joiner side (censored, Android)
|
### Joiner side (censored, Android)
|
||||||
|
|
||||||
1. Build the Go library:
|
1. Install `whitelist-bypass.apk` from `prebuilts/`
|
||||||
```
|
2. Paste the call link in the app
|
||||||
./build-go.sh
|
3. The app joins the call, establishes the tunnel, starts VPN
|
||||||
```
|
4. All device traffic flows through the call
|
||||||
|
|
||||||
2. Build the APK:
|
## Building from source
|
||||||
```
|
|
||||||
./build-app.sh
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Install `whitelist-bypass.apk` on the phone.
|
### Requirements
|
||||||
|
|
||||||
4. Set the VK call link in `MainActivity.kt` (`VK_CALL_LINK` constant) or paste it in the app.
|
|
||||||
|
|
||||||
5. The app joins the call, establishes the tunnel, starts VPN. All device traffic flows through the VK call.
|
|
||||||
|
|
||||||
### Joiner side (censored, PC)
|
|
||||||
|
|
||||||
1. Start the relay:
|
|
||||||
```
|
|
||||||
./relay --mode joiner
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Open Chrome, go to Sources -> Snippets, create snippet with contents of `hook.js`, run it.
|
|
||||||
|
|
||||||
3. Navigate to the VK call link.
|
|
||||||
|
|
||||||
4. Wait for `=== CALL CONNECTED ===` and `WebSocket connected to Go relay`.
|
|
||||||
|
|
||||||
5. Set system proxy to `socks5://127.0.0.1:1080`.
|
|
||||||
|
|
||||||
## Build requirements
|
|
||||||
|
|
||||||
- Go 1.21+
|
- Go 1.21+
|
||||||
- gomobile (`go install golang.org/x/mobile/cmd/gomobile@latest`)
|
- gomobile (`go install golang.org/x/mobile/cmd/gomobile@latest`)
|
||||||
- gobind (`go install golang.org/x/mobile/cmd/gobind@latest`)
|
- gobind (`go install golang.org/x/mobile/cmd/gobind@latest`)
|
||||||
- Android SDK + NDK 28+
|
- Android SDK + NDK 29
|
||||||
- Java 11+
|
- Java 11+
|
||||||
|
- Node.js 18+
|
||||||
|
|
||||||
|
### Build scripts
|
||||||
|
|
||||||
|
```sh
|
||||||
|
# Build Go .aar for Android (includes hooks copy)
|
||||||
|
./build-go.sh
|
||||||
|
|
||||||
|
# Build Android APK -> prebuilts/whitelist-bypass.apk
|
||||||
|
./build-app.sh
|
||||||
|
|
||||||
|
# Build Electron apps for all platforms -> prebuilts/
|
||||||
|
./build-creator.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
### Relay cross-compilation
|
||||||
|
|
||||||
|
The Go relay is split into platform-specific files:
|
||||||
|
- `relay/mobile/mobile.go` - Shared networking code (SOCKS5, WebSocket, framing)
|
||||||
|
- `relay/mobile/tun_android.go` - Android-only: tun2socks + fdsan fix (CGo)
|
||||||
|
- `relay/mobile/tun_stub.go` - Desktop stub (no tun2socks needed)
|
||||||
|
|
||||||
|
This allows cross-compiling the relay for macOS/Windows/Linux without CGo or Android NDK.
|
||||||
@@ -14,7 +14,7 @@ android {
|
|||||||
minSdk = 23
|
minSdk = 23
|
||||||
targetSdk = 36
|
targetSdk = 36
|
||||||
versionCode = 1
|
versionCode = 1
|
||||||
versionName = "1.0"
|
versionName = "0.1"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
(() => {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||||
|
const log = (...args) => console.log('[HOOK]', ...args);
|
||||||
|
const peers = [];
|
||||||
|
let activeWS = null;
|
||||||
|
let wsOpen = false;
|
||||||
|
let outboundDC = null;
|
||||||
|
let dcCreating = false;
|
||||||
|
let tunnelReady = false;
|
||||||
|
|
||||||
|
var origGUM = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
||||||
|
navigator.mediaDevices.getUserMedia = function(c) {
|
||||||
|
log('Intercepting getUserMedia');
|
||||||
|
var canvas = document.createElement('canvas');
|
||||||
|
canvas.width = 2; canvas.height = 2;
|
||||||
|
var stream = canvas.captureStream(1);
|
||||||
|
if (c && c.audio) {
|
||||||
|
var actx = new AudioContext();
|
||||||
|
var dest = actx.createMediaStreamDestination();
|
||||||
|
var t = dest.stream.getAudioTracks()[0];
|
||||||
|
t.enabled = false;
|
||||||
|
stream.addTrack(t);
|
||||||
|
}
|
||||||
|
return Promise.resolve(stream);
|
||||||
|
};
|
||||||
|
navigator.mediaDevices.enumerateDevices = function() {
|
||||||
|
return Promise.resolve([
|
||||||
|
{deviceId:'fake-cam',kind:'videoinput',label:'Camera',groupId:'g1',toJSON:function(){return this}},
|
||||||
|
{deviceId:'fake-mic',kind:'audioinput',label:'Microphone',groupId:'g2',toJSON:function(){return this}},
|
||||||
|
{deviceId:'fake-spk',kind:'audiooutput',label:'Speaker',groupId:'g3',toJSON:function(){return this}}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
var signalingWS = null;
|
||||||
|
var lastPcSeq = 0;
|
||||||
|
var OrigWebSocket = window.WebSocket;
|
||||||
|
window.WebSocket = function(url, protocols) {
|
||||||
|
var ws = protocols ? new OrigWebSocket(url, protocols) : new OrigWebSocket(url);
|
||||||
|
if (url && (url.indexOf('strm.yandex') !== -1 || url.indexOf('jvb.telemost') !== -1)) {
|
||||||
|
log('Signaling WS found: ' + url);
|
||||||
|
signalingWS = ws;
|
||||||
|
var origSend = ws.send.bind(ws);
|
||||||
|
ws.send = function(data) {
|
||||||
|
try {
|
||||||
|
var msg = JSON.parse(data);
|
||||||
|
if (msg.type === 'publisherSdpOffer' && msg.payload && msg.payload.pcSeq) {
|
||||||
|
lastPcSeq = msg.payload.pcSeq;
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
return origSend(data);
|
||||||
|
};
|
||||||
|
ws.addEventListener('message', function(e) {
|
||||||
|
try {
|
||||||
|
var msg = JSON.parse(e.data);
|
||||||
|
if (msg.type === 'publisherSdpAnswer' && msg.payload && msg.payload.sdp) {
|
||||||
|
var pc0 = peers[0];
|
||||||
|
if (pc0 && pc0.signalingState === 'have-local-offer') {
|
||||||
|
pc0.setRemoteDescription({ type: 'answer', sdp: msg.payload.sdp }).catch(function(e) {
|
||||||
|
log('setRemoteDescription error: ' + e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ws;
|
||||||
|
};
|
||||||
|
window.WebSocket.prototype = OrigWebSocket.prototype;
|
||||||
|
window.WebSocket.CONNECTING = OrigWebSocket.CONNECTING;
|
||||||
|
window.WebSocket.OPEN = OrigWebSocket.OPEN;
|
||||||
|
window.WebSocket.CLOSING = OrigWebSocket.CLOSING;
|
||||||
|
window.WebSocket.CLOSED = OrigWebSocket.CLOSED;
|
||||||
|
|
||||||
|
const OrigPC = window.RTCPeerConnection;
|
||||||
|
window.RTCPeerConnection = function (config) {
|
||||||
|
log('New PeerConnection created');
|
||||||
|
const pc = new OrigPC(config);
|
||||||
|
peers.push(pc);
|
||||||
|
var pcIdx = peers.length - 1;
|
||||||
|
|
||||||
|
pc.addEventListener('connectionstatechange', () => {
|
||||||
|
log('Connection state:', pc.connectionState);
|
||||||
|
if (pc.connectionState === 'connected') {
|
||||||
|
log('=== CALL CONNECTED on PC' + pcIdx + ' ===');
|
||||||
|
pc.getSenders().forEach(function(s) {
|
||||||
|
if (s.track) s.track.stop();
|
||||||
|
s.replaceTrack(null).catch(function(){});
|
||||||
|
});
|
||||||
|
if (!outboundDC && !dcCreating) {
|
||||||
|
createTunnelDC(pc, origCreateDC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var origCreateDC = pc.createDataChannel.bind(pc);
|
||||||
|
pc.createDataChannel = function(label, opts) {
|
||||||
|
return origCreateDC(label, opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
pc.addEventListener('datachannel', function(e) {
|
||||||
|
var ch = e.channel;
|
||||||
|
ch.binaryType = 'arraybuffer';
|
||||||
|
log('Incoming DC: label=' + ch.label + ' id=' + ch.id + ' on PC' + pcIdx);
|
||||||
|
|
||||||
|
if (ch.label === 'sharing') {
|
||||||
|
log('Inbound tunnel DC found on PC' + pcIdx);
|
||||||
|
ch.addEventListener('message', function(m) {
|
||||||
|
if (typeof m.data === 'string') {
|
||||||
|
if (m.data === 'tunnel:ping') { sendRaw('tunnel:pong'); return; }
|
||||||
|
if (m.data === 'tunnel:pong') {
|
||||||
|
if (!tunnelReady) {
|
||||||
|
tunnelReady = true;
|
||||||
|
log('DataChannel confirmed on PC' + pcIdx);
|
||||||
|
connectWS();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m.data instanceof ArrayBuffer) {
|
||||||
|
handleChunk(m.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createTunnelDC(pc, origCreateDC) {
|
||||||
|
dcCreating = true;
|
||||||
|
setTimeout(function() {
|
||||||
|
log('Creating tunnel DC');
|
||||||
|
var dc = origCreateDC('sharing', { ordered: true });
|
||||||
|
dc.binaryType = 'arraybuffer';
|
||||||
|
outboundDC = dc;
|
||||||
|
dc.addEventListener('open', function() {
|
||||||
|
log('DataChannel open');
|
||||||
|
startPinging();
|
||||||
|
});
|
||||||
|
dc.addEventListener('close', function() {
|
||||||
|
log('DataChannel closed');
|
||||||
|
outboundDC = null;
|
||||||
|
dcCreating = false;
|
||||||
|
dcQueue = [];
|
||||||
|
tunnelReady = false;
|
||||||
|
});
|
||||||
|
pc.createOffer().then(function(offer) {
|
||||||
|
return pc.setLocalDescription(offer).then(function() {
|
||||||
|
if (signalingWS && signalingWS.readyState === 1) {
|
||||||
|
signalingWS.send(JSON.stringify({
|
||||||
|
type: 'publisherSdpOffer',
|
||||||
|
payload: { pcSeq: lastPcSeq, sdp: offer.sdp, tracks: [] }
|
||||||
|
}));
|
||||||
|
log('Sent renegotiation offer via signaling WS');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(function(e) {
|
||||||
|
log('Renegotiation error: ' + e.message);
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(OrigPC).forEach((key) => {
|
||||||
|
window.RTCPeerConnection[key] = OrigPC[key];
|
||||||
|
});
|
||||||
|
window.RTCPeerConnection.prototype = OrigPC.prototype;
|
||||||
|
|
||||||
|
var CHUNK = 994;
|
||||||
|
var dcQueue = [];
|
||||||
|
var dcDraining = false;
|
||||||
|
var sendMsgId = 0;
|
||||||
|
var recvBufs = {};
|
||||||
|
|
||||||
|
function sendRaw(data) {
|
||||||
|
if (!outboundDC || outboundDC.readyState !== 'open') return;
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
dcQueue.push(data);
|
||||||
|
drainDC();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var u8 = new Uint8Array(data instanceof ArrayBuffer ? data : data.buffer || data);
|
||||||
|
var total = Math.ceil(u8.length / CHUNK) || 1;
|
||||||
|
var id = (sendMsgId++) & 0xFFFF;
|
||||||
|
for (var i = 0; i < total; i++) {
|
||||||
|
var p = u8.subarray(i * CHUNK, Math.min((i + 1) * CHUNK, u8.length));
|
||||||
|
var f = new Uint8Array(6 + p.length);
|
||||||
|
f[0] = id >> 8; f[1] = id & 0xFF;
|
||||||
|
f[2] = i >> 8; f[3] = i & 0xFF;
|
||||||
|
f[4] = total >> 8; f[5] = total & 0xFF;
|
||||||
|
f.set(p, 6);
|
||||||
|
dcQueue.push(f.buffer);
|
||||||
|
}
|
||||||
|
drainDC();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChunk(data) {
|
||||||
|
var u8 = new Uint8Array(data);
|
||||||
|
if (u8.length < 6) return;
|
||||||
|
var id = (u8[0] << 8) | u8[1];
|
||||||
|
var idx = (u8[2] << 8) | u8[3];
|
||||||
|
var total = (u8[4] << 8) | u8[5];
|
||||||
|
var payload = u8.subarray(6);
|
||||||
|
if (total === 1) {
|
||||||
|
if (activeWS && wsOpen) activeWS.send(payload.buffer.slice(payload.byteOffset, payload.byteOffset + payload.byteLength));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var r = recvBufs[id];
|
||||||
|
if (!r) { r = { c: [], n: 0, s: 0 }; recvBufs[id] = r; }
|
||||||
|
if (!r.c[idx]) { r.c[idx] = payload; r.n++; r.s += payload.length; }
|
||||||
|
if (r.n === total) {
|
||||||
|
var out = new Uint8Array(r.s);
|
||||||
|
for (var i = 0, o = 0; i < total; i++) { out.set(r.c[i], o); o += r.c[i].length; }
|
||||||
|
delete recvBufs[id];
|
||||||
|
if (activeWS && wsOpen) activeWS.send(out.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drainDC() {
|
||||||
|
if (dcDraining) return;
|
||||||
|
dcDraining = true;
|
||||||
|
while (dcQueue.length > 0) {
|
||||||
|
if (outboundDC.bufferedAmount > 64 * 1024) {
|
||||||
|
outboundDC.bufferedAmountLowThreshold = 16 * 1024;
|
||||||
|
outboundDC.onbufferedamountlow = function() {
|
||||||
|
outboundDC.onbufferedamountlow = null;
|
||||||
|
dcDraining = false;
|
||||||
|
drainDC();
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
outboundDC.send(dcQueue.shift());
|
||||||
|
}
|
||||||
|
dcDraining = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startPinging() {
|
||||||
|
var iv = setInterval(function() {
|
||||||
|
if (tunnelReady) { clearInterval(iv); return; }
|
||||||
|
sendRaw('tunnel:ping');
|
||||||
|
log('Sent tunnel:ping');
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectWS() {
|
||||||
|
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
||||||
|
activeWS.close();
|
||||||
|
}
|
||||||
|
var ws = new WebSocket(WS_URL);
|
||||||
|
ws.binaryType = 'arraybuffer';
|
||||||
|
activeWS = ws;
|
||||||
|
ws.onopen = function() {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
log('WebSocket connected to Go relay');
|
||||||
|
wsOpen = true;
|
||||||
|
if (typeof AndroidBridge !== 'undefined' && AndroidBridge.onTunnelReady) {
|
||||||
|
AndroidBridge.onTunnelReady();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onclose = function() {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
wsOpen = false;
|
||||||
|
if (tunnelReady) {
|
||||||
|
log('WebSocket disconnected, reconnecting in 2s...');
|
||||||
|
setTimeout(function() { if (tunnelReady) connectWS(); }, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onerror = function() {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
log('WebSocket error');
|
||||||
|
};
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
sendRaw(e.data);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__hook = { peers: peers, log: log };
|
||||||
|
window.__hook.runBandwidthTest = function(totalMB) {
|
||||||
|
totalMB = totalMB || 1;
|
||||||
|
if (!tunnelReady || !outboundDC) { log('Tunnel not ready'); return; }
|
||||||
|
var chunkSize = 4096;
|
||||||
|
var totalBytes = totalMB * 1024 * 1024;
|
||||||
|
var sent = 0;
|
||||||
|
var start = performance.now();
|
||||||
|
sendRaw('bw:start');
|
||||||
|
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||||
|
var sendBatch = function() {
|
||||||
|
while (sent < totalBytes) {
|
||||||
|
if (outboundDC.bufferedAmount > 512 * 1024) {
|
||||||
|
setTimeout(sendBatch, 5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendRaw(new ArrayBuffer(chunkSize));
|
||||||
|
sent += chunkSize;
|
||||||
|
}
|
||||||
|
sendRaw('bw:done');
|
||||||
|
var elapsed = (performance.now() - start) / 1000;
|
||||||
|
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
|
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
|
};
|
||||||
|
sendBatch();
|
||||||
|
};
|
||||||
|
|
||||||
|
log('Hook installed');
|
||||||
|
})();
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||||
const log = (...args) => console.log('[VK-HOOK]', ...args);
|
const log = (...args) => console.log('[HOOK]', ...args);
|
||||||
const peers = [];
|
const peers = [];
|
||||||
let activeWS = null;
|
let activeWS = null;
|
||||||
let activeDC = null;
|
let activeDC = null;
|
||||||
@@ -70,8 +70,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
||||||
const elapsed = (performance.now() - bwRecvStart) / 1000;
|
var elapsed = (performance.now() - bwRecvStart) / 1000;
|
||||||
const kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
var kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
bwRecvBytes = 0;
|
bwRecvBytes = 0;
|
||||||
bwRecvStart = 0;
|
bwRecvStart = 0;
|
||||||
@@ -91,11 +91,12 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function connectWS() {
|
function connectWS() {
|
||||||
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
||||||
activeWS.close();
|
activeWS.close();
|
||||||
}
|
}
|
||||||
const ws = new WebSocket(WS_URL);
|
var ws = new WebSocket(WS_URL);
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
activeWS = ws;
|
activeWS = ws;
|
||||||
|
|
||||||
@@ -131,17 +132,18 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__vkHook = { peers, log };
|
window.__hook = { peers: peers, log: log };
|
||||||
window.__vkHook.runBandwidthTest = (totalMB = 1) => {
|
window.__hook.runBandwidthTest = function(totalMB) {
|
||||||
|
totalMB = totalMB || 1;
|
||||||
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
||||||
const chunkSize = 16384;
|
var chunkSize = 16384;
|
||||||
const chunk = new ArrayBuffer(chunkSize);
|
var chunk = new ArrayBuffer(chunkSize);
|
||||||
const totalBytes = totalMB * 1024 * 1024;
|
var totalBytes = totalMB * 1024 * 1024;
|
||||||
let sent = 0;
|
var sent = 0;
|
||||||
const start = performance.now();
|
var start = performance.now();
|
||||||
activeDC.send('bw:start');
|
activeDC.send('bw:start');
|
||||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||||
const sendBatch = () => {
|
var sendBatch = function() {
|
||||||
while (sent < totalBytes) {
|
while (sent < totalBytes) {
|
||||||
if (activeDC.bufferedAmount > 512 * 1024) {
|
if (activeDC.bufferedAmount > 512 * 1024) {
|
||||||
setTimeout(sendBatch, 5);
|
setTimeout(sendBatch, 5);
|
||||||
@@ -151,12 +153,12 @@
|
|||||||
sent += chunkSize;
|
sent += chunkSize;
|
||||||
}
|
}
|
||||||
activeDC.send('bw:done');
|
activeDC.send('bw:done');
|
||||||
const elapsed = (performance.now() - start) / 1000;
|
var elapsed = (performance.now() - start) / 1000;
|
||||||
const kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
};
|
};
|
||||||
sendBatch();
|
sendBatch();
|
||||||
};
|
};
|
||||||
|
|
||||||
log('Hook installed. Now open the VK call link.');
|
log('Hook installed');
|
||||||
})();
|
})();
|
||||||
|
After Width: | Height: | Size: 236 KiB |
@@ -2,13 +2,17 @@ package bypass.whitelist
|
|||||||
|
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.ClipData
|
||||||
|
import android.content.ClipboardManager
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.VpnService
|
import android.net.VpnService
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.webkit.*
|
import android.webkit.*
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
|
import android.widget.ImageButton
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.activity.enableEdgeToEdge
|
import androidx.activity.enableEdgeToEdge
|
||||||
import androidx.activity.result.contract.ActivityResultContracts
|
import androidx.activity.result.contract.ActivityResultContracts
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@@ -19,10 +23,6 @@ import mobile.LogCallback
|
|||||||
|
|
||||||
class MainActivity : AppCompatActivity() {
|
class MainActivity : AppCompatActivity() {
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val VK_CALL_LINK = "" // Open call page on app start
|
|
||||||
}
|
|
||||||
|
|
||||||
private lateinit var webView: WebView
|
private lateinit var webView: WebView
|
||||||
private lateinit var logView: TextView
|
private lateinit var logView: TextView
|
||||||
private lateinit var urlInput: EditText
|
private lateinit var urlInput: EditText
|
||||||
@@ -37,8 +37,16 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val hookJs by lazy {
|
private val hookVk by lazy {
|
||||||
assets.open("hook.js").bufferedReader().readText()
|
assets.open("joiner-vk.js").bufferedReader().readText()
|
||||||
|
}
|
||||||
|
|
||||||
|
private val hookTelemost by lazy {
|
||||||
|
assets.open("joiner-telemost.js").bufferedReader().readText()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun hookForUrl(url: String): String {
|
||||||
|
return if (url.contains("telemost.yandex")) hookTelemost else hookVk
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SetJavaScriptEnabled")
|
@SuppressLint("SetJavaScriptEnabled")
|
||||||
@@ -68,8 +76,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VK_CALL_LINK.isNotEmpty()) {
|
findViewById<ImageButton>(R.id.copyLogsButton).setOnClickListener {
|
||||||
urlInput.setText(VK_CALL_LINK)
|
val clip = ClipData.newPlainText("logs", logView.text)
|
||||||
|
(getSystemService(CLIPBOARD_SERVICE) as ClipboardManager).setPrimaryClip(clip)
|
||||||
|
Toast.makeText(this, "Logs copied", Toast.LENGTH_SHORT).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
if (CALL_LINK.isNotEmpty()) {
|
||||||
|
urlInput.setText(CALL_LINK)
|
||||||
goButton.performClick()
|
goButton.performClick()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -120,8 +134,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
|
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
|
||||||
val text = msg.message()
|
val text = msg.message()
|
||||||
Log.d("VK-HOOK", text)
|
Log.d("HOOK", text)
|
||||||
if (text.contains("[VK-HOOK]")) {
|
if (text.contains("[HOOK]")) {
|
||||||
appendLog(text)
|
appendLog(text)
|
||||||
if (text.contains("CALL CONNECTED")) updateVpnStatus(VpnStatus.CALL_CONNECTED)
|
if (text.contains("CALL CONNECTED")) updateVpnStatus(VpnStatus.CALL_CONNECTED)
|
||||||
else if (text.contains("DataChannel open")) updateVpnStatus(VpnStatus.DATACHANNEL_OPEN)
|
else if (text.contains("DataChannel open")) updateVpnStatus(VpnStatus.DATACHANNEL_OPEN)
|
||||||
@@ -137,6 +151,33 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
webView.webViewClient = object : WebViewClient() {
|
webView.webViewClient = object : WebViewClient() {
|
||||||
|
override fun shouldInterceptRequest(view: WebView, request: WebResourceRequest): WebResourceResponse? {
|
||||||
|
val url = request.url.toString()
|
||||||
|
if (!url.contains("telemost.yandex.ru/j/")) return null
|
||||||
|
if (request.method != "GET") return null
|
||||||
|
try {
|
||||||
|
val conn = java.net.URL(url).openConnection() as java.net.HttpURLConnection
|
||||||
|
conn.requestMethod = "GET"
|
||||||
|
request.requestHeaders?.forEach { (k, v) -> conn.setRequestProperty(k, v) }
|
||||||
|
val headers = mutableMapOf<String, String>()
|
||||||
|
conn.headerFields?.forEach { (k, v) ->
|
||||||
|
if (k != null && !k.equals("content-security-policy", ignoreCase = true)
|
||||||
|
&& !k.equals("content-security-policy-report-only", ignoreCase = true)) {
|
||||||
|
headers[k] = v.joinToString(", ")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return WebResourceResponse(
|
||||||
|
conn.contentType?.split(";")?.firstOrNull() ?: "text/html",
|
||||||
|
"utf-8",
|
||||||
|
conn.responseCode,
|
||||||
|
conn.responseMessage ?: "OK",
|
||||||
|
headers,
|
||||||
|
conn.inputStream
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
override fun onPageStarted(view: WebView, url: String, favicon: android.graphics.Bitmap?) {
|
override fun onPageStarted(view: WebView, url: String, favicon: android.graphics.Bitmap?) {
|
||||||
view.evaluateJavascript("""(function(){
|
view.evaluateJavascript("""(function(){
|
||||||
var oac=window.AudioContext||window.webkitAudioContext;
|
var oac=window.AudioContext||window.webkitAudioContext;
|
||||||
@@ -148,15 +189,16 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
|||||||
})()""", null)
|
})()""", null)
|
||||||
}
|
}
|
||||||
override fun onPageFinished(view: WebView, url: String) {
|
override fun onPageFinished(view: WebView, url: String) {
|
||||||
appendLog("Page loaded, injecting hook...")
|
val hook = hookForUrl(url)
|
||||||
view.evaluateJavascript(hookJs, null)
|
appendLog("Page loaded, injecting hook for $url")
|
||||||
|
view.evaluateJavascript(hook, null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun appendLog(msg: String) {
|
private fun appendLog(msg: String) {
|
||||||
runOnUiThread {
|
runOnUiThread {
|
||||||
val clean = msg.replace("[VK-HOOK] ", "")
|
val clean = msg.replace("[HOOK] ", "")
|
||||||
logView.append("$clean\n")
|
logView.append("$clean\n")
|
||||||
val scrollAmount = logView.layout?.let {
|
val scrollAmount = logView.layout?.let {
|
||||||
it.getLineTop(logView.lineCount) - logView.height
|
it.getLineTop(logView.lineCount) - logView.height
|
||||||
@@ -182,6 +224,7 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Suppress("unused")
|
||||||
inner class JsBridge {
|
inner class JsBridge {
|
||||||
@JavascriptInterface
|
@JavascriptInterface
|
||||||
fun log(msg: String) {
|
fun log(msg: String) {
|
||||||
@@ -195,4 +238,8 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
|||||||
runOnUiThread { requestVpn() }
|
runOnUiThread { requestVpn() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private const val CALL_LINK = "" // Open call page on app start
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -20,8 +20,7 @@ enum class VpnStatus(val label: String) {
|
|||||||
TUNNEL_ACTIVE("Tunnel active"),
|
TUNNEL_ACTIVE("Tunnel active"),
|
||||||
TUNNEL_LOST("Tunnel lost, reconnecting..."),
|
TUNNEL_LOST("Tunnel lost, reconnecting..."),
|
||||||
CALL_DISCONNECTED("Call disconnected"),
|
CALL_DISCONNECTED("Call disconnected"),
|
||||||
CALL_FAILED("Call failed"),
|
CALL_FAILED("Call failed")
|
||||||
STOPPED("Stopped")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class TunnelVpnService : VpnService() {
|
class TunnelVpnService : VpnService() {
|
||||||
@@ -79,7 +78,8 @@ class TunnelVpnService : VpnService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isRunning = true
|
isRunning = true
|
||||||
val fd = vpnFd!!.fd
|
val fd = vpnFd!!.detachFd()
|
||||||
|
vpnFd = null
|
||||||
Log.i(TAG, "VPN established, fd=$fd")
|
Log.i(TAG, "VPN established, fd=$fd")
|
||||||
updateStatus(VpnStatus.TUNNEL_ACTIVE)
|
updateStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||||
|
|
||||||
@@ -100,7 +100,6 @@ class TunnelVpnService : VpnService() {
|
|||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e(TAG, "tun2socks stop error: ${e.message}")
|
Log.e(TAG, "tun2socks stop error: ${e.message}")
|
||||||
}
|
}
|
||||||
vpnFd?.close()
|
|
||||||
vpnFd = null
|
vpnFd = null
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
stopForeground(true)
|
stopForeground(true)
|
||||||
@@ -108,6 +107,12 @@ class TunnelVpnService : VpnService() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun buildNotification(text: String): Notification {
|
private fun buildNotification(text: String): Notification {
|
||||||
|
val openIntent = Intent(this, bypass.whitelist.MainActivity::class.java).apply {
|
||||||
|
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP or Intent.FLAG_ACTIVITY_CLEAR_TOP
|
||||||
|
}
|
||||||
|
val openPending = PendingIntent.getActivity(
|
||||||
|
this, 1, openIntent, PendingIntent.FLAG_IMMUTABLE
|
||||||
|
)
|
||||||
val stopIntent = Intent(this, TunnelVpnService::class.java).apply {
|
val stopIntent = Intent(this, TunnelVpnService::class.java).apply {
|
||||||
action = ACTION_STOP
|
action = ACTION_STOP
|
||||||
}
|
}
|
||||||
@@ -125,7 +130,7 @@ class TunnelVpnService : VpnService() {
|
|||||||
.setContentText(text)
|
.setContentText(text)
|
||||||
.setSmallIcon(android.R.drawable.ic_lock_lock)
|
.setSmallIcon(android.R.drawable.ic_lock_lock)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContentIntent(stopPending)
|
.setContentIntent(openPending)
|
||||||
.addAction(Notification.Action.Builder(null, "Disconnect", stopPending).build())
|
.addAction(Notification.Action.Builder(null, "Disconnect", stopPending).build())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
@@ -138,13 +143,13 @@ class TunnelVpnService : VpnService() {
|
|||||||
private fun startForegroundNotification() {
|
private fun startForegroundNotification() {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||||
val channel = NotificationChannel(
|
val channel = NotificationChannel(
|
||||||
CHANNEL_ID, "VPN Tunnel", NotificationManager.IMPORTANCE_LOW
|
CHANNEL_ID, "VPN Tunnel", NotificationManager.IMPORTANCE_DEFAULT
|
||||||
)
|
)
|
||||||
val nm = getSystemService(NotificationManager::class.java)
|
val nm = getSystemService(NotificationManager::class.java)
|
||||||
nm.createNotificationChannel(channel)
|
nm.createNotificationChannel(channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
startForeground(NOTIFICATION_ID, buildNotification("Starting..."))
|
startForeground(NOTIFICATION_ID, buildNotification(VpnStatus.STARTING.label))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
After Width: | Height: | Size: 322 B |
@@ -0,0 +1,74 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector
|
||||||
|
android:height="108dp"
|
||||||
|
android:width="108dp"
|
||||||
|
android:viewportHeight="108"
|
||||||
|
android:viewportWidth="108"
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="#3DDC84"
|
||||||
|
android:pathData="M0,0h108v108h-108z"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M9,0L9,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,0L19,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M29,0L29,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M39,0L39,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M49,0L49,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M59,0L59,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M69,0L69,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M79,0L79,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M89,0L89,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M99,0L99,108"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,9L108,9"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,19L108,19"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,29L108,29"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,39L108,39"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,49L108,49"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,59L108,59"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,69L108,69"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,79L108,79"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,89L108,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M0,99L108,99"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,29L89,29"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,39L89,39"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,49L89,49"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,59L89,59"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,69L89,69"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M19,79L89,79"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M29,19L29,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M39,19L39,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M49,19L49,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M59,19L59,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M69,19L69,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
<path android:fillColor="#00000000" android:pathData="M79,19L79,89"
|
||||||
|
android:strokeColor="#33FFFFFF" android:strokeWidth="0.8"/>
|
||||||
|
</vector>
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:id="@+id/main"
|
android:id="@+id/main"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
@@ -28,10 +29,14 @@
|
|||||||
android:text="GO" />
|
android:text="GO" />
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="100dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/logView"
|
android:id="@+id/logView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="100dp"
|
android:layout_height="match_parent"
|
||||||
android:background="#111111"
|
android:background="#111111"
|
||||||
android:fontFamily="monospace"
|
android:fontFamily="monospace"
|
||||||
android:padding="4dp"
|
android:padding="4dp"
|
||||||
@@ -39,6 +44,20 @@
|
|||||||
android:textColor="#00FF00"
|
android:textColor="#00FF00"
|
||||||
android:textSize="10sp" />
|
android:textSize="10sp" />
|
||||||
|
|
||||||
|
<ImageButton
|
||||||
|
android:id="@+id/copyLogsButton"
|
||||||
|
android:layout_width="32dp"
|
||||||
|
android:layout_height="32dp"
|
||||||
|
android:scaleType="fitXY"
|
||||||
|
android:layout_gravity="top|end"
|
||||||
|
android:layout_margin="4dp"
|
||||||
|
android:background="?attr/selectableItemBackgroundBorderless"
|
||||||
|
android:contentDescription="Copy logs"
|
||||||
|
android:src="@drawable/ic_copy"
|
||||||
|
app:tint="#888888"
|
||||||
|
android:padding="4dp" />
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
<WebView
|
<WebView
|
||||||
android:id="@+id/webView"
|
android:id="@+id/webView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<background android:drawable="@drawable/ic_launcher_background"/>
|
<background android:drawable="@drawable/ic_launcher_background"/>
|
||||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
|
||||||
</adaptive-icon>
|
</adaptive-icon>
|
||||||
|
After Width: | Height: | Size: 3.5 KiB |
|
After Width: | Height: | Size: 8.5 KiB |
|
After Width: | Height: | Size: 5.9 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 4.5 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
|
After Width: | Height: | Size: 5.4 KiB |
|
After Width: | Height: | Size: 13 KiB |
|
After Width: | Height: | Size: 9.1 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 26 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 25 KiB |
@@ -1,170 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:width="108dp"
|
|
||||||
android:height="108dp"
|
|
||||||
android:viewportWidth="108"
|
|
||||||
android:viewportHeight="108">
|
|
||||||
<path
|
|
||||||
android:fillColor="#3DDC84"
|
|
||||||
android:pathData="M0,0h108v108h-108z" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M9,0L9,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,0L19,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M29,0L29,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M39,0L39,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M49,0L49,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M59,0L59,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M69,0L69,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M79,0L79,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M89,0L89,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M99,0L99,108"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,9L108,9"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,19L108,19"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,29L108,29"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,39L108,39"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,49L108,49"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,59L108,59"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,69L108,69"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,79L108,79"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,89L108,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M0,99L108,99"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,29L89,29"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,39L89,39"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,49L89,49"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,59L89,59"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,69L89,69"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M19,79L89,79"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M29,19L29,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M39,19L39,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M49,19L49,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M59,19L59,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M69,19L69,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
<path
|
|
||||||
android:fillColor="#00000000"
|
|
||||||
android:pathData="M79,19L79,89"
|
|
||||||
android:strokeWidth="0.8"
|
|
||||||
android:strokeColor="#33FFFFFF" />
|
|
||||||
</vector>
|
|
||||||
|
Before Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 982 B |
|
Before Width: | Height: | Size: 1.7 KiB |
|
Before Width: | Height: | Size: 1.9 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.8 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 7.6 KiB |
@@ -2,7 +2,7 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
||||||
cd "$ROOT/app"
|
cd "$ROOT/android-app"
|
||||||
|
|
||||||
[ -f "./gradlew" ] || { echo "gradlew not found"; exit 1; }
|
[ -f "./gradlew" ] || { echo "gradlew not found"; exit 1; }
|
||||||
|
|
||||||
@@ -11,8 +11,9 @@ echo "Building APK..."
|
|||||||
|
|
||||||
APK="app/build/outputs/apk/debug/app-debug.apk"
|
APK="app/build/outputs/apk/debug/app-debug.apk"
|
||||||
if [ -f "$APK" ]; then
|
if [ -f "$APK" ]; then
|
||||||
cp "$APK" "$ROOT/whitelist-bypass.apk"
|
mkdir -p "$ROOT/prebuilts"
|
||||||
echo "APK ready: whitelist-bypass.apk ($(du -h "$ROOT/whitelist-bypass.apk" | cut -f1))"
|
cp "$APK" "$ROOT/prebuilts/whitelist-bypass.apk"
|
||||||
|
echo "APK ready: prebuilts/whitelist-bypass.apk ($(du -h "$ROOT/prebuilts/whitelist-bypass.apk" | cut -f1))"
|
||||||
else
|
else
|
||||||
echo "Build failed, APK not found"
|
echo "Build failed, APK not found"
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
set -e
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "$0")" && pwd)"
|
||||||
|
RELAY_DIR="$ROOT/relay"
|
||||||
|
CREATOR_DIR="$ROOT/creator-app"
|
||||||
|
|
||||||
|
echo "=== Building relay binaries ==="
|
||||||
|
cd "$RELAY_DIR"
|
||||||
|
|
||||||
|
echo "macOS (universal)..."
|
||||||
|
GOOS=darwin GOARCH=amd64 go build -o relay-darwin-amd64 .
|
||||||
|
GOOS=darwin GOARCH=arm64 go build -o relay-darwin-arm64 .
|
||||||
|
lipo -create -output relay-darwin relay-darwin-amd64 relay-darwin-arm64
|
||||||
|
rm relay-darwin-amd64 relay-darwin-arm64
|
||||||
|
|
||||||
|
echo "Windows x64..."
|
||||||
|
GOOS=windows GOARCH=amd64 go build -o relay-windows-x64.exe .
|
||||||
|
echo "Windows x86..."
|
||||||
|
GOOS=windows GOARCH=386 go build -o relay-windows-ia32.exe .
|
||||||
|
|
||||||
|
echo "Linux x64..."
|
||||||
|
GOOS=linux GOARCH=amd64 go build -o relay-linux-x64 .
|
||||||
|
echo "Linux x86..."
|
||||||
|
GOOS=linux GOARCH=386 go build -o relay-linux-ia32 .
|
||||||
|
|
||||||
|
ls -lh relay-darwin relay-windows-*.exe relay-linux-*
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Building Electron apps ==="
|
||||||
|
cd "$CREATOR_DIR"
|
||||||
|
npm install --quiet 2>&1
|
||||||
|
|
||||||
|
# macOS (universal binary already)
|
||||||
|
echo ""
|
||||||
|
echo "--- macOS ---"
|
||||||
|
npx electron-builder --mac
|
||||||
|
|
||||||
|
# Windows x64
|
||||||
|
echo ""
|
||||||
|
echo "--- Windows x64 ---"
|
||||||
|
cp "$RELAY_DIR/relay-windows-x64.exe" "$RELAY_DIR/relay-bundle.exe"
|
||||||
|
npx electron-builder --win --x64
|
||||||
|
|
||||||
|
# Windows x86
|
||||||
|
echo ""
|
||||||
|
echo "--- Windows x86 ---"
|
||||||
|
cp "$RELAY_DIR/relay-windows-ia32.exe" "$RELAY_DIR/relay-bundle.exe"
|
||||||
|
npx electron-builder --win --ia32
|
||||||
|
|
||||||
|
# Linux x64
|
||||||
|
echo ""
|
||||||
|
echo "--- Linux x64 ---"
|
||||||
|
cp "$RELAY_DIR/relay-linux-x64" "$RELAY_DIR/relay-bundle"
|
||||||
|
npx electron-builder --linux --x64
|
||||||
|
|
||||||
|
# Cleanup
|
||||||
|
rm -f "$RELAY_DIR/relay-bundle" "$RELAY_DIR/relay-bundle.exe"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "=== Done ==="
|
||||||
|
ls -lh "$ROOT/prebuilts/"
|
||||||
@@ -17,12 +17,13 @@ cd "$(dirname "$0")/relay"
|
|||||||
echo "Building gomobile .aar..."
|
echo "Building gomobile .aar..."
|
||||||
gomobile bind -v -target=android -androidapi 23 -o mobile.aar ./mobile/ 2>&1
|
gomobile bind -v -target=android -androidapi 23 -o mobile.aar ./mobile/ 2>&1
|
||||||
|
|
||||||
echo "Copying .aar to app/libs..."
|
echo "Copying .aar to android-app/libs..."
|
||||||
mkdir -p ../app/app/libs
|
mkdir -p ../android-app/app/libs
|
||||||
cp mobile.aar ../app/app/libs/mobile.aar
|
cp mobile.aar ../android-app/app/libs/mobile.aar
|
||||||
|
|
||||||
echo "Copying hook.js to assets..."
|
echo "Copying hooks to assets..."
|
||||||
mkdir -p ../app/app/src/main/assets
|
mkdir -p ../android-app/app/src/main/assets
|
||||||
cp ../hook.js ../app/app/src/main/assets/hook.js
|
cp ../hooks/joiner-vk.js ../android-app/app/src/main/assets/joiner-vk.js
|
||||||
|
cp ../hooks/joiner-telemost.js ../android-app/app/src/main/assets/joiner-telemost.js
|
||||||
|
|
||||||
echo "Done. .aar size: $(du -h mobile.aar | cut -f1)"
|
echo "Done. .aar size: $(du -h mobile.aar | cut -f1)"
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
node_modules/
|
||||||
|
dist/
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
const { webFrame } = require('electron');
|
||||||
|
const fs = require('fs');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const url = window.location.href;
|
||||||
|
const hookFile = url.includes('telemost.yandex') ? 'creator-telemost.js' : 'creator-vk.js';
|
||||||
|
const hookCode = fs.readFileSync(path.join(__dirname, '..', 'hooks', hookFile), 'utf8');
|
||||||
|
|
||||||
|
const logCapture = `
|
||||||
|
window.__hookLogs = window.__hookLogs || [];
|
||||||
|
var _origLog = console.log;
|
||||||
|
console.log = function() {
|
||||||
|
_origLog.apply(console, arguments);
|
||||||
|
var m = Array.prototype.slice.call(arguments).join(' ');
|
||||||
|
if (m.indexOf('[HOOK]') !== -1) window.__hookLogs.push(m);
|
||||||
|
};
|
||||||
|
`;
|
||||||
|
|
||||||
|
webFrame.executeJavaScript(logCapture + hookCode);
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<style>
|
||||||
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||||
|
body { font-family: -apple-system, sans-serif; background: #1a1a1a; color: #e0e0e0; height: 100vh; display: flex; flex-direction: column; }
|
||||||
|
.toolbar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: #222; border-bottom: 1px solid #333; height: 40px; flex-shrink: 0; }
|
||||||
|
.toolbar button { padding: 4px 14px; border: none; border-radius: 6px; font-size: 13px; cursor: pointer; font-weight: 500; }
|
||||||
|
.btn-home { background: #444; color: #e0e0e0; }
|
||||||
|
.btn-vk { background: #0077ff; color: white; }
|
||||||
|
.btn-telemost { background: #fc3f1d; color: white; }
|
||||||
|
.btn-inject { background: #f59e0b; color: black; }
|
||||||
|
.link-text { font-family: monospace; font-size: 12px; color: #aaa; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||||
|
.content { flex: 1; position: relative; }
|
||||||
|
.content webview { width: 100%; height: 100%; border: none; }
|
||||||
|
.welcome { display: flex; align-items: center; justify-content: center; height: 100%; flex-direction: column; gap: 16px; }
|
||||||
|
.welcome h1 { font-size: 22px; font-weight: 500; }
|
||||||
|
.welcome p { color: #888; font-size: 14px; }
|
||||||
|
.logs { display: flex; gap: 0; border-top: 1px solid #333; height: 140px; flex-shrink: 0; }
|
||||||
|
.log-panel { flex: 1; display: flex; flex-direction: column; }
|
||||||
|
.log-panel:first-child { border-right: 1px solid #333; }
|
||||||
|
.log-title { font-size: 11px; font-weight: 600; color: #888; padding: 4px 8px; background: #1e1e1e; border-bottom: 1px solid #333; }
|
||||||
|
.log-content { flex: 1; overflow-y: auto; padding: 4px 8px; font-family: monospace; font-size: 11px; background: #111; white-space: pre-wrap; word-break: break-all; }
|
||||||
|
.log-content.relay { color: #4fc3f7; }
|
||||||
|
.log-content.hook { color: #66bb6a; }
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="toolbar">
|
||||||
|
<button class="btn-home" onclick="goHome()">Home</button>
|
||||||
|
<button class="btn-vk" onclick="loadURL('https://vk.com/im')">VK Call</button>
|
||||||
|
<button class="btn-telemost" onclick="loadURL('https://telemost.yandex.ru/')">Telemost</button>
|
||||||
|
</div>
|
||||||
|
<div class="content" id="content">
|
||||||
|
<div class="welcome" id="welcome">
|
||||||
|
<h1>Whitelist Bypass - Creator</h1>
|
||||||
|
<p>Click VK Call or Telemost to start</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="logs">
|
||||||
|
<div class="log-panel">
|
||||||
|
<div class="log-title">Relay <span onclick="copyLog('relayLog')" style="cursor:pointer;float:right;margin-left:6px" title="Copy"><img src="resources/icons8-copy-50.png" style="height:16px;vertical-align:middle;filter:invert(1) brightness(2);padding:0 4px"></span><span onclick="saveLogs()" style="cursor:pointer;float:right;margin-left:6px" title="Save all"><img src="resources/icons8-download-64.png" style="height:19px;vertical-align:middle;filter:invert(1) brightness(2);padding:0 4px"></span><span onclick="document.getElementById('relayLog').textContent=''" style="cursor:pointer;float:right" title="Clear"><span style="font-size:16px;line-height:16px">✕</span></span></div>
|
||||||
|
<div class="log-content relay" id="relayLog"></div>
|
||||||
|
</div>
|
||||||
|
<div class="log-panel">
|
||||||
|
<div class="log-title">Hook <span onclick="copyLog('hookLog')" style="cursor:pointer;float:right;margin-left:6px" title="Copy"><img src="resources/icons8-copy-50.png" style="height:16px;vertical-align:middle;filter:invert(1) brightness(2);padding:0 4px"></span><span onclick="saveLogs()" style="cursor:pointer;float:right;margin-left:6px" title="Save all"><img src="resources/icons8-download-64.png" style="height:19px;vertical-align:middle;filter:invert(1) brightness(2);padding:0 4px"></span><span onclick="document.getElementById('hookLog').textContent=''" style="cursor:pointer;float:right" title="Clear"><span style="font-size:16px;line-height:16px">✕</span></span></div>
|
||||||
|
<div class="log-content hook" id="hookLog"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
var wv = null;
|
||||||
|
|
||||||
|
function copyLog(id) {
|
||||||
|
navigator.clipboard.writeText(document.getElementById(id).textContent);
|
||||||
|
}
|
||||||
|
|
||||||
|
function saveLogs() {
|
||||||
|
var relay = document.getElementById('relayLog').textContent;
|
||||||
|
var hook = document.getElementById('hookLog').textContent;
|
||||||
|
var text = '=== RELAY ===\n' + relay + '\n\n=== HOOK ===\n' + hook;
|
||||||
|
var blob = new Blob([text], { type: 'text/plain' });
|
||||||
|
var a = document.createElement('a');
|
||||||
|
a.href = URL.createObjectURL(blob);
|
||||||
|
a.download = 'tunnel-logs-' + new Date().toISOString().replace(/[:.]/g, '-') + '.txt';
|
||||||
|
a.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
function appendHookLog(msg) {
|
||||||
|
var el = document.getElementById('hookLog');
|
||||||
|
if (el.textContent.length > 0) el.textContent += '\n';
|
||||||
|
el.textContent += msg.replace('[HOOK] ', '');
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
function goHome() {
|
||||||
|
if (wv) { wv.remove(); wv = null; }
|
||||||
|
document.getElementById('welcome').style.display = 'flex';
|
||||||
|
}
|
||||||
|
|
||||||
|
function injectHook() {
|
||||||
|
if (!wv) return;
|
||||||
|
var url = wv.getURL();
|
||||||
|
window.bridge.getHookCode(url).then(function(code) {
|
||||||
|
wv.executeJavaScript(code).catch(function(e) {
|
||||||
|
appendHookLog('Inject error: ' + e.message);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function loadURL(url) {
|
||||||
|
document.getElementById('welcome').style.display = 'none';
|
||||||
|
if (wv) wv.remove();
|
||||||
|
|
||||||
|
wv = document.createElement('webview');
|
||||||
|
wv.setAttribute('src', url);
|
||||||
|
wv.setAttribute('partition', 'persist:creator');
|
||||||
|
wv.setAttribute('preload', './call-preload.js');
|
||||||
|
wv.setAttribute('nodeintegration', '');
|
||||||
|
wv.setAttribute('nodeintegrationinsubframes', '');
|
||||||
|
wv.style.width = '100%';
|
||||||
|
wv.style.height = '100%';
|
||||||
|
document.getElementById('content').appendChild(wv);
|
||||||
|
wv.addEventListener('dom-ready', function() { wv.setAudioMuted(true); });
|
||||||
|
|
||||||
|
// Inject hook on first load
|
||||||
|
wv.addEventListener('did-finish-load', function() {
|
||||||
|
injectHook();
|
||||||
|
}, { once: true });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Poll hook logs from webview
|
||||||
|
setInterval(function() {
|
||||||
|
if (!wv) return;
|
||||||
|
wv.executeJavaScript('(window.__hookLogs && window.__hookLogs.length) ? window.__hookLogs.splice(0) : []')
|
||||||
|
.then(function(logs) {
|
||||||
|
logs.forEach(function(msg) { appendHookLog(msg); });
|
||||||
|
}).catch(function() {});
|
||||||
|
}, 500);
|
||||||
|
|
||||||
|
window.bridge.onRelayLog(function(msg) {
|
||||||
|
var el = document.getElementById('relayLog');
|
||||||
|
if (el.textContent.length > 0) el.textContent += '\n';
|
||||||
|
el.textContent += msg;
|
||||||
|
el.scrollTop = el.scrollHeight;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,128 @@
|
|||||||
|
const { app, BrowserWindow, session, ipcMain } = require('electron');
|
||||||
|
const { spawn } = require('child_process');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs');
|
||||||
|
|
||||||
|
var hooksDir = app.isPackaged
|
||||||
|
? path.join(process.resourcesPath, 'hooks')
|
||||||
|
: path.join(__dirname, '..', 'hooks');
|
||||||
|
const hookVk = fs.readFileSync(path.join(hooksDir, 'creator-vk.js'), 'utf8');
|
||||||
|
const hookTelemost = fs.readFileSync(path.join(hooksDir, 'creator-telemost.js'), 'utf8');
|
||||||
|
const logCapture = "window.__hookLogs=window.__hookLogs||[];var _ol=console.log;console.log=function(){_ol.apply(console,arguments);var m=Array.prototype.slice.call(arguments).join(' ');if(m.indexOf('[HOOK]')!==-1)window.__hookLogs.push(m)};";
|
||||||
|
|
||||||
|
let mainWindow;
|
||||||
|
let relayProcess;
|
||||||
|
|
||||||
|
function startRelay() {
|
||||||
|
const net = require('net');
|
||||||
|
const sock = new net.Socket();
|
||||||
|
sock.setTimeout(1000);
|
||||||
|
sock.on('connect', () => {
|
||||||
|
sock.destroy();
|
||||||
|
console.log('[relay] already running on :9000');
|
||||||
|
if (mainWindow) mainWindow.webContents.send('relay-log', 'Using existing relay on :9000');
|
||||||
|
});
|
||||||
|
sock.on('error', () => {
|
||||||
|
sock.destroy();
|
||||||
|
spawnRelay();
|
||||||
|
});
|
||||||
|
sock.on('timeout', () => {
|
||||||
|
sock.destroy();
|
||||||
|
spawnRelay();
|
||||||
|
});
|
||||||
|
sock.connect(9000, '127.0.0.1');
|
||||||
|
}
|
||||||
|
|
||||||
|
function spawnRelay() {
|
||||||
|
var relayName = process.platform === 'win32' ? 'relay.exe' : 'relay';
|
||||||
|
var relayPath = app.isPackaged
|
||||||
|
? path.join(process.resourcesPath, relayName)
|
||||||
|
: path.join(__dirname, '..', 'relay', relayName);
|
||||||
|
relayProcess = spawn(relayPath, ['--mode', 'creator'], {
|
||||||
|
stdio: ['ignore', 'pipe', 'pipe']
|
||||||
|
});
|
||||||
|
relayProcess.stdout.on('data', (data) => {
|
||||||
|
data.toString().trim().split('\n').forEach((msg) => {
|
||||||
|
if (!msg) return;
|
||||||
|
console.log('[relay]', msg);
|
||||||
|
if (mainWindow) mainWindow.webContents.send('relay-log', msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
relayProcess.stderr.on('data', (data) => {
|
||||||
|
data.toString().trim().split('\n').forEach((msg) => {
|
||||||
|
if (!msg) return;
|
||||||
|
console.log('[relay]', msg);
|
||||||
|
if (mainWindow) mainWindow.webContents.send('relay-log', msg);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
relayProcess.on('close', (code) => {
|
||||||
|
if (mainWindow) mainWindow.webContents.send('relay-log', 'Relay exited with code ' + code);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function stripCSP(ses) {
|
||||||
|
ses.webRequest.onHeadersReceived((details, callback) => {
|
||||||
|
var headers = { ...details.responseHeaders };
|
||||||
|
delete headers['content-security-policy'];
|
||||||
|
delete headers['Content-Security-Policy'];
|
||||||
|
delete headers['content-security-policy-report-only'];
|
||||||
|
delete headers['Content-Security-Policy-Report-Only'];
|
||||||
|
callback({ responseHeaders: headers });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function createWindow() {
|
||||||
|
const ses = session.fromPartition('persist:creator');
|
||||||
|
stripCSP(ses);
|
||||||
|
ses.setPermissionRequestHandler((webContents, permission, callback) => {
|
||||||
|
callback(true);
|
||||||
|
});
|
||||||
|
ses.setPermissionCheckHandler(() => true);
|
||||||
|
|
||||||
|
mainWindow = new BrowserWindow({
|
||||||
|
width: 1200,
|
||||||
|
height: 800,
|
||||||
|
icon: path.join(__dirname, 'resources', 'icon.png'),
|
||||||
|
webPreferences: {
|
||||||
|
preload: path.join(__dirname, 'preload.js'),
|
||||||
|
nodeIntegration: false,
|
||||||
|
contextIsolation: true,
|
||||||
|
webviewTag: true
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
ses.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
|
||||||
|
|
||||||
|
app.on('session-created', stripCSP);
|
||||||
|
|
||||||
|
mainWindow.loadFile('index.html');
|
||||||
|
mainWindow.on('closed', () => { mainWindow = null; });
|
||||||
|
}
|
||||||
|
|
||||||
|
function killRelay() {
|
||||||
|
if (relayProcess) {
|
||||||
|
relayProcess.kill();
|
||||||
|
relayProcess = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
ipcMain.handle('get-hook-code', (e, url) => {
|
||||||
|
var hook = url.includes('telemost.yandex') ? hookTelemost : hookVk;
|
||||||
|
return logCapture + hook;
|
||||||
|
});
|
||||||
|
|
||||||
|
app.whenReady().then(() => {
|
||||||
|
startRelay();
|
||||||
|
createWindow();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('window-all-closed', () => {
|
||||||
|
killRelay();
|
||||||
|
app.quit();
|
||||||
|
});
|
||||||
|
|
||||||
|
app.on('before-quit', killRelay);
|
||||||
|
process.on('exit', killRelay);
|
||||||
|
process.on('SIGINT', () => { killRelay(); process.exit(); });
|
||||||
|
process.on('SIGTERM', () => { killRelay(); process.exit(); });
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
{
|
||||||
|
"name": "whitelist-bypass-creator",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"main": "main.js",
|
||||||
|
"scripts": {
|
||||||
|
"start": "electron .",
|
||||||
|
"build": "electron-builder"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"electron": "^33.0.0",
|
||||||
|
"electron-builder": "^25.0.0"
|
||||||
|
},
|
||||||
|
"build": {
|
||||||
|
"appId": "whitelist.bypass.creator",
|
||||||
|
"productName": "WhitelistBypass Creator",
|
||||||
|
"directories": {
|
||||||
|
"output": "../prebuilts"
|
||||||
|
},
|
||||||
|
"extraResources": [
|
||||||
|
{ "from": "../hooks/creator-vk.js", "to": "hooks/creator-vk.js" },
|
||||||
|
{ "from": "../hooks/creator-telemost.js", "to": "hooks/creator-telemost.js" }
|
||||||
|
],
|
||||||
|
"mac": {
|
||||||
|
"target": "dmg",
|
||||||
|
"icon": "resources/icon.icns",
|
||||||
|
"extraResources": [
|
||||||
|
{ "from": "../relay/relay-darwin", "to": "relay" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"win": {
|
||||||
|
"target": "portable",
|
||||||
|
"artifactName": "${productName}-${version}-${arch}.${ext}",
|
||||||
|
"icon": "resources/icon.ico",
|
||||||
|
"extraResources": [
|
||||||
|
{ "from": "../relay/relay-bundle.exe", "to": "relay.exe" }
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"linux": {
|
||||||
|
"target": "AppImage",
|
||||||
|
"icon": "resources/icon.png",
|
||||||
|
"extraResources": [
|
||||||
|
{ "from": "../relay/relay-bundle", "to": "relay" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
const { contextBridge, ipcRenderer } = require('electron');
|
||||||
|
|
||||||
|
contextBridge.exposeInMainWorld('bridge', {
|
||||||
|
onRelayLog: (cb) => ipcRenderer.on('relay-log', (e, msg) => cb(msg)),
|
||||||
|
getHookCode: (url) => ipcRenderer.invoke('get-hook-code', url)
|
||||||
|
});
|
||||||
|
After Width: | Height: | Size: 90 KiB |
|
After Width: | Height: | Size: 236 KiB |
|
After Width: | Height: | Size: 322 B |
|
After Width: | Height: | Size: 374 B |
@@ -0,0 +1,263 @@
|
|||||||
|
(() => {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||||
|
const log = (...args) => console.log('[HOOK]', ...args);
|
||||||
|
const peers = [];
|
||||||
|
let activeWS = null;
|
||||||
|
let outboundDC = null;
|
||||||
|
let dcCreating = false;
|
||||||
|
let tunnelReady = false;
|
||||||
|
let wsOpen = false;
|
||||||
|
|
||||||
|
var signalingWS = null;
|
||||||
|
var lastPcSeq = 0;
|
||||||
|
var OrigWebSocket = window.WebSocket;
|
||||||
|
window.WebSocket = function(url, protocols) {
|
||||||
|
var ws = protocols ? new OrigWebSocket(url, protocols) : new OrigWebSocket(url);
|
||||||
|
if (url && (url.indexOf('strm.yandex') !== -1 || url.indexOf('jvb.telemost') !== -1)) {
|
||||||
|
log('Signaling WS found: ' + url);
|
||||||
|
signalingWS = ws;
|
||||||
|
var origSend = ws.send.bind(ws);
|
||||||
|
ws.send = function(data) {
|
||||||
|
try {
|
||||||
|
var msg = JSON.parse(data);
|
||||||
|
if (msg.type === 'publisherSdpOffer' && msg.payload && msg.payload.pcSeq) {
|
||||||
|
lastPcSeq = msg.payload.pcSeq;
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
return origSend(data);
|
||||||
|
};
|
||||||
|
ws.addEventListener('message', function(e) {
|
||||||
|
try {
|
||||||
|
var msg = JSON.parse(e.data);
|
||||||
|
if (msg.type === 'publisherSdpAnswer' && msg.payload && msg.payload.sdp) {
|
||||||
|
var pc0 = peers[0];
|
||||||
|
if (pc0 && pc0.signalingState === 'have-local-offer') {
|
||||||
|
pc0.setRemoteDescription({ type: 'answer', sdp: msg.payload.sdp }).catch(function(e) {
|
||||||
|
log('setRemoteDescription error: ' + e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ws;
|
||||||
|
};
|
||||||
|
window.WebSocket.prototype = OrigWebSocket.prototype;
|
||||||
|
window.WebSocket.CONNECTING = OrigWebSocket.CONNECTING;
|
||||||
|
window.WebSocket.OPEN = OrigWebSocket.OPEN;
|
||||||
|
window.WebSocket.CLOSING = OrigWebSocket.CLOSING;
|
||||||
|
window.WebSocket.CLOSED = OrigWebSocket.CLOSED;
|
||||||
|
|
||||||
|
const OrigPC = window.RTCPeerConnection;
|
||||||
|
window.RTCPeerConnection = function (config) {
|
||||||
|
log('New PeerConnection created');
|
||||||
|
const pc = new OrigPC(config);
|
||||||
|
peers.push(pc);
|
||||||
|
var pcIdx = peers.length - 1;
|
||||||
|
|
||||||
|
pc.addEventListener('connectionstatechange', () => {
|
||||||
|
log('Connection state:', pc.connectionState);
|
||||||
|
if (pc.connectionState === 'connected') {
|
||||||
|
log('=== CALL CONNECTED on PC' + pcIdx + ' ===');
|
||||||
|
pc.getSenders().forEach(function(s) {
|
||||||
|
if (s.track) s.track.stop();
|
||||||
|
s.replaceTrack(null).catch(function(){});
|
||||||
|
});
|
||||||
|
if (!outboundDC && !dcCreating) {
|
||||||
|
createTunnelDC(pc, origCreateDC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var origCreateDC = pc.createDataChannel.bind(pc);
|
||||||
|
pc.createDataChannel = function(label, opts) {
|
||||||
|
return origCreateDC(label, opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
pc.addEventListener('datachannel', function(e) {
|
||||||
|
var ch = e.channel;
|
||||||
|
ch.binaryType = 'arraybuffer';
|
||||||
|
log('Incoming DC: label=' + ch.label + ' id=' + ch.id + ' on PC' + pcIdx);
|
||||||
|
|
||||||
|
if (ch.label === 'sharing') {
|
||||||
|
log('Inbound tunnel DC found on PC' + pcIdx);
|
||||||
|
ch.addEventListener('message', function(m) {
|
||||||
|
if (typeof m.data === 'string') {
|
||||||
|
if (m.data === 'tunnel:ping') {
|
||||||
|
sendRaw('tunnel:pong');
|
||||||
|
if (!tunnelReady) {
|
||||||
|
tunnelReady = true;
|
||||||
|
log('DataChannel confirmed');
|
||||||
|
connectWS();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m.data instanceof ArrayBuffer) {
|
||||||
|
handleChunk(m.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createTunnelDC(pc, origCreateDC) {
|
||||||
|
dcCreating = true;
|
||||||
|
setTimeout(function() {
|
||||||
|
log('Creating tunnel DC');
|
||||||
|
var dc = origCreateDC('sharing', { ordered: true });
|
||||||
|
dc.binaryType = 'arraybuffer';
|
||||||
|
outboundDC = dc;
|
||||||
|
dc.addEventListener('open', function() {
|
||||||
|
log('DataChannel open');
|
||||||
|
});
|
||||||
|
dc.addEventListener('close', function() {
|
||||||
|
log('DataChannel closed');
|
||||||
|
outboundDC = null;
|
||||||
|
dcCreating = false;
|
||||||
|
dcQueue = [];
|
||||||
|
tunnelReady = false;
|
||||||
|
});
|
||||||
|
pc.createOffer().then(function(offer) {
|
||||||
|
return pc.setLocalDescription(offer).then(function() {
|
||||||
|
if (signalingWS && signalingWS.readyState === 1) {
|
||||||
|
signalingWS.send(JSON.stringify({
|
||||||
|
type: 'publisherSdpOffer',
|
||||||
|
payload: { pcSeq: lastPcSeq, sdp: offer.sdp, tracks: [] }
|
||||||
|
}));
|
||||||
|
log('Sent renegotiation offer via signaling WS');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(function(e) {
|
||||||
|
log('Renegotiation error: ' + e.message);
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(OrigPC).forEach((key) => {
|
||||||
|
window.RTCPeerConnection[key] = OrigPC[key];
|
||||||
|
});
|
||||||
|
window.RTCPeerConnection.prototype = OrigPC.prototype;
|
||||||
|
|
||||||
|
var CHUNK = 994;
|
||||||
|
var dcQueue = [];
|
||||||
|
var dcDraining = false;
|
||||||
|
var sendMsgId = 0;
|
||||||
|
var recvBufs = {};
|
||||||
|
|
||||||
|
function sendRaw(data) {
|
||||||
|
if (!outboundDC || outboundDC.readyState !== 'open') return;
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
dcQueue.push(data);
|
||||||
|
drainDC();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var u8 = new Uint8Array(data instanceof ArrayBuffer ? data : data.buffer || data);
|
||||||
|
var total = Math.ceil(u8.length / CHUNK) || 1;
|
||||||
|
var id = (sendMsgId++) & 0xFFFF;
|
||||||
|
for (var i = 0; i < total; i++) {
|
||||||
|
var p = u8.subarray(i * CHUNK, Math.min((i + 1) * CHUNK, u8.length));
|
||||||
|
var f = new Uint8Array(6 + p.length);
|
||||||
|
f[0] = id >> 8; f[1] = id & 0xFF;
|
||||||
|
f[2] = i >> 8; f[3] = i & 0xFF;
|
||||||
|
f[4] = total >> 8; f[5] = total & 0xFF;
|
||||||
|
f.set(p, 6);
|
||||||
|
dcQueue.push(f.buffer);
|
||||||
|
}
|
||||||
|
drainDC();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChunk(data) {
|
||||||
|
var u8 = new Uint8Array(data);
|
||||||
|
if (u8.length < 6) return;
|
||||||
|
var id = (u8[0] << 8) | u8[1];
|
||||||
|
var idx = (u8[2] << 8) | u8[3];
|
||||||
|
var total = (u8[4] << 8) | u8[5];
|
||||||
|
var payload = u8.subarray(6);
|
||||||
|
if (total === 1) {
|
||||||
|
if (activeWS && wsOpen) activeWS.send(payload.buffer.slice(payload.byteOffset, payload.byteOffset + payload.byteLength));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var r = recvBufs[id];
|
||||||
|
if (!r) { r = { c: [], n: 0, s: 0 }; recvBufs[id] = r; }
|
||||||
|
if (!r.c[idx]) { r.c[idx] = payload; r.n++; r.s += payload.length; }
|
||||||
|
if (r.n === total) {
|
||||||
|
var out = new Uint8Array(r.s);
|
||||||
|
for (var i = 0, o = 0; i < total; i++) { out.set(r.c[i], o); o += r.c[i].length; }
|
||||||
|
delete recvBufs[id];
|
||||||
|
if (activeWS && wsOpen) activeWS.send(out.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drainDC() {
|
||||||
|
if (dcDraining) return;
|
||||||
|
dcDraining = true;
|
||||||
|
while (dcQueue.length > 0) {
|
||||||
|
if (outboundDC.bufferedAmount > 64 * 1024) {
|
||||||
|
outboundDC.bufferedAmountLowThreshold = 16 * 1024;
|
||||||
|
outboundDC.onbufferedamountlow = function() {
|
||||||
|
outboundDC.onbufferedamountlow = null;
|
||||||
|
dcDraining = false;
|
||||||
|
drainDC();
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
outboundDC.send(dcQueue.shift());
|
||||||
|
}
|
||||||
|
dcDraining = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectWS() {
|
||||||
|
var ws = new WebSocket(WS_URL);
|
||||||
|
ws.binaryType = 'arraybuffer';
|
||||||
|
activeWS = ws;
|
||||||
|
ws.onopen = function() {
|
||||||
|
log('WebSocket connected to Go relay');
|
||||||
|
wsOpen = true;
|
||||||
|
};
|
||||||
|
ws.onclose = function() {
|
||||||
|
wsOpen = false;
|
||||||
|
if (tunnelReady) {
|
||||||
|
log('WebSocket disconnected, reconnecting in 2s...');
|
||||||
|
setTimeout(function() { if (tunnelReady) connectWS(); }, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onerror = function() { log('WebSocket error'); };
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
sendRaw(e.data);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__hook = { peers: peers, log: log };
|
||||||
|
window.__hook.runBandwidthTest = function(totalMB) {
|
||||||
|
totalMB = totalMB || 1;
|
||||||
|
if (!tunnelReady || !outboundDC) { log('Tunnel not ready'); return; }
|
||||||
|
var chunkSize = 4096;
|
||||||
|
var totalBytes = totalMB * 1024 * 1024;
|
||||||
|
var sent = 0;
|
||||||
|
var start = performance.now();
|
||||||
|
sendRaw('bw:start');
|
||||||
|
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||||
|
var sendBatch = function() {
|
||||||
|
while (sent < totalBytes) {
|
||||||
|
if (outboundDC.bufferedAmount > 512 * 1024) {
|
||||||
|
setTimeout(sendBatch, 5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendRaw(new ArrayBuffer(chunkSize));
|
||||||
|
sent += chunkSize;
|
||||||
|
}
|
||||||
|
sendRaw('bw:done');
|
||||||
|
var elapsed = (performance.now() - start) / 1000;
|
||||||
|
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
|
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
|
};
|
||||||
|
sendBatch();
|
||||||
|
};
|
||||||
|
|
||||||
|
log('Hook installed');
|
||||||
|
})();
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
(() => {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||||
|
const log = (...args) => console.log('[HOOK]', ...args);
|
||||||
|
const peers = [];
|
||||||
|
let activeWS = null;
|
||||||
|
let activeDC = null;
|
||||||
|
let dcOpen = false;
|
||||||
|
let wsOpen = false;
|
||||||
|
|
||||||
|
const OrigPC = window.RTCPeerConnection;
|
||||||
|
window.RTCPeerConnection = function (config) {
|
||||||
|
log('New PeerConnection created');
|
||||||
|
const pc = new OrigPC(config);
|
||||||
|
peers.push(pc);
|
||||||
|
|
||||||
|
pc.addEventListener('connectionstatechange', () => {
|
||||||
|
log('Connection state:', pc.connectionState);
|
||||||
|
if (pc.connectionState === 'connected') {
|
||||||
|
log('=== CALL CONNECTED ===');
|
||||||
|
setupDC(pc);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(OrigPC).forEach((key) => {
|
||||||
|
window.RTCPeerConnection[key] = OrigPC[key];
|
||||||
|
});
|
||||||
|
window.RTCPeerConnection.prototype = OrigPC.prototype;
|
||||||
|
|
||||||
|
function setupDC(pc) {
|
||||||
|
const dc = pc.createDataChannel('tunnel', { negotiated: true, id: 2 });
|
||||||
|
dc.binaryType = 'arraybuffer';
|
||||||
|
bindDC(dc);
|
||||||
|
}
|
||||||
|
|
||||||
|
function bindDC(dc) {
|
||||||
|
if (activeDC && activeDC !== dc && activeDC.readyState === 'open') {
|
||||||
|
activeDC.close();
|
||||||
|
}
|
||||||
|
activeDC = dc;
|
||||||
|
dcOpen = false;
|
||||||
|
|
||||||
|
dc.onopen = () => {
|
||||||
|
if (dc !== activeDC) return;
|
||||||
|
log('DataChannel open');
|
||||||
|
dcOpen = true;
|
||||||
|
connectWS();
|
||||||
|
};
|
||||||
|
|
||||||
|
dc.onclose = () => {
|
||||||
|
if (dc !== activeDC) return;
|
||||||
|
log('DataChannel closed');
|
||||||
|
dcOpen = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
let bwRecvBytes = 0;
|
||||||
|
let bwRecvStart = 0;
|
||||||
|
let bwMode = false;
|
||||||
|
|
||||||
|
dc.onmessage = (e) => {
|
||||||
|
if (dc !== activeDC) return;
|
||||||
|
if (bwMode) {
|
||||||
|
if (e.data instanceof ArrayBuffer) {
|
||||||
|
if (bwRecvStart === 0) bwRecvStart = performance.now();
|
||||||
|
bwRecvBytes += e.data.byteLength;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
||||||
|
var elapsed = (performance.now() - bwRecvStart) / 1000;
|
||||||
|
var kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
|
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
|
bwRecvBytes = 0;
|
||||||
|
bwRecvStart = 0;
|
||||||
|
bwMode = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof e.data === 'string' && e.data === 'bw:start') {
|
||||||
|
bwMode = true;
|
||||||
|
bwRecvBytes = 0;
|
||||||
|
bwRecvStart = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (activeWS && wsOpen) {
|
||||||
|
activeWS.send(e.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectWS() {
|
||||||
|
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
||||||
|
activeWS.close();
|
||||||
|
}
|
||||||
|
var ws = new WebSocket(WS_URL);
|
||||||
|
ws.binaryType = 'arraybuffer';
|
||||||
|
activeWS = ws;
|
||||||
|
|
||||||
|
ws.onopen = () => {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
log('WebSocket connected to Go relay');
|
||||||
|
wsOpen = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onclose = () => {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
wsOpen = false;
|
||||||
|
if (dcOpen) {
|
||||||
|
log('WebSocket disconnected, reconnecting in 2s...');
|
||||||
|
setTimeout(() => {
|
||||||
|
if (dcOpen && ws === activeWS) connectWS();
|
||||||
|
}, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onerror = () => {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
log('WebSocket error');
|
||||||
|
};
|
||||||
|
|
||||||
|
ws.onmessage = (e) => {
|
||||||
|
if (activeDC && dcOpen) {
|
||||||
|
activeDC.send(e.data);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__hook = { peers: peers, log: log };
|
||||||
|
window.__hook.runBandwidthTest = function(totalMB) {
|
||||||
|
totalMB = totalMB || 1;
|
||||||
|
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
||||||
|
var chunkSize = 16384;
|
||||||
|
var chunk = new ArrayBuffer(chunkSize);
|
||||||
|
var totalBytes = totalMB * 1024 * 1024;
|
||||||
|
var sent = 0;
|
||||||
|
var start = performance.now();
|
||||||
|
activeDC.send('bw:start');
|
||||||
|
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||||
|
var sendBatch = function() {
|
||||||
|
while (sent < totalBytes) {
|
||||||
|
if (activeDC.bufferedAmount > 512 * 1024) {
|
||||||
|
setTimeout(sendBatch, 5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
activeDC.send(chunk);
|
||||||
|
sent += chunkSize;
|
||||||
|
}
|
||||||
|
activeDC.send('bw:done');
|
||||||
|
var elapsed = (performance.now() - start) / 1000;
|
||||||
|
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
|
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
|
};
|
||||||
|
sendBatch();
|
||||||
|
};
|
||||||
|
|
||||||
|
log('Hook installed');
|
||||||
|
})();
|
||||||
@@ -0,0 +1,306 @@
|
|||||||
|
(() => {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||||
|
const log = (...args) => console.log('[HOOK]', ...args);
|
||||||
|
const peers = [];
|
||||||
|
let activeWS = null;
|
||||||
|
let wsOpen = false;
|
||||||
|
let outboundDC = null;
|
||||||
|
let dcCreating = false;
|
||||||
|
let tunnelReady = false;
|
||||||
|
|
||||||
|
var origGUM = navigator.mediaDevices.getUserMedia.bind(navigator.mediaDevices);
|
||||||
|
navigator.mediaDevices.getUserMedia = function(c) {
|
||||||
|
log('Intercepting getUserMedia');
|
||||||
|
var canvas = document.createElement('canvas');
|
||||||
|
canvas.width = 2; canvas.height = 2;
|
||||||
|
var stream = canvas.captureStream(1);
|
||||||
|
if (c && c.audio) {
|
||||||
|
var actx = new AudioContext();
|
||||||
|
var dest = actx.createMediaStreamDestination();
|
||||||
|
var t = dest.stream.getAudioTracks()[0];
|
||||||
|
t.enabled = false;
|
||||||
|
stream.addTrack(t);
|
||||||
|
}
|
||||||
|
return Promise.resolve(stream);
|
||||||
|
};
|
||||||
|
navigator.mediaDevices.enumerateDevices = function() {
|
||||||
|
return Promise.resolve([
|
||||||
|
{deviceId:'fake-cam',kind:'videoinput',label:'Camera',groupId:'g1',toJSON:function(){return this}},
|
||||||
|
{deviceId:'fake-mic',kind:'audioinput',label:'Microphone',groupId:'g2',toJSON:function(){return this}},
|
||||||
|
{deviceId:'fake-spk',kind:'audiooutput',label:'Speaker',groupId:'g3',toJSON:function(){return this}}
|
||||||
|
]);
|
||||||
|
};
|
||||||
|
|
||||||
|
var signalingWS = null;
|
||||||
|
var lastPcSeq = 0;
|
||||||
|
var OrigWebSocket = window.WebSocket;
|
||||||
|
window.WebSocket = function(url, protocols) {
|
||||||
|
var ws = protocols ? new OrigWebSocket(url, protocols) : new OrigWebSocket(url);
|
||||||
|
if (url && (url.indexOf('strm.yandex') !== -1 || url.indexOf('jvb.telemost') !== -1)) {
|
||||||
|
log('Signaling WS found: ' + url);
|
||||||
|
signalingWS = ws;
|
||||||
|
var origSend = ws.send.bind(ws);
|
||||||
|
ws.send = function(data) {
|
||||||
|
try {
|
||||||
|
var msg = JSON.parse(data);
|
||||||
|
if (msg.type === 'publisherSdpOffer' && msg.payload && msg.payload.pcSeq) {
|
||||||
|
lastPcSeq = msg.payload.pcSeq;
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
return origSend(data);
|
||||||
|
};
|
||||||
|
ws.addEventListener('message', function(e) {
|
||||||
|
try {
|
||||||
|
var msg = JSON.parse(e.data);
|
||||||
|
if (msg.type === 'publisherSdpAnswer' && msg.payload && msg.payload.sdp) {
|
||||||
|
var pc0 = peers[0];
|
||||||
|
if (pc0 && pc0.signalingState === 'have-local-offer') {
|
||||||
|
pc0.setRemoteDescription({ type: 'answer', sdp: msg.payload.sdp }).catch(function(e) {
|
||||||
|
log('setRemoteDescription error: ' + e.message);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(e) {}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
return ws;
|
||||||
|
};
|
||||||
|
window.WebSocket.prototype = OrigWebSocket.prototype;
|
||||||
|
window.WebSocket.CONNECTING = OrigWebSocket.CONNECTING;
|
||||||
|
window.WebSocket.OPEN = OrigWebSocket.OPEN;
|
||||||
|
window.WebSocket.CLOSING = OrigWebSocket.CLOSING;
|
||||||
|
window.WebSocket.CLOSED = OrigWebSocket.CLOSED;
|
||||||
|
|
||||||
|
const OrigPC = window.RTCPeerConnection;
|
||||||
|
window.RTCPeerConnection = function (config) {
|
||||||
|
log('New PeerConnection created');
|
||||||
|
const pc = new OrigPC(config);
|
||||||
|
peers.push(pc);
|
||||||
|
var pcIdx = peers.length - 1;
|
||||||
|
|
||||||
|
pc.addEventListener('connectionstatechange', () => {
|
||||||
|
log('Connection state:', pc.connectionState);
|
||||||
|
if (pc.connectionState === 'connected') {
|
||||||
|
log('=== CALL CONNECTED on PC' + pcIdx + ' ===');
|
||||||
|
pc.getSenders().forEach(function(s) {
|
||||||
|
if (s.track) s.track.stop();
|
||||||
|
s.replaceTrack(null).catch(function(){});
|
||||||
|
});
|
||||||
|
if (!outboundDC && !dcCreating) {
|
||||||
|
createTunnelDC(pc, origCreateDC);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var origCreateDC = pc.createDataChannel.bind(pc);
|
||||||
|
pc.createDataChannel = function(label, opts) {
|
||||||
|
return origCreateDC(label, opts);
|
||||||
|
};
|
||||||
|
|
||||||
|
pc.addEventListener('datachannel', function(e) {
|
||||||
|
var ch = e.channel;
|
||||||
|
ch.binaryType = 'arraybuffer';
|
||||||
|
log('Incoming DC: label=' + ch.label + ' id=' + ch.id + ' on PC' + pcIdx);
|
||||||
|
|
||||||
|
if (ch.label === 'sharing') {
|
||||||
|
log('Inbound tunnel DC found on PC' + pcIdx);
|
||||||
|
ch.addEventListener('message', function(m) {
|
||||||
|
if (typeof m.data === 'string') {
|
||||||
|
if (m.data === 'tunnel:ping') { sendRaw('tunnel:pong'); return; }
|
||||||
|
if (m.data === 'tunnel:pong') {
|
||||||
|
if (!tunnelReady) {
|
||||||
|
tunnelReady = true;
|
||||||
|
log('DataChannel confirmed on PC' + pcIdx);
|
||||||
|
connectWS();
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (m.data instanceof ArrayBuffer) {
|
||||||
|
handleChunk(m.data);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
};
|
||||||
|
|
||||||
|
function createTunnelDC(pc, origCreateDC) {
|
||||||
|
dcCreating = true;
|
||||||
|
setTimeout(function() {
|
||||||
|
log('Creating tunnel DC');
|
||||||
|
var dc = origCreateDC('sharing', { ordered: true });
|
||||||
|
dc.binaryType = 'arraybuffer';
|
||||||
|
outboundDC = dc;
|
||||||
|
dc.addEventListener('open', function() {
|
||||||
|
log('DataChannel open');
|
||||||
|
startPinging();
|
||||||
|
});
|
||||||
|
dc.addEventListener('close', function() {
|
||||||
|
log('DataChannel closed');
|
||||||
|
outboundDC = null;
|
||||||
|
dcCreating = false;
|
||||||
|
dcQueue = [];
|
||||||
|
tunnelReady = false;
|
||||||
|
});
|
||||||
|
pc.createOffer().then(function(offer) {
|
||||||
|
return pc.setLocalDescription(offer).then(function() {
|
||||||
|
if (signalingWS && signalingWS.readyState === 1) {
|
||||||
|
signalingWS.send(JSON.stringify({
|
||||||
|
type: 'publisherSdpOffer',
|
||||||
|
payload: { pcSeq: lastPcSeq, sdp: offer.sdp, tracks: [] }
|
||||||
|
}));
|
||||||
|
log('Sent renegotiation offer via signaling WS');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}).catch(function(e) {
|
||||||
|
log('Renegotiation error: ' + e.message);
|
||||||
|
});
|
||||||
|
}, 3000);
|
||||||
|
}
|
||||||
|
|
||||||
|
Object.keys(OrigPC).forEach((key) => {
|
||||||
|
window.RTCPeerConnection[key] = OrigPC[key];
|
||||||
|
});
|
||||||
|
window.RTCPeerConnection.prototype = OrigPC.prototype;
|
||||||
|
|
||||||
|
var CHUNK = 994;
|
||||||
|
var dcQueue = [];
|
||||||
|
var dcDraining = false;
|
||||||
|
var sendMsgId = 0;
|
||||||
|
var recvBufs = {};
|
||||||
|
|
||||||
|
function sendRaw(data) {
|
||||||
|
if (!outboundDC || outboundDC.readyState !== 'open') return;
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
dcQueue.push(data);
|
||||||
|
drainDC();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var u8 = new Uint8Array(data instanceof ArrayBuffer ? data : data.buffer || data);
|
||||||
|
var total = Math.ceil(u8.length / CHUNK) || 1;
|
||||||
|
var id = (sendMsgId++) & 0xFFFF;
|
||||||
|
for (var i = 0; i < total; i++) {
|
||||||
|
var p = u8.subarray(i * CHUNK, Math.min((i + 1) * CHUNK, u8.length));
|
||||||
|
var f = new Uint8Array(6 + p.length);
|
||||||
|
f[0] = id >> 8; f[1] = id & 0xFF;
|
||||||
|
f[2] = i >> 8; f[3] = i & 0xFF;
|
||||||
|
f[4] = total >> 8; f[5] = total & 0xFF;
|
||||||
|
f.set(p, 6);
|
||||||
|
dcQueue.push(f.buffer);
|
||||||
|
}
|
||||||
|
drainDC();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleChunk(data) {
|
||||||
|
var u8 = new Uint8Array(data);
|
||||||
|
if (u8.length < 6) return;
|
||||||
|
var id = (u8[0] << 8) | u8[1];
|
||||||
|
var idx = (u8[2] << 8) | u8[3];
|
||||||
|
var total = (u8[4] << 8) | u8[5];
|
||||||
|
var payload = u8.subarray(6);
|
||||||
|
if (total === 1) {
|
||||||
|
if (activeWS && wsOpen) activeWS.send(payload.buffer.slice(payload.byteOffset, payload.byteOffset + payload.byteLength));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var r = recvBufs[id];
|
||||||
|
if (!r) { r = { c: [], n: 0, s: 0 }; recvBufs[id] = r; }
|
||||||
|
if (!r.c[idx]) { r.c[idx] = payload; r.n++; r.s += payload.length; }
|
||||||
|
if (r.n === total) {
|
||||||
|
var out = new Uint8Array(r.s);
|
||||||
|
for (var i = 0, o = 0; i < total; i++) { out.set(r.c[i], o); o += r.c[i].length; }
|
||||||
|
delete recvBufs[id];
|
||||||
|
if (activeWS && wsOpen) activeWS.send(out.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function drainDC() {
|
||||||
|
if (dcDraining) return;
|
||||||
|
dcDraining = true;
|
||||||
|
while (dcQueue.length > 0) {
|
||||||
|
if (outboundDC.bufferedAmount > 64 * 1024) {
|
||||||
|
outboundDC.bufferedAmountLowThreshold = 16 * 1024;
|
||||||
|
outboundDC.onbufferedamountlow = function() {
|
||||||
|
outboundDC.onbufferedamountlow = null;
|
||||||
|
dcDraining = false;
|
||||||
|
drainDC();
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
outboundDC.send(dcQueue.shift());
|
||||||
|
}
|
||||||
|
dcDraining = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function startPinging() {
|
||||||
|
var iv = setInterval(function() {
|
||||||
|
if (tunnelReady) { clearInterval(iv); return; }
|
||||||
|
sendRaw('tunnel:ping');
|
||||||
|
log('Sent tunnel:ping');
|
||||||
|
}, 5000);
|
||||||
|
}
|
||||||
|
|
||||||
|
function connectWS() {
|
||||||
|
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
||||||
|
activeWS.close();
|
||||||
|
}
|
||||||
|
var ws = new WebSocket(WS_URL);
|
||||||
|
ws.binaryType = 'arraybuffer';
|
||||||
|
activeWS = ws;
|
||||||
|
ws.onopen = function() {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
log('WebSocket connected to Go relay');
|
||||||
|
wsOpen = true;
|
||||||
|
if (typeof AndroidBridge !== 'undefined' && AndroidBridge.onTunnelReady) {
|
||||||
|
AndroidBridge.onTunnelReady();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onclose = function() {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
wsOpen = false;
|
||||||
|
if (tunnelReady) {
|
||||||
|
log('WebSocket disconnected, reconnecting in 2s...');
|
||||||
|
setTimeout(function() { if (tunnelReady) connectWS(); }, 2000);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
ws.onerror = function() {
|
||||||
|
if (ws !== activeWS) return;
|
||||||
|
log('WebSocket error');
|
||||||
|
};
|
||||||
|
ws.onmessage = function(e) {
|
||||||
|
sendRaw(e.data);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.__hook = { peers: peers, log: log };
|
||||||
|
window.__hook.runBandwidthTest = function(totalMB) {
|
||||||
|
totalMB = totalMB || 1;
|
||||||
|
if (!tunnelReady || !outboundDC) { log('Tunnel not ready'); return; }
|
||||||
|
var chunkSize = 4096;
|
||||||
|
var totalBytes = totalMB * 1024 * 1024;
|
||||||
|
var sent = 0;
|
||||||
|
var start = performance.now();
|
||||||
|
sendRaw('bw:start');
|
||||||
|
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||||
|
var sendBatch = function() {
|
||||||
|
while (sent < totalBytes) {
|
||||||
|
if (outboundDC.bufferedAmount > 512 * 1024) {
|
||||||
|
setTimeout(sendBatch, 5);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sendRaw(new ArrayBuffer(chunkSize));
|
||||||
|
sent += chunkSize;
|
||||||
|
}
|
||||||
|
sendRaw('bw:done');
|
||||||
|
var elapsed = (performance.now() - start) / 1000;
|
||||||
|
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
|
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
|
};
|
||||||
|
sendBatch();
|
||||||
|
};
|
||||||
|
|
||||||
|
log('Hook installed');
|
||||||
|
})();
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
const WS_URL = 'ws://127.0.0.1:9000/ws';
|
||||||
const log = (...args) => console.log('[VK-HOOK]', ...args);
|
const log = (...args) => console.log('[HOOK]', ...args);
|
||||||
const peers = [];
|
const peers = [];
|
||||||
let activeWS = null;
|
let activeWS = null;
|
||||||
let activeDC = null;
|
let activeDC = null;
|
||||||
@@ -70,8 +70,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
if (typeof e.data === 'string' && e.data === 'bw:done') {
|
||||||
const elapsed = (performance.now() - bwRecvStart) / 1000;
|
var elapsed = (performance.now() - bwRecvStart) / 1000;
|
||||||
const kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
var kbps = (bwRecvBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
log('=== RECV COMPLETE: ' + (bwRecvBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
bwRecvBytes = 0;
|
bwRecvBytes = 0;
|
||||||
bwRecvStart = 0;
|
bwRecvStart = 0;
|
||||||
@@ -91,11 +91,12 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function connectWS() {
|
function connectWS() {
|
||||||
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
if (activeWS && activeWS.readyState === WebSocket.OPEN) {
|
||||||
activeWS.close();
|
activeWS.close();
|
||||||
}
|
}
|
||||||
const ws = new WebSocket(WS_URL);
|
var ws = new WebSocket(WS_URL);
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
activeWS = ws;
|
activeWS = ws;
|
||||||
|
|
||||||
@@ -131,17 +132,18 @@
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
window.__vkHook = { peers, log };
|
window.__hook = { peers: peers, log: log };
|
||||||
window.__vkHook.runBandwidthTest = (totalMB = 1) => {
|
window.__hook.runBandwidthTest = function(totalMB) {
|
||||||
|
totalMB = totalMB || 1;
|
||||||
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
if (!dcOpen || !activeDC) { log('DC not open'); return; }
|
||||||
const chunkSize = 16384;
|
var chunkSize = 16384;
|
||||||
const chunk = new ArrayBuffer(chunkSize);
|
var chunk = new ArrayBuffer(chunkSize);
|
||||||
const totalBytes = totalMB * 1024 * 1024;
|
var totalBytes = totalMB * 1024 * 1024;
|
||||||
let sent = 0;
|
var sent = 0;
|
||||||
const start = performance.now();
|
var start = performance.now();
|
||||||
activeDC.send('bw:start');
|
activeDC.send('bw:start');
|
||||||
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
log('Starting bandwidth test: ' + totalMB + ' MB...');
|
||||||
const sendBatch = () => {
|
var sendBatch = function() {
|
||||||
while (sent < totalBytes) {
|
while (sent < totalBytes) {
|
||||||
if (activeDC.bufferedAmount > 512 * 1024) {
|
if (activeDC.bufferedAmount > 512 * 1024) {
|
||||||
setTimeout(sendBatch, 5);
|
setTimeout(sendBatch, 5);
|
||||||
@@ -151,12 +153,12 @@
|
|||||||
sent += chunkSize;
|
sent += chunkSize;
|
||||||
}
|
}
|
||||||
activeDC.send('bw:done');
|
activeDC.send('bw:done');
|
||||||
const elapsed = (performance.now() - start) / 1000;
|
var elapsed = (performance.now() - start) / 1000;
|
||||||
const kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
var kbps = (totalBytes * 8 / 1024 / elapsed).toFixed(1);
|
||||||
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
log('=== SEND COMPLETE: ' + (totalBytes/1024).toFixed(1) + ' KB in ' + elapsed.toFixed(2) + 's = ' + kbps + ' kbps ===');
|
||||||
};
|
};
|
||||||
sendBatch();
|
sendBatch();
|
||||||
};
|
};
|
||||||
|
|
||||||
log('Hook installed. Now open the VK call link.');
|
log('Hook installed');
|
||||||
})();
|
})();
|
||||||
@@ -7,12 +7,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
"github.com/xjasonlyu/tun2socks/v2/engine"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -21,10 +20,13 @@ const (
|
|||||||
msgConnectErr byte = 0x03
|
msgConnectErr byte = 0x03
|
||||||
msgData byte = 0x04
|
msgData byte = 0x04
|
||||||
msgClose byte = 0x05
|
msgClose byte = 0x05
|
||||||
|
msgUDP byte = 0x06
|
||||||
|
msgUDPReply byte = 0x07
|
||||||
)
|
)
|
||||||
|
|
||||||
const readBufSize = 65536
|
const readBufSize = 65536
|
||||||
|
|
||||||
|
|
||||||
var framePool = sync.Pool{
|
var framePool = sync.Pool{
|
||||||
New: func() any {
|
New: func() any {
|
||||||
buf := make([]byte, 5+readBufSize)
|
buf := make([]byte, 5+readBufSize)
|
||||||
@@ -63,31 +65,13 @@ var logCb LogCallback
|
|||||||
|
|
||||||
func logMsg(format string, args ...any) {
|
func logMsg(format string, args ...any) {
|
||||||
msg := fmt.Sprintf(format, args...)
|
msg := fmt.Sprintf(format, args...)
|
||||||
log.Print(msg)
|
|
||||||
if logCb != nil {
|
if logCb != nil {
|
||||||
logCb.OnLog(msg)
|
logCb.OnLog(msg)
|
||||||
|
} else {
|
||||||
|
log.Print(msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func StartTun2Socks(fd, mtu, socksPort int) error {
|
|
||||||
proxy := fmt.Sprintf("socks5://127.0.0.1:%d", socksPort)
|
|
||||||
logMsg("tun2socks: starting fd=%d mtu=%d proxy=%s", fd, mtu, proxy)
|
|
||||||
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
|
|
||||||
key := &engine.Key{
|
|
||||||
Proxy: proxy,
|
|
||||||
Device: fmt.Sprintf("fd://%d", fd),
|
|
||||||
MTU: mtu,
|
|
||||||
}
|
|
||||||
engine.Insert(key)
|
|
||||||
engine.Start()
|
|
||||||
logMsg("tun2socks: running")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func StopTun2Socks() {
|
|
||||||
engine.Stop()
|
|
||||||
logMsg("tun2socks: stopped")
|
|
||||||
}
|
|
||||||
|
|
||||||
type wsWriter struct {
|
type wsWriter struct {
|
||||||
ws *websocket.Conn
|
ws *websocket.Conn
|
||||||
@@ -129,6 +113,7 @@ func (w *wsWriter) close() {
|
|||||||
<-w.done
|
<-w.done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func StartJoiner(wsPort, socksPort int, cb LogCallback) error {
|
func StartJoiner(wsPort, socksPort int, cb LogCallback) error {
|
||||||
logCb = cb
|
logCb = cb
|
||||||
j := &joinerRelay{
|
j := &joinerRelay{
|
||||||
@@ -137,6 +122,7 @@ func StartJoiner(wsPort, socksPort int, cb LogCallback) error {
|
|||||||
}
|
}
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/ws", j.handleWS)
|
mux.HandleFunc("/ws", j.handleWS)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", wsPort)
|
addr := fmt.Sprintf("127.0.0.1:%d", wsPort)
|
||||||
logMsg("joiner: WebSocket on %s", addr)
|
logMsg("joiner: WebSocket on %s", addr)
|
||||||
@@ -156,6 +142,7 @@ func StartCreator(wsPort int, cb LogCallback) error {
|
|||||||
}
|
}
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.HandleFunc("/ws", c.handleWS)
|
mux.HandleFunc("/ws", c.handleWS)
|
||||||
|
|
||||||
addr := fmt.Sprintf("127.0.0.1:%d", wsPort)
|
addr := fmt.Sprintf("127.0.0.1:%d", wsPort)
|
||||||
logMsg("creator: WebSocket on %s", addr)
|
logMsg("creator: WebSocket on %s", addr)
|
||||||
return http.ListenAndServe(addr, mux)
|
return http.ListenAndServe(addr, mux)
|
||||||
@@ -164,6 +151,7 @@ func StartCreator(wsPort int, cb LogCallback) error {
|
|||||||
type joinerRelay struct {
|
type joinerRelay struct {
|
||||||
writer *wsWriter
|
writer *wsWriter
|
||||||
conns sync.Map
|
conns sync.Map
|
||||||
|
udpClients sync.Map
|
||||||
nextID atomic.Uint32
|
nextID atomic.Uint32
|
||||||
ready chan struct{}
|
ready chan struct{}
|
||||||
once sync.Once
|
once sync.Once
|
||||||
@@ -176,6 +164,96 @@ type socksConn struct {
|
|||||||
rdy chan error
|
rdy chan error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type udpClient struct {
|
||||||
|
udpConn *net.UDPConn
|
||||||
|
clientAddr *net.UDPAddr
|
||||||
|
socksHeader []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
func (j *joinerRelay) handleUDPAssociate(tcpConn net.Conn) {
|
||||||
|
udpAddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0")
|
||||||
|
if err != nil {
|
||||||
|
tcpConn.Write([]byte{0x05, 0x01, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
|
||||||
|
tcpConn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
udpConn, err := net.ListenUDP("udp", udpAddr)
|
||||||
|
if err != nil {
|
||||||
|
tcpConn.Write([]byte{0x05, 0x01, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
|
||||||
|
tcpConn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
localAddr := udpConn.LocalAddr().(*net.UDPAddr)
|
||||||
|
reply := []byte{0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0, 0}
|
||||||
|
binary.BigEndian.PutUint16(reply[8:10], uint16(localAddr.Port))
|
||||||
|
tcpConn.Write(reply)
|
||||||
|
logMsg("joiner: UDP ASSOCIATE on port %d", localAddr.Port)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
buf := make([]byte, 1)
|
||||||
|
tcpConn.Read(buf)
|
||||||
|
udpConn.Close()
|
||||||
|
}()
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer udpConn.Close()
|
||||||
|
defer tcpConn.Close()
|
||||||
|
buf := make([]byte, readBufSize)
|
||||||
|
var clientAddr *net.UDPAddr
|
||||||
|
for {
|
||||||
|
n, addr, err := udpConn.ReadFromUDP(buf)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if n < 10 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
clientAddr = addr
|
||||||
|
frag := buf[2]
|
||||||
|
if frag != 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
atyp := buf[3]
|
||||||
|
var dstAddr string
|
||||||
|
var headerLen int
|
||||||
|
switch atyp {
|
||||||
|
case 0x01:
|
||||||
|
if n < 10 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dstAddr = fmt.Sprintf("%d.%d.%d.%d:%d", buf[4], buf[5], buf[6], buf[7],
|
||||||
|
binary.BigEndian.Uint16(buf[8:10]))
|
||||||
|
headerLen = 10
|
||||||
|
case 0x03:
|
||||||
|
dlen := int(buf[4])
|
||||||
|
if n < 5+dlen+2 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
dstAddr = fmt.Sprintf("%s:%d", string(buf[5:5+dlen]),
|
||||||
|
binary.BigEndian.Uint16(buf[5+dlen:7+dlen]))
|
||||||
|
headerLen = 5 + dlen + 2
|
||||||
|
case 0x04:
|
||||||
|
if n < 22 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ip := net.IP(buf[4:20])
|
||||||
|
dstAddr = fmt.Sprintf("[%s]:%d", ip.String(),
|
||||||
|
binary.BigEndian.Uint16(buf[20:22]))
|
||||||
|
headerLen = 22
|
||||||
|
default:
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
id := j.nextID.Add(1)
|
||||||
|
payload := make([]byte, len(dstAddr)+1+n-headerLen)
|
||||||
|
payload[0] = byte(len(dstAddr))
|
||||||
|
copy(payload[1:], dstAddr)
|
||||||
|
copy(payload[1+len(dstAddr):], buf[headerLen:n])
|
||||||
|
j.udpClients.Store(id, &udpClient{udpConn: udpConn, clientAddr: clientAddr, socksHeader: buf[:headerLen]})
|
||||||
|
j.send(id, msgUDP, payload)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
func (j *joinerRelay) handleWS(w http.ResponseWriter, r *http.Request) {
|
func (j *joinerRelay) handleWS(w http.ResponseWriter, r *http.Request) {
|
||||||
ws, err := upgrader.Upgrade(w, r, nil)
|
ws, err := upgrader.Upgrade(w, r, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -201,6 +279,19 @@ func (j *joinerRelay) handleMessage(connID uint32, msgType byte, payload []byte)
|
|||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if msgType == msgUDPReply {
|
||||||
|
uval, ok := j.udpClients.Load(connID)
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
uc := uval.(*udpClient)
|
||||||
|
reply := make([]byte, len(uc.socksHeader)+len(payload))
|
||||||
|
copy(reply, uc.socksHeader)
|
||||||
|
copy(reply[len(uc.socksHeader):], payload)
|
||||||
|
uc.udpConn.WriteToUDP(reply, uc.clientAddr)
|
||||||
|
j.udpClients.Delete(connID)
|
||||||
|
return
|
||||||
|
}
|
||||||
sc := val.(*socksConn)
|
sc := val.(*socksConn)
|
||||||
switch msgType {
|
switch msgType {
|
||||||
case msgConnectOK:
|
case msgConnectOK:
|
||||||
@@ -252,7 +343,17 @@ func (j *joinerRelay) handleSOCKS(conn net.Conn) {
|
|||||||
}
|
}
|
||||||
conn.Write([]byte{0x05, 0x00})
|
conn.Write([]byte{0x05, 0x00})
|
||||||
n, err = conn.Read(buf)
|
n, err = conn.Read(buf)
|
||||||
if err != nil || n < 7 || buf[0] != 0x05 || buf[1] != 0x01 {
|
if err != nil || n < 7 || buf[0] != 0x05 {
|
||||||
|
conn.Write([]byte{0x05, 0x01, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
|
||||||
|
conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cmd := buf[1]
|
||||||
|
if cmd == 0x03 {
|
||||||
|
j.handleUDPAssociate(conn)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if cmd != 0x01 {
|
||||||
conn.Write([]byte{0x05, 0x07, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
|
conn.Write([]byte{0x05, 0x07, 0x00, 0x01, 0, 0, 0, 0, 0, 0})
|
||||||
conn.Close()
|
conn.Close()
|
||||||
return
|
return
|
||||||
@@ -345,6 +446,8 @@ func (c *creatorRelay) handleMessage(connID uint32, msgType byte, payload []byte
|
|||||||
switch msgType {
|
switch msgType {
|
||||||
case msgConnect:
|
case msgConnect:
|
||||||
go c.connect(connID, string(payload))
|
go c.connect(connID, string(payload))
|
||||||
|
case msgUDP:
|
||||||
|
go c.handleUDP(connID, payload)
|
||||||
case msgData:
|
case msgData:
|
||||||
val, ok := c.conns.Load(connID)
|
val, ok := c.conns.Load(connID)
|
||||||
if ok {
|
if ok {
|
||||||
@@ -370,6 +473,41 @@ func (c *creatorRelay) send(connID uint32, msgType byte, payload []byte) {
|
|||||||
framePool.Put(bufp)
|
framePool.Put(bufp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *creatorRelay) handleUDP(connID uint32, payload []byte) {
|
||||||
|
if len(payload) < 2 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addrLen := int(payload[0])
|
||||||
|
if len(payload) < 1+addrLen {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
addr := string(payload[1 : 1+addrLen])
|
||||||
|
data := payload[1+addrLen:]
|
||||||
|
|
||||||
|
udpAddr, err := net.ResolveUDPAddr("udp", addr)
|
||||||
|
if err != nil {
|
||||||
|
logMsg("creator: UDP resolve %s failed: %v", addr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conn, err := net.DialUDP("udp", nil, udpAddr)
|
||||||
|
if err != nil {
|
||||||
|
logMsg("creator: UDP dial %s failed: %v", addr, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer conn.Close()
|
||||||
|
conn.SetDeadline(time.Now().Add(5 * time.Second))
|
||||||
|
_, err = conn.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
buf := make([]byte, 4096)
|
||||||
|
n, err := conn.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.send(connID, msgUDPReply, buf[:n])
|
||||||
|
}
|
||||||
|
|
||||||
func (c *creatorRelay) connect(connID uint32, addr string) {
|
func (c *creatorRelay) connect(connID uint32, addr string) {
|
||||||
logMsg("creator: CONNECT %d -> %s", connID, addr)
|
logMsg("creator: CONNECT %d -> %s", connID, addr)
|
||||||
conn, err := net.DialTimeout("tcp", addr, 10e9)
|
conn, err := net.DialTimeout("tcp", addr, 10e9)
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
//go:build android
|
||||||
|
|
||||||
|
package mobile
|
||||||
|
|
||||||
|
/*
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void disable_fdsan() {
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
extern void android_fdsan_set_error_level(uint32_t) __attribute__((weak));
|
||||||
|
if (android_fdsan_set_error_level) {
|
||||||
|
android_fdsan_set_error_level(0);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/xjasonlyu/tun2socks/v2/engine"
|
||||||
|
)
|
||||||
|
|
||||||
|
func StartTun2Socks(fd, mtu, socksPort int) error {
|
||||||
|
proxy := fmt.Sprintf("socks5://127.0.0.1:%d", socksPort)
|
||||||
|
logMsg("tun2socks: starting fd=%d mtu=%d proxy=%s", fd, mtu, proxy)
|
||||||
|
os.Setenv("TUN2SOCKS_LOG_LEVEL", "info")
|
||||||
|
key := &engine.Key{
|
||||||
|
Proxy: proxy,
|
||||||
|
Device: fmt.Sprintf("fd://%d", fd),
|
||||||
|
MTU: mtu,
|
||||||
|
}
|
||||||
|
engine.Insert(key)
|
||||||
|
engine.Start()
|
||||||
|
logMsg("tun2socks: running")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func StopTun2Socks() {
|
||||||
|
C.disable_fdsan()
|
||||||
|
engine.Stop()
|
||||||
|
logMsg("tun2socks: stopped")
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
//go:build !android
|
||||||
|
|
||||||
|
package mobile
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func StartTun2Socks(fd, mtu, socksPort int) error {
|
||||||
|
return fmt.Errorf("tun2socks is only available on Android")
|
||||||
|
}
|
||||||
|
|
||||||
|
func StopTun2Socks() {}
|
||||||