From 2b4bdf1bbdc2ebea547394a4695d8df11bd8db94 Mon Sep 17 00:00:00 2001 From: Wang Han Date: Tue, 21 Sep 2021 18:53:31 +0800 Subject: [PATCH] [core] Don't hardcode injected AID in native code (#1152) * Update build.gradle.kts * Update Android.mk * Update main.cpp --- core/build.gradle.kts | 8 ++++++-- core/src/main/cpp/main/Android.mk | 1 + core/src/main/cpp/main/src/main.cpp | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/core/build.gradle.kts b/core/build.gradle.kts index b30d68fa..7ba0594c 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -43,6 +43,9 @@ val moduleMinRiruApiVersion = 25 val moduleMinRiruVersionName = "25.0.1" val moduleMaxRiruApiVersion = 25 +val injectedPackageName = "com.android.shell" +val injectedPackageUid = 2000 + val defaultManagerPackageName: String by rootProject.extra val apiCode: Int by rootProject.extra @@ -97,6 +100,7 @@ android { ndkBuild { arguments += "RIRU_MODULE_API_VERSION=$moduleMaxRiruApiVersion" arguments += "MODULE_NAME=$riruModuleId" + arguments += "INJECTED_AID=$injectedPackageUid" arguments += "-j${Runtime.getRuntime().availableProcessors()}" } } @@ -107,8 +111,8 @@ android { "DEFAULT_MANAGER_PACKAGE_NAME", """"$defaultManagerPackageName"""" ) - buildConfigField("String", "MANAGER_INJECTED_PKG_NAME", """"com.android.shell"""") - buildConfigField("int", "MANAGER_INJECTED_UID", """2000""") + buildConfigField("String", "MANAGER_INJECTED_PKG_NAME", """"$injectedPackageName"""") + buildConfigField("int", "MANAGER_INJECTED_UID", """$injectedPackageUid""") } lint { diff --git a/core/src/main/cpp/main/Android.mk b/core/src/main/cpp/main/Android.mk index 203c01b5..131244e3 100644 --- a/core/src/main/cpp/main/Android.mk +++ b/core/src/main/cpp/main/Android.mk @@ -11,5 +11,6 @@ LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%) LOCAL_STATIC_LIBRARIES := cxx yahfa riru dobby dex_builder LOCAL_CFLAGS := -DRIRU_MODULE -DRIRU_MODULE_API_VERSION=${RIRU_MODULE_API_VERSION} LOCAL_CFLAGS += -DMODULE_NAME=${MODULE_NAME} +LOCAL_CFLAGS += -DINJECTED_AID=${INJECTED_AID} LOCAL_LDLIBS := -llog include $(BUILD_SHARED_LIBRARY) diff --git a/core/src/main/cpp/main/src/main.cpp b/core/src/main/cpp/main/src/main.cpp index 07cc3c4f..5358798b 100644 --- a/core/src/main/cpp/main/src/main.cpp +++ b/core/src/main/cpp/main/src/main.cpp @@ -31,7 +31,7 @@ namespace lspd { int *allowUnload = nullptr; - static constexpr uid_t kAidShell = 2000; + static constexpr uid_t kAidInjected = INJECTED_AID; static constexpr uid_t kAidInet = 3003; namespace { @@ -59,7 +59,7 @@ namespace lspd { jobjectArray *, jboolean *, jboolean *) { - if (*_uid == kAidShell) { + if (*_uid == kAidInjected) { int array_size = *gids ? env->GetArrayLength(*gids) : 0; auto region = std::make_unique(array_size + 1); auto *new_gids = env->NewIntArray(array_size + 1); @@ -102,7 +102,7 @@ namespace lspd { jobjectArray *, jboolean *, jboolean *) { - if (*_uid == kAidShell) { + if (*_uid == kAidInjected) { int array_size = *gids ? env->GetArrayLength(*gids) : 0; auto region = std::make_unique(array_size + 1); auto *new_gids = env->NewIntArray(array_size + 1);