diff --git a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt
index 615c2a3da..9bbbfd959 100644
--- a/app/src/main/java/com/topjohnwu/magisk/core/Config.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/core/Config.kt
@@ -59,6 +59,7 @@ object Config : PreferenceConfig, DBConfig {
const val THEME_ORDINAL = "theme_ordinal"
const val ASKED_HOME = "asked_home"
const val DOH = "doh"
+ const val RAND_NAME = "rand_name"
}
object Value {
@@ -125,6 +126,7 @@ object Config : PreferenceConfig, DBConfig {
var updateChannel by preferenceStrInt(Key.UPDATE_CHANNEL, defaultChannel)
var customChannelUrl by preference(Key.CUSTOM_CHANNEL, "")
var downloadDir by preference(Key.DOWNLOAD_DIR, "")
+ var randName by preference(Key.RAND_NAME, true)
var checkUpdate
get() = checkUpdatePrefs
set(value) {
diff --git a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
index 42620a449..d7a11ace1 100644
--- a/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
@@ -71,14 +71,18 @@ abstract class MagiskInstallImpl protected constructor(
private val localFS get() = FileSystemManager.getLocal()
private val destName: String by lazy {
- val alpha = "abcdefghijklmnopqrstuvwxyz"
- val alphaNum = "$alpha${alpha.uppercase(Locale.ROOT)}0123456789"
- val random = SecureRandom()
- StringBuilder("magisk_patched-${BuildConfig.VERSION_CODE}_").run {
- for (i in 1..5) {
- append(alphaNum[random.nextInt(alphaNum.length)])
+ if (Config.randName) {
+ val alpha = "abcdefghijklmnopqrstuvwxyz"
+ val alphaNum = "$alpha${alpha.uppercase(Locale.ROOT)}0123456789"
+ val random = SecureRandom()
+ StringBuilder("magisk_patched-${BuildConfig.VERSION_CODE}_").run {
+ for (i in 1..5) {
+ append(alphaNum[random.nextInt(alphaNum.length)])
+ }
+ toString()
}
- toString()
+ } else {
+ "magisk_patched"
}
}
@@ -440,7 +444,7 @@ abstract class MagiskInstallImpl protected constructor(
srcBoot = if (tarMagic.contentEquals("ustar".toByteArray())) {
// tar file
- outFile = MediaStoreUtils.getFile("$destName.tar", true)
+ outFile = MediaStoreUtils.getFile("$destName.tar")
outStream = TarArchiveOutputStream(outFile.uri.outputStream()).also {
it.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR)
it.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU)
@@ -456,7 +460,7 @@ abstract class MagiskInstallImpl protected constructor(
}
} else {
// raw image
- outFile = MediaStoreUtils.getFile("$destName.img", true)
+ outFile = MediaStoreUtils.getFile("$destName.img")
outStream = outFile.uri.outputStream()
try {
diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
index 62a1e6df7..57ec1c47e 100644
--- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsItems.kt
@@ -212,6 +212,12 @@ object SystemlessHosts : BaseSettingsItem.Blank() {
override val description = R.string.settings_hosts_summary.asText()
}
+object RandNameToggle : BaseSettingsItem.Toggle() {
+ override val title = R.string.settings_random_name_title.asText()
+ override val description = R.string.settings_random_name_description.asText()
+ override var value by Config::randName
+}
+
// --- Magisk
object Magisk : BaseSettingsItem.Section() {
diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
index 16b539a7f..ef2b75c47 100644
--- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
+++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsViewModel.kt
@@ -51,7 +51,7 @@ class SettingsViewModel : BaseViewModel(), BaseSettingsItem.Handler {
// Manager
list.addAll(listOf(
AppSettings,
- UpdateChannel, UpdateChannelUrl, DoHToggle, UpdateChecker, DownloadPath
+ UpdateChannel, UpdateChannelUrl, DoHToggle, UpdateChecker, DownloadPath, RandNameToggle
))
if (Info.env.isActive && Const.USER_ID == 0) {
if (hidden) list.add(Restore) else list.add(Hide)
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 86af664ad..4305a0160 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -178,6 +178,8 @@
Add a pretty shortcut to the home screen in case the name and icon are difficult to recognize after hiding the app
DNS over HTTPS
Workaround DNS poisoning in some nations
+ Randomize output name
+ Randomize the output file name of patched images and tar files to prevent detection
Multiuser Mode
Device Owner Only