Skip to content

Commit

Permalink
Move config path to /data/adb and /data/misc
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveSy authored and solohsu committed Dec 6, 2020
1 parent 8bde89c commit baf1d6b
Show file tree
Hide file tree
Showing 15 changed files with 304 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
public class BaseEdxpConfig implements EdxpConfig {

@Override
public String getInstallerConfigPath(String suffix) {
return ConfigManager.getInstallerConfigPath(suffix != null ? suffix : "");
public String getConfigPath(String suffix) {
return ConfigManager.getConfigPath(suffix != null ? suffix : "");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static boolean shouldUseCompatMode(String packageName) {
&& (result = compatModeCache.get(packageName)) != null) {
return result;
}
result = isFileExists(getInstallerConfigPath("compatlist/" + packageName));
result = isFileExists(getConfigPath("compatlist/" + packageName));
compatModeCache.put(packageName, result);
return result;
}
Expand All @@ -41,7 +41,9 @@ private static boolean isFileExists(String path) {

public static native String getLibSandHookName();

public static native String getInstallerConfigPath(String suffix);
public static native String getConfigPath(String suffix);

public static native String getBaseConfigPath();

public static native String getDataPathPrefix();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.elderdrivers.riru.edxp.hooker;

import android.app.AndroidAppHelper;
import android.view.View;

import com.elderdrivers.riru.edxp.config.ConfigManager;
import com.elderdrivers.riru.edxp.util.Utils;

Expand All @@ -16,7 +19,7 @@ public class XposedInstallerHooker {

private static final String LEGACY_INSTALLER_PACKAGE_NAME = "de.robv.android.xposed.installer";

public static void hookXposedInstaller(ClassLoader classLoader) {
public static void hookXposedInstaller(final ClassLoader classLoader) {
try {
final String xposedAppClass = LEGACY_INSTALLER_PACKAGE_NAME + ".XposedApp";
final Class InstallZipUtil = XposedHelpers.findClass(LEGACY_INSTALLER_PACKAGE_NAME
Expand Down Expand Up @@ -66,6 +69,31 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}
});
XposedHelpers.findAndHookMethod("org.meowcat.edxposed.manager.XposedApp", classLoader, "onCreate", new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
XposedHelpers.setStaticObjectField(param.thisObject.getClass(), "BASE_DIR", ConfigManager.getBaseConfigPath() + "/");
XposedHelpers.setStaticObjectField(param.thisObject.getClass(), "ENABLED_MODULES_LIST_FILE", ConfigManager.getConfigPath("enabled_modules.list"));
}
});
XposedHelpers.findAndHookMethod("org.meowcat.edxposed.manager.util.ModuleUtil", classLoader, "updateModulesList", boolean.class, View.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
final Object thisObject = param.thisObject;
synchronized (thisObject) {
XposedHelpers.setStaticObjectField(param.thisObject.getClass(), "MODULES_LIST_FILE", ConfigManager.getConfigPath("modules.list"));
}
}
});
XposedHelpers.findAndHookMethod("org.meowcat.edxposed.manager.StatusInstallerFragment", classLoader, "getCanonicalFile", File.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
File arg = (File)param.args[0];
if(arg.equals(new File(AndroidAppHelper.currentApplicationInfo().deviceProtectedDataDir))) {
param.args[0] = new File(ConfigManager.getBaseConfigPath());
}
}
});
} catch (Throwable t) {
Utils.logE("Could not hook Xposed Installer", t);
}
Expand Down
26 changes: 21 additions & 5 deletions edxp-core/src/main/cpp/main/include/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#include <string>
#include <filesystem>
#include <sys/system_properties.h>
#include <unistd.h>
#include <sys/stat.h>
#include "logging.h"
#include <sys/system_properties.h>

namespace edxp {

Expand All @@ -31,9 +32,24 @@ namespace edxp {
}
}

static inline int32_t GetAndroidApiLevel() {
char prop_value[PROP_VALUE_MAX];
__system_property_get("ro.build.version.sdk", prop_value);
return std::atoi(prop_value);
inline void path_chown(const std::filesystem::path &path, uid_t uid, gid_t gid, bool recursively=false) {
if (chown(path.c_str(), uid, gid) != 0) {
throw std::filesystem::filesystem_error(strerror(errno), path,
{errno, std::system_category()});
}
if(recursively) {
for(const auto &item : std::filesystem::recursive_directory_iterator(path)) {
if (chown(item.path().c_str(), uid, gid) != 0) {
throw std::filesystem::filesystem_error(strerror(errno), item.path(),
{errno, std::system_category()});
}
}
}
}

inline std::tuple<uid_t, gid_t> path_own(const std::filesystem::path& path) {
struct stat sb;
stat(path.c_str(), &sb);
return {sb.st_uid, sb.st_gid};
}
}
Loading

0 comments on commit baf1d6b

Please sign in to comment.