Add option to disable filename randomization

This commit is contained in:
topjohnwu 2024-07-02 14:28:20 -07:00
parent 4a2a37c87a
commit e9694c6195
5 changed files with 24 additions and 10 deletions

View File

@ -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) {

View File

@ -71,6 +71,7 @@ abstract class MagiskInstallImpl protected constructor(
private val localFS get() = FileSystemManager.getLocal()
private val destName: String by lazy {
if (Config.randName) {
val alpha = "abcdefghijklmnopqrstuvwxyz"
val alphaNum = "$alpha${alpha.uppercase(Locale.ROOT)}0123456789"
val random = SecureRandom()
@ -80,6 +81,9 @@ abstract class MagiskInstallImpl protected constructor(
}
toString()
}
} else {
"magisk_patched"
}
}
private fun findImage(slot: String): Boolean {
@ -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 {

View File

@ -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() {

View File

@ -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)

View File

@ -178,6 +178,8 @@
<string name="setting_add_shortcut_summary">Add a pretty shortcut to the home screen in case the name and icon are difficult to recognize after hiding the app</string>
<string name="settings_doh_title">DNS over HTTPS</string>
<string name="settings_doh_description">Workaround DNS poisoning in some nations</string>
<string name="settings_random_name_title">Randomize output name</string>
<string name="settings_random_name_description">Randomize the output file name of patched images and tar files to prevent detection</string>
<string name="multiuser_mode">Multiuser Mode</string>
<string name="settings_owner_only">Device Owner Only</string>