Dump all the possible useful information
This commit is contained in:
@@ -13,6 +13,7 @@ import be.mygod.vpnhotspot.net.Routing
|
|||||||
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers
|
import com.takisoft.fix.support.v7.preference.PreferenceFragmentCompatDividers
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.io.PrintWriter
|
||||||
|
|
||||||
class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
|
class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
|
||||||
private val customTabsIntent by lazy {
|
private val customTabsIntent by lazy {
|
||||||
@@ -31,19 +32,23 @@ class SettingsPreferenceFragment : PreferenceFragmentCompatDividers() {
|
|||||||
val logDir = File(activity.cacheDir, "log")
|
val logDir = File(activity.cacheDir, "log")
|
||||||
logDir.mkdir()
|
logDir.mkdir()
|
||||||
val logFile = File.createTempFile("vpnhotspot-", ".log", logDir)
|
val logFile = File.createTempFile("vpnhotspot-", ".log", logDir)
|
||||||
logFile.printWriter().use { writer ->
|
logFile.outputStream().use { out ->
|
||||||
|
PrintWriter(out.bufferedWriter()).use { writer ->
|
||||||
writer.write("${BuildConfig.VERSION_CODE} is running on API ${Build.VERSION.SDK_INT}\n\n")
|
writer.write("${BuildConfig.VERSION_CODE} is running on API ${Build.VERSION.SDK_INT}\n\n")
|
||||||
|
writer.flush()
|
||||||
try {
|
try {
|
||||||
writer.write(Runtime.getRuntime().exec(arrayOf("logcat", "-d"))
|
Runtime.getRuntime().exec(arrayOf("logcat", "-d")).inputStream.use { it.copyTo(out) }
|
||||||
.inputStream.bufferedReader().readText())
|
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace(writer)
|
e.printStackTrace(writer)
|
||||||
}
|
}
|
||||||
writer.write("\n")
|
writer.write("\n")
|
||||||
|
writer.flush()
|
||||||
try {
|
try {
|
||||||
writer.write(Routing.dump())
|
Routing.dump()?.use { it.copyTo(out) }
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace(writer)
|
e.printStackTrace(writer)
|
||||||
|
writer.flush()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND)
|
startActivity(Intent.createChooser(Intent(Intent.ACTION_SEND)
|
||||||
|
|||||||
@@ -8,7 +8,9 @@ import android.databinding.BindingAdapter
|
|||||||
import android.support.annotation.DrawableRes
|
import android.support.annotation.DrawableRes
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
import java.net.NetworkInterface
|
import java.net.NetworkInterface
|
||||||
|
|
||||||
fun debugLog(tag: String?, message: String?) {
|
fun debugLog(tag: String?, message: String?) {
|
||||||
@@ -37,23 +39,27 @@ fun NetworkInterface.formatAddresses() =
|
|||||||
|
|
||||||
private const val NOISYSU_TAG = "NoisySU"
|
private const val NOISYSU_TAG = "NoisySU"
|
||||||
private const val NOISYSU_SUFFIX = "SUCCESS\n"
|
private const val NOISYSU_SUFFIX = "SUCCESS\n"
|
||||||
fun loggerSu(command: String): String? {
|
fun loggerSuStream(command: String): InputStream? {
|
||||||
val process = try {
|
val process = try {
|
||||||
ProcessBuilder("su", "-c", command)
|
ProcessBuilder("su", "-c", command)
|
||||||
.redirectErrorStream(true)
|
.redirectErrorStream(true)
|
||||||
|
.directory(app.cacheDir)
|
||||||
.start()
|
.start()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
process.waitFor()
|
|
||||||
try {
|
try {
|
||||||
val err = process.errorStream.bufferedReader().readText()
|
val err = process.errorStream.bufferedReader().readText()
|
||||||
if (err.isNotBlank()) Log.e(NOISYSU_TAG, err)
|
if (err.isNotBlank()) Log.e(NOISYSU_TAG, err)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
}
|
}
|
||||||
|
return process.inputStream
|
||||||
|
}
|
||||||
|
fun loggerSu(command: String): String? {
|
||||||
|
val stream = loggerSuStream(command) ?: return null
|
||||||
return try {
|
return try {
|
||||||
process.inputStream.bufferedReader().readText()
|
stream.bufferedReader().readText()
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
null
|
null
|
||||||
|
|||||||
@@ -4,9 +4,10 @@ import android.os.Build
|
|||||||
import be.mygod.vpnhotspot.App.Companion.app
|
import be.mygod.vpnhotspot.App.Companion.app
|
||||||
import be.mygod.vpnhotspot.R
|
import be.mygod.vpnhotspot.R
|
||||||
import be.mygod.vpnhotspot.debugLog
|
import be.mygod.vpnhotspot.debugLog
|
||||||
import be.mygod.vpnhotspot.loggerSu
|
import be.mygod.vpnhotspot.loggerSuStream
|
||||||
import be.mygod.vpnhotspot.noisySu
|
import be.mygod.vpnhotspot.noisySu
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
import java.io.InputStream
|
||||||
import java.net.Inet4Address
|
import java.net.Inet4Address
|
||||||
import java.net.InetAddress
|
import java.net.InetAddress
|
||||||
import java.net.NetworkInterface
|
import java.net.NetworkInterface
|
||||||
@@ -30,19 +31,28 @@ class Routing(val upstream: String?, val downstream: String, ownerAddress: InetA
|
|||||||
"$IPTABLES -X vpnhotspot_fwd",
|
"$IPTABLES -X vpnhotspot_fwd",
|
||||||
"quiet while ip rule del priority 17900; do done")
|
"quiet while ip rule del priority 17900; do done")
|
||||||
|
|
||||||
fun dump() = loggerSu("""
|
fun dump(): InputStream? {
|
||||||
|
val commands = StringBuilder()
|
||||||
|
// https://android.googlesource.com/platform/external/iptables/+/android-7.0.0_r1/iptables/Android.mk#34
|
||||||
|
val iptablesSave = if (Build.VERSION.SDK_INT >= 24) "iptables-save" else {
|
||||||
|
commands.appendln("ln -sf /system/bin/iptables ./iptables-save")
|
||||||
|
"./iptables-save"
|
||||||
|
}
|
||||||
|
commands.append("""
|
||||||
|echo logcat-su
|
|echo logcat-su
|
||||||
|logcat -d
|
|logcat -d
|
||||||
|echo
|
|echo
|
||||||
|echo iptables
|
|echo iptables
|
||||||
|sh -c 'exec -a iptables-save iptables'
|
|$iptablesSave
|
||||||
|echo
|
|echo
|
||||||
|echo iptables -t nat
|
|echo iptables -t nat
|
||||||
|sh -c 'exec -a iptables-save iptables -t nat'
|
|$iptablesSave -t nat
|
||||||
|echo
|
|echo
|
||||||
|echo ip rule
|
|echo ip rule
|
||||||
|ip rule
|
|ip rule
|
||||||
""".trimMargin())
|
""".trimMargin())
|
||||||
|
return loggerSuStream(commands.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class InterfaceNotFoundException : IOException() {
|
class InterfaceNotFoundException : IOException() {
|
||||||
|
|||||||
Reference in New Issue
Block a user