Skip to content

Commit

Permalink
Hook getSharedPreference for new modules target > 93
Browse files Browse the repository at this point in the history
  • Loading branch information
LoveSy committed Dec 3, 2020
1 parent e612e57 commit 7471143
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
package com.elderdrivers.riru.edxp._hooker.impl;

import android.app.ActivityThread;
import android.app.ContextImpl;
import android.app.LoadedApk;
import android.content.ComponentName;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.content.res.CompatibilityInfo;
import android.content.res.XResources;
import android.graphics.Bitmap;
import android.os.UserHandle;

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

import java.io.File;

import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.XposedInit;
Expand All @@ -25,7 +32,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
Hookers.logD("ActivityThread#handleBindApplication() starts");
ActivityThread activityThread = (ActivityThread) param.thisObject;
Object bindData = param.args[0];
ApplicationInfo appInfo = (ApplicationInfo) XposedHelpers.getObjectField(bindData, "appInfo");
final ApplicationInfo appInfo = (ApplicationInfo) XposedHelpers.getObjectField(bindData, "appInfo");
// save app process name here for later use
ConfigManager.appProcessName = (String) XposedHelpers.getObjectField(bindData, "processName");
String reportedPackageName = appInfo.packageName.equals("android") ? "system" : appInfo.packageName;
Expand All @@ -42,7 +49,6 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
if (appInfo.sourceDir == null) {
return;
}

XposedHelpers.setObjectField(activityThread, "mBoundApplication", bindData);
XposedInit.loadedPackagesInProcess.add(reportedPackageName);
LoadedApk loadedApk = activityThread.getPackageInfoNoCheck(appInfo, compatInfo);
Expand All @@ -51,6 +57,19 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

String processName = (String) XposedHelpers.getObjectField(bindData, "processName");


final ApplicationInfo ai = ActivityThread.currentActivityThread().getSystemContext().getPackageManager().getApplicationInfo(appInfo.packageName, PackageManager.GET_META_DATA);

if(ai.metaData.getBoolean("xposedmodule") && ai.metaData.getInt("xposedminversion", -1) > 92) {
Utils.logW("New modules detected, hook preferences");
XposedHelpers.findAndHookMethod(ContextImpl.class, "getSharedPreferences", File.class, int.class, new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
String fileName = ((File)param.args[0]).getName();
param.args[0] = new File(ConfigManager.getPrefsPath(ai.packageName), fileName);
}
});
}
LoadedApkGetCL hook = new LoadedApkGetCL(loadedApk, reportedPackageName,
processName, true);
hook.setUnhook(XposedHelpers.findAndHookMethod(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private static boolean isFileExists(String path) {

public static native String getConfigPath(String suffix);

public static native String getPrefsPath(String suffix);

public static native String getBaseConfigPath();

public static native String getDataPathPrefix();
Expand Down
9 changes: 9 additions & 0 deletions edxp-core/src/main/cpp/main/src/jni/edxp_config_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ namespace edxp {
return env->NewStringUTF(result.c_str());
}

static jstring ConfigManager_getPrefsPath(JNI_START, jstring jSuffix) {
const char *suffix = env->GetStringUTFChars(jSuffix, JNI_FALSE);
auto result = ConfigManager::GetInstance()->GetPrefsPath(suffix);
env->ReleaseStringUTFChars(jSuffix, suffix);
return env->NewStringUTF(result.c_str());
}

static jstring ConfigManager_getBaseConfigPath(JNI_START) {
auto result = ConfigManager::GetInstance()->GetBaseConfigPath();
return env->NewStringUTF(result.c_str());
Expand All @@ -71,6 +78,8 @@ namespace edxp {
NATIVE_METHOD(ConfigManager, getDataPathPrefix, "()Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getConfigPath,
"(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getPrefsPath,
"(Ljava/lang/String;)Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getBaseConfigPath,"()Ljava/lang/String;"),
NATIVE_METHOD(ConfigManager, getModulesList, "()Ljava/lang/String;"),
};
Expand Down
3 changes: 3 additions & 0 deletions hiddenapi-stubs/src/main/java/android/app/ActivityThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ public static String currentPackageName() {
public final LoadedApk getPackageInfoNoCheck(ApplicationInfo ai, CompatibilityInfo compatInfo) {
throw new UnsupportedOperationException("STUB");
}
public ContextImpl getSystemContext() {
throw new UnsupportedOperationException("STUB");
}
}
Loading

0 comments on commit 7471143

Please sign in to comment.