This commit is contained in:
kulikov committed 2026-03-23 21:13:15 +01:00
1 parent 61ef2aa2bd
commit e8da07179a
32 files changed
+3633 -161

No files matched your search

@@ -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()
}
}