v0.1.5
This commit is contained in:
1 parent
61ef2aa2bd
commit
e8da07179a
32 files changed
+3633
-161
No files matched your search
@@ -3,6 +3,11 @@ plugins {
|
||||
alias(libs.plugins.kotlin.android)
|
||||
}
|
||||
|
||||
val versionMajor = 0
|
||||
val versionMinor = 1
|
||||
val versionPatch = 5
|
||||
val versionBuild = System.getenv("BUILD_NUMBER")?.toIntOrNull() ?: 0
|
||||
|
||||
android {
|
||||
namespace = "bypass.whitelist"
|
||||
compileSdk {
|
||||
@@ -13,8 +18,8 @@ android {
|
||||
applicationId = "bypass.whitelist"
|
||||
minSdk = 23
|
||||
targetSdk = 36
|
||||
versionCode = 1
|
||||
versionName = "0.1"
|
||||
versionCode = 1_000_000 * versionMajor + 1_000 * versionMinor + versionPatch + versionBuild
|
||||
versionName = "$versionMajor.$versionMinor.$versionPatch"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
Binary file not shown.
@@ -2,6 +2,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
|
||||
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
|
||||
@@ -15,7 +16,8 @@
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.WhitelistBypass"
|
||||
android:usesCleartextTraffic="true">
|
||||
android:usesCleartextTraffic="true"
|
||||
android:extractNativeLibs="true">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:screenOrientation="portrait"
|
||||
|
||||
@@ -0,0 +1,436 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
var PION_WS_URL = 'ws://127.0.0.1:' + (window.PION_PORT || 9001) + '/signaling';
|
||||
var log = function() {
|
||||
var args = ['[HOOK]'].concat(Array.prototype.slice.call(arguments));
|
||||
console.log.apply(console, args);
|
||||
};
|
||||
|
||||
var OrigWebSocket = window.WebSocket;
|
||||
var pionWS = null;
|
||||
var pionReady = false;
|
||||
var pendingMessages = [];
|
||||
var requestId = 0;
|
||||
var pendingRequests = {};
|
||||
var mockPCs = [];
|
||||
var pcCount = 0;
|
||||
|
||||
function connectPion() {
|
||||
var ws = new OrigWebSocket(PION_WS_URL);
|
||||
pionWS = ws;
|
||||
ws.onopen = function() {
|
||||
log('Connected to Pion relay');
|
||||
pionReady = true;
|
||||
pendingMessages.forEach(function(m) { ws.send(m); });
|
||||
pendingMessages = [];
|
||||
};
|
||||
ws.onclose = function() {
|
||||
pionReady = false;
|
||||
pionWS = null;
|
||||
var hasActive = mockPCs.some(function(pc) { return pc._connectionState !== 'closed'; });
|
||||
if (hasActive) {
|
||||
log('Pion relay disconnected, reconnecting...');
|
||||
setTimeout(connectPion, 2000);
|
||||
}
|
||||
};
|
||||
ws.onerror = function() {};
|
||||
ws.onmessage = function(e) {
|
||||
var msg = JSON.parse(e.data);
|
||||
handlePionMessage(msg);
|
||||
};
|
||||
}
|
||||
|
||||
function sendToPion(type, data, role) {
|
||||
var msg = JSON.stringify({ type: type, data: data, role: role || '' });
|
||||
if (pionReady && pionWS && pionWS.readyState === 1) {
|
||||
pionWS.send(msg);
|
||||
} else {
|
||||
pendingMessages.push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function requestPion(type, data, role) {
|
||||
var id = ++requestId;
|
||||
return new Promise(function(resolve, reject) {
|
||||
pendingRequests[id] = { resolve: resolve, reject: reject };
|
||||
var msg = JSON.stringify({ type: type, data: data, id: id, role: role || '' });
|
||||
if (pionReady && pionWS && pionWS.readyState === 1) {
|
||||
pionWS.send(msg);
|
||||
} else {
|
||||
pendingMessages.push(msg);
|
||||
}
|
||||
setTimeout(function() {
|
||||
if (pendingRequests[id]) {
|
||||
delete pendingRequests[id];
|
||||
reject(new Error('Pion request timeout: ' + type));
|
||||
}
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
|
||||
function handlePionMessage(msg) {
|
||||
if (msg.id && pendingRequests[msg.id]) {
|
||||
pendingRequests[msg.id].resolve(msg.data);
|
||||
delete pendingRequests[msg.id];
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.type) {
|
||||
case 'ice-candidate':
|
||||
var targetRole = msg.role || '';
|
||||
mockPCs.forEach(function(pc) {
|
||||
if (pc._connectionState === 'closed') return;
|
||||
if (targetRole && pc._role !== targetRole) return;
|
||||
var evt = { candidate: new RTCIceCandidate(msg.data) };
|
||||
if (pc._onicecandidate) pc._onicecandidate(evt);
|
||||
pc._listeners.icecandidate.forEach(function(fn) { fn(evt); });
|
||||
});
|
||||
break;
|
||||
case 'remote-track':
|
||||
log('remote-track received: kind=' + (msg.data && msg.data.kind));
|
||||
break;
|
||||
case 'connection-state':
|
||||
log('Pion connection state:', msg.data);
|
||||
mockPCs.forEach(function(pc) {
|
||||
pc._connectionState = msg.data;
|
||||
if (msg.data === 'connected') {
|
||||
if (typeof AndroidBridge !== 'undefined' && AndroidBridge.onTunnelReady) {
|
||||
AndroidBridge.onTunnelReady();
|
||||
}
|
||||
}
|
||||
if (pc._onconnectionstatechange) pc._onconnectionstatechange(new Event('connectionstatechange'));
|
||||
pc._listeners.connectionstatechange.forEach(function(fn) { fn(new Event('connectionstatechange')); });
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// MockPC for Telemost GOLOOM SDK
|
||||
function MockPeerConnection(config) {
|
||||
this._config = config;
|
||||
this._connectionState = 'new';
|
||||
this._signalingState = 'stable';
|
||||
this._iceConnectionState = 'new';
|
||||
this._iceGatheringState = 'new';
|
||||
this._localDescription = null;
|
||||
this._remoteDescription = null;
|
||||
this._senders = [];
|
||||
this._receivers = [];
|
||||
this._transceivers = [];
|
||||
this._onicecandidate = null;
|
||||
this._onconnectionstatechange = null;
|
||||
this._ontrack = null;
|
||||
this._ondatachannel = null;
|
||||
this._onsignalingstatechange = null;
|
||||
this._onnegotiationneeded = null;
|
||||
this._oniceconnectionstatechange = null;
|
||||
this._pcIdx = pcCount++;
|
||||
this._listeners = {
|
||||
connectionstatechange: [],
|
||||
icecandidate: [],
|
||||
track: [],
|
||||
datachannel: [],
|
||||
iceconnectionstatechange: [],
|
||||
icegatheringstatechange: [],
|
||||
signalingstatechange: [],
|
||||
negotiationneeded: []
|
||||
};
|
||||
|
||||
var existingPub = mockPCs.find(function(pc) { return pc._role === 'pub' && pc._connectionState !== 'closed'; });
|
||||
this._role = existingPub ? 'sub' : 'pub';
|
||||
|
||||
if (config && config.iceServers) {
|
||||
var servers = config.iceServers.map(function(s) {
|
||||
var urls = Array.isArray(s.urls) ? s.urls : (s.urls ? [s.urls] : []);
|
||||
if (typeof AndroidBridge !== 'undefined' && AndroidBridge.resolveHost) {
|
||||
urls = urls.map(function(url) {
|
||||
var match = url.match(/^(turn:|stun:)([^:?]+)(.*)/);
|
||||
if (match) {
|
||||
var resolved = AndroidBridge.resolveHost(match[2]);
|
||||
if (resolved) return match[1] + resolved + match[3];
|
||||
}
|
||||
return url;
|
||||
});
|
||||
}
|
||||
return {
|
||||
urls: urls,
|
||||
username: s.username || '',
|
||||
credential: s.credential || ''
|
||||
};
|
||||
});
|
||||
sendToPion('ice-servers', servers, this._role);
|
||||
}
|
||||
|
||||
mockPCs.push(this);
|
||||
if (!pionWS) {
|
||||
if (typeof AndroidBridge !== 'undefined' && AndroidBridge.getLocalIP) {
|
||||
var ip = AndroidBridge.getLocalIP();
|
||||
if (ip) {
|
||||
log('Local IP from Android: ' + ip);
|
||||
pendingMessages.push(JSON.stringify({ type: 'local-ip', data: ip }));
|
||||
}
|
||||
}
|
||||
connectPion();
|
||||
}
|
||||
log('MockPC #' + this._pcIdx + ' created (role=' + this._role + ')');
|
||||
}
|
||||
|
||||
MockPeerConnection.prototype = {
|
||||
get connectionState() { return this._connectionState; },
|
||||
get signalingState() { return this._signalingState; },
|
||||
get iceConnectionState() { return this._iceConnectionState; },
|
||||
get iceGatheringState() { return this._iceGatheringState; },
|
||||
get localDescription() { return this._localDescription; },
|
||||
get remoteDescription() { return this._remoteDescription; },
|
||||
get currentLocalDescription() { return this._localDescription; },
|
||||
get currentRemoteDescription() { return this._remoteDescription; },
|
||||
|
||||
set onicecandidate(fn) { this._onicecandidate = fn; },
|
||||
get onicecandidate() { return this._onicecandidate; },
|
||||
set onconnectionstatechange(fn) { this._onconnectionstatechange = fn; },
|
||||
get onconnectionstatechange() { return this._onconnectionstatechange; },
|
||||
set ontrack(fn) { log('MockPC #' + this._pcIdx + ' ontrack SET (role=' + this._role + ')'); this._ontrack = fn; },
|
||||
get ontrack() { return this._ontrack; },
|
||||
set ondatachannel(fn) { this._ondatachannel = fn; },
|
||||
get ondatachannel() { return this._ondatachannel; },
|
||||
set oniceconnectionstatechange(fn) { this._oniceconnectionstatechange = fn; },
|
||||
get oniceconnectionstatechange() { return this._oniceconnectionstatechange; },
|
||||
set onicegatheringstatechange(fn) { this._onicegatheringstatechange = fn; },
|
||||
get onicegatheringstatechange() { return this._onicegatheringstatechange; },
|
||||
set onsignalingstatechange(fn) { this._onsignalingstatechange = fn; },
|
||||
get onsignalingstatechange() { return this._onsignalingstatechange; },
|
||||
set onnegotiationneeded(fn) { this._onnegotiationneeded = fn; },
|
||||
get onnegotiationneeded() { return this._onnegotiationneeded; },
|
||||
|
||||
addEventListener: function(type, fn) {
|
||||
if (this._listeners[type]) this._listeners[type].push(fn);
|
||||
},
|
||||
removeEventListener: function(type, fn) {
|
||||
if (this._listeners[type]) this._listeners[type] = this._listeners[type].filter(function(f) { return f !== fn; });
|
||||
},
|
||||
dispatchEvent: function(event) {
|
||||
var type = event.type;
|
||||
if (this._listeners[type]) this._listeners[type].forEach(function(fn) { fn(event); });
|
||||
var handler = this['on' + type];
|
||||
if (handler) handler.call(this, event);
|
||||
},
|
||||
|
||||
createOffer: function(options) {
|
||||
log('MockPC #' + this._pcIdx + ' createOffer');
|
||||
return requestPion('create-offer', options || {}, this._role).then(function(sdp) {
|
||||
return new RTCSessionDescription(sdp);
|
||||
});
|
||||
},
|
||||
|
||||
createAnswer: function(options) {
|
||||
log('MockPC #' + this._pcIdx + ' createAnswer');
|
||||
return requestPion('create-answer', options || {}, this._role).then(function(sdp) {
|
||||
return new RTCSessionDescription(sdp);
|
||||
});
|
||||
},
|
||||
|
||||
setLocalDescription: function(desc) {
|
||||
this._localDescription = desc;
|
||||
var oldState = this._signalingState;
|
||||
this._signalingState = desc.type === 'offer' ? 'have-local-offer' : 'stable';
|
||||
log('MockPC #' + this._pcIdx + ' setLocalDescription:', desc.type);
|
||||
sendToPion('set-local-description', { type: desc.type, sdp: desc.sdp }, this._role);
|
||||
var self = this;
|
||||
if (oldState !== this._signalingState) {
|
||||
setTimeout(function() {
|
||||
if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange'));
|
||||
self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); });
|
||||
}, 0);
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
setRemoteDescription: function(desc) {
|
||||
var oldState = this._signalingState;
|
||||
this._signalingState = desc.type === 'offer' ? 'have-remote-offer' : 'stable';
|
||||
this._remoteDescription = desc;
|
||||
log('MockPC #' + this._pcIdx + ' setRemoteDescription:', desc.type);
|
||||
var self = this;
|
||||
return requestPion('set-remote-description', { type: desc.type, sdp: desc.sdp }, this._role).then(function() {
|
||||
if (oldState !== self._signalingState) {
|
||||
if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange'));
|
||||
self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); });
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
addIceCandidate: function(candidate) {
|
||||
if (candidate && candidate.candidate) {
|
||||
sendToPion('add-ice-candidate', {
|
||||
candidate: candidate.candidate,
|
||||
sdpMid: candidate.sdpMid,
|
||||
sdpMLineIndex: candidate.sdpMLineIndex
|
||||
}, this._role);
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
addTrack: function(track, stream) {
|
||||
var sender = {
|
||||
track: track,
|
||||
replaceTrack: function(t) { this.track = t; return Promise.resolve(); },
|
||||
getParameters: function() { return { encodings: [{}] }; },
|
||||
setParameters: function() { return Promise.resolve(); }
|
||||
};
|
||||
this._senders.push(sender);
|
||||
sendToPion('add-track', { kind: track.kind }, this._role);
|
||||
return sender;
|
||||
},
|
||||
|
||||
addTransceiver: function(trackOrKind, init) {
|
||||
var kind = typeof trackOrKind === 'string' ? trackOrKind : trackOrKind.kind;
|
||||
var sender = {
|
||||
track: typeof trackOrKind === 'string' ? null : trackOrKind,
|
||||
replaceTrack: function(t) { this.track = t; return Promise.resolve(); },
|
||||
getParameters: function() { return { encodings: [{}] }; },
|
||||
setParameters: function() { return Promise.resolve(); },
|
||||
setStreams: function() {}
|
||||
};
|
||||
var receiver = {
|
||||
track: { kind: kind, readyState: 'live', enabled: true, muted: true, id: 'mock-' + kind + '-' + this._pcIdx,
|
||||
addEventListener: function() {}, removeEventListener: function() {},
|
||||
getSettings: function() { return {}; } },
|
||||
getStats: function() { return Promise.resolve(new Map()); },
|
||||
getSynchronizationSources: function() { return []; }
|
||||
};
|
||||
var transceiver = {
|
||||
sender: sender, receiver: receiver,
|
||||
direction: (init && init.direction) || 'sendrecv',
|
||||
setDirection: function(d) { this.direction = d; },
|
||||
mid: String(this._transceivers.length),
|
||||
stopped: false,
|
||||
stop: function() { this.stopped = true; },
|
||||
setCodecPreferences: function() {}
|
||||
};
|
||||
this._senders.push(sender);
|
||||
this._receivers.push(receiver);
|
||||
this._transceivers.push(transceiver);
|
||||
return transceiver;
|
||||
},
|
||||
|
||||
removeTrack: function(sender) {
|
||||
this._senders = this._senders.filter(function(s) { return s !== sender; });
|
||||
},
|
||||
|
||||
getSenders: function() { return this._senders; },
|
||||
getReceivers: function() { return this._receivers; },
|
||||
getTransceivers: function() { return this._transceivers; },
|
||||
getStats: function() { return Promise.resolve(new Map()); },
|
||||
getConfiguration: function() { return this._config || {}; },
|
||||
|
||||
createDataChannel: function(label, opts) {
|
||||
log('MockPC #' + this._pcIdx + ' createDataChannel:', label);
|
||||
sendToPion('create-data-channel', { label: label, opts: opts }, this._role);
|
||||
var dc = {
|
||||
label: label,
|
||||
id: opts && opts.id != null ? opts.id : null,
|
||||
readyState: 'connecting',
|
||||
binaryType: 'arraybuffer',
|
||||
bufferedAmount: 0,
|
||||
bufferedAmountLowThreshold: 0,
|
||||
onopen: null, onclose: null, onmessage: null, onerror: null,
|
||||
onbufferedamountlow: null,
|
||||
send: function() {},
|
||||
close: function() { this.readyState = 'closed'; },
|
||||
addEventListener: function() {},
|
||||
removeEventListener: function() {}
|
||||
};
|
||||
return dc;
|
||||
},
|
||||
|
||||
close: function() {
|
||||
this._connectionState = 'closed';
|
||||
this._signalingState = 'closed';
|
||||
log('MockPC #' + this._pcIdx + ' close');
|
||||
var allClosed = mockPCs.every(function(pc) { return pc._connectionState === 'closed'; });
|
||||
if (allClosed) {
|
||||
sendToPion('close', {});
|
||||
log('All MockPCs closed, closing Pion');
|
||||
}
|
||||
},
|
||||
|
||||
restartIce: function() {},
|
||||
setConfiguration: function() {}
|
||||
};
|
||||
|
||||
// Hook RTCPeerConnection
|
||||
var OrigPC = window.RTCPeerConnection;
|
||||
window.RTCPeerConnection = function(config) {
|
||||
if (!config || !config.iceServers || config.iceServers.length === 0) {
|
||||
log('RTCPeerConnection probe (no ICE servers) -> real PC');
|
||||
return new OrigPC(config);
|
||||
}
|
||||
log('RTCPeerConnection intercepted -> MockPC');
|
||||
return new MockPeerConnection(config);
|
||||
};
|
||||
Object.keys(OrigPC).forEach(function(key) {
|
||||
window.RTCPeerConnection[key] = OrigPC[key];
|
||||
});
|
||||
window.RTCPeerConnection.prototype = OrigPC.prototype;
|
||||
window.RTCPeerConnection.generateCertificate = OrigPC.generateCertificate;
|
||||
|
||||
// Intercept signaling via JSON.stringify/parse
|
||||
var origStringify = JSON.stringify;
|
||||
JSON.stringify = function(obj) {
|
||||
var result = origStringify.apply(JSON, arguments);
|
||||
return result;
|
||||
};
|
||||
|
||||
var origParse = JSON.parse;
|
||||
JSON.parse = function(str) {
|
||||
var result = origParse.apply(JSON, arguments);
|
||||
if (result && result.serverHello && result.serverHello.rtcConfiguration) {
|
||||
var rtcConfig = result.serverHello.rtcConfiguration;
|
||||
if (rtcConfig.iceServers && rtcConfig.iceServers.length > 0) {
|
||||
log('ICE servers from serverHello:', rtcConfig.iceServers.length);
|
||||
}
|
||||
}
|
||||
if (result && result.publisherSdpAnswer) {
|
||||
log('Incoming publisherSdpAnswer, pcSeq=' + result.publisherSdpAnswer.pcSeq);
|
||||
}
|
||||
if (result && result.subscriberSdpOffer) {
|
||||
log('Incoming subscriberSdpOffer, pcSeq=' + result.subscriberSdpOffer.pcSeq);
|
||||
}
|
||||
if (result && result.slotsChanged) {
|
||||
log('Incoming slotsChanged:', JSON.stringify(result.slotsChanged).substring(0, 200));
|
||||
}
|
||||
if (result && result.participantsChanged) {
|
||||
log('Incoming participantsChanged');
|
||||
}
|
||||
if (result && result.connectionStatusChanged) {
|
||||
log('Incoming connectionStatusChanged:', JSON.stringify(result.connectionStatusChanged).substring(0, 200));
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
// Fake media - static black canvas + silent audio
|
||||
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();
|
||||
stream.addTrack(dest.stream.getAudioTracks()[0]);
|
||||
}
|
||||
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}}
|
||||
]);
|
||||
};
|
||||
|
||||
window.__hook = { log: log, mockPCs: mockPCs };
|
||||
log('Telemost Pion hook installed (MockPC mode)');
|
||||
})();
|
||||
@@ -0,0 +1,385 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
|
||||
var PION_WS_URL = 'ws://127.0.0.1:' + (window.PION_PORT || 9001) + '/signaling';
|
||||
var log = function() {
|
||||
var args = ['[HOOK]'].concat(Array.prototype.slice.call(arguments));
|
||||
console.log.apply(console, args);
|
||||
};
|
||||
|
||||
var OrigWebSocket = window.WebSocket;
|
||||
var pionWS = null;
|
||||
var pionReady = false;
|
||||
var pendingMessages = [];
|
||||
var requestId = 0;
|
||||
var pendingRequests = {};
|
||||
|
||||
function connectPion() {
|
||||
var ws = new OrigWebSocket(PION_WS_URL);
|
||||
pionWS = ws;
|
||||
ws.onopen = function() {
|
||||
log('Connected to Pion relay');
|
||||
pionReady = true;
|
||||
pendingMessages.forEach(function(m) { ws.send(m); });
|
||||
pendingMessages = [];
|
||||
};
|
||||
ws.onclose = function() {
|
||||
pionReady = false;
|
||||
pionWS = null;
|
||||
if (mockPC && mockPC._connectionState !== 'closed') {
|
||||
log('Pion relay disconnected, reconnecting...');
|
||||
setTimeout(connectPion, 2000);
|
||||
}
|
||||
};
|
||||
ws.onerror = function() {};
|
||||
ws.onmessage = function(e) {
|
||||
var msg = JSON.parse(e.data);
|
||||
handlePionMessage(msg);
|
||||
};
|
||||
}
|
||||
|
||||
function sendToPion(type, data) {
|
||||
var msg = JSON.stringify({ type: type, data: data });
|
||||
if (pionReady && pionWS && pionWS.readyState === 1) {
|
||||
pionWS.send(msg);
|
||||
} else {
|
||||
pendingMessages.push(msg);
|
||||
}
|
||||
}
|
||||
|
||||
function requestPion(type, data) {
|
||||
var id = ++requestId;
|
||||
return new Promise(function(resolve, reject) {
|
||||
pendingRequests[id] = { resolve: resolve, reject: reject };
|
||||
var msg = JSON.stringify({ type: type, data: data, id: id });
|
||||
if (pionReady && pionWS && pionWS.readyState === 1) {
|
||||
pionWS.send(msg);
|
||||
} else {
|
||||
pendingMessages.push(msg);
|
||||
}
|
||||
setTimeout(function() {
|
||||
if (pendingRequests[id]) {
|
||||
delete pendingRequests[id];
|
||||
reject(new Error('Pion request timeout: ' + type));
|
||||
}
|
||||
}, 10000);
|
||||
});
|
||||
}
|
||||
|
||||
var mockPC = null;
|
||||
function handlePionMessage(msg) {
|
||||
if (msg.id && pendingRequests[msg.id]) {
|
||||
pendingRequests[msg.id].resolve(msg.data);
|
||||
delete pendingRequests[msg.id];
|
||||
return;
|
||||
}
|
||||
|
||||
switch (msg.type) {
|
||||
case 'ice-candidate':
|
||||
if (mockPC && mockPC._onicecandidate) {
|
||||
mockPC._onicecandidate({ candidate: new RTCIceCandidate(msg.data) });
|
||||
}
|
||||
break;
|
||||
case 'remote-track':
|
||||
log('remote-track received: kind=' + (msg.data && msg.data.kind) + ' mockPC=' + !!mockPC + ' ontrack=' + !!( mockPC && mockPC._ontrack));
|
||||
if (mockPC && mockPC._ontrack) {
|
||||
var kind = msg.data.kind;
|
||||
log('Firing ontrack for remote ' + kind);
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 2; canvas.height = 2;
|
||||
var fakeStream = canvas.captureStream(1);
|
||||
var fakeTrack = kind === 'audio'
|
||||
? (function() { var a = new AudioContext(); var d = a.createMediaStreamDestination(); return d.stream.getAudioTracks()[0]; })()
|
||||
: fakeStream.getVideoTracks()[0];
|
||||
log('Fake track created: kind=' + fakeTrack.kind + ' readyState=' + fakeTrack.readyState + ' enabled=' + fakeTrack.enabled);
|
||||
var evt = new Event('track');
|
||||
evt.track = fakeTrack;
|
||||
evt.receiver = { track: fakeTrack };
|
||||
evt.transceiver = { receiver: { track: fakeTrack } };
|
||||
evt.streams = [kind === 'audio' ? new MediaStream([fakeTrack]) : fakeStream];
|
||||
log('Calling mockPC._ontrack with streams[0].getTracks()=' + evt.streams[0].getTracks().length);
|
||||
mockPC._ontrack(evt);
|
||||
log('ontrack callback completed');
|
||||
} else {
|
||||
log('WARNING: remote-track but no mockPC or no ontrack handler!');
|
||||
}
|
||||
break;
|
||||
case 'connection-state':
|
||||
if (mockPC) {
|
||||
mockPC._connectionState = msg.data;
|
||||
log('Pion connection state:', msg.data);
|
||||
if (msg.data === 'connected') {
|
||||
if (typeof AndroidBridge !== 'undefined' && AndroidBridge.onTunnelReady) {
|
||||
AndroidBridge.onTunnelReady();
|
||||
}
|
||||
}
|
||||
if (mockPC._onconnectionstatechange) {
|
||||
mockPC._onconnectionstatechange(new Event('connectionstatechange'));
|
||||
}
|
||||
mockPC._listeners.connectionstatechange.forEach(function(fn) {
|
||||
fn(new Event('connectionstatechange'));
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
function MockPeerConnection(config) {
|
||||
this._config = config;
|
||||
this._connectionState = 'new';
|
||||
this._signalingState = 'stable';
|
||||
this._iceConnectionState = 'new';
|
||||
this._iceGatheringState = 'new';
|
||||
this._localDescription = null;
|
||||
this._remoteDescription = null;
|
||||
this._senders = [];
|
||||
this._receivers = [];
|
||||
this._onicecandidate = null;
|
||||
this._onconnectionstatechange = null;
|
||||
this._ontrack = null;
|
||||
this._ondatachannel = null;
|
||||
this._listeners = {
|
||||
connectionstatechange: [],
|
||||
icecandidate: [],
|
||||
track: [],
|
||||
datachannel: [],
|
||||
iceconnectionstatechange: [],
|
||||
icegatheringstatechange: [],
|
||||
signalingstatechange: [],
|
||||
negotiationneeded: []
|
||||
};
|
||||
|
||||
if (config && config.iceServers) {
|
||||
var servers = config.iceServers.map(function(s) {
|
||||
return {
|
||||
urls: Array.isArray(s.urls) ? s.urls : (s.urls ? [s.urls] : []),
|
||||
username: s.username || '',
|
||||
credential: s.credential || ''
|
||||
};
|
||||
});
|
||||
sendToPion('ice-servers', servers);
|
||||
}
|
||||
|
||||
mockPC = this;
|
||||
if (!pionWS) connectPion();
|
||||
log('MockPC created');
|
||||
}
|
||||
|
||||
MockPeerConnection.prototype = {
|
||||
get connectionState() { return this._connectionState; },
|
||||
get signalingState() { return this._signalingState; },
|
||||
get iceConnectionState() { return this._iceConnectionState; },
|
||||
get iceGatheringState() { return this._iceGatheringState; },
|
||||
get localDescription() { return this._localDescription; },
|
||||
get remoteDescription() { return this._remoteDescription; },
|
||||
set onicecandidate(fn) { this._onicecandidate = fn; },
|
||||
get onicecandidate() { return this._onicecandidate; },
|
||||
set onconnectionstatechange(fn) { this._onconnectionstatechange = fn; },
|
||||
get onconnectionstatechange() { return this._onconnectionstatechange; },
|
||||
set ontrack(fn) { log('MockPC.ontrack SET by caller'); this._ontrack = fn; },
|
||||
get ontrack() { return this._ontrack; },
|
||||
set ondatachannel(fn) { this._ondatachannel = fn; },
|
||||
get ondatachannel() { return this._ondatachannel; },
|
||||
set oniceconnectionstatechange(fn) { this._oniceconnectionstatechange = fn; },
|
||||
get oniceconnectionstatechange() { return this._oniceconnectionstatechange; },
|
||||
set onicegatheringstatechange(fn) { this._onicegatheringstatechange = fn; },
|
||||
get onicegatheringstatechange() { return this._onicegatheringstatechange; },
|
||||
set onsignalingstatechange(fn) { this._onsignalingstatechange = fn; },
|
||||
get onsignalingstatechange() { return this._onsignalingstatechange; },
|
||||
set onnegotiationneeded(fn) { this._onnegotiationneeded = fn; },
|
||||
get onnegotiationneeded() { return this._onnegotiationneeded; },
|
||||
addEventListener: function(type, fn) {
|
||||
if (this._listeners[type]) this._listeners[type].push(fn);
|
||||
},
|
||||
removeEventListener: function(type, fn) {
|
||||
if (this._listeners[type]) this._listeners[type] = this._listeners[type].filter(function(f) { return f !== fn; });
|
||||
},
|
||||
dispatchEvent: function(event) {
|
||||
var type = event.type;
|
||||
if (this._listeners[type]) this._listeners[type].forEach(function(fn) { fn(event); });
|
||||
var handler = this['on' + type];
|
||||
if (handler) handler(event);
|
||||
},
|
||||
createOffer: function(options) {
|
||||
log('MockPC.createOffer');
|
||||
return requestPion('create-offer', options || {}).then(function(sdp) {
|
||||
log('MockPC.createOffer resolved');
|
||||
return new RTCSessionDescription(sdp);
|
||||
});
|
||||
},
|
||||
createAnswer: function(options) {
|
||||
log('MockPC.createAnswer');
|
||||
return requestPion('create-answer', options || {}).then(function(sdp) {
|
||||
log('MockPC.createAnswer resolved');
|
||||
return new RTCSessionDescription(sdp);
|
||||
});
|
||||
},
|
||||
setLocalDescription: function(desc) {
|
||||
this._localDescription = desc;
|
||||
var oldState = this._signalingState;
|
||||
this._signalingState = desc.type === 'offer' ? 'have-local-offer' : 'stable';
|
||||
log('MockPC.setLocalDescription:', desc.type);
|
||||
sendToPion('set-local-description', { type: desc.type, sdp: desc.sdp });
|
||||
var self = this;
|
||||
if (oldState !== this._signalingState) {
|
||||
setTimeout(function() {
|
||||
if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange'));
|
||||
self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); });
|
||||
}, 0);
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
setRemoteDescription: function(desc) {
|
||||
this._remoteDescription = desc;
|
||||
var oldState = this._signalingState;
|
||||
this._signalingState = desc.type === 'offer' ? 'have-remote-offer' : 'stable';
|
||||
log('MockPC.setRemoteDescription:', desc.type);
|
||||
var self = this;
|
||||
return requestPion('set-remote-description', { type: desc.type, sdp: desc.sdp }).then(function() {
|
||||
if (oldState !== self._signalingState) {
|
||||
if (self._onsignalingstatechange) self._onsignalingstatechange(new Event('signalingstatechange'));
|
||||
self._listeners.signalingstatechange.forEach(function(fn) { fn(new Event('signalingstatechange')); });
|
||||
}
|
||||
});
|
||||
},
|
||||
addIceCandidate: function(candidate) {
|
||||
if (candidate && candidate.candidate) {
|
||||
sendToPion('add-ice-candidate', { candidate: candidate.candidate, sdpMid: candidate.sdpMid, sdpMLineIndex: candidate.sdpMLineIndex });
|
||||
}
|
||||
return Promise.resolve();
|
||||
},
|
||||
addTrack: function(track, stream) {
|
||||
var sender = { track: track, replaceTrack: function(t) { this.track = t; return Promise.resolve(); }, getParameters: function() { return { encodings: [{}] }; }, setParameters: function() { return Promise.resolve(); } };
|
||||
this._senders.push(sender);
|
||||
sendToPion('add-track', { kind: track.kind });
|
||||
return sender;
|
||||
},
|
||||
addTransceiver: function(trackOrKind, init) {
|
||||
var kind = typeof trackOrKind === 'string' ? trackOrKind : trackOrKind.kind;
|
||||
var sender = { track: typeof trackOrKind === 'string' ? null : trackOrKind, replaceTrack: function(t) { this.track = t; return Promise.resolve(); }, getParameters: function() { return { encodings: [{}] }; }, setParameters: function() { return Promise.resolve(); } };
|
||||
var receiver = { track: { kind: kind, readyState: 'live', enabled: true, muted: true, id: 'mock-' + kind, addEventListener: function() {}, removeEventListener: function() {} } };
|
||||
var transceiver = { sender: sender, receiver: receiver, direction: (init && init.direction) || 'sendrecv', setDirection: function(d) { this.direction = d; }, mid: null, stopped: false, stop: function() { this.stopped = true; } };
|
||||
this._senders.push(sender);
|
||||
this._receivers.push(receiver);
|
||||
return transceiver;
|
||||
},
|
||||
removeTrack: function(sender) {
|
||||
this._senders = this._senders.filter(function(s) { return s !== sender; });
|
||||
},
|
||||
getSenders: function() { return this._senders; },
|
||||
getReceivers: function() { return this._receivers; },
|
||||
getTransceivers: function() { return []; },
|
||||
getStats: function() { return Promise.resolve(new Map()); },
|
||||
getConfiguration: function() { return this._config || {}; },
|
||||
createDataChannel: function(label, opts) {
|
||||
log('MockPC.createDataChannel:', label);
|
||||
sendToPion('create-data-channel', { label: label, opts: opts });
|
||||
var dc = {
|
||||
label: label,
|
||||
id: opts && opts.id != null ? opts.id : null,
|
||||
readyState: 'connecting',
|
||||
binaryType: 'arraybuffer',
|
||||
bufferedAmount: 0,
|
||||
onopen: null, onclose: null, onmessage: null, onerror: null,
|
||||
send: function() {},
|
||||
close: function() { this.readyState = 'closed'; },
|
||||
addEventListener: function() {},
|
||||
removeEventListener: function() {}
|
||||
};
|
||||
return dc;
|
||||
},
|
||||
close: function() {
|
||||
this._connectionState = 'closed';
|
||||
this._signalingState = 'closed';
|
||||
sendToPion('close', {});
|
||||
log('MockPC.close');
|
||||
},
|
||||
restartIce: function() {}
|
||||
};
|
||||
|
||||
var OrigPC = window.RTCPeerConnection;
|
||||
window.RTCPeerConnection = function(config) {
|
||||
log('RTCPeerConnection intercepted -> MockPC');
|
||||
return new MockPeerConnection(config);
|
||||
};
|
||||
Object.keys(OrigPC).forEach(function(key) {
|
||||
window.RTCPeerConnection[key] = OrigPC[key];
|
||||
});
|
||||
window.RTCPeerConnection.prototype = OrigPC.prototype;
|
||||
window.RTCPeerConnection.generateCertificate = OrigPC.generateCertificate;
|
||||
|
||||
var origStringify = JSON.stringify;
|
||||
JSON.stringify = function(obj) {
|
||||
if (obj && obj.command && typeof obj.sequence === 'number') {
|
||||
if (obj.command === 'change-media-settings' && obj.mediaSettings) {
|
||||
obj.mediaSettings.isVideoEnabled = true;
|
||||
log('Forced isVideoEnabled=true in change-media-settings');
|
||||
}
|
||||
try { handleOutgoing(obj); } catch(e) {}
|
||||
}
|
||||
var result = origStringify.apply(JSON, arguments);
|
||||
return result;
|
||||
};
|
||||
|
||||
var origParse = JSON.parse;
|
||||
JSON.parse = function(str) {
|
||||
var result = origParse.apply(JSON, arguments);
|
||||
if (result && (result.type === 'notification' || result.type === 'response')) {
|
||||
try { handleIncoming(result); } catch(e) {}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
function handleOutgoing(msg) {
|
||||
if (msg.command === 'transmit-data') {
|
||||
if (msg.data && msg.data.sdp) {
|
||||
log('VK sending SDP:', msg.data.sdp.type);
|
||||
}
|
||||
if (msg.data && msg.data.candidate) {
|
||||
log('VK sending ICE candidate');
|
||||
}
|
||||
}
|
||||
if (msg.command === 'change-media-settings') {
|
||||
log('VK outgoing change-media-settings:', JSON.stringify(msg.mediaSettings));
|
||||
}
|
||||
if (msg.command === 'join-conversation' || msg.command === 'start-conversation') {
|
||||
log('VK outgoing ' + msg.command + ': mediaSettings=' + JSON.stringify(msg.mediaSettings));
|
||||
}
|
||||
}
|
||||
|
||||
function handleIncoming(msg) {
|
||||
if (msg.type === 'notification') {
|
||||
if (msg.notification === 'connection' && msg.conversationParams && msg.conversationParams.turn) {
|
||||
var turn = msg.conversationParams.turn;
|
||||
log('TURN servers:', turn.urls.length);
|
||||
sendToPion('ice-servers', [{
|
||||
urls: turn.urls,
|
||||
username: turn.username,
|
||||
credential: turn.credential
|
||||
}]);
|
||||
}
|
||||
if (msg.notification === 'transmitted-data' && msg.data) {
|
||||
if (msg.data.candidate) {
|
||||
sendToPion('remote-ice-candidate', msg.data.candidate);
|
||||
}
|
||||
if (msg.data.sdp) {
|
||||
log('VK incoming SDP: type=' + msg.data.sdp.type);
|
||||
}
|
||||
}
|
||||
if (msg.notification === 'remote-media-settings' || msg.notification === 'media-settings' || msg.notification === 'media-settings-changed') {
|
||||
log('VK media-settings notification:', JSON.stringify(msg).substring(0, 300));
|
||||
}
|
||||
if (msg.notification === 'participant-added' || msg.notification === 'participant-removed') {
|
||||
log('VK participant event: ' + msg.notification);
|
||||
}
|
||||
}
|
||||
if (msg.type === 'response') {
|
||||
if (msg.data && msg.data.mediaSettings) {
|
||||
log('VK response mediaSettings: isVideoEnabled=' + msg.data.mediaSettings.isVideoEnabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.__hook = { log: log };
|
||||
log('Signaling proxy hook installed (MockPC mode)');
|
||||
})();
|
||||
@@ -1,16 +1,21 @@
|
||||
package bypass.whitelist
|
||||
|
||||
import android.util.Log
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.net.VpnService
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.webkit.*
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.Button
|
||||
import android.widget.EditText
|
||||
import android.widget.ImageButton
|
||||
import android.widget.Spinner
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.activity.enableEdgeToEdge
|
||||
@@ -18,36 +23,34 @@ import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.view.ViewCompat
|
||||
import androidx.core.view.WindowInsetsCompat
|
||||
import mobile.Mobile
|
||||
import mobile.LogCallback
|
||||
import mobile.Mobile
|
||||
import java.io.File
|
||||
|
||||
class MainActivity : AppCompatActivity() {
|
||||
|
||||
private var tunnelMode = TunnelMode.DC
|
||||
private var pionProcess: Process? = null
|
||||
|
||||
private lateinit var webView: WebView
|
||||
private lateinit var logView: TextView
|
||||
private lateinit var urlInput: EditText
|
||||
|
||||
private val vpnPrepLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) {}
|
||||
|
||||
private val vpnLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult()
|
||||
) { result ->
|
||||
if (result.resultCode == RESULT_OK) {
|
||||
startVpnService()
|
||||
} else {
|
||||
appendLog("VPN permission denied")
|
||||
}
|
||||
if (result.resultCode == RESULT_OK) startVpnService()
|
||||
else appendLog("VPN permission denied")
|
||||
}
|
||||
|
||||
private val hookVk by lazy {
|
||||
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
|
||||
}
|
||||
private val hookVk by lazy { assets.open("joiner-vk.js").bufferedReader().readText() }
|
||||
private val hookTelemost by lazy { assets.open("joiner-telemost.js").bufferedReader().readText() }
|
||||
private val hookPionVk by lazy { assets.open("pion-vk.js").bufferedReader().readText() }
|
||||
private val hookPionTelemost by lazy { assets.open("pion-telemost.js").bufferedReader().readText() }
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@@ -65,12 +68,14 @@ class MainActivity : AppCompatActivity() {
|
||||
webView = findViewById(R.id.webView)
|
||||
|
||||
setupWebView()
|
||||
startRelay()
|
||||
setupModeSpinner()
|
||||
|
||||
val goButton = findViewById<Button>(R.id.goButton)
|
||||
goButton.setOnClickListener {
|
||||
val url = urlInput.text.toString().trim()
|
||||
if (url.isNotEmpty()) {
|
||||
stopRelay()
|
||||
startRelay()
|
||||
appendLog("Loading: $url")
|
||||
webView.loadUrl(url)
|
||||
}
|
||||
@@ -82,17 +87,57 @@ class MainActivity : AppCompatActivity() {
|
||||
Toast.makeText(this, "Logs copied", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
VpnService.prepare(this)?.let { vpnPrepLauncher.launch(it) }
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU &&
|
||||
checkSelfPermission(android.Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) {
|
||||
requestPermissions(arrayOf(android.Manifest.permission.POST_NOTIFICATIONS), 0)
|
||||
}
|
||||
|
||||
if (CALL_LINK.isNotEmpty()) {
|
||||
urlInput.setText(CALL_LINK)
|
||||
goButton.performClick()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateVpnStatus(status: VpnStatus) {
|
||||
TunnelVpnService.instance?.updateStatus(status)
|
||||
override fun onDestroy() {
|
||||
stopRelay()
|
||||
TunnelVpnService.instance?.stopSelf()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
private fun setupModeSpinner() {
|
||||
val spinner = findViewById<Spinner>(R.id.modeSpinner)
|
||||
val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, TunnelMode.entries.map { it.label })
|
||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
|
||||
spinner.adapter = adapter
|
||||
spinner.setSelection(TunnelMode.entries.indexOf(tunnelMode))
|
||||
spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
var init = true
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: android.view.View?, pos: Int, id: Long) {
|
||||
if (init) { init = false; return }
|
||||
tunnelMode = TunnelMode.entries[pos]
|
||||
appendLog("Mode: ${tunnelMode.label}")
|
||||
stopRelay()
|
||||
startRelay()
|
||||
}
|
||||
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||
}
|
||||
}
|
||||
|
||||
private fun startRelay() {
|
||||
Log.d("RELAY", "startRelay mode=${tunnelMode.label}")
|
||||
if (tunnelMode.isPion) startPionRelay() else startDcRelay()
|
||||
}
|
||||
|
||||
private fun stopRelay() {
|
||||
pionProcess?.let {
|
||||
it.destroy()
|
||||
it.waitFor()
|
||||
}
|
||||
pionProcess = null
|
||||
}
|
||||
|
||||
private fun startDcRelay() {
|
||||
val cb = LogCallback { msg ->
|
||||
appendLog(msg)
|
||||
if (msg.contains("browser connected")) updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
@@ -105,7 +150,60 @@ class MainActivity : AppCompatActivity() {
|
||||
appendLog("Relay error: ${e.message}")
|
||||
}
|
||||
}.start()
|
||||
appendLog("Relay started (SOCKS5 :1080, WS :9000)")
|
||||
appendLog("Relay started DC mode (SOCKS5 :1080, WS :9000)")
|
||||
}
|
||||
|
||||
private fun startPionRelay() {
|
||||
val relayBin = File(applicationInfo.nativeLibraryDir, "librelay.so")
|
||||
if (!relayBin.exists()) {
|
||||
appendLog("Pion relay binary not found")
|
||||
return
|
||||
}
|
||||
Thread {
|
||||
try {
|
||||
val isTelemost = urlInput.text.toString().contains("telemost")
|
||||
val mode = tunnelMode.relayMode(isTelemost)
|
||||
val pb = ProcessBuilder(
|
||||
relayBin.absolutePath, "--mode", mode, "--ws-port", "9001", "--socks-port", "1080"
|
||||
)
|
||||
pb.redirectErrorStream(true)
|
||||
val proc = pb.start()
|
||||
pionProcess = proc
|
||||
appendLog("Pion relay started mode=$mode (signaling :9001, SOCKS5 :1080)")
|
||||
proc.inputStream.bufferedReader().forEachLine { line ->
|
||||
Log.d("RELAY", line)
|
||||
appendLog(line)
|
||||
if (line.contains("CONNECTED")) updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
else if (line.contains("session cleaned up")) updateVpnStatus(VpnStatus.TUNNEL_LOST)
|
||||
}
|
||||
appendLog("Pion relay exited: ${proc.exitValue()}")
|
||||
} catch (e: Exception) {
|
||||
Log.e("RELAY", "Pion relay error", e)
|
||||
appendLog("Pion relay error: ${e.message}")
|
||||
}
|
||||
}.start()
|
||||
}
|
||||
|
||||
private fun updateVpnStatus(status: VpnStatus) {
|
||||
TunnelVpnService.instance?.updateStatus(status)
|
||||
}
|
||||
|
||||
private fun requestVpn() {
|
||||
val intent = VpnService.prepare(this)
|
||||
if (intent != null) vpnLauncher.launch(intent) else startVpnService()
|
||||
}
|
||||
|
||||
private fun startVpnService() {
|
||||
startService(Intent(this, TunnelVpnService::class.java))
|
||||
appendLog("VPN started")
|
||||
updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
}
|
||||
|
||||
private fun hookForUrl(url: String): String {
|
||||
if (tunnelMode.isPion) {
|
||||
return if (url.contains("telemost.yandex")) hookPionTelemost else hookPionVk
|
||||
}
|
||||
return if (url.contains("telemost.yandex")) hookTelemost else hookVk
|
||||
}
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@@ -137,14 +235,16 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.d("HOOK", text)
|
||||
if (text.contains("[HOOK]")) {
|
||||
appendLog(text)
|
||||
if (text.contains("CALL CONNECTED")) updateVpnStatus(VpnStatus.CALL_CONNECTED)
|
||||
else if (text.contains("DataChannel open")) updateVpnStatus(VpnStatus.DATACHANNEL_OPEN)
|
||||
else if (text.contains("DataChannel closed")) updateVpnStatus(VpnStatus.DATACHANNEL_LOST)
|
||||
else if (text.contains("WebSocket connected")) updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
else if (text.contains("WebSocket disconnected")) updateVpnStatus(VpnStatus.TUNNEL_LOST)
|
||||
else if (text.contains("Connection state: connecting")) updateVpnStatus(VpnStatus.CONNECTING)
|
||||
else if (text.contains("Connection state: disconnected")) updateVpnStatus(VpnStatus.CALL_DISCONNECTED)
|
||||
else if (text.contains("Connection state: failed")) updateVpnStatus(VpnStatus.CALL_FAILED)
|
||||
when {
|
||||
text.contains("CALL CONNECTED") -> updateVpnStatus(VpnStatus.CALL_CONNECTED)
|
||||
text.contains("DataChannel open") -> updateVpnStatus(VpnStatus.DATACHANNEL_OPEN)
|
||||
text.contains("DataChannel closed") -> updateVpnStatus(VpnStatus.DATACHANNEL_LOST)
|
||||
text.contains("WebSocket connected") -> updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
text.contains("WebSocket disconnected") -> updateVpnStatus(VpnStatus.TUNNEL_LOST)
|
||||
text.contains("Connection state: connecting") -> updateVpnStatus(VpnStatus.CONNECTING)
|
||||
text.contains("Connection state: disconnected") -> updateVpnStatus(VpnStatus.CALL_DISCONNECTED)
|
||||
text.contains("Connection state: failed") -> updateVpnStatus(VpnStatus.CALL_FAILED)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
@@ -153,31 +253,28 @@ class MainActivity : AppCompatActivity() {
|
||||
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 {
|
||||
if (!url.contains("telemost.yandex.ru/j/") || request.method != "GET") return null
|
||||
return 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)) {
|
||||
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(
|
||||
WebResourceResponse(
|
||||
conn.contentType?.split(";")?.firstOrNull() ?: "text/html",
|
||||
"utf-8",
|
||||
conn.responseCode,
|
||||
conn.responseMessage ?: "OK",
|
||||
headers,
|
||||
conn.inputStream
|
||||
"utf-8", conn.responseCode, conn.responseMessage ?: "OK",
|
||||
headers, conn.inputStream
|
||||
)
|
||||
} catch (e: Exception) {
|
||||
return null
|
||||
}
|
||||
} catch (_: Exception) { null }
|
||||
}
|
||||
|
||||
override fun onPageStarted(view: WebView, url: String, favicon: android.graphics.Bitmap?) {
|
||||
view.evaluateJavascript("""(function(){
|
||||
var oac=window.AudioContext||window.webkitAudioContext;
|
||||
@@ -188,18 +285,17 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
||||
if(window.webkitAudioContext)window.webkitAudioContext=nac}
|
||||
})()""", null)
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView, url: String) {
|
||||
val hook = hookForUrl(url)
|
||||
appendLog("Page loaded, injecting hook for $url")
|
||||
view.evaluateJavascript(hook, null)
|
||||
view.evaluateJavascript(hookForUrl(url), null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun appendLog(msg: String) {
|
||||
runOnUiThread {
|
||||
val clean = msg.replace("[HOOK] ", "")
|
||||
logView.append("$clean\n")
|
||||
logView.append("${msg.replace("[HOOK] ", "")}\n")
|
||||
val scrollAmount = logView.layout?.let {
|
||||
it.getLineTop(logView.lineCount) - logView.height
|
||||
} ?: 0
|
||||
@@ -207,29 +303,35 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestVpn() {
|
||||
val intent = VpnService.prepare(this)
|
||||
if (intent != null) {
|
||||
vpnLauncher.launch(intent)
|
||||
} else {
|
||||
startVpnService()
|
||||
private fun getLocalIPAddress(): String {
|
||||
try {
|
||||
val cm = getSystemService(CONNECTIVITY_SERVICE) as android.net.ConnectivityManager
|
||||
val network = cm.activeNetwork ?: return ""
|
||||
val props = cm.getLinkProperties(network) ?: return ""
|
||||
for (addr in props.linkAddresses) {
|
||||
val ip = addr.address
|
||||
if (!ip.isLoopbackAddress && ip is java.net.Inet4Address) {
|
||||
return ip.hostAddress ?: ""
|
||||
}
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.e("RELAY", "getLocalIPAddress error", e)
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
private fun startVpnService() {
|
||||
val intent = Intent(this, TunnelVpnService::class.java)
|
||||
startService(intent)
|
||||
appendLog("VPN started")
|
||||
updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
|
||||
}
|
||||
|
||||
|
||||
@Suppress("unused")
|
||||
inner class JsBridge {
|
||||
@JavascriptInterface
|
||||
fun log(msg: String) {
|
||||
appendLog(msg)
|
||||
}
|
||||
fun log(msg: String) = appendLog(msg)
|
||||
|
||||
@JavascriptInterface
|
||||
fun getLocalIP(): String = getLocalIPAddress()
|
||||
|
||||
@JavascriptInterface
|
||||
fun resolveHost(hostname: String): String = try {
|
||||
java.net.InetAddress.getByName(hostname).hostAddress ?: ""
|
||||
} catch (_: Exception) { "" }
|
||||
|
||||
@JavascriptInterface
|
||||
fun onTunnelReady() {
|
||||
@@ -239,6 +341,17 @@ if(oac){var nac=function(){var c=new oac();c.suspend();
|
||||
}
|
||||
}
|
||||
|
||||
private enum class TunnelMode(val label: String, val relayArg: String, val isPion: Boolean) {
|
||||
DC("DC", "joiner", false),
|
||||
PION_VIDEO("Pion Video", "video", true);
|
||||
|
||||
fun relayMode(isTelemost: Boolean): String {
|
||||
if (!isPion) return "joiner"
|
||||
val platform = if (isTelemost) "telemost" else "vk"
|
||||
return "$platform-$relayArg-joiner"
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val CALL_LINK = "" // Open call page on app start
|
||||
}
|
||||
|
||||
@@ -52,6 +52,28 @@ class TunnelVpnService : VpnService() {
|
||||
return START_STICKY
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
stop()
|
||||
super.onDestroy()
|
||||
}
|
||||
|
||||
fun updateStatus(status: VpnStatus) {
|
||||
val nm = getSystemService(NotificationManager::class.java)
|
||||
nm.notify(NOTIFICATION_ID, buildNotification(status.label))
|
||||
}
|
||||
|
||||
private fun startForegroundNotification() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(
|
||||
CHANNEL_ID, "VPN Tunnel", NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
val nm = getSystemService(NotificationManager::class.java)
|
||||
nm.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
startForeground(NOTIFICATION_ID, buildNotification(VpnStatus.STARTING.label))
|
||||
}
|
||||
|
||||
private fun start() {
|
||||
if (isRunning) return
|
||||
|
||||
@@ -134,26 +156,4 @@ class TunnelVpnService : VpnService() {
|
||||
.addAction(Notification.Action.Builder(null, "Disconnect", stopPending).build())
|
||||
.build()
|
||||
}
|
||||
|
||||
fun updateStatus(status: VpnStatus) {
|
||||
val nm = getSystemService(NotificationManager::class.java)
|
||||
nm.notify(NOTIFICATION_ID, buildNotification(status.label))
|
||||
}
|
||||
|
||||
private fun startForegroundNotification() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
val channel = NotificationChannel(
|
||||
CHANNEL_ID, "VPN Tunnel", NotificationManager.IMPORTANCE_DEFAULT
|
||||
)
|
||||
val nm = getSystemService(NotificationManager::class.java)
|
||||
nm.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
startForeground(NOTIFICATION_ID, buildNotification(VpnStatus.STARTING.label))
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
stop()
|
||||
super.onDestroy()
|
||||
}
|
||||
}
|
||||
BIN
Binary file not shown.
Binary file not shown.
@@ -17,11 +17,17 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:hint="Paste VK call link"
|
||||
android:hint="Paste call link"
|
||||
android:inputType="textUri"
|
||||
android:singleLine="true"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/modeSpinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:minWidth="100dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/goButton"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
Reference in new issue
Block a user