Skip to content

Commit

Permalink
feat: prevent from being detected
Browse files Browse the repository at this point in the history
  • Loading branch information
Dr-TSNG committed Oct 8, 2021
1 parent 67542fd commit 6be018d
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 31 deletions.
6 changes: 0 additions & 6 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.tsng.hidemyapplist">

<queries>
<intent>
<action android:name="android.intent.action.MAIN" />
</intent>
</queries>

<uses-permission
android:name="android.permission.QUERY_ALL_PACKAGES"
tools:ignore="QueryAllPackagesPermission" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ import kotlin.concurrent.thread

object PackageManagerService {
private const val hmaApp = "com.tsng.hidemyapplist"
private const val dataDir = "/data/misc/hide_my_applist"
private val logFile = File("$dataDir/tmp/runtime.log")

private val customPms = arrayOf(
"com.android.server.pm.OplusPackageManagerService",
"com.android.server.pm.OppoPackageManagerService"
Expand All @@ -51,6 +50,8 @@ object PackageManagerService {
private var riruModuleVersion = 0
private var mLock = Any()

private lateinit var dataDir: String
private lateinit var logFile: File
private lateinit var token: String

@Volatile
Expand Down Expand Up @@ -83,17 +84,20 @@ object PackageManagerService {
}
}

private fun generateToken() {
private fun generateRandomString(length: Int): String {
val leftLimit = 97 // letter 'a'
val rightLimit = 122 // letter 'z'
val targetStringLength = 10
val random = Random()
val buffer = StringBuilder(targetStringLength)
for (i in 0 until targetStringLength) {
val buffer = StringBuilder(length)
for (i in 0 until length) {
val randomLimitedInt = leftLimit + (random.nextFloat() * (rightLimit - leftLimit + 1)).toInt()
buffer.append(randomLimitedInt.toChar())
}
token = buffer.toString()
return buffer.toString()
}

private fun generateToken() {
token = generateRandomString(10)
File("$dataDir/tmp/token").writeText(token)
}

Expand Down Expand Up @@ -251,7 +255,7 @@ object PackageManagerService {
param.result = provideLogs()

arg == "cleanLogs" -> {
synchronized(mLock) { with(logFile) { delete(); createNewFile() } }
synchronized(mLock) { logFile.apply { delete(); createNewFile() } }
param.result = "OK"
}

Expand Down Expand Up @@ -295,7 +299,7 @@ object PackageManagerService {

private fun syncWithRiru() {
/* If riru extension not installed, make tmp by the service */
with(File("$dataDir/tmp/riru_v")) {
File("$dataDir/tmp/riru_v").apply {
if (exists()) {
var minApkVersion: Int
try {
Expand All @@ -316,17 +320,30 @@ object PackageManagerService {
File("$dataDir/tmp/stop_riru").createNewFile()
Log.e("System service version too old to work with the new riru extension")
}
} else {
File(dataDir).mkdir()
File("$dataDir/tmp").deleteRecursively()
File("$dataDir/tmp").mkdir()
delete()
} else File("$dataDir/tmp").apply {
deleteRecursively()
mkdirs()
}
delete()
}
}

private fun searchDataDir() {
File("/data/misc/hide_my_applist").deleteRecursively()
File("/data/system").list()?.forEach {
if (it.startsWith("hide_my_applist")) {
dataDir = "/data/system/$it"
}
}
if (!this::dataDir.isInitialized) {
dataDir = "/data/system/hide_my_applist_" + generateRandomString(16)
}
logFile = File("$dataDir/tmp/runtime.log")
}

/* Load system service */
fun entry() {
searchDataDir()
syncWithRiru()
generateToken()
try {
Expand Down Expand Up @@ -362,6 +379,7 @@ object PackageManagerService {
File("$dataDir/tmp/system_apps.list").appendText("$pkg\n")

Log.i("System hook installed (Version ${BuildConfig.SERVICE_VERSION})")
Log.i("Data directory is at $dataDir")
})

/* ---Deal with 💩 ROMs--- */
Expand Down Expand Up @@ -404,7 +422,10 @@ object PackageManagerService {

"getPackageInfo",
"getPackageGids",
"getApplicationInfo"
"getApplicationInfo",
"getInstallSourceInfo",
"getLaunchIntentForPackage",
"getLeanbackLaunchIntentForPackage"
-> setResult(method, "API requests", null)

"queryIntentActivities",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class XposedEntry : IXposedHookZygoteInit, IXposedHookLoadPackage {
EzXHelperInit.setToastTag("HMA")

if (hostPackageName == BuildConfig.APPLICATION_ID) {
getFieldBySig("Lcom/tsng/hidemyapplist/app/MyApplication;->isModuleActivated:Z")
.setBoolean(null, true)
getFieldBySig("Lcom/tsng/hidemyapplist/app/MyApplication;->isModuleActivated:Z").setBoolean(null, true)
}
if (hostPackageName == "android")
PackageManagerService.entry()
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="settings_stop_system_service">Stopper le service du système</string>
<string name="settings_stop_system_service_summary">Redémarrage nécessaire pour redémarrer le service</string>
<string name="settings_is_clean_env">Nettoyer l\’environnement de fonctionnement en même temps?</string>
<string name="settings_is_clean_env_summary">Supprimer le cache du service du système dans /data/misc/hide_my_applist. Cela signifie que vous devez lancer l\’application du module une fois manuellement après le prochain redémarrage afin d\’activer les interceptions, et les compteurs d\’interceptions seront également nettoyés.</string>
<string name="settings_is_clean_env_summary">Supprimer le cache du service du système dans /data/system/hide_my_applist_*. Cela signifie que vous devez lancer l\’application du module une fois manuellement après le prochain redémarrage afin d\’activer les interceptions, et les compteurs d\’interceptions seront également nettoyés.</string>
<string name="settings_force_clean_env">Forcer le nettoyage de l\’environnement d\’exécution (root)</string>
<string name="settings_force_clean_env_summary">Uniquement si le service du système ne parvient pas à démarrer, ou sinon vous devriez cliquer sur l\’option ci-dessous.</string>
<string name="settings_force_clean_env_toast_successful">Environnement de fonctionnement nettoyé</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rCN/strings_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="settings_stop_system_service">终止系统服务</string>
<string name="settings_stop_system_service_summary">需要重启设备才能重新启动服务</string>
<string name="settings_is_clean_env">是否同时清理运行环境</string>
<string name="settings_is_clean_env_summary">移除位于 /data/misc/hide_my_applist 的系统服务缓存,这会使下次重启后需要先手动打开一次模块 APP 才能使拦截生效,同时拦截次数记录也会被清空。</string>
<string name="settings_is_clean_env_summary">移除位于 /data/system/hide_my_applist_* 的系统服务缓存,这会使下次重启后需要先手动打开一次模块 APP 才能使拦截生效,同时拦截次数记录也会被清空。</string>
<string name="settings_force_clean_env">强制清理运行环境 (root)</string>
<string name="settings_force_clean_env_summary">当且仅当系统服务无法启动时尝试此选项,否则你应该点击终止系统服务并自动执行清理</string>
<string name="settings_force_clean_env_toast_successful">运行环境清理完成</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-zh-rTW/strings_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="settings_stop_system_service">終止系統服務</string>
<string name="settings_stop_system_service_summary">需要重啟設備才能重新啟動服務</string>
<string name="settings_is_clean_env">是否同時清理運作環境</string>
<string name="settings_is_clean_env_summary">移除位於 /data/misc/hide_my_applist 的系統服務緩存,這會使下次重啟後需要先手動打開一次模組應用程式才能使攔截生效,同時攔截次數記錄也會被清空。</string>
<string name="settings_is_clean_env_summary">移除位於 /data/system/hide_my_applist_* 的系統服務緩存,這會使下次重啟後需要先手動打開一次模組應用程式才能使攔截生效,同時攔截次數記錄也會被清空。</string>
<string name="settings_force_clean_env">強制清理運作環境 (root)</string>
<string name="settings_force_clean_env_summary">當且僅當系統服務無法啟動時嘗試此選項,否則你應該點擊終止系統服務並自動執行清理</string>
<string name="settings_force_clean_env_toast_successful">運作環境清理完成</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<string name="settings_stop_system_service">Stop system service</string>
<string name="settings_stop_system_service_summary">Need reboot to restart service</string>
<string name="settings_is_clean_env">Clean runtime environment at the same time?</string>
<string name="settings_is_clean_env_summary">Remove system service cache in /data/misc/hide_my_applist. This means you need to launch the module app once manually after next reboot in order to enable interceptions, and interception counts will also be cleaned.</string>
<string name="settings_is_clean_env_summary">Remove system service cache in /data/system/hide_my_applist_*. This means you need to launch the module app once manually after next reboot in order to enable interceptions, and interception counts will also be cleaned.</string>
<string name="settings_force_clean_env">Force clean runtime environment (root)</string>
<string name="settings_force_clean_env_summary">Only if system service fails to start, otherwise you should click the above option.</string>
<string name="settings_force_clean_env_toast_successful">Runtime environment cleaned</string>
Expand Down
6 changes: 3 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ val buildToolsVer by extra("31.0.0")
val ndkVer by extra("23.0.7599858")

val appVerName by extra("2.2")
val appVerCode by extra(65)
val serviceVer by extra(65)
val minRiruVer by extra(26)
val appVerCode by extra(66)
val serviceVer by extra(66)
val minRiruVer by extra(28)
val minBackupVer by extra(65)

val gitCommitCount by extra("git rev-list HEAD --count".execute())
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pluginManagement {
plugins {
id("com.android.application").version("7.1.0-alpha13")
id("com.android.library").version("7.1.0-alpha13")
id("org.jetbrains.kotlin.android").version("1.5.30")
id("org.jetbrains.kotlin.android").version("1.5.31")
}
}

Expand Down

0 comments on commit 6be018d

Please sign in to comment.