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