Compare commits

...
29 Commits
Author SHA1 Message Date
Kr328 b42d762fa0 update clash core 2020-05-14 21:33:29 +08:00
Kr328 f23e6e82b0 update tun2socket 2020-05-11 18:23:11 +08:00
Kr328 2af11c29a5 fix bypass private route comment 2020-05-03 22:43:44 +08:00
Kr328 b0bf57e715 reject all localhost traffic 2020-05-03 21:33:49 +08:00
Kr328 cdd0e3dd30 fix break connection 2020-05-03 00:51:51 +08:00
Kr328 5823955c71 update clash core 2020-05-03 00:50:34 +08:00
Kr328 714c9a554f break connection if set proxy for selector 2020-05-03 00:50:14 +08:00
Kr328 e621324b48 update clash core 2020-05-03 00:29:45 +08:00
Kr328 dfe1e7ecd9 exclude 127.0.0.0/8 from route table 2020-05-03 00:17:55 +08:00
Kr328 4c3380d822 update clash core & tun2socket 2020-04-29 13:22:36 +08:00
Kr328 1d68516cdb fix receivers & service connection leak 2020-04-24 00:49:03 +08:00
Kr328 821bb49914 update issue template 2020-04-23 19:33:28 +08:00
Kr328 c95993a629 fix crash on uploaded 2020-04-23 19:15:46 +08:00
Kr328 e6495f5e1f add uploaded feedback 2020-04-23 19:15:16 +08:00
Kr328 c104942b5f update version 2020-04-23 19:13:34 +08:00
Kr328 59835667aa add report logcat button 2020-04-23 19:04:51 +08:00
Kr328 8a98eea8fa improve core log 2020-04-23 18:52:23 +08:00
Kr328 3dc20b9e70 update issue template 2020-04-23 16:29:17 +08:00
Kr328 d8ab6fd755 update tun2socket version 2020-04-23 13:10:22 +08:00
Kr328 cc499a7897 improve package name modify 2020-04-23 12:14:05 +08:00
Kr328 76f5261b20 Revert "Fix tun start at second user"
This reverts commit 94a0282c
2020-04-23 11:08:36 +08:00
Kr328 6a506b761f update tun2socket 2020-04-23 11:06:50 +08:00
Kr328 fe966f9c5d Revert "Fix tun start at second user"
This reverts commit 94a0282c
2020-04-23 10:52:59 +08:00
Kr328 bcf7f793ec add stop tun on destroy & update version 2020-04-23 10:51:20 +08:00
Kr328 75de6ce041 add full crash logcat report 2020-04-23 00:12:07 +08:00
Kr328 4417a85ef7 update version 2020-04-23 00:09:24 +08:00
Kr328 9e0b67c04a add dump AndroidRuntime tag 2020-04-23 00:06:53 +08:00
Kr328 8cd203e7b0 detect vpn establish failure 2020-04-23 00:03:05 +08:00
Kr328 211160f7f8 Rename fields to let lint happy :) 2020-04-22 13:25:50 +08:00
26 changed files with 307 additions and 148 deletions

No files matched your search

