Fix variant switch
This commit is contained in:
parent
d482970284
commit
7b19a95b9e
|
|
@ -163,7 +163,8 @@ namespace edxp {
|
|||
white_list_(GetAppList(GetConfigPath("whitelist/"))),
|
||||
black_list_(GetAppList(GetConfigPath("blacklist/"))),
|
||||
modules_list_(GetModuleList()),
|
||||
last_write_time_(GetLastWriteTime()) {
|
||||
last_write_time_(GetLastWriteTime()),
|
||||
variant_(GetVariant(GetMiscPath() / "variant")) {
|
||||
// use_white_list snapshot
|
||||
LOGI("base config path: %s", base_config_path_.c_str());
|
||||
LOGI(" using installer package name: %s", installer_pkg_name_.c_str());
|
||||
|
|
@ -195,6 +196,16 @@ namespace edxp {
|
|||
})().c_str());
|
||||
}
|
||||
|
||||
int ConfigManager::GetVariant(const fs::path &dir) {
|
||||
std::ifstream ifs(dir);
|
||||
if (!ifs.good()) {
|
||||
return 0;
|
||||
}
|
||||
int variant;
|
||||
ifs >> variant;
|
||||
return variant;
|
||||
}
|
||||
|
||||
auto ConfigManager::GetModuleList() -> std::remove_const_t<decltype(modules_list_)> {
|
||||
std::remove_const_t<decltype(modules_list_)> modules_list;
|
||||
auto global_modules_list = GetConfigPath("modules.list");
|
||||
|
|
@ -257,7 +268,7 @@ namespace edxp {
|
|||
return std::max({path_exists<true>(config_path) ? fs::last_write_time(config_path)
|
||||
: fs::file_time_type{},
|
||||
path_exists<true>(list_path) ? fs::last_write_time(list_path)
|
||||
: fs::file_time_type{},
|
||||
: fs::file_time_type{},
|
||||
path_exists<true>(blacklist_path) ? fs::last_write_time(blacklist_path)
|
||||
: fs::file_time_type{},
|
||||
path_exists<true>(whitelist_path) ? fs::last_write_time(whitelist_path)
|
||||
|
|
|
|||
|
|
@ -44,8 +44,7 @@ namespace edxp {
|
|||
return std::move(instances_);
|
||||
}
|
||||
|
||||
// Always true now
|
||||
inline auto IsBlackWhiteListEnabled() const { return true; }
|
||||
inline const auto &GetVariant() const { return variant_; }
|
||||
|
||||
inline const auto &IsResourcesHookEnabled() const { return resources_hook_enabled_; }
|
||||
|
||||
|
|
@ -114,6 +113,7 @@ namespace edxp {
|
|||
inline static std::filesystem::path inject_dex_path_;
|
||||
|
||||
const uid_t user_;
|
||||
const int variant_;
|
||||
const std::filesystem::path data_path_prefix_; // /data/user_de/{user}
|
||||
const std::filesystem::path base_config_path_; // /data/misc/edxp_xxxx/{user}
|
||||
const bool initialized_ = false;
|
||||
|
|
@ -149,6 +149,8 @@ namespace edxp {
|
|||
friend std::unique_ptr<ConfigManager> std::make_unique<ConfigManager>(uid_t &, bool &&);
|
||||
|
||||
std::filesystem::path RetrieveBaseConfigPath() const;
|
||||
|
||||
static int GetVariant(const std::filesystem::path &dir);
|
||||
};
|
||||
|
||||
} // namespace edxp
|
||||
|
|
|
|||
|
|
@ -125,15 +125,7 @@ namespace edxp {
|
|||
RegisterEdxpYahfa(env);
|
||||
RegisterPendingHooks(env);
|
||||
|
||||
// must call entry class's methods after all native methods registered
|
||||
if (LIKELY(entry_class_)) {
|
||||
jmethodID get_variant_mid = JNI_GetStaticMethodID(env, entry_class_,
|
||||
"getEdxpVariant", "()I");
|
||||
if (LIKELY(get_variant_mid)) {
|
||||
int variant = JNI_CallStaticIntMethod(env, entry_class_, get_variant_mid);
|
||||
variant_ = static_cast<Variant>(variant);
|
||||
}
|
||||
}
|
||||
variant_ = Variant(ConfigManager::GetInstance()->GetVariant());
|
||||
// LOGI("EdxpVariant: %d", variant_);
|
||||
|
||||
initialized_ = true;
|
||||
|
|
@ -308,7 +300,8 @@ namespace edxp {
|
|||
InstallInlineHooks();
|
||||
PrepareJavaEnv(env);
|
||||
// only do work in child since FindAndCall would print log
|
||||
FindAndCall(env, "forkSystemServerPost", "(I)V", res);
|
||||
FindAndCall(env, "forkSystemServerPost", "(II)V", res,
|
||||
variant_);
|
||||
}
|
||||
RegisterEdxpService(env);
|
||||
} else {
|
||||
|
|
@ -422,8 +415,9 @@ namespace edxp {
|
|||
PrepareJavaEnv(env);
|
||||
LOGD("Done prepare");
|
||||
FindAndCall(env, "forkAndSpecializePost",
|
||||
"(ILjava/lang/String;Ljava/lang/String;)V",
|
||||
res, app_data_dir_, nice_name_);
|
||||
"(ILjava/lang/String;Ljava/lang/String;I)V",
|
||||
res, app_data_dir_, nice_name_,
|
||||
variant_);
|
||||
LOGD("injected xposed into %s", process_name.get());
|
||||
} else {
|
||||
[[maybe_unused]] auto config_manager = ConfigManager::ReleaseInstances();
|
||||
|
|
|
|||
|
|
@ -79,8 +79,7 @@ namespace edxp {
|
|||
"(Ljava/lang/String;)Ljava/lang/String;"),
|
||||
NATIVE_METHOD(ConfigManager, getCachePath,
|
||||
"(Ljava/lang/String;)Ljava/lang/String;"),
|
||||
NATIVE_METHOD(ConfigManager, getBaseConfigPath,"()Ljava/lang/String;"),
|
||||
NATIVE_METHOD(ConfigManager, getMiscPath,"()Ljava/lang/String;"),
|
||||
NATIVE_METHOD(ConfigManager, getBaseConfigPath, "()Ljava/lang/String;"),
|
||||
NATIVE_METHOD(ConfigManager, getModulesList, "()Ljava/lang/String;"),
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -22,8 +22,6 @@ public class ConfigManager {
|
|||
|
||||
public static native String getBaseConfigPath();
|
||||
|
||||
public static native String getMiscPath();
|
||||
|
||||
public static native String getDataPathPrefix();
|
||||
|
||||
public static native String getModulesList();
|
||||
|
|
|
|||
|
|
@ -3,21 +3,14 @@ package com.elderdrivers.riru.edxp.core;
|
|||
import android.annotation.SuppressLint;
|
||||
|
||||
import com.elderdrivers.riru.common.KeepAll;
|
||||
import com.elderdrivers.riru.edxp.config.ConfigManager;
|
||||
import com.elderdrivers.riru.edxp.util.Utils;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
public class Main implements KeepAll {
|
||||
private static final AtomicReference<EdxpImpl> edxpImplRef = new AtomicReference<>(null);
|
||||
|
||||
static {
|
||||
loadEdxpImpls();
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// entry points
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -30,8 +23,8 @@ public class Main implements KeepAll {
|
|||
// won't be loaded
|
||||
}
|
||||
|
||||
public static void forkAndSpecializePost(int pid, String appDataDir, String niceName) {
|
||||
final EdxpImpl edxp = getEdxpImpl();
|
||||
public static void forkAndSpecializePost(int pid, String appDataDir, String niceName, int variant) {
|
||||
EdxpImpl edxp = getEdxpImpl(variant);
|
||||
if (edxp == null || !edxp.isInitialized()) {
|
||||
Utils.logE("Not started up");
|
||||
return;
|
||||
|
|
@ -46,8 +39,8 @@ public class Main implements KeepAll {
|
|||
// Won't load
|
||||
}
|
||||
|
||||
public static void forkSystemServerPost(int pid) {
|
||||
final EdxpImpl edxp = getEdxpImpl();
|
||||
public static void forkSystemServerPost(int pid, int variant) {
|
||||
EdxpImpl edxp = getEdxpImpl(variant);
|
||||
if (edxp == null || !edxp.isInitialized()) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -60,27 +53,12 @@ public class Main implements KeepAll {
|
|||
return edxpImplRef.compareAndSet(null, edxp);
|
||||
}
|
||||
|
||||
public static synchronized EdxpImpl getEdxpImpl() {
|
||||
return edxpImplRef.get();
|
||||
}
|
||||
|
||||
@EdxpImpl.Variant
|
||||
public static synchronized int getEdxpVariant() {
|
||||
return getEdxpImpl().getVariant();
|
||||
}
|
||||
|
||||
private static void loadEdxpImpls() {
|
||||
String file_name = ConfigManager.getMiscPath() + "/variant";
|
||||
int variant = EdxpImpl.NONE;
|
||||
try {
|
||||
String f = new String(Files.readAllBytes(Paths.get(file_name))).trim();
|
||||
variant = Integer.parseInt(f);
|
||||
} catch (Exception e) {
|
||||
Utils.logE("loadEdxpImpls: ", e);
|
||||
public static synchronized EdxpImpl getEdxpImpl(int variant) {
|
||||
EdxpImpl edxp = edxpImplRef.get();
|
||||
if (edxp != null) {
|
||||
return edxp;
|
||||
}
|
||||
|
||||
Utils.logD("Loading variant " + variant);
|
||||
|
||||
try {
|
||||
switch (variant) {
|
||||
case EdxpImpl.YAHFA:
|
||||
|
|
@ -96,5 +74,15 @@ public class Main implements KeepAll {
|
|||
} catch (ClassNotFoundException e) {
|
||||
Utils.logE("loadEdxpImpls: Class not found", e);
|
||||
}
|
||||
return edxpImplRef.get();
|
||||
}
|
||||
|
||||
public static synchronized EdxpImpl getEdxpImpl() {
|
||||
return edxpImplRef.get();
|
||||
}
|
||||
|
||||
@EdxpImpl.Variant
|
||||
public static synchronized int getEdxpVariant() {
|
||||
return getEdxpImpl().getVariant();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue