This commit is contained in:
kulikov committed 2026-03-21 16:44:42 +01:00
1 parent a92a76b7ae
commit 61ef2aa2bd
86 files changed
+7230 -327

No files matched your search

@@ -0,0 +1,245 @@
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.net.VpnService
import android.os.Bundle
import android.webkit.*
import android.widget.Button
import android.widget.EditText
import android.widget.ImageButton
import android.widget.TextView
import android.widget.Toast
import androidx.activity.enableEdgeToEdge
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
class MainActivity : AppCompatActivity() {
private lateinit var webView: WebView
private lateinit var logView: TextView
private lateinit var urlInput: EditText
private val vpnLauncher = registerForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { result ->
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
}
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
logView = findViewById(R.id.logView)
urlInput = findViewById(R.id.urlInput)
webView = findViewById(R.id.webView)
setupWebView()
startRelay()
val goButton = findViewById<Button>(R.id.goButton)
goButton.setOnClickListener {
val url = urlInput.text.toString().trim()
if (url.isNotEmpty()) {
appendLog("Loading: $url")
webView.loadUrl(url)
}
}
findViewById<ImageButton>(R.id.copyLogsButton).setOnClickListener {
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()
}
}
private fun updateVpnStatus(status: VpnStatus) {
TunnelVpnService.instance?.updateStatus(status)
}
private fun startRelay() {
val cb = LogCallback { msg ->
appendLog(msg)
if (msg.contains("browser connected")) updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
else if (msg.contains("ws read error")) updateVpnStatus(VpnStatus.TUNNEL_LOST)
}
Thread {
try {
Mobile.startJoiner(9000, 1080, cb)
} catch (e: Exception) {
appendLog("Relay error: ${e.message}")
}
}.start()
appendLog("Relay started (SOCKS5 :1080, WS :9000)")
}
@SuppressLint("SetJavaScriptEnabled")
private fun setupWebView() {
webView.settings.apply {
javaScriptEnabled = true
domStorageEnabled = true
mediaPlaybackRequiresUserGesture = false
allowContentAccess = true
allowFileAccess = true
databaseEnabled = true
setSupportMultipleWindows(false)
useWideViewPort = true
loadWithOverviewMode = true
builtInZoomControls = true
displayZoomControls = false
userAgentString = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36"
}
webView.addJavascriptInterface(JsBridge(), "AndroidBridge")
webView.webChromeClient = object : WebChromeClient() {
override fun onPermissionRequest(request: PermissionRequest) {
runOnUiThread { request.grant(request.resources) }
}
override fun onConsoleMessage(msg: ConsoleMessage): Boolean {
val text = msg.message()
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)
}
return true
}
}
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?) {
view.evaluateJavascript("""(function(){
var oac=window.AudioContext||window.webkitAudioContext;
if(oac){var nac=function(){var c=new oac();c.suspend();
c.resume=function(){return Promise.resolve()};
return c};
nac.prototype=oac.prototype;window.AudioContext=nac;
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)
}
}
}
private fun appendLog(msg: String) {
runOnUiThread {
val clean = msg.replace("[HOOK] ", "")
logView.append("$clean\n")
val scrollAmount = logView.layout?.let {
it.getLineTop(logView.lineCount) - logView.height
} ?: 0
if (scrollAmount > 0) logView.scrollTo(0, scrollAmount)
}
}
private fun requestVpn() {
val intent = VpnService.prepare(this)
if (intent != null) {
vpnLauncher.launch(intent)
} else {
startVpnService()
}
}
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)
}
@JavascriptInterface
fun onTunnelReady() {
appendLog("Tunnel ready, starting VPN...")
updateVpnStatus(VpnStatus.TUNNEL_ACTIVE)
runOnUiThread { requestVpn() }
}
}
companion object {
private const val CALL_LINK = "" // Open call page on app start
}
}
@@ -0,0 +1,159 @@
package bypass.whitelist
import android.app.Notification
import android.app.NotificationChannel
import android.app.NotificationManager
import android.app.PendingIntent
import android.content.Intent
import android.net.VpnService
import android.os.Build
import android.os.ParcelFileDescriptor
import android.util.Log
import mobile.Mobile
enum class VpnStatus(val label: String) {
STARTING("Starting..."),
CONNECTING("Connecting..."),
CALL_CONNECTED("Call connected"),
DATACHANNEL_OPEN("DataChannel open"),
DATACHANNEL_LOST("DataChannel lost"),
TUNNEL_ACTIVE("Tunnel active"),
TUNNEL_LOST("Tunnel lost, reconnecting..."),
CALL_DISCONNECTED("Call disconnected"),
CALL_FAILED("Call failed")
}
class TunnelVpnService : VpnService() {
companion object {
const val TAG = "TunnelVPN"
const val SOCKS_PORT = 1080
const val MTU = 1500
const val CHANNEL_ID = "vpn_channel"
const val NOTIFICATION_ID = 1
const val ACTION_STOP = "bypass.whitelist.STOP_VPN"
var isRunning = false
var instance: TunnelVpnService? = null
}
private var vpnFd: ParcelFileDescriptor? = null
override fun onCreate() {
super.onCreate()
instance = this
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent?.action == ACTION_STOP) {
stop()
return START_NOT_STICKY
}
start()
return START_STICKY
}
private fun start() {
if (isRunning) return
startForegroundNotification()
val builder = Builder()
.setSession("WhitelistBypass")
.addAddress("10.0.0.2", 32)
.addRoute("0.0.0.0", 0)
.addDnsServer("8.8.8.8")
.addDnsServer("8.8.4.4")
.setMtu(MTU)
try {
builder.addDisallowedApplication(packageName)
} catch (e: Exception) {
Log.e(TAG, "Cannot exclude self: ${e.message}")
}
vpnFd = builder.establish()
if (vpnFd == null) {
Log.e(TAG, "Failed to establish VPN")
return
}
isRunning = true
val fd = vpnFd!!.detachFd()
vpnFd = null
Log.i(TAG, "VPN established, fd=$fd")
updateStatus(VpnStatus.TUNNEL_ACTIVE)
Thread {
try {
Mobile.startTun2Socks(fd.toLong(), MTU.toLong(), SOCKS_PORT.toLong())
} catch (e: Exception) {
Log.e(TAG, "tun2socks error: ${e.message}")
isRunning = false
}
}.start()
}
private fun stop() {
isRunning = false
try {
Mobile.stopTun2Socks()
} catch (e: Exception) {
Log.e(TAG, "tun2socks stop error: ${e.message}")
}
vpnFd = null
@Suppress("DEPRECATION")
stopForeground(true)
stopSelf()
}
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 {
action = ACTION_STOP
}
val stopPending = PendingIntent.getService(
this, 0, stopIntent, PendingIntent.FLAG_IMMUTABLE
)
@Suppress("DEPRECATION")
val builder = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
Notification.Builder(this, CHANNEL_ID)
} else {
Notification.Builder(this)
}
return builder
.setContentTitle("VPN active")
.setContentText(text)
.setSmallIcon(android.R.drawable.ic_lock_lock)
.setOngoing(true)
.setContentIntent(openPending)
.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()
}
}