mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-07 11:44:29 +00:00
Verify caller before uninstallation
This commit is contained in:
parent
aadb2d825c
commit
fa60daf9b5
@ -9,6 +9,7 @@ import androidx.databinding.ViewDataBinding
|
|||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.topjohnwu.magisk.BuildConfig.APPLICATION_ID
|
import com.topjohnwu.magisk.BuildConfig.APPLICATION_ID
|
||||||
import com.topjohnwu.magisk.R
|
import com.topjohnwu.magisk.R
|
||||||
|
import com.topjohnwu.magisk.StubApk
|
||||||
import com.topjohnwu.magisk.core.Config
|
import com.topjohnwu.magisk.core.Config
|
||||||
import com.topjohnwu.magisk.core.Const
|
import com.topjohnwu.magisk.core.Const
|
||||||
import com.topjohnwu.magisk.core.JobService
|
import com.topjohnwu.magisk.core.JobService
|
||||||
@ -95,10 +96,19 @@ abstract class BaseMainActivity<Binding : ViewDataBinding> : NavigationActivity<
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun preLoad() {
|
private fun preLoad() {
|
||||||
val prevPkg = intent.getStringExtra(Const.Key.PREV_PKG)
|
val prevPkg = intent.getStringExtra(Const.Key.PREV_PKG)?.let {
|
||||||
|
// Make sure the calling package matches (prevent DoS)
|
||||||
|
if (it == callingPackage)
|
||||||
|
it
|
||||||
|
else
|
||||||
|
null
|
||||||
|
}
|
||||||
|
|
||||||
Config.load(prevPkg)
|
Config.load(prevPkg)
|
||||||
handleRepackage(prevPkg)
|
handleRepackage(prevPkg)
|
||||||
|
if (prevPkg != null) {
|
||||||
|
StubApk.restartProcess(this)
|
||||||
|
}
|
||||||
Notifications.setup(this)
|
Notifications.setup(this)
|
||||||
JobService.schedule(this)
|
JobService.schedule(this)
|
||||||
Shortcuts.setupDynamic(this)
|
Shortcuts.setupDynamic(this)
|
||||||
|
@ -163,7 +163,7 @@ object Config : PreferenceConfig, DBConfig {
|
|||||||
fun load(pkg: String?) {
|
fun load(pkg: String?) {
|
||||||
// Only try to load prefs when fresh install and a previous package name is set
|
// Only try to load prefs when fresh install and a previous package name is set
|
||||||
if (pkg != null && prefs.all.isEmpty()) runCatching {
|
if (pkg != null && prefs.all.isEmpty()) runCatching {
|
||||||
context.contentResolver.openInputStream(Provider.PREFS_URI(pkg))?.use {
|
context.contentResolver.openInputStream(Provider.preferencesUri(pkg))?.use {
|
||||||
prefs.edit { parsePrefs(it) }
|
prefs.edit { parsePrefs(it) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import android.os.ParcelFileDescriptor
|
|||||||
import android.os.ParcelFileDescriptor.MODE_READ_ONLY
|
import android.os.ParcelFileDescriptor.MODE_READ_ONLY
|
||||||
import com.topjohnwu.magisk.core.base.BaseProvider
|
import com.topjohnwu.magisk.core.base.BaseProvider
|
||||||
import com.topjohnwu.magisk.core.su.SuCallbackHandler
|
import com.topjohnwu.magisk.core.su.SuCallbackHandler
|
||||||
import java.io.File
|
|
||||||
|
|
||||||
class Provider : BaseProvider() {
|
class Provider : BaseProvider() {
|
||||||
|
|
||||||
@ -17,17 +16,13 @@ class Provider : BaseProvider() {
|
|||||||
|
|
||||||
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
|
override fun openFile(uri: Uri, mode: String): ParcelFileDescriptor? {
|
||||||
return when (uri.encodedPath ?: return null) {
|
return when (uri.encodedPath ?: return null) {
|
||||||
"/apk_file" -> ParcelFileDescriptor.open(File(context!!.packageCodePath), MODE_READ_ONLY)
|
|
||||||
"/prefs_file" -> ParcelFileDescriptor.open(Config.prefsFile, MODE_READ_ONLY)
|
"/prefs_file" -> ParcelFileDescriptor.open(Config.prefsFile, MODE_READ_ONLY)
|
||||||
else -> super.openFile(uri, mode)
|
else -> super.openFile(uri, mode)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
fun APK_URI(pkg: String) =
|
fun preferencesUri(pkg: String): Uri =
|
||||||
Uri.Builder().scheme("content").authority("$pkg.provider").path("apk_file").build()
|
|
||||||
|
|
||||||
fun PREFS_URI(pkg: String) =
|
|
||||||
Uri.Builder().scheme("content").authority("$pkg.provider").path("prefs_file").build()
|
Uri.Builder().scheme("content").authority("$pkg.provider").path("prefs_file").build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,10 +97,10 @@ object HideAPK {
|
|||||||
Config.suManager = if (pkg == APPLICATION_ID) "" else pkg
|
Config.suManager = if (pkg == APPLICATION_ID) "" else pkg
|
||||||
val self = activity.packageName
|
val self = activity.packageName
|
||||||
val flag = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
val flag = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
activity.grantUriPermission(pkg, Provider.APK_URI(self), flag)
|
activity.grantUriPermission(pkg, Provider.preferencesUri(self), flag)
|
||||||
activity.grantUriPermission(pkg, Provider.PREFS_URI(self), flag)
|
|
||||||
intent.putExtra(Const.Key.PREV_PKG, self)
|
intent.putExtra(Const.Key.PREV_PKG, self)
|
||||||
activity.startActivity(intent)
|
intent.flags = 0
|
||||||
|
activity.startActivityForResult(intent, Int.MAX_VALUE)
|
||||||
activity.finish()
|
activity.finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user