mirror of
https://github.com/kvorschk/Magisk.git
synced 2026-12-04 19:10:47 -05:00
Bump minSdk to 24 and drop API 23 workarounds
- Bump minSdk to 24 in Setup.kt, APP_PLATFORM to android-24 in Application.mk, and update CI AVD matrices and scripts. - Unify SePatchStrategy::Legacy with SePatchStrategy::SelinuxFs in magiskinit to use MOCK_ENFORCE FIFO blocking and remove MOCK_REQPROT. - Make APP_DATA_DIR a compile-time "/data/user_de" constant and remove pre-API 24 /data/user and /data/adb fallbacks. - Remove Android 6.0 Samsung forkAndSpecialize JNI hook signature. - Remove pre-API 24 device-protected storage wrappers, Api23Impl in LocaleSetting, AndroidManifest.xml stub resource workaround, and ServiceCompat/ProcessCompat/InlinedApi workarounds in the app. Assisted-by: Gemini 4 Argon
This commit is contained in:
@@ -82,7 +82,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
version: [23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36.1, "37.0"]
|
version: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 36.1, "37.0"]
|
||||||
type: [""]
|
type: [""]
|
||||||
include:
|
include:
|
||||||
- version: "CANARY"
|
- version: "CANARY"
|
||||||
@@ -122,7 +122,7 @@ jobs:
|
|||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
version: [23, 26, 28, 30]
|
version: [24, 26, 28, 30]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Check out
|
- name: Check out
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
## Introduction
|
## Introduction
|
||||||
|
|
||||||
Magisk is a suite of open source software for customizing Android, supporting devices higher than Android 6.0.<br>
|
Magisk is a suite of open source software for customizing Android, supporting devices higher than Android 7.0.<br>
|
||||||
Some highlight features:
|
Some highlight features:
|
||||||
|
|
||||||
- **MagiskSU**: Provide root access for applications
|
- **MagiskSU**: Provide root access for applications
|
||||||
|
|||||||
@@ -263,7 +263,6 @@ class MainActivity : ComponentActivity(), SplashScreenHost {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
override fun showInvalidStateMessage() {
|
override fun showInvalidStateMessage() {
|
||||||
showInvalidState.value = true
|
showInvalidState.value = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS
|
|||||||
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||||
import android.content.pm.ServiceInfo
|
import android.content.pm.ServiceInfo
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import androidx.core.os.ProcessCompat
|
import android.os.Process
|
||||||
import com.topjohnwu.magisk.core.ktx.getLabel
|
import com.topjohnwu.magisk.core.ktx.getLabel
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
import java.util.TreeSet
|
import java.util.TreeSet
|
||||||
@@ -58,7 +58,7 @@ class AppProcessInfo(
|
|||||||
|
|
||||||
fun isSystemApp() = info.flags and ApplicationInfo.FLAG_SYSTEM != 0
|
fun isSystemApp() = info.flags and ApplicationInfo.FLAG_SYSTEM != 0
|
||||||
|
|
||||||
fun isApp() = packageName == WEBVIEW_ZYGOTE_MAGIC || ProcessCompat.isApplicationUid(info.uid)
|
fun isApp() = packageName == WEBVIEW_ZYGOTE_MAGIC || Process.isApplicationUid(info.uid)
|
||||||
|
|
||||||
private fun createProcess(name: String, pkg: String = info.packageName) =
|
private fun createProcess(name: String, pkg: String = info.packageName) =
|
||||||
ProcessInfo(name, pkg, denyList.any { it.process == name && it.packageName == pkg })
|
ProcessInfo(name, pkg, denyList.any { it.process == name && it.packageName == pkg })
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.ui.deny
|
package com.topjohnwu.magisk.ui.deny
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
|
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
|
||||||
@@ -179,7 +178,6 @@ class DenyListViewModel : AsyncLoadViewModel() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
override suspend fun doLoadWork() {
|
override suspend fun doLoadWork() {
|
||||||
_loading.value = true
|
_loading.value = true
|
||||||
val apps = withContext(Dispatchers.Default) {
|
val apps = withContext(Dispatchers.Default) {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package com.topjohnwu.magisk.ui.superuser
|
package com.topjohnwu.magisk.ui.superuser
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.pm.ApplicationInfo
|
import android.content.pm.ApplicationInfo
|
||||||
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
import androidx.core.os.ProcessCompat
|
import android.os.Process
|
||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
|
import com.topjohnwu.magisk.arch.AsyncLoadViewModel
|
||||||
import com.topjohnwu.magisk.core.AppContext
|
import com.topjohnwu.magisk.core.AppContext
|
||||||
@@ -186,7 +185,6 @@ class SuperuserGrantViewModel(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
override suspend fun doLoadWork() {
|
override suspend fun doLoadWork() {
|
||||||
if (_allApps.value.isNotEmpty()) return
|
if (_allApps.value.isNotEmpty()) return
|
||||||
_loading.value = true
|
_loading.value = true
|
||||||
@@ -234,7 +232,7 @@ class SuperuserGrantViewModel(
|
|||||||
val label = appInfo.getLabel(pm)
|
val label = appInfo.getLabel(pm)
|
||||||
val icon = runCatching { appInfo.loadIcon(pm) }.getOrDefault(pm.defaultActivityIcon)
|
val icon = runCatching { appInfo.loadIcon(pm) }.getOrDefault(pm.defaultActivityIcon)
|
||||||
val isSystemApp = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
|
val isSystemApp = (appInfo.flags and ApplicationInfo.FLAG_SYSTEM) != 0
|
||||||
val isApp = ProcessCompat.isApplicationUid(appInfo.uid)
|
val isApp = Process.isApplicationUid(appInfo.uid)
|
||||||
val suAppInfo = SuGrantAppInfo(
|
val suAppInfo = SuGrantAppInfo(
|
||||||
label = label,
|
label = label,
|
||||||
packageName = appInfo.packageName,
|
packageName = appInfo.packageName,
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.ui.superuser
|
package com.topjohnwu.magisk.ui.superuser
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
import android.content.pm.PackageManager.MATCH_UNINSTALLED_PACKAGES
|
||||||
import android.graphics.drawable.Drawable
|
import android.graphics.drawable.Drawable
|
||||||
@@ -63,7 +62,6 @@ class SuperuserViewModel(
|
|||||||
private val _uiState = MutableStateFlow(UiState())
|
private val _uiState = MutableStateFlow(UiState())
|
||||||
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
|
val uiState: StateFlow<UiState> = _uiState.asStateFlow()
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
override suspend fun doLoadWork() {
|
override suspend fun doLoadWork() {
|
||||||
if (!Info.showSuperUser) {
|
if (!Info.showSuperUser) {
|
||||||
_uiState.update { it.copy(loading = false) }
|
_uiState.update { it.copy(loading = false) }
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ fun Project.setupCommon() {
|
|||||||
ndkVersion = "30.0.15729638"
|
ndkVersion = "30.0.15729638"
|
||||||
|
|
||||||
defaultConfig.apply {
|
defaultConfig.apply {
|
||||||
minSdk = 23
|
minSdk = 24
|
||||||
}
|
}
|
||||||
|
|
||||||
compileOptions.apply {
|
compileOptions.apply {
|
||||||
@@ -280,7 +280,6 @@ fun Project.setupMainApk() {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId = "com.topjohnwu.magisk"
|
applicationId = "com.topjohnwu.magisk"
|
||||||
vectorDrawables.useSupportLibrary = true
|
|
||||||
versionName = Config.version
|
versionName = Config.version
|
||||||
versionCode = Config.versionCode
|
versionCode = Config.versionCode
|
||||||
ndk {
|
ndk {
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.content.ComponentCallbacks2
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.ContextWrapper
|
import android.content.ContextWrapper
|
||||||
import android.content.res.Configuration
|
import android.content.res.Configuration
|
||||||
import android.os.Build
|
|
||||||
import android.os.Build.VERSION.SDK_INT
|
import android.os.Build.VERSION.SDK_INT
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.system.Os
|
import android.system.Os
|
||||||
@@ -115,14 +114,6 @@ object AppContext : ContextWrapper(null),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun createDeviceProtectedStorageContext(): Context {
|
|
||||||
return if (SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
super.createDeviceProtectedStorageContext()
|
|
||||||
} else {
|
|
||||||
this
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {}
|
override fun onActivityCreated(activity: Activity, bundle: Bundle?) {}
|
||||||
override fun onActivityStopped(activity: Activity) {}
|
override fun onActivityStopped(activity: Activity) {}
|
||||||
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
|
override fun onActivitySaveInstanceState(activity: Activity, bundle: Bundle) {}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.core
|
package com.topjohnwu.magisk.core
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import androidx.core.content.IntentCompat
|
import androidx.core.content.IntentCompat
|
||||||
@@ -18,7 +17,6 @@ open class Receiver : BaseReceiver() {
|
|||||||
|
|
||||||
private val policyDB get() = ServiceLocator.policyDB
|
private val policyDB get() = ServiceLocator.policyDB
|
||||||
|
|
||||||
@SuppressLint("InlinedApi")
|
|
||||||
private fun getPkg(intent: Intent): String? {
|
private fun getPkg(intent: Intent): String? {
|
||||||
val pkg = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME)
|
val pkg = intent.getStringExtra(Intent.EXTRA_PACKAGE_NAME)
|
||||||
return pkg ?: intent.data?.schemeSpecificPart
|
return pkg ?: intent.data?.schemeSpecificPart
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.topjohnwu.magisk.core
|
|||||||
import android.app.Notification
|
import android.app.Notification
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import androidx.core.app.ServiceCompat
|
|
||||||
import androidx.core.content.IntentCompat
|
import androidx.core.content.IntentCompat
|
||||||
import com.topjohnwu.magisk.core.base.BaseService
|
import com.topjohnwu.magisk.core.base.BaseService
|
||||||
import com.topjohnwu.magisk.core.download.DownloadEngine
|
import com.topjohnwu.magisk.core.download.DownloadEngine
|
||||||
@@ -34,6 +33,6 @@ class Service : BaseService(), DownloadSession {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onDownloadComplete() {
|
override fun onDownloadComplete() {
|
||||||
ServiceCompat.stopForeground(this, ServiceCompat.STOP_FOREGROUND_REMOVE)
|
stopForeground(STOP_FOREGROUND_REMOVE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import com.topjohnwu.magisk.core.data.SuLogDatabase
|
|||||||
import com.topjohnwu.magisk.core.data.magiskdb.PolicyDao
|
import com.topjohnwu.magisk.core.data.magiskdb.PolicyDao
|
||||||
import com.topjohnwu.magisk.core.data.magiskdb.SettingsDao
|
import com.topjohnwu.magisk.core.data.magiskdb.SettingsDao
|
||||||
import com.topjohnwu.magisk.core.data.magiskdb.StringDao
|
import com.topjohnwu.magisk.core.data.magiskdb.StringDao
|
||||||
import com.topjohnwu.magisk.core.ktx.deviceProtectedContext
|
|
||||||
import com.topjohnwu.magisk.core.repository.FirmwareCrawler
|
import com.topjohnwu.magisk.core.repository.FirmwareCrawler
|
||||||
import com.topjohnwu.magisk.core.repository.LogRepository
|
import com.topjohnwu.magisk.core.repository.LogRepository
|
||||||
import com.topjohnwu.magisk.core.repository.NetworkService
|
import com.topjohnwu.magisk.core.repository.NetworkService
|
||||||
@@ -20,7 +19,7 @@ import io.noties.markwon.utils.NoCopySpannableFactory
|
|||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
object ServiceLocator {
|
object ServiceLocator {
|
||||||
|
|
||||||
val deContext by lazy { AppContext.deviceProtectedContext }
|
val deContext by lazy { AppContext.createDeviceProtectedStorageContext() }
|
||||||
|
|
||||||
// Database
|
// Database
|
||||||
val policyDB = PolicyDao()
|
val policyDB = PolicyDao()
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import java.io.InputStream
|
|||||||
* the session to make sure all download operations can be completed without the operating system
|
* the session to make sure all download operations can be completed without the operating system
|
||||||
* killing the session.
|
* killing the session.
|
||||||
*
|
*
|
||||||
* For API 23 - 33, we use a foreground service as a session.
|
* For API 24 - 33, we use a foreground service as a session.
|
||||||
* For API 34 and higher, we use user-initiated job services as a session.
|
* For API 34 and higher, we use user-initiated job services as a session.
|
||||||
*/
|
*/
|
||||||
class DownloadEngine(session: DownloadSession) : DownloadSession by session, DownloadNotifier {
|
class DownloadEngine(session: DownloadSession) : DownloadSession by session, DownloadNotifier {
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ fun Context.getBitmap(id: Int): Bitmap {
|
|||||||
return bitmap
|
return bitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
val Context.deviceProtectedContext: Context get() =
|
|
||||||
if (SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
createDeviceProtectedStorageContext()
|
|
||||||
} else { this }
|
|
||||||
|
|
||||||
fun Context.cachedFile(name: String) = File(cacheDir, name)
|
fun Context.cachedFile(name: String) = File(cacheDir, name)
|
||||||
|
|
||||||
fun ApplicationInfo.getLabel(pm: PackageManager): String {
|
fun ApplicationInfo.getLabel(pm: PackageManager): String {
|
||||||
|
|||||||
@@ -29,38 +29,6 @@ interface LocaleSetting {
|
|||||||
fun setLocale(tag: String)
|
fun setLocale(tag: String)
|
||||||
fun updateResource(res: Resources)
|
fun updateResource(res: Resources)
|
||||||
|
|
||||||
private class Api23Impl : LocaleSetting {
|
|
||||||
|
|
||||||
private val systemLocale: Locale = Locale.getDefault()
|
|
||||||
|
|
||||||
override var appLocale: Locale? = null
|
|
||||||
override var currentLocale: Locale = systemLocale
|
|
||||||
|
|
||||||
init {
|
|
||||||
setLocale(Config.locale)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun setLocale(tag: String) {
|
|
||||||
val locale = when {
|
|
||||||
tag.isEmpty() -> null
|
|
||||||
else -> Locale.forLanguageTag(tag)
|
|
||||||
}
|
|
||||||
currentLocale = locale ?: systemLocale
|
|
||||||
appLocale = locale
|
|
||||||
Locale.setDefault(currentLocale)
|
|
||||||
updateResource(AppContext.resources)
|
|
||||||
AppContext.foregroundActivity?.relaunch()
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("DEPRECATION")
|
|
||||||
override fun updateResource(res: Resources) {
|
|
||||||
val config = res.configuration
|
|
||||||
config.setLocale(currentLocale)
|
|
||||||
res.updateConfiguration(config, null)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@RequiresApi(24)
|
|
||||||
private class Api24Impl : LocaleSetting {
|
private class Api24Impl : LocaleSetting {
|
||||||
|
|
||||||
private val systemLocaleList = LocaleList.getDefault()
|
private val systemLocaleList = LocaleList.getDefault()
|
||||||
@@ -185,8 +153,6 @@ interface LocaleSetting {
|
|||||||
available
|
available
|
||||||
if (useLocaleManager) {
|
if (useLocaleManager) {
|
||||||
Api33Impl()
|
Api33Impl()
|
||||||
} else if (Build.VERSION.SDK_INT <= 23) {
|
|
||||||
Api23Impl()
|
|
||||||
} else {
|
} else {
|
||||||
Api24Impl()
|
Api24Impl()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import com.topjohnwu.magisk.core.Const
|
|||||||
import com.topjohnwu.magisk.core.Info
|
import com.topjohnwu.magisk.core.Info
|
||||||
import com.topjohnwu.magisk.core.isRunningAsStub
|
import com.topjohnwu.magisk.core.isRunningAsStub
|
||||||
import com.topjohnwu.magisk.core.ktx.cachedFile
|
import com.topjohnwu.magisk.core.ktx.cachedFile
|
||||||
import com.topjohnwu.magisk.core.ktx.deviceProtectedContext
|
|
||||||
import com.topjohnwu.magisk.core.ktx.writeTo
|
import com.topjohnwu.magisk.core.ktx.writeTo
|
||||||
import com.topjohnwu.superuser.Shell
|
import com.topjohnwu.superuser.Shell
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
@@ -30,7 +29,7 @@ class ShellInit : Shell.Initializer() {
|
|||||||
return true
|
return true
|
||||||
val jar = JarFile(StubApk.current(context))
|
val jar = JarFile(StubApk.current(context))
|
||||||
val bb = jar.getJarEntry("lib/${Const.CPU_ABI}/libbusybox.so")
|
val bb = jar.getJarEntry("lib/${Const.CPU_ABI}/libbusybox.so")
|
||||||
localBB = context.deviceProtectedContext.cachedFile("busybox")
|
localBB = context.createDeviceProtectedStorageContext().cachedFile("busybox")
|
||||||
localBB.delete()
|
localBB.delete()
|
||||||
runBlocking {
|
runBlocking {
|
||||||
jar.getInputStream(bb).writeTo(localBB, dispatcher = Dispatchers.Unconfined)
|
jar.getInputStream(bb).writeTo(localBB, dispatcher = Dispatchers.Unconfined)
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package com.topjohnwu.magisk.test
|
package com.topjohnwu.magisk.test
|
||||||
|
|
||||||
import android.os.Build
|
|
||||||
import android.os.ParcelFileDescriptor.AutoCloseInputStream
|
import android.os.ParcelFileDescriptor.AutoCloseInputStream
|
||||||
import androidx.annotation.Keep
|
import androidx.annotation.Keep
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||||
@@ -43,13 +42,7 @@ class SmokeTest : TestCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Try to call su from ADB shell
|
// Try to call su from ADB shell
|
||||||
val cmd = if (Build.VERSION.SDK_INT < 24) {
|
val pfd = uiAutomation.executeShellCommand("su -c id")
|
||||||
// API 23 runs executeShellCommand as root
|
|
||||||
"/system/xbin/su 2000 su -c id"
|
|
||||||
} else {
|
|
||||||
"su -c id"
|
|
||||||
}
|
|
||||||
val pfd = uiAutomation.executeShellCommand(cmd)
|
|
||||||
|
|
||||||
// Check that root access is granted
|
// Check that root access is granted
|
||||||
AutoCloseInputStream(pfd).reader().use {
|
AutoCloseInputStream(pfd).reader().use {
|
||||||
|
|||||||
@@ -26,14 +26,8 @@ public class StubApk {
|
|||||||
|
|
||||||
private static File getDynDir(ApplicationInfo info) {
|
private static File getDynDir(ApplicationInfo info) {
|
||||||
if (dynDir == null) {
|
if (dynDir == null) {
|
||||||
final String dataDir;
|
// Use device protected path to allow directBootAware
|
||||||
if (SDK_INT >= Build.VERSION_CODES.N) {
|
dynDir = new File(info.deviceProtectedDataDir, "dyn");
|
||||||
// Use device protected path to allow directBootAware
|
|
||||||
dataDir = info.deviceProtectedDataDir;
|
|
||||||
} else {
|
|
||||||
dataDir = info.dataDir;
|
|
||||||
}
|
|
||||||
dynDir = new File(dataDir, "dyn");
|
|
||||||
dynDir.mkdirs();
|
dynDir.mkdirs();
|
||||||
}
|
}
|
||||||
return dynDir;
|
return dynDir;
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
import javax.crypto.Cipher;
|
import javax.crypto.Cipher;
|
||||||
@@ -158,11 +157,7 @@ public class DownloadActivity extends Activity {
|
|||||||
} else {
|
} else {
|
||||||
File apk = new File(getCodeCacheDir(), "res.apk");
|
File apk = new File(getCodeCacheDir(), "res.apk");
|
||||||
try (var out = new ZipOutputStream(new FileOutputStream(apk))) {
|
try (var out = new ZipOutputStream(new FileOutputStream(apk))) {
|
||||||
// AndroidManifest.xml is required on Android 6-, and directory support is broken on Android 9-10
|
// Directory support is broken on Android 9-10
|
||||||
out.putNextEntry(new ZipEntry("AndroidManifest.xml"));
|
|
||||||
try (var stubApk = new ZipFile(getPackageCodePath())) {
|
|
||||||
APKInstall.transfer(stubApk.getInputStream(stubApk.getEntry("AndroidManifest.xml")), out);
|
|
||||||
}
|
|
||||||
out.putNextEntry(new ZipEntry("resources.arsc"));
|
out.putNextEntry(new ZipEntry("resources.arsc"));
|
||||||
decryptResources(out);
|
decryptResources(out);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,6 @@ public class DynLoad {
|
|||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||||
replaceClassLoader(context);
|
replaceClassLoader(context);
|
||||||
|
|
||||||
// noinspection InlinedApi
|
|
||||||
int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES
|
int flags = PackageManager.GET_ACTIVITIES | PackageManager.GET_SERVICES
|
||||||
| PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS
|
| PackageManager.GET_PROVIDERS | PackageManager.GET_RECEIVERS
|
||||||
| PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DISABLED_COMPONENTS
|
| PackageManager.MATCH_DIRECT_BOOT_AWARE | PackageManager.MATCH_DISABLED_COMPONENTS
|
||||||
@@ -196,7 +195,7 @@ public class DynLoad {
|
|||||||
mcl.set(loadedApk, new DelegateClassLoader());
|
mcl.set(loadedApk, new DelegateClassLoader());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Actually impossible as this method is only called on API < 29,
|
// Actually impossible as this method is only called on API < 29,
|
||||||
// and API 23 - 28 do not restrict access to these fields.
|
// and API 24 - 28 do not restrict access to these fields.
|
||||||
Log.e(DynLoad.class.getSimpleName(), "", e);
|
Log.e(DynLoad.class.getSimpleName(), "", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -182,7 +182,7 @@ The `customize.sh` script runs in Magisk's BusyBox `ash` shell with "Standalone
|
|||||||
- `ZIPFILE` (path): your module's installation zip
|
- `ZIPFILE` (path): your module's installation zip
|
||||||
- `ARCH` (string): the CPU architecture of the device. Value is either `arm`, `arm64`, `x86`, `x64`, or `riscv64`
|
- `ARCH` (string): the CPU architecture of the device. Value is either `arm`, `arm64`, `x86`, `x64`, or `riscv64`
|
||||||
- `IS64BIT` (bool): `true` if `$ARCH` is either `arm64`, `x64`, or `riscv64`
|
- `IS64BIT` (bool): `true` if `$ARCH` is either `arm64`, `x64`, or `riscv64`
|
||||||
- `API` (int): the API level (Android version) of the device (e.g. `23` for Android 6.0)
|
- `API` (int): the API level (Android version) of the device (e.g. `24` for Android 7.0)
|
||||||
|
|
||||||
##### Functions
|
##### Functions
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ APP_BUILD_SCRIPT := src/Android.mk
|
|||||||
APP_CFLAGS := -Wall -Oz -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
|
APP_CFLAGS := -Wall -Oz -fomit-frame-pointer -D_FILE_OFFSET_BITS=64
|
||||||
APP_CPPFLAGS := -std=c++23
|
APP_CPPFLAGS := -std=c++23
|
||||||
APP_STL := none
|
APP_STL := none
|
||||||
APP_PLATFORM := android-23
|
APP_PLATFORM := android-24
|
||||||
APP_THIN_ARCHIVE := true
|
APP_THIN_ARCHIVE := true
|
||||||
APP_STRIP_MODE := none
|
APP_STRIP_MODE := none
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::consts::{APP_PACKAGE_NAME, BBPATH, DATABIN, MODULEROOT, SECURE_DIR};
|
use crate::consts::{APP_DATA_DIR, APP_PACKAGE_NAME, BBPATH, DATABIN, MODULEROOT, SECURE_DIR};
|
||||||
use crate::daemon::MagiskD;
|
use crate::daemon::MagiskD;
|
||||||
use crate::db::MultiuserMode;
|
use crate::db::MultiuserMode;
|
||||||
use crate::ffi::{
|
use crate::ffi::{
|
||||||
@@ -36,7 +36,7 @@ impl MagiskD {
|
|||||||
let mut buf = cstr::buf::default();
|
let mut buf = cstr::buf::default();
|
||||||
|
|
||||||
for user in self.get_users() {
|
for user in self.get_users() {
|
||||||
buf.append_path(self.app_data_dir())
|
buf.append_path(APP_DATA_DIR)
|
||||||
.append_path_fmt(user)
|
.append_path_fmt(user)
|
||||||
.append_path(APP_PACKAGE_NAME)
|
.append_path(APP_PACKAGE_NAME)
|
||||||
.append_path("install");
|
.append_path("install");
|
||||||
@@ -118,14 +118,9 @@ impl MagiskD {
|
|||||||
self.preserve_stub_apk();
|
self.preserve_stub_apk();
|
||||||
|
|
||||||
// Check secure dir
|
// Check secure dir
|
||||||
let secure_dir = cstr!(SECURE_DIR);
|
if !cstr!(SECURE_DIR).exists() {
|
||||||
if !secure_dir.exists() {
|
error!("* {} is not present, abort", SECURE_DIR);
|
||||||
if self.sdk_int < 24 {
|
return true;
|
||||||
secure_dir.mkdir(0o700).log_ok();
|
|
||||||
} else {
|
|
||||||
error!("* {} is not present, abort", SECURE_DIR);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.prune_su_access();
|
self.prune_su_access();
|
||||||
|
|||||||
@@ -78,14 +78,6 @@ impl MagiskD {
|
|||||||
self.sdk_int
|
self.sdk_int
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn app_data_dir(&self) -> &'static Utf8CStr {
|
|
||||||
if self.sdk_int >= 24 {
|
|
||||||
cstr!("/data/user_de")
|
|
||||||
} else {
|
|
||||||
cstr!("/data/user")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_request_sync(&self, mut client: UnixStream, code: RequestCode) {
|
fn handle_request_sync(&self, mut client: UnixStream, code: RequestCode) {
|
||||||
match code {
|
match code {
|
||||||
RequestCode::CHECK_VERSION => {
|
RequestCode::CHECK_VERSION => {
|
||||||
|
|||||||
@@ -15,7 +15,6 @@
|
|||||||
#define to_user_id(uid) (uid / AID_USER_OFFSET)
|
#define to_user_id(uid) (uid / AID_USER_OFFSET)
|
||||||
|
|
||||||
#define SDK_INT (MagiskD::Get().sdk_int())
|
#define SDK_INT (MagiskD::Get().sdk_int())
|
||||||
#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user")
|
|
||||||
|
|
||||||
inline int connect_daemon(RequestCode req) {
|
inline int connect_daemon(RequestCode req) {
|
||||||
return connect_daemon(req, false);
|
return connect_daemon(req, false);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
use crate::consts::{APP_PACKAGE_NAME, MAGISK_VER_CODE};
|
use crate::consts::{APP_DATA_DIR, APP_PACKAGE_NAME, MAGISK_VER_CODE};
|
||||||
use crate::daemon::{AID_APP_END, AID_APP_START, AID_USER_OFFSET, MagiskD, to_app_id};
|
use crate::daemon::{AID_APP_END, AID_APP_START, AID_USER_OFFSET, MagiskD, to_app_id};
|
||||||
use crate::ffi::{DbEntryKey, get_magisk_tmp, install_apk, uninstall_pkg};
|
use crate::ffi::{DbEntryKey, get_magisk_tmp, install_apk, uninstall_pkg};
|
||||||
use base::WalkResult::{Abort, Continue, Skip};
|
use base::WalkResult::{Abort, Continue, Skip};
|
||||||
@@ -227,9 +227,9 @@ impl TrackedFile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl ManagerInfo {
|
impl ManagerInfo {
|
||||||
fn check_dyn(&mut self, daemon: &MagiskD, user: i32, pkg: &str) -> Status {
|
fn check_dyn(&mut self, user: i32, pkg: &str) -> Status {
|
||||||
let apk = cstr::buf::default()
|
let apk = cstr::buf::default()
|
||||||
.join_path(daemon.app_data_dir())
|
.join_path(APP_DATA_DIR)
|
||||||
.join_path_fmt(user)
|
.join_path_fmt(user)
|
||||||
.join_path(pkg)
|
.join_path(pkg)
|
||||||
.join_path("dyn")
|
.join_path("dyn")
|
||||||
@@ -349,7 +349,7 @@ impl ManagerInfo {
|
|||||||
return (-1, "");
|
return (-1, "");
|
||||||
}
|
}
|
||||||
// dyn APK is still the same
|
// dyn APK is still the same
|
||||||
if file.path.starts_with(daemon.app_data_dir().as_str()) {
|
if file.path.starts_with(APP_DATA_DIR) {
|
||||||
return (
|
return (
|
||||||
user * AID_USER_OFFSET + self.repackaged_app_id,
|
user * AID_USER_OFFSET + self.repackaged_app_id,
|
||||||
&self.repackaged_pkg,
|
&self.repackaged_pkg,
|
||||||
@@ -358,7 +358,7 @@ impl ManagerInfo {
|
|||||||
// stub APK is still the same
|
// stub APK is still the same
|
||||||
if !self.repackaged_pkg.is_empty() {
|
if !self.repackaged_pkg.is_empty() {
|
||||||
return if matches!(
|
return if matches!(
|
||||||
self.check_dyn(daemon, user, self.repackaged_pkg.clone().as_str()),
|
self.check_dyn(user, self.repackaged_pkg.clone().as_str()),
|
||||||
Status::Installed
|
Status::Installed
|
||||||
) {
|
) {
|
||||||
(
|
(
|
||||||
@@ -381,7 +381,7 @@ impl ManagerInfo {
|
|||||||
if !db_pkg.is_empty() {
|
if !db_pkg.is_empty() {
|
||||||
match self.check_stub(user, &db_pkg) {
|
match self.check_stub(user, &db_pkg) {
|
||||||
Status::Installed => {
|
Status::Installed => {
|
||||||
return if matches!(self.check_dyn(daemon, user, &db_pkg), Status::Installed) {
|
return if matches!(self.check_dyn(user, &db_pkg), Status::Installed) {
|
||||||
(
|
(
|
||||||
user * AID_USER_OFFSET + self.repackaged_app_id,
|
user * AID_USER_OFFSET + self.repackaged_app_id,
|
||||||
&self.repackaged_pkg,
|
&self.repackaged_pkg,
|
||||||
@@ -430,7 +430,7 @@ impl ManagerInfo {
|
|||||||
impl MagiskD {
|
impl MagiskD {
|
||||||
fn get_package_uid(&self, user: i32, pkg: &str) -> i32 {
|
fn get_package_uid(&self, user: i32, pkg: &str) -> i32 {
|
||||||
let path = cstr::buf::default()
|
let path = cstr::buf::default()
|
||||||
.join_path(self.app_data_dir())
|
.join_path(APP_DATA_DIR)
|
||||||
.join_path_fmt(user)
|
.join_path_fmt(user)
|
||||||
.join_path(pkg);
|
.join_path(pkg);
|
||||||
path.get_attr()
|
path.get_attr()
|
||||||
@@ -483,7 +483,7 @@ impl MagiskD {
|
|||||||
pub fn get_app_no_list(&self) -> BitSet {
|
pub fn get_app_no_list(&self) -> BitSet {
|
||||||
let mut list = BitSet::new();
|
let mut list = BitSet::new();
|
||||||
let _ = || -> LoggedResult<()> {
|
let _ = || -> LoggedResult<()> {
|
||||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
let mut app_data_dir = Directory::open(cstr!(APP_DATA_DIR))?;
|
||||||
// For each user
|
// For each user
|
||||||
loop {
|
loop {
|
||||||
let entry = match app_data_dir.read()? {
|
let entry = match app_data_dir.read()? {
|
||||||
@@ -512,7 +512,7 @@ impl MagiskD {
|
|||||||
pub fn get_users(&self) -> Vec<i32> {
|
pub fn get_users(&self) -> Vec<i32> {
|
||||||
let mut users = Vec::new();
|
let mut users = Vec::new();
|
||||||
let _ = || -> LoggedResult<()> {
|
let _ = || -> LoggedResult<()> {
|
||||||
let mut app_data_dir = Directory::open(self.app_data_dir())?;
|
let mut app_data_dir = Directory::open(cstr!(APP_DATA_DIR))?;
|
||||||
while let Some(e) = app_data_dir.read()? {
|
while let Some(e) = app_data_dir.read()? {
|
||||||
if e.is_dir()
|
if e.is_dir()
|
||||||
&& let Ok(user) = e.name().parse::<i32>()
|
&& let Ok(user) = e.name().parse::<i32>()
|
||||||
|
|||||||
@@ -370,25 +370,6 @@ fas_c = ForkApp(
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
fas_samsung_m = ForkApp(
|
|
||||||
"samsung_m",
|
|
||||||
[
|
|
||||||
uid,
|
|
||||||
gid,
|
|
||||||
gids,
|
|
||||||
runtime_flags,
|
|
||||||
rlimits,
|
|
||||||
mount_external,
|
|
||||||
se_info,
|
|
||||||
Anon(jint),
|
|
||||||
Anon(jint),
|
|
||||||
nice_name,
|
|
||||||
fds_to_close,
|
|
||||||
instruction_set,
|
|
||||||
app_data_dir,
|
|
||||||
],
|
|
||||||
)
|
|
||||||
|
|
||||||
fas_samsung_n = ForkApp(
|
fas_samsung_n = ForkApp(
|
||||||
"samsung_n",
|
"samsung_n",
|
||||||
[
|
[
|
||||||
@@ -718,7 +699,6 @@ with open("jni_hooks.hpp", "w") as f:
|
|||||||
fas_samsung_p,
|
fas_samsung_p,
|
||||||
fas_samsung_o,
|
fas_samsung_o,
|
||||||
fas_samsung_n,
|
fas_samsung_n,
|
||||||
fas_samsung_m,
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ static JniHookDefinitions *get_defs();
|
|||||||
|
|
||||||
struct JniHookDefinitions {
|
struct JniHookDefinitions {
|
||||||
|
|
||||||
std::array<JNINativeMethod, 13> fork_app_methods = {{
|
std::array<JNINativeMethod, 12> fork_app_methods = {{
|
||||||
// nativeForkAndSpecialize_c
|
// nativeForkAndSpecialize_c
|
||||||
{
|
{
|
||||||
"nativeForkAndSpecialize",
|
"nativeForkAndSpecialize",
|
||||||
@@ -177,7 +177,7 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
|||||||
"nativeForkAndSpecialize",
|
"nativeForkAndSpecialize",
|
||||||
// IIILILILLLLZLLZZLLZZZL
|
// IIILILILLLLZLLZZLLZZZL
|
||||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;ZZ[Ljava/lang/String;[Ljava/lang/String;ZZZLjava/lang/String;)I",
|
"(II[II[[IILjava/lang/String;Ljava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;ZZ[Ljava/lang/String;[Ljava/lang/String;ZZZLjava/lang/String;)I",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _9) static -> jint {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _7) static -> jint {
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||||
args.fds_to_ignore = &fds_to_ignore;
|
args.fds_to_ignore = &fds_to_ignore;
|
||||||
args.is_child_zygote = &is_child_zygote;
|
args.is_child_zygote = &is_child_zygote;
|
||||||
@@ -189,8 +189,8 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
|||||||
args.mount_sysprop_overrides = &mount_sysprop_overrides;
|
args.mount_sysprop_overrides = &mount_sysprop_overrides;
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeForkAndSpecialize_pre();
|
ctx.nativeForkAndSpecialize_pre();
|
||||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _9)>(get_defs()->fork_app_methods[8].fnPtr)(
|
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jboolean use_fifo_ui, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _7)>(get_defs()->fork_app_methods[8].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, use_fifo_ui, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _9
|
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir, is_top_app, use_fifo_ui, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _7
|
||||||
);
|
);
|
||||||
ctx.nativeForkAndSpecialize_post();
|
ctx.nativeForkAndSpecialize_post();
|
||||||
return ctx.pid;
|
return ctx.pid;
|
||||||
@@ -201,14 +201,14 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
|||||||
"nativeForkAndSpecialize",
|
"nativeForkAndSpecialize",
|
||||||
// IIILILILIILLLZLL
|
// IIILILILIILLLZLL
|
||||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I",
|
"(II[II[[IILjava/lang/String;IILjava/lang/String;[I[IZLjava/lang/String;Ljava/lang/String;)I",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _7, jint _8, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> jint {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||||
args.fds_to_ignore = &fds_to_ignore;
|
args.fds_to_ignore = &fds_to_ignore;
|
||||||
args.is_child_zygote = &is_child_zygote;
|
args.is_child_zygote = &is_child_zygote;
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeForkAndSpecialize_pre();
|
ctx.nativeForkAndSpecialize_pre();
|
||||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _7, jint _8, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[9].fnPtr)(
|
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[9].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _7, _8, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir
|
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _5, _6, nice_name, fds_to_close, fds_to_ignore, is_child_zygote, instruction_set, app_data_dir
|
||||||
);
|
);
|
||||||
ctx.nativeForkAndSpecialize_post();
|
ctx.nativeForkAndSpecialize_post();
|
||||||
return ctx.pid;
|
return ctx.pid;
|
||||||
@@ -219,13 +219,13 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
|||||||
"nativeForkAndSpecialize",
|
"nativeForkAndSpecialize",
|
||||||
// IIILILILIILLLLL
|
// IIILILILIILLLLL
|
||||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[I[ILjava/lang/String;Ljava/lang/String;)I",
|
"(II[II[[IILjava/lang/String;IILjava/lang/String;[I[ILjava/lang/String;Ljava/lang/String;)I",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir) static -> jint {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _3, jint _4, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir) static -> jint {
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||||
args.fds_to_ignore = &fds_to_ignore;
|
args.fds_to_ignore = &fds_to_ignore;
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeForkAndSpecialize_pre();
|
ctx.nativeForkAndSpecialize_pre();
|
||||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _5, jint _6, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[10].fnPtr)(
|
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _3, jint _4, jstring nice_name, jintArray fds_to_close, jintArray fds_to_ignore, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[10].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _5, _6, nice_name, fds_to_close, fds_to_ignore, instruction_set, app_data_dir
|
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _3, _4, nice_name, fds_to_close, fds_to_ignore, instruction_set, app_data_dir
|
||||||
);
|
);
|
||||||
ctx.nativeForkAndSpecialize_post();
|
ctx.nativeForkAndSpecialize_post();
|
||||||
return ctx.pid;
|
return ctx.pid;
|
||||||
@@ -236,28 +236,12 @@ std::array<JNINativeMethod, 13> fork_app_methods = {{
|
|||||||
"nativeForkAndSpecialize",
|
"nativeForkAndSpecialize",
|
||||||
// IIILILILIILLLLI
|
// IIILILILIILLLLI
|
||||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[ILjava/lang/String;Ljava/lang/String;I)I",
|
"(II[II[[IILjava/lang/String;IILjava/lang/String;[ILjava/lang/String;Ljava/lang/String;I)I",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _2, jint _3, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _4) static -> jint {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _2) static -> jint {
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeForkAndSpecialize_pre();
|
ctx.nativeForkAndSpecialize_pre();
|
||||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _2, jint _3, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _4)>(get_defs()->fork_app_methods[11].fnPtr)(
|
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir, jint _2)>(get_defs()->fork_app_methods[11].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _2, _3, nice_name, fds_to_close, instruction_set, app_data_dir, _4
|
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _0, _1, nice_name, fds_to_close, instruction_set, app_data_dir, _2
|
||||||
);
|
|
||||||
ctx.nativeForkAndSpecialize_post();
|
|
||||||
return ctx.pid;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
// nativeForkAndSpecialize_samsung_m
|
|
||||||
{
|
|
||||||
"nativeForkAndSpecialize",
|
|
||||||
// IIILILILIILLLL
|
|
||||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;[ILjava/lang/String;Ljava/lang/String;)I",
|
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir) static -> jint {
|
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
|
||||||
ZygiskContext ctx(env, &args);
|
|
||||||
ctx.nativeForkAndSpecialize_pre();
|
|
||||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _0, jint _1, jstring nice_name, jintArray fds_to_close, jstring instruction_set, jstring app_data_dir)>(get_defs()->fork_app_methods[12].fnPtr)(
|
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _0, _1, nice_name, fds_to_close, instruction_set, app_data_dir
|
|
||||||
);
|
);
|
||||||
ctx.nativeForkAndSpecialize_post();
|
ctx.nativeForkAndSpecialize_post();
|
||||||
return ctx.pid;
|
return ctx.pid;
|
||||||
@@ -352,7 +336,7 @@ std::array<JNINativeMethod, 8> specialize_app_methods = {{
|
|||||||
"nativeSpecializeAppProcess",
|
"nativeSpecializeAppProcess",
|
||||||
// VIILILILLZLLZLLZZZL
|
// VIILILILLZLLZLLZZZL
|
||||||
"(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/String;ZZZLjava/lang/String;)V",
|
"(II[II[[IILjava/lang/String;Ljava/lang/String;ZLjava/lang/String;Ljava/lang/String;Z[Ljava/lang/String;[Ljava/lang/String;ZZZLjava/lang/String;)V",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _12) static -> void {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _10) static -> void {
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||||
args.is_child_zygote = &is_child_zygote;
|
args.is_child_zygote = &is_child_zygote;
|
||||||
args.is_top_app = &is_top_app;
|
args.is_top_app = &is_top_app;
|
||||||
@@ -363,8 +347,8 @@ std::array<JNINativeMethod, 8> specialize_app_methods = {{
|
|||||||
args.mount_sysprop_overrides = &mount_sysprop_overrides;
|
args.mount_sysprop_overrides = &mount_sysprop_overrides;
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeSpecializeAppProcess_pre();
|
ctx.nativeSpecializeAppProcess_pre();
|
||||||
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _12)>(get_defs()->specialize_app_methods[4].fnPtr)(
|
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir, jboolean is_top_app, jobjectArray pkg_data_info_list, jobjectArray whitelisted_data_info_list, jboolean mount_data_dirs, jboolean mount_storage_dirs, jboolean mount_sysprop_overrides, jstring _10)>(get_defs()->specialize_app_methods[4].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _12
|
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, is_child_zygote, instruction_set, app_data_dir, is_top_app, pkg_data_info_list, whitelisted_data_info_list, mount_data_dirs, mount_storage_dirs, mount_sysprop_overrides, _10
|
||||||
);
|
);
|
||||||
ctx.nativeSpecializeAppProcess_post();
|
ctx.nativeSpecializeAppProcess_post();
|
||||||
}
|
}
|
||||||
@@ -395,13 +379,13 @@ std::array<JNINativeMethod, 8> specialize_app_methods = {{
|
|||||||
"nativeSpecializeAppProcess",
|
"nativeSpecializeAppProcess",
|
||||||
// VIILILILIILZLL
|
// VIILILILIILZLL
|
||||||
"(II[II[[IILjava/lang/String;IILjava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V",
|
"(II[II[[IILjava/lang/String;IILjava/lang/String;ZLjava/lang/String;Ljava/lang/String;)V",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _10, jint _11, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> void {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _8, jint _9, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir) static -> void {
|
||||||
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
AppSpecializeArgs_v5 args(uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, nice_name, instruction_set, app_data_dir);
|
||||||
args.is_child_zygote = &is_child_zygote;
|
args.is_child_zygote = &is_child_zygote;
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeSpecializeAppProcess_pre();
|
ctx.nativeSpecializeAppProcess_pre();
|
||||||
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _10, jint _11, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->specialize_app_methods[6].fnPtr)(
|
reinterpret_cast<void(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jobjectArray rlimits, jint mount_external, jstring se_info, jint _8, jint _9, jstring nice_name, jboolean is_child_zygote, jstring instruction_set, jstring app_data_dir)>(get_defs()->specialize_app_methods[6].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _10, _11, nice_name, is_child_zygote, instruction_set, app_data_dir
|
env, clazz, uid, gid, gids, runtime_flags, rlimits, mount_external, se_info, _8, _9, nice_name, is_child_zygote, instruction_set, app_data_dir
|
||||||
);
|
);
|
||||||
ctx.nativeSpecializeAppProcess_post();
|
ctx.nativeSpecializeAppProcess_post();
|
||||||
}
|
}
|
||||||
@@ -447,12 +431,12 @@ std::array<JNINativeMethod, 2> fork_server_methods = {{
|
|||||||
"nativeForkSystemServer",
|
"nativeForkSystemServer",
|
||||||
// IIILIIILJJ
|
// IIILIIILJJ
|
||||||
"(II[IIII[[IJJ)I",
|
"(II[IIII[[IJJ)I",
|
||||||
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _13, jint _14, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) static -> jint {
|
(void *) +[] [[clang::no_stack_protector]] (JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _11, jint _12, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities) static -> jint {
|
||||||
ServerSpecializeArgs_v1 args(uid, gid, gids, runtime_flags, permitted_capabilities, effective_capabilities);
|
ServerSpecializeArgs_v1 args(uid, gid, gids, runtime_flags, permitted_capabilities, effective_capabilities);
|
||||||
ZygiskContext ctx(env, &args);
|
ZygiskContext ctx(env, &args);
|
||||||
ctx.nativeForkSystemServer_pre();
|
ctx.nativeForkSystemServer_pre();
|
||||||
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _13, jint _14, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities)>(get_defs()->fork_server_methods[1].fnPtr)(
|
reinterpret_cast<jint(*)(JNIEnv *env, jclass clazz, jint uid, jint gid, jintArray gids, jint runtime_flags, jint _11, jint _12, jobjectArray rlimits, jlong permitted_capabilities, jlong effective_capabilities)>(get_defs()->fork_server_methods[1].fnPtr)(
|
||||||
env, clazz, uid, gid, gids, runtime_flags, _13, _14, rlimits, permitted_capabilities, effective_capabilities
|
env, clazz, uid, gid, gids, runtime_flags, _11, _12, rlimits, permitted_capabilities, effective_capabilities
|
||||||
);
|
);
|
||||||
ctx.nativeForkSystemServer_post();
|
ctx.nativeForkSystemServer_post();
|
||||||
return ctx.pid;
|
return ctx.pid;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define JAVA_PACKAGE_NAME "com.topjohnwu.magisk"
|
#define JAVA_PACKAGE_NAME "com.topjohnwu.magisk"
|
||||||
|
#define APP_DATA_DIR "/data/user_de"
|
||||||
#define SECURE_DIR "/data/adb"
|
#define SECURE_DIR "/data/adb"
|
||||||
#define MODULEROOT SECURE_DIR "/modules"
|
#define MODULEROOT SECURE_DIR "/modules"
|
||||||
#define DATABIN SECURE_DIR "/magisk"
|
#define DATABIN SECURE_DIR "/magisk"
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ pub const APP_PACKAGE_NAME: &str = "com.topjohnwu.magisk";
|
|||||||
pub const LOGFILE: &str = "/cache/magisk.log";
|
pub const LOGFILE: &str = "/cache/magisk.log";
|
||||||
|
|
||||||
// data paths
|
// data paths
|
||||||
|
pub const APP_DATA_DIR: &str = "/data/user_de";
|
||||||
pub const SECURE_DIR: &str = "/data/adb";
|
pub const SECURE_DIR: &str = "/data/adb";
|
||||||
pub const MODULEROOT: &str = concatcp!(SECURE_DIR, "/modules");
|
pub const MODULEROOT: &str = concatcp!(SECURE_DIR, "/modules");
|
||||||
pub const MODULEUPGRADE: &str = concatcp!(SECURE_DIR, "/modules_update");
|
pub const MODULEUPGRADE: &str = concatcp!(SECURE_DIR, "/modules_update");
|
||||||
|
|||||||
@@ -15,12 +15,10 @@ use std::time::Duration;
|
|||||||
const MOCK_VERSION: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/version"));
|
const MOCK_VERSION: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/version"));
|
||||||
const MOCK_LOAD: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/load"));
|
const MOCK_LOAD: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/load"));
|
||||||
const MOCK_ENFORCE: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/enforce"));
|
const MOCK_ENFORCE: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/enforce"));
|
||||||
const MOCK_REQPROT: &Utf8CStr = cstr!(concatcp!(SELINUXMOCK, "/checkreqprot"));
|
|
||||||
|
|
||||||
const SELINUX_MNT: &str = "/sys/fs/selinux";
|
const SELINUX_MNT: &str = "/sys/fs/selinux";
|
||||||
const SELINUX_ENFORCE: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/enforce"));
|
const SELINUX_ENFORCE: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/enforce"));
|
||||||
const SELINUX_LOAD: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/load"));
|
const SELINUX_LOAD: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/load"));
|
||||||
const SELINUX_REQPROT: &Utf8CStr = cstr!(concatcp!(SELINUX_MNT, "/checkreqprot"));
|
|
||||||
|
|
||||||
enum SePatchStrategy {
|
enum SePatchStrategy {
|
||||||
// 2SI, Android 10+
|
// 2SI, Android 10+
|
||||||
@@ -32,7 +30,7 @@ enum SePatchStrategy {
|
|||||||
// selinuxfs is mounted in init.cpp. Errors when mounting selinuxfs is ignored,
|
// selinuxfs is mounted in init.cpp. Errors when mounting selinuxfs is ignored,
|
||||||
// which means that we can directly mount selinuxfs ourselves and hijack nodes in it.
|
// which means that we can directly mount selinuxfs ourselves and hijack nodes in it.
|
||||||
SelinuxFs,
|
SelinuxFs,
|
||||||
// Dynamic patching, Android 6.0 - 7.1
|
// Dynamic patching, Android 7.0 - 7.1
|
||||||
// selinuxfs is mounted in libselinux's selinux_android_load_policy(). Errors when
|
// selinuxfs is mounted in libselinux's selinux_android_load_policy(). Errors when
|
||||||
// mounting selinuxfs is fatal, which means we need to block init's control flow after
|
// mounting selinuxfs is fatal, which means we need to block init's control flow after
|
||||||
// it mounted selinuxfs for us, then we can hijack nodes in it.
|
// it mounted selinuxfs for us, then we can hijack nodes in it.
|
||||||
@@ -43,9 +41,9 @@ enum SePatchStrategy {
|
|||||||
//
|
//
|
||||||
// We need to make sure the actual init process is blocked until sepolicy is loaded,
|
// We need to make sure the actual init process is blocked until sepolicy is loaded,
|
||||||
// or else restorecon will fail and re-exec won't change context, causing boot failure.
|
// or else restorecon will fail and re-exec won't change context, causing boot failure.
|
||||||
// We (ab)use the fact that init either reads the enforce node, or writes the checkreqprot
|
// We (ab)use the fact that init reads the enforce node, and because it has been replaced
|
||||||
// node, and because both has been replaced with FIFO files, init will block until we
|
// with our FIFO file, init will block until we write something into the pipe, effectively
|
||||||
// handle it, effectively hijacking its control flow until the patched sepolicy is loaded.
|
// hijacking its control flow until the patched sepolicy is loaded.
|
||||||
|
|
||||||
fn mock_fifo(target: &Utf8CStr, mock: &Utf8CStr) -> LoggedResult<()> {
|
fn mock_fifo(target: &Utf8CStr, mock: &Utf8CStr) -> LoggedResult<()> {
|
||||||
debug!("Hijack [{}]", target);
|
debug!("Hijack [{}]", target);
|
||||||
@@ -69,7 +67,6 @@ impl MagiskInit {
|
|||||||
cstr!("/init").unmount().ok();
|
cstr!("/init").unmount().ok();
|
||||||
SELINUX_LOAD.unmount().log_ok();
|
SELINUX_LOAD.unmount().log_ok();
|
||||||
SELINUX_ENFORCE.unmount().ok();
|
SELINUX_ENFORCE.unmount().ok();
|
||||||
SELINUX_REQPROT.unmount().ok();
|
|
||||||
|
|
||||||
let mut sepol = SePolicy::from_file(MOCK_LOAD);
|
let mut sepol = SePolicy::from_file(MOCK_LOAD);
|
||||||
sepol.magisk_rules();
|
sepol.magisk_rules();
|
||||||
@@ -186,25 +183,16 @@ impl MagiskInit {
|
|||||||
|
|
||||||
// Step 2: wait for selinuxfs to be mounted (only for LEGACY)
|
// Step 2: wait for selinuxfs to be mounted (only for LEGACY)
|
||||||
|
|
||||||
let wait = Duration::from_millis(100);
|
|
||||||
|
|
||||||
if matches!(strat, SePatchStrategy::Legacy) {
|
if matches!(strat, SePatchStrategy::Legacy) {
|
||||||
|
let wait = Duration::from_millis(100);
|
||||||
// Busy wait until selinuxfs is mounted
|
// Busy wait until selinuxfs is mounted
|
||||||
while !SELINUX_ENFORCE.exists() {
|
while !SELINUX_ENFORCE.exists() {
|
||||||
// Retry every 100ms
|
// Retry every 100ms
|
||||||
sleep(wait);
|
sleep(wait);
|
||||||
}
|
}
|
||||||
|
|
||||||
// On Android 6.0, init does not call security_getenforce() first; instead it directly
|
|
||||||
// call security_setenforce() after security_load_policy(). What's even worse, it opens
|
|
||||||
// the enforce node with O_RDWR, which will not block when opening FIFO files.
|
|
||||||
// As a workaround, we do not mock the enforce node, and block init with mocking
|
|
||||||
// checkreqprot instead.
|
|
||||||
// Android 7.0 - 7.1 doesn't have this issue, but for simplicity, let's just use the
|
|
||||||
// same blocking strategy for both since it also works just fine.
|
|
||||||
|
|
||||||
mock_file(SELINUX_LOAD, MOCK_LOAD)?;
|
mock_file(SELINUX_LOAD, MOCK_LOAD)?;
|
||||||
mock_fifo(SELINUX_REQPROT, MOCK_REQPROT)?;
|
mock_fifo(SELINUX_ENFORCE, MOCK_ENFORCE)?;
|
||||||
|
|
||||||
// This will unblock init at selinux_android_load_policy() -> set_policy_index().
|
// This will unblock init at selinux_android_load_policy() -> set_policy_index().
|
||||||
drop(MOCK_VERSION.open(OFlag::O_WRONLY)?);
|
drop(MOCK_VERSION.open(OFlag::O_WRONLY)?);
|
||||||
@@ -241,7 +229,7 @@ impl MagiskInit {
|
|||||||
// Write ack to restore preload.so's control flow
|
// Write ack to restore preload.so's control flow
|
||||||
ack_fd.write_all("0".as_bytes())?;
|
ack_fd.write_all("0".as_bytes())?;
|
||||||
}
|
}
|
||||||
SePatchStrategy::SelinuxFs => {
|
SePatchStrategy::SelinuxFs | SePatchStrategy::Legacy => {
|
||||||
// This open will block until init calls security_getenforce().
|
// This open will block until init calls security_getenforce().
|
||||||
let mut mock_enforce = MOCK_ENFORCE.open(OFlag::O_WRONLY)?;
|
let mut mock_enforce = MOCK_ENFORCE.open(OFlag::O_WRONLY)?;
|
||||||
|
|
||||||
@@ -254,29 +242,6 @@ impl MagiskInit {
|
|||||||
.read_to_end(&mut data)?;
|
.read_to_end(&mut data)?;
|
||||||
mock_enforce.write_all(&data)?;
|
mock_enforce.write_all(&data)?;
|
||||||
}
|
}
|
||||||
SePatchStrategy::Legacy => {
|
|
||||||
let mut sz = 0_usize;
|
|
||||||
// Busy wait until sepolicy is fully written.
|
|
||||||
loop {
|
|
||||||
let attr = MOCK_LOAD.get_attr()?;
|
|
||||||
if sz != 0 && sz == attr.st.st_size as usize {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sz = attr.st.st_size as usize;
|
|
||||||
// Check every 100ms
|
|
||||||
sleep(wait);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.cleanup_and_load(&rules);
|
|
||||||
|
|
||||||
// init is blocked on checkreqprot, write to the real node first, then
|
|
||||||
// unblock init by opening the mock FIFO.
|
|
||||||
SELINUX_REQPROT
|
|
||||||
.open(OFlag::O_WRONLY)?
|
|
||||||
.write_all("0".as_bytes())?;
|
|
||||||
let mut v = vec![];
|
|
||||||
MOCK_REQPROT.open(OFlag::O_RDONLY)?.read_to_end(&mut v)?;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// At this point, the init process will be unblocked
|
// At this point, the init process will be unblocked
|
||||||
|
|||||||
+10
-14
@@ -152,20 +152,16 @@ check_boot_ramdisk() {
|
|||||||
|
|
||||||
check_encryption() {
|
check_encryption() {
|
||||||
if $ISENCRYPTED; then
|
if $ISENCRYPTED; then
|
||||||
if [ $SDK_INT -lt 24 ]; then
|
# First see what the system tells us
|
||||||
CRYPTOTYPE="block"
|
CRYPTOTYPE=$(getprop ro.crypto.type)
|
||||||
else
|
if [ -z $CRYPTOTYPE ]; then
|
||||||
# First see what the system tells us
|
# If not mounting through device mapper, we are FBE
|
||||||
CRYPTOTYPE=$(getprop ro.crypto.type)
|
if grep ' /data ' /proc/mounts | grep -qv 'dm-'; then
|
||||||
if [ -z $CRYPTOTYPE ]; then
|
CRYPTOTYPE="file"
|
||||||
# If not mounting through device mapper, we are FBE
|
else
|
||||||
if grep ' /data ' /proc/mounts | grep -qv 'dm-'; then
|
# We are either FDE or metadata encryption (which is also FBE)
|
||||||
CRYPTOTYPE="file"
|
CRYPTOTYPE="block"
|
||||||
else
|
grep -q ' /metadata ' /proc/mounts && CRYPTOTYPE="file"
|
||||||
# We are either FDE or metadata encryption (which is also FBE)
|
|
||||||
CRYPTOTYPE="block"
|
|
||||||
grep -q ' /metadata ' /proc/mounts && CRYPTOTYPE="file"
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# AVD MagiskInit Setup
|
# AVD MagiskInit Setup
|
||||||
#####################################################################
|
#####################################################################
|
||||||
#
|
#
|
||||||
# Support API level: 23 - 36
|
# Support API level: 24 - 36
|
||||||
#
|
#
|
||||||
# With an emulator booted and accessible via ADB, usage:
|
# With an emulator booted and accessible via ADB, usage:
|
||||||
# ./build.py patch --avd path/to/booted/avd-image/ramdisk.img
|
# ./build.py patch --avd path/to/booted/avd-image/ramdisk.img
|
||||||
@@ -15,7 +15,7 @@
|
|||||||
#####################################################################
|
#####################################################################
|
||||||
# AVD Init Configurations:
|
# AVD Init Configurations:
|
||||||
#
|
#
|
||||||
# rootfs w/o early mount: API 23 - 25
|
# rootfs w/o early mount: API 24 - 25
|
||||||
# rootfs with early mount: API 26 - 27
|
# rootfs with early mount: API 26 - 27
|
||||||
# Legacy system-as-root: API 28
|
# Legacy system-as-root: API 28
|
||||||
# 2 stage init: API 29 - 35
|
# 2 stage init: API 29 - 35
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# AVD Magisk Setup
|
# AVD Magisk Setup
|
||||||
#####################################################################
|
#####################################################################
|
||||||
#
|
#
|
||||||
# Support API level: 23 - 36
|
# Support API level: 24 - 36
|
||||||
#
|
#
|
||||||
# For developing Magisk, just use:
|
# For developing Magisk, just use:
|
||||||
# ./build.py emulator
|
# ./build.py emulator
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ ui_print "- Target image: $BOOTIMAGE"
|
|||||||
# Detect version and architecture
|
# Detect version and architecture
|
||||||
api_level_arch_detect
|
api_level_arch_detect
|
||||||
|
|
||||||
[ $API -lt 23 ] && abort "! Magisk only support Android 6.0 and above"
|
[ $API -lt 24 ] && abort "! Magisk only support Android 7.0 and above"
|
||||||
|
|
||||||
ui_print "- Device platform: $ABI"
|
ui_print "- Device platform: $ABI"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user