diff --git a/edxp-core/src/main/cpp/main/src/config_manager.cpp b/edxp-core/src/main/cpp/main/src/config_manager.cpp index c10a7eb2..1da91d94 100644 --- a/edxp-core/src/main/cpp/main/src/config_manager.cpp +++ b/edxp-core/src/main/cpp/main/src/config_manager.cpp @@ -133,9 +133,8 @@ namespace edxp { return {}; } - // TODO ignore unrelated processes bool ConfigManager::IsAppNeedHook(const std::string &package_name) const { - if (package_name == installer_pkg_name_) { + if (IsInstaller(package_name)) { return true; } @@ -229,7 +228,7 @@ namespace edxp { scope.emplace(std::move(app_pkg_name)); } scope.insert(module_pkg_name); // Always add module itself - if (module_pkg_name == installer_pkg_name_) scope.erase("android"); + if (IsInstaller(module_pkg_name)) scope.erase("android"); LOGI("scope of %s is:\n%s", module_pkg_name.c_str(), ([&scope = scope]() { std::ostringstream join; std::copy(scope.begin(), scope.end(), @@ -297,8 +296,7 @@ namespace edxp { fs::perms::others_exec); path_chown(prefs_path, uid, 0); } - if (pkg_name == installer_pkg_name_ || pkg_name == kPrimaryInstallerPkgName || - pkg_name == "android") { + if (IsInstaller(pkg_name) || pkg_name == "android") { auto conf_path = GetConfigPath(); if (!path_exists(conf_path)) { fs::create_directories(conf_path); @@ -320,13 +318,9 @@ namespace edxp { } if (pkg_name == kPrimaryInstallerPkgName) { - try { - auto installer_pkg_name_path = GetConfigPath("installer"); - if (path_exists(installer_pkg_name_path)) { - fs::remove(installer_pkg_name_path); - } - } catch (const fs::filesystem_error &e) { - LOGE("%s", e.what()); + auto installer_pkg_name_path = GetConfigPath("installer"); + if (path_exists(installer_pkg_name_path)) { + fs::remove(installer_pkg_name_path); } } } diff --git a/edxp-core/src/main/cpp/main/src/config_manager.h b/edxp-core/src/main/cpp/main/src/config_manager.h index 957b1aa9..17af2816 100644 --- a/edxp-core/src/main/cpp/main/src/config_manager.h +++ b/edxp-core/src/main/cpp/main/src/config_manager.h @@ -42,6 +42,7 @@ namespace edxp { instances_[user] = std::make_unique(user, instance->second->IsInitialized()); } + current_user = user; } inline static auto ReleaseInstances() { @@ -97,6 +98,10 @@ namespace edxp { static const auto &GetInjectDexPaths() { return inject_dex_paths_; }; + bool IsInstaller(const std::string& pkg_name) const { + return pkg_name == installer_pkg_name_ || pkg_name == kPrimaryInstallerPkgName; + } + private: inline static std::unordered_map> instances_{}; inline static uid_t current_user = 0u; diff --git a/edxp-core/src/main/cpp/main/src/edxp_context.cpp b/edxp-core/src/main/cpp/main/src/edxp_context.cpp index 5f53c3f5..b0baf3b7 100644 --- a/edxp-core/src/main/cpp/main/src/edxp_context.cpp +++ b/edxp-core/src/main/cpp/main/src/edxp_context.cpp @@ -68,7 +68,7 @@ namespace edxp { } dexes.emplace_back(std::istreambuf_iterator(is), std::istreambuf_iterator()); - LOGD("Loaded %s with size %zu", path.c_str(), dexes.back().size()); + LOGI("Loaded %s with size %zu", path.c_str(), dexes.back().size()); } } @@ -97,7 +97,7 @@ namespace edxp { env->SetObjectArrayElement(buffer_array, i, buffer); } jobject my_cl = JNI_NewObject(env, in_memory_classloader, initMid, - buffer_array, sys_classloader); + buffer_array, sys_classloader); env->DeleteLocalRef(classloader); env->DeleteLocalRef(sys_classloader); env->DeleteLocalRef(in_memory_classloader); @@ -248,7 +248,7 @@ namespace edxp { } std::vector dex{std::istreambuf_iterator(is), std::istreambuf_iterator()}; - LOGD("Loaded %s with size %zu", path.c_str(), dex.size()); + LOGI("Loaded %s with size %zu", path.c_str(), dex.size()); jclass classloader = JNI_FindClass(env, "java/lang/ClassLoader"); jmethodID getsyscl_mid = JNI_GetStaticMethodID( @@ -336,7 +336,7 @@ namespace edxp { std::vector splits(path.begin(), path.end()); if (splits.size() < 5u) { LOGE("can't parse %s", path.c_str()); - return {false, uid, {}}; + return {false, 0, name.get()}; } const auto &uid_str = splits[3]; const auto &package_name = splits[4]; @@ -383,8 +383,7 @@ namespace edxp { package_name.c_str()); } - if (!skip && empty_list() && - package_name != ConfigManager::GetInstance()->GetInstallerPackageName()) { + if (!skip && empty_list() && !ConfigManager::GetInstance()->IsInstaller(package_name)) { skip = true; LOGW("skip injecting xposed into %s because no module hooks it", package_name.c_str()); @@ -417,7 +416,7 @@ namespace edxp { return app_modules_list_.empty(); }, is_child_zygote); if (!skip_) { - ConfigManager::GetInstance()->EnsurePermission(package_name, uid % PER_USER_RANGE); + ConfigManager::GetInstance()->EnsurePermission(package_name, uid); PreLoadDex(ConfigManager::GetInjectDexPaths()); } }