+11 -3
View File
@@ -7,6 +7,10 @@ assignees: ''
---
<!-- Be sure to put a clear title after [BUG] in the text box above -->
<!-- Be sure to put a clear title after [BUG] in the text box above -->
<!-- Be sure to put a clear title after [BUG] in the text box above -->
**Describe the bug**
A clear and concise description of what the bug is.
@@ -23,9 +27,6 @@ A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Logs**
if applicable, add logs to help detect problem
**Device Info (please complete the following information):**
- Device: [e.g. Pixel 4]
@@ -41,3 +42,10 @@ if applicable, add logs to help detect problem
**Additional context**
Add any other context about the problem here.
<!--
*Logs*
if applicable, upload logs to help detect problem
`Open App` -> `Support` -> `Feedback` -> `Upload Logcat`
-->
@@ -7,6 +7,10 @@ assignees: ''
---
<!-- Be sure to put a clear title after [Feature Request] in the text box above -->
<!-- Be sure to put a clear title after [Feature Request] in the text box above -->
<!-- Be sure to put a clear title after [Feature Request] in the text box above -->
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
+11 -3
View File
@@ -7,6 +7,10 @@ assignees: ''
---
<!-- 请务必在上方文本框处 [BUG] 后填入清晰明了的标题 -->
<!-- 请务必在上方文本框处 [BUG] 后填入清晰明了的标题 -->
<!-- 请务必在上方文本框处 [BUG] 后填入清晰明了的标题 -->
**描述出现的错误**
请简洁的描述你遇到的错误
@@ -23,9 +27,6 @@ assignees: ''
**屏幕截图**
如果适用, 上传屏幕截图以帮助描述错误
**日志**
如果适用, 上传日志以帮助侦测错误
**设备信息 (请完成以下信息):**
- 机型: [例如: Pixel 4]
- 系统/ROM: [例如: MIUI 11]
@@ -39,3 +40,10 @@ assignees: ''
**附加信息**
其他的可能与改错误相关的信息
<!--
*日志*
如果适用, 上传日志以帮助侦测错误
`打开应用` -> `支持` -> `反馈` -> `上传日志`
-->
@@ -7,6 +7,10 @@ assignees: ''
---
<!-- 请务必在上方文本框处 [Feature Request] 后填入清晰明了的标题 -->
<!-- 请务必在上方文本框处 [Feature Request] 后填入清晰明了的标题 -->
<!-- 请务必在上方文本框处 [Feature Request] 后填入清晰明了的标题 -->
**功能描述**
请清晰的描述你想要的功能
+14 -1
View File
@@ -1,4 +1,5 @@
import java.util.*
import java.security.*
plugins {
id("com.android.application")
@@ -121,6 +122,18 @@ task("injectAppCenterKey") {
}
}
task("injectPackageNameBase64") {
doFirst {
val packageName = android.defaultConfig.applicationId ?: return@doFirst
val base64 = Base64.getEncoder().encodeToString(packageName.toByteArray(Charsets.UTF_8))
android.buildTypes.forEach {
it.buildConfigField("String", "PACKAGE_NAME_BASE64", "\"$base64\"")
}
}
}
afterEvaluate {
tasks["preBuild"].dependsOn(tasks["injectAppCenterKey"])
tasks["preBuild"].dependsOn(tasks["injectAppCenterKey"], tasks["injectPackageNameBase64"])
}
@@ -19,7 +19,6 @@ import java.io.File
class LogViewerActivity : BaseActivity() {
private val pauseMutex = Mutex()
private var pollingThread: Thread? = null
private val connection = object : ServiceConnection {
override fun onServiceDisconnected(name: ComponentName?) {
finish()
@@ -48,12 +47,6 @@ class LogViewerActivity : BaseActivity() {
startFileMode(file.toFile())
}
override fun onDestroy() {
super.onDestroy()
pollingThread?.interrupt()
}
override fun onStop() {
super.onStop()
@@ -78,6 +71,7 @@ class LogViewerActivity : BaseActivity() {
mainList.itemAnimator?.removeDuration = 100
stop.setOnClickListener {
unbindService(connection)
stopService(LogcatService::class.intent)
finish()
}
@@ -42,7 +42,7 @@ class MainApplication : Application() {
if (!report.stackTrace.contains("DeadObjectException"))
return mutableListOf()
val logcat = LogcatDumper.dump().joinToString(separator = "\n")
val logcat = LogcatDumper.dumpCrash()
return mutableListOf(
ErrorAttachmentLog.attachmentWithText(logcat, "logcat.txt")
@@ -4,9 +4,19 @@ import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.text.Html
import androidx.appcompat.app.AlertDialog
import com.github.kr328.clash.dump.LogcatDumper
import com.google.android.material.snackbar.Snackbar
import com.microsoft.appcenter.crashes.Crashes
import com.microsoft.appcenter.crashes.ingestion.models.ErrorAttachmentLog
import kotlinx.android.synthetic.main.activity_support.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class SupportActivity : BaseActivity() {
class UserRequestTrackException: Exception()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
@@ -46,6 +56,20 @@ class SupportActivity : BaseActivity() {
category(text = getString(R.string.feedback))
option(
title = getString(R.string.upload_logcat),
summary = getString(R.string.upload_logcat_summary)
) {
onClick {
AlertDialog.Builder(this@SupportActivity)
.setTitle(R.string.upload_logcat)
.setMessage(R.string.upload_logcat_warn)
.setNegativeButton(R.string.cancel) {_, _ -> }
.setPositiveButton(R.string.ok) {_, _ -> upload() }
.show()
}
}
option(
title = getString(R.string.github_issues),
summary = getString(R.string.github_issues_url)
@@ -77,4 +101,19 @@ class SupportActivity : BaseActivity() {
}
}
}
private fun upload() {
launch {
withContext(Dispatchers.IO) {
val attachment = ErrorAttachmentLog
.attachmentWithText(LogcatDumper.dumpAll(), "logcat.txt")
Crashes.trackError(UserRequestTrackException(), null, listOf(attachment))
}
withContext(Dispatchers.Main) {
Snackbar.make(rootView, R.string.uploaded, Snackbar.LENGTH_LONG).show()
}
}
}
}
@@ -1,34 +1,37 @@
package com.github.kr328.clash.dump
object LogcatDumper {
fun dump(): List<String> {
fun dumpCrash(): String {
return try {
val process =
Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-s", "-v", "raw", "Go"))
Runtime.getRuntime().exec(arrayOf("logcat", "-d", "-s", "Go", "AndroidRuntime", "DEBUG"))
val result = process.inputStream.bufferedReader().useLines {
var list = mutableListOf<String>()
var capture = false
it.forEach { line ->
if (line.startsWith("panic")) {
capture = true
list = mutableListOf()
}
if (capture)
list.add(line)
}
list
val result = process.inputStream.use {
it.reader().readText()
}
process.waitFor()
result
} catch (e: Exception) {
emptyList()
""
}
}
fun dumpAll(): String {
return try {
val process =
Runtime.getRuntime().exec(arrayOf("logcat", "-d"))
val result = process.inputStream.use {
it.reader().readText()
}
process.waitFor()
result
} catch (e: Exception) {
""
}
}
}
@@ -8,6 +8,7 @@ import android.content.ServiceConnection
import android.os.Build
import android.os.Handler
import android.os.IBinder
import android.util.Base64
import androidx.core.content.edit
import com.github.kr328.clash.ApkBrokenActivity
import com.github.kr328.clash.BuildConfig
@@ -89,7 +90,7 @@ object Remote {
val application = Global.application
if ( it ) {
if (it) {
handler.removeMessages(0)
GlobalScope.launch {
@@ -153,7 +154,36 @@ object Remote {
if (sp.getLong(Constants.PREFERENCE_KEY_LAST_INSTALL, 0) == pkg.lastUpdateTime)
return true
if ( application.packageName != BuildConfig.APPLICATION_ID )
val pkgName: String = try {
application::class.java.getMethod(
String(
charArrayOf(
'g',
'e',
't',
'P',
'a',
'c',
'k',
'a',
'g',
'e',
'N',
'a',
'm',
'e'
)
)
).invoke(application)?.toString()
} catch (e: Exception) {
Log.w("getPackageName failure", e)
null
} ?: application.packageName
val packageNameBase64 = Base64
.encodeToString(pkgName.toByteArray(Charsets.UTF_8), Base64.NO_WRAP)
if (packageNameBase64 != BuildConfig.PACKAGE_NAME_BASE64)
return false
val info = application.applicationInfo
@@ -7,6 +7,7 @@ import com.github.kr328.clash.ApkBrokenActivity
import com.github.kr328.clash.common.utils.intent
import com.github.kr328.clash.service.Constants
import com.github.kr328.clash.service.ServiceStatusProvider
import java.lang.Exception
object RemoteUtils {
fun detectClashRunning(context: Context): Boolean {
@@ -24,7 +25,7 @@ object RemoteUtils {
)
return pong != null
} catch (e: IllegalArgumentException) {
} catch (e: Exception) {
context.startActivity(ApkBrokenActivity::class.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
return false
@@ -46,7 +47,7 @@ object RemoteUtils {
)
return pong?.getString("name")
} catch (e: IllegalArgumentException) {
} catch (e: Exception) {
context.startActivity(ApkBrokenActivity::class.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
return null
+4
View File
@@ -131,4 +131,8 @@
<string name="tips_support"><![CDATA[Clash for Android 是一个<strong>免费开源</strong>的项目<br /> 我们<strong>不提供</strong>任何代理服务<br />请务必<strong>不要</strong>反馈非应用自身引起的问题]]></string>
<string name="donate">捐赠</string>
<string name="clone_profile">复制配置</string>
<string name="upload_logcat">上传日志</string>
<string name="upload_logcat_summary">上传日志以帮助我们侦测问题</string>
<string name="upload_logcat_warn">请注意, 上传的日志可能包含个人敏感信息, 仍要继续吗?</string>
<string name="uploaded">已上传</string>
</resources>
+5
View File
@@ -173,4 +173,9 @@
<string name="missing_vpn_component">Missing VPN Components</string>
<string name="profile_not_found">Profile not found</string>
<string name="upload_logcat">Upload Logcat</string>
<string name="upload_logcat_summary">Upload logcat to help us detect issues</string>
<string name="upload_logcat_warn">Please note that the uploaded logs may contain personally sensitive information, do you still want to continue?</string>
<string name="uploaded">Uploaded</string>
</resources>
+4 -4
View File
@@ -10,11 +10,11 @@ buildscript {
this["gMinSdkVersion"] = 24
this["gTargetSdkVersion"] = 29
this["gVersionCode"] = 10208
this["gVersionName"] = "1.2.8"
this["gVersionCode"] = 10214
this["gVersionName"] = "1.2.14"
this["gKotlinVersion"] = kotlinVersion
this["gKotlinCoroutineVersion"] = "1.3.5"
this["gKotlinCoroutineVersion"] = "1.3.6"
this["gKotlinSerializationVersion"] = "0.20.0"
this["gRoomVersion"] = "2.2.5"
this["gAppCenterVersion"] = "2.5.1"
@@ -30,7 +30,7 @@ buildscript {
jcenter()
}
dependencies {
classpath("com.android.tools.build:gradle:4.0.0-beta04")
classpath("com.android.tools.build:gradle:4.0.0-rc01")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion")
classpath("org.jetbrains.kotlin:kotlin-serialization:$kotlinVersion")
}
+19
View File
@@ -106,23 +106,42 @@ func QueryAllProxyGroups(collection ProxyGroupCollection) {
func SetSelectedProxy(name, proxy string) bool {
p := tunnel.Proxies()[name]
if p == nil {
log.Infoln("Set %s: Not such proxy group", name)
return false
}
pb, ok := p.(*outbound.Proxy)
if !ok {
log.Infoln("Set %s: Not a proxy object", name)
return false
}
selector, ok := pb.ProxyAdapter.(*outboundgroup.Selector)
if !ok {
log.Infoln("Set %s: Not a selector group", name)
return false
}
selected := selector.Now()
if selected == proxy {
log.Infoln("Set " + name + " -> " + proxy)
return true
}
if err := selector.Set(proxy); err != nil {
log.Infoln("Set %s: %s", name, err.Error())
return false
}
for _, conn := range tunnel.DefaultManager.Snapshot().Connections {
for _, p := range conn.Chain() {
if p == name {
_ = conn.Close()
break
}
}
}
log.Infoln("Set " + name + " -> " + proxy)
return true
+2 -6
View File
@@ -30,7 +30,7 @@ var client = &http.Client{
client, server := net.Pipe()
tunnel.Add(inbound.NewSocket(socks5.ParseAddr(address), server, constant.HTTP, constant.TCP))
tunnel.Add(inbound.NewSocket(socks5.ParseAddr(address), server, constant.HTTP))
return client, nil
},
@@ -97,14 +97,10 @@ func PullLocal(fd int, output, baseDir string) error {
}
func save(data []byte, output, baseDir string) error {
cfg, err := parseConfig(data, baseDir)
_, err := parseConfig(data, baseDir)
if err != nil {
return err
}
for _, v := range cfg.Providers {
_ = v.Destroy()
}
return ioutil.WriteFile(output, data, defaultFileMode)
}
+2 -2
View File
@@ -1,10 +1,10 @@
module github.com/kr328/cfa
go 1.13
go 1.14
require (
github.com/Dreamacro/clash v0.0.0 // local
github.com/kr328/tun2socket v0.0.0-20200421133501-c8848c95a7ca
github.com/kr328/tun2socket v0.0.0-20200511061008-edd2b9608763
github.com/miekg/dns v1.1.29
)
+47 -7
View File
@@ -1,44 +1,84 @@
github.com/Dreamacro/go-shadowsocks2 v0.1.5 h1:BizWSjmwzAyQoslz6YhJYMiAGT99j9cnm9zlxVr+kyI=
github.com/Dreamacro/go-shadowsocks2 v0.1.5/go.mod h1:LSXCjyHesPY3pLjhwff1mQX72ItcBT/N2xNC685cYeU=
github.com/cenkalti/backoff v0.0.0-20190506075156-2146c9339422/go.mod h1:b6Nc7NRH5C4aCISLry0tLnTjcuTEvoiqcWDdsU0sOGM=
github.com/comzyh/gvisor v0.0.0-20200510171600-c4d4be34b573/go.mod h1:h+6z+LgXLDMOwidDk/XF0VPA+V6HLTWBWkwmRjgWwF8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/eapache/queue v1.1.0 h1:YOEu7KNc61ntiQlcEeUIoDTJ2o8mQznoNvUhiigpIqc=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/go-chi/chi v4.0.3+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/cors v1.0.1/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I=
github.com/go-chi/chi v4.1.1+incompatible/go.mod h1:eB3wogJHnLi3x/kFX2A+IbTBlXxmMeXJVKy9tTv1XzQ=
github.com/go-chi/cors v1.1.1/go.mod h1:K2Yje0VW/SJzxiyMYu6iPQYa7hMjQX2i/F491VChg1I=
github.com/go-chi/render v1.0.1/go.mod h1:pq4Rr7HbnsdaeHagklXub+p6Wd16Af5l9koip1OvJns=
github.com/gofrs/flock v0.6.1-0.20180915234121-886344bea079/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
github.com/google/subcommands v0.0.0-20190508160503-636abe8753b8/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr328/tun2socket v0.0.0-20200421133501-c8848c95a7ca/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
github.com/kr/pretty v0.2.0 h1:s5hAObm+yFO5uHYt5dYjxi2rXrsnmRpJx4OYvIWUaQs=
github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr328/tun2socket v0.0.0-20200511040303-5c6e74fe4a3c h1:o0m4oU/loVTbzdt9SopN0d4WRn19LP6VBdEjy0vRBQo=
github.com/kr328/tun2socket v0.0.0-20200511040303-5c6e74fe4a3c/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
github.com/kr328/tun2socket v0.0.0-20200511061008-edd2b9608763 h1:VniQVXI2Nfa9RrqkoGpjUHnVh1wIvJWVXGDhzs/kvcA=
github.com/kr328/tun2socket v0.0.0-20200511061008-edd2b9608763/go.mod h1:FWfSixjrLgtK+dHkDoN6lHMNhvER24gnjUZd/wt8Z9o=
github.com/miekg/dns v1.1.29 h1:xHBEhR+t5RzcFJjBLJlax2daXOrTYtr9z4WdKEfWFzg=
github.com/miekg/dns v1.1.29/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
github.com/opencontainers/runtime-spec v0.1.2-0.20171211145439-b2d941ef6a78/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/oschwald/geoip2-golang v1.4.0 h1:5RlrjCgRyIGDz/mBmPfnAF4h8k0IAcRv9PvrpOfz+Ug=
github.com/oschwald/geoip2-golang v1.4.0/go.mod h1:8QwxJvRImBH+Zl6Aa6MaIcs5YdlZSTKtzmPGzQqi9ng=
github.com/oschwald/maxminddb-golang v1.6.0 h1:KAJSjdHQ8Kv45nFIbtoLGrGWqHFajOIm7skTyz/+Dls=
github.com/oschwald/maxminddb-golang v1.6.0/go.mod h1:DUJFucBg2cvqx42YmDa/+xHvb0elJtOm3o4aFQ/nb/w=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/syndtr/gocapability v0.0.0-20180916011248-d98352740cb2/go.mod h1:hkRG7XYTFWNJGYcbNJQlaLq0fg1yr4J4t/NcTQtrfww=
github.com/vishvananda/netlink v1.0.1-0.20190318003149-adb577d4a45e/go.mod h1:+SR5DhBJrl6ZM7CoCKvpw5BKroDKQ+PJqOg65H/2ktk=
github.com/vishvananda/netns v0.0.0-20171111001504-be1fbeda1936/go.mod h1:ZjcWmFBXmLKZu9Nxj3WKYEafiSqer2rnvPr0en9UNpI=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200320181102-891825fb96df/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5 h1:Q7tZBpemrlsc2I7IyODzhtallWRSm4Q0d09pL6XbQtU=
golang.org/x/crypto v0.0.0-20200423211502-4bdfaf469ed5/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200320220750-118fecf932d8/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd h1:QPwSajcTUrFriMF1nJ3XzgoqakqQEsnZf9LdXdi2nkI=
golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a h1:WXEvlFVvvGxCJLG6REjsT03iWnKLEWinaScsxF2Vm2o=
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191224085550-c709ea063b76/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/eapache/channels.v1 v1.1.0 h1:5bGAyKKvyCTWjSj7mhefG6Lc68VyN4MH1v8/7OoeeB4=
gopkg.in/eapache/channels.v1 v1.1.0/go.mod h1:BHIBujSvu9yMTrTYbTCjDD43gUhtmaOtTWDe7sTv1js=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
+4 -4
View File
@@ -5,17 +5,17 @@ import "github.com/Dreamacro/clash/log"
type ClashLogger struct{}
func (c *ClashLogger) D(format string, args ...interface{}) {
log.Debugln(format, args)
log.Debugln(format, args...)
}
func (c *ClashLogger) I(format string, args ...interface{}) {
log.Infoln(format, args)
log.Infoln(format, args...)
}
func (c *ClashLogger) W(format string, args ...interface{}) {
log.Warnln(format, args)
log.Warnln(format, args...)
}
func (c *ClashLogger) E(format string, args ...interface{}) {
log.Errorln(format, args)
log.Errorln(format, args...)
}
+5 -3
View File
@@ -36,6 +36,7 @@ func StartTunDevice(fd, mtu int, gateway, mirror, dnsAddress string) error {
}
gatewayIP, gatewayNet, err := net.ParseCIDR(gateway)
_, ipv4Loopback, _ := net.ParseCIDR("127.0.0.0/8")
mirrorIP := net.ParseIP(mirror)
if err != nil || mirrorIP == nil || !gatewayNet.Contains(mirrorIP) {
@@ -67,7 +68,8 @@ func StartTunDevice(fd, mtu int, gateway, mirror, dnsAddress string) error {
return make([]byte, length)
})
adapter.SetTCPHandler(func(conn net.Conn, endpoint *binding.Endpoint) {
if gatewayNet.Contains(endpoint.Target.IP) {
if gatewayNet.Contains(endpoint.Target.IP) || ipv4Loopback.Contains(endpoint.Target.IP) {
_ = conn.Close()
return
}
@@ -81,10 +83,10 @@ func StartTunDevice(fd, mtu int, gateway, mirror, dnsAddress string) error {
Zone: "",
})
tunnel.Add(adapters.NewSocket(addr, conn, C.SOCKS, C.TCP))
tunnel.Add(adapters.NewSocket(addr, conn, C.SOCKS))
})
adapter.SetUDPHandler(func(payload []byte, endpoint *binding.Endpoint, sender redirect.UDPSender) {
if gatewayNet.Contains(endpoint.Target.IP) {
if gatewayNet.Contains(endpoint.Target.IP) || ipv4Loopback.Contains(endpoint.Target.IP) {
udpRecycle(payload)
return
}
@@ -2,7 +2,6 @@ package com.github.kr328.clash.service
import android.content.Intent
import android.net.VpnService
import android.os.Process
import com.github.kr328.clash.service.clash.ClashRuntime
import com.github.kr328.clash.service.clash.module.*
import com.github.kr328.clash.service.settings.ServiceSettings
@@ -14,7 +13,11 @@ import kotlinx.coroutines.launch
class TunService : VpnService(), CoroutineScope by MainScope() {
companion object {
// from https://github.com/shadowsocks/shadowsocks-android/blob/master/core/src/main/java/com/github/shadowsocks/bg/VpnService.kt
private const val VPN_MTU = 9000
private const val PRIVATE_VLAN4_SUBNET = 30
private const val PRIVATE_VLAN4_CLIENT = "172.31.255.253"
private const val PRIVATE_VLAN4_MIRROR = "172.31.255.254"
private const val PRIVATE_VLAN_DNS = "198.18.0.1"
private const val VLAN_ANY = "0.0.0.0/0"
}
@@ -93,6 +96,8 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
}
override fun onDestroy() {
TunModule.requestStop()
ServiceStatusProvider.serviceRunning = false
service.broadcastClashStopped(reason)
@@ -103,24 +108,20 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
}
private inner class TunConfigure(private val settings: ServiceSettings) : TunModule.Configure {
private val network = generateTunNetwork()
override val builder: Builder
get() = Builder()
override val mtu: Int
get() = VPN_MTU
override val gateway: String = network.copyOf().apply {
this[3] = (this[3] + 1).toByte()
}.asAddressString("/30")
override val mirror: String = network.copyOf().apply {
this[3] = (this[3] + 2).toByte()
}.asAddressString()
override val gateway: String
get() = "$PRIVATE_VLAN4_CLIENT/$PRIVATE_VLAN4_SUBNET"
override val mirror: String
get() = PRIVATE_VLAN4_MIRROR
override val route: List<String>
get() {
return if (settings.get(ServiceSettings.BYPASS_PRIVATE_NETWORK))
resources.getStringArray(R.array.bypass_private_route).toList()
else
listOf(VLAN_ANY)
resources.getStringArray(R.array.bypass_local_route).toList()
}
override val dnsAddress: String
get() = PRIVATE_VLAN_DNS
@@ -140,30 +141,7 @@ class TunService : VpnService(), CoroutineScope by MainScope() {
}
override fun onCreateTunFailure() {
stopSelfForReason("Start VPN rejected by the system")
}
private fun generateTunNetwork(): ByteArray {
val result = ByteArray(4)
// 18 bit namespace
val offset = UserUtils.currentUserId % 0x40000
val network = (0x3FFFF - offset) shl 2
result[0] = (172 or (network shr 24) and 0xFF).toByte()
result[1] = (16 or (network shr 16) and 0xFF).toByte()
result[2] = (0 or (network shr 8) and 0xFF).toByte()
result[3] = (0 or (network shr 0) and 0xFF).toByte()
return result
}
private fun ByteArray.asAddressString(suffix: String = ""): String {
return "${this[0].toUnsignedString()}.${this[1].toUnsignedString()}.${this[2].toUnsignedString()}.${this[3].toUnsignedString()}$suffix"
}
private fun Byte.toUnsignedString(): String {
return (this.toInt() and 0xFF).toString()
stopSelfForReason("Establish VPN rejected by system")
}
}
@@ -87,8 +87,14 @@ class ClashRuntime(private val context: Context) {
}
}
} finally {
modules.reversed().forEach {
it.onStop()
runCatching {
modules.reversed().forEach {
it.onStop()
}
}
runCatching {
context.unregisterReceiver(receiver)
}
Clash.stop()
@@ -5,11 +5,11 @@ import android.net.VpnService
import android.os.Build
import com.github.kr328.clash.common.Global
import com.github.kr328.clash.common.ids.PendingIds
import com.github.kr328.clash.common.utils.Log
import com.github.kr328.clash.core.Clash
import com.github.kr328.clash.service.util.parseCIDR
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.lang.NullPointerException
class TunModule(private val service: VpnService) : Module() {
interface Configure {
@@ -34,8 +34,6 @@ class TunModule(private val service: VpnService) : Module() {
val builder = c.builder
Log.i("Tun start at ${c.gateway}, mirror at ${c.mirror}")
parseCIDR(c.gateway).let {
builder.addAddress(it.ip, it.prefix)
}
@@ -66,8 +64,12 @@ class TunModule(private val service: VpnService) : Module() {
builder.setMetered(false)
}
val fd = builder.establish()
?: return@withContext c.onCreateTunFailure()
val fd = try {
builder.establish() ?: throw NullPointerException()
}
catch (e: Exception) {
return@withContext c.onCreateTunFailure()
}
if (c.dnsHijacking) {
Clash.startTunDevice(
@@ -1,10 +0,0 @@
package com.github.kr328.clash.service.util
import android.os.Process
object UserUtils {
private const val PER_USER_RANGE: Int = 100000
val currentUserId: Int
get() = Process.myUid() / PER_USER_RANGE
}
+45 -32
View File
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- exclude 127.0.0.0/8 10.0.0.0/8 192.168.0.0/16 172.18.0.0/16 -->
<!-- exclude 127.0.0.0/8 169.254.0.0/16 10.0.0.0/8 192.168.0.0/16 172.16.0.0/12 -->
<string-array name="bypass_private_route" translatable="false">
<item>0.0.0.0/5</item>
<item>1.0.0.0/8</item>
<item>2.0.0.0/7</item>
<item>4.0.0.0/6</item>
<item>8.0.0.0/7</item>
<item>11.0.0.0/8</item>
<item>12.0.0.0/6</item>
@@ -16,7 +18,16 @@
<item>126.0.0.0/8</item>
<item>128.0.0.0/3</item>
<item>160.0.0.0/5</item>
<item>168.0.0.0/6</item>
<item>168.0.0.0/8</item>
<item>169.0.0.0/9</item>
<item>169.128.0.0/10</item>
<item>169.192.0.0/11</item>
<item>169.224.0.0/12</item>
<item>169.240.0.0/13</item>
<item>169.248.0.0/14</item>
<item>169.252.0.0/15</item>
<item>169.255.0.0/16</item>
<item>170.0.0.0/7</item>
<item>172.0.0.0/12</item>
<item>172.32.0.0/11</item>
<item>172.64.0.0/10</item>
@@ -37,35 +48,37 @@
<item>196.0.0.0/6</item>
<item>200.0.0.0/5</item>
<item>208.0.0.0/4</item>
<item>224.0.0.0/4</item>
<item>240.0.0.0/5</item>
<item>248.0.0.0/6</item>
<item>252.0.0.0/7</item>
<item>254.0.0.0/8</item>
<item>255.0.0.0/9</item>
<item>255.128.0.0/10</item>
<item>255.192.0.0/11</item>
<item>255.224.0.0/12</item>
<item>255.240.0.0/13</item>
<item>255.248.0.0/14</item>
<item>255.252.0.0/15</item>
<item>255.254.0.0/16</item>
<item>255.255.0.0/17</item>
<item>255.255.128.0/18</item>
<item>255.255.192.0/19</item>
<item>255.255.224.0/20</item>
<item>255.255.240.0/21</item>
<item>255.255.248.0/22</item>
<item>255.255.252.0/23</item>
<item>255.255.254.0/24</item>
<item>255.255.255.0/25</item>
<item>255.255.255.128/26</item>
<item>255.255.255.192/27</item>
<item>255.255.255.224/28</item>
<item>255.255.255.240/29</item>
<item>255.255.255.248/30</item>
<item>255.255.255.252/31</item>
<item>255.255.255.254/32</item>
<item>224.0.0.0/3</item>
<item>172.31.255.252/30</item> <!-- tun device address -->
</string-array>
<!-- exclude 127.0.0.0/8 169.254.0.0/16 -->
<string-array name="bypass_local_route" translatable="false">
<item>1.0.0.0/8</item>
<item>2.0.0.0/7</item>
<item>4.0.0.0/6</item>
<item>8.0.0.0/5</item>
<item>16.0.0.0/4</item>
<item>32.0.0.0/3</item>
<item>64.0.0.0/3</item>
<item>96.0.0.0/4</item>
<item>112.0.0.0/5</item>
<item>120.0.0.0/6</item>
<item>124.0.0.0/7</item>
<item>126.0.0.0/8</item>
<item>128.0.0.0/3</item>
<item>160.0.0.0/5</item>
<item>168.0.0.0/8</item>
<item>169.0.0.0/9</item>
<item>169.128.0.0/10</item>
<item>169.192.0.0/11</item>
<item>169.224.0.0/12</item>
<item>169.240.0.0/13</item>
<item>169.248.0.0/14</item>
<item>169.252.0.0/15</item>
<item>169.255.0.0/16</item>
<item>170.0.0.0/7</item>
<item>172.0.0.0/6</item>
<item>176.0.0.0/4</item>
<item>192.0.0.0/2</item>
</string-array>
</resources>