Skip to content

Commit

Permalink
重构 dexkit 缓存(Tip:可能部分功能不可用,明天再修)
Browse files Browse the repository at this point in the history
  • Loading branch information
lingqiqi5211 committed Dec 7, 2024
1 parent 446a037 commit ffbc20b
Show file tree
Hide file tree
Showing 100 changed files with 829 additions and 824 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
*/
package com.sevtinge.hyperceiler.module.base.dexkit;

import static com.sevtinge.hyperceiler.utils.shell.ShellUtils.safeExecCommandWithRoot;

import android.content.Context;

import androidx.annotation.NonNull;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.sevtinge.hyperceiler.R;
import com.tencent.mmkv.MMKV;

import org.jetbrains.annotations.NotNull;
Expand All @@ -48,7 +53,7 @@
* @author 焕晨HChen
*/
public class DexKit {
private static final int mVersion = 4;
private static final int mVersion = 5;
public boolean isInit = false;
private static final String MMKV_PATH = "/files/mmkv";
private static XC_LoadPackage.LoadPackageParam mParam;
Expand Down Expand Up @@ -165,8 +170,7 @@ public static <T> List<T> findMemberList(@NonNull String key, ClassLoader classL
throw new RuntimeException(e);
}
} else {
MemberData data = mGson.fromJson(descriptor, new TypeToken<MemberData>() {
}.getType());
MemberData data = mGson.fromJson(descriptor, new TypeToken<MemberData>() {}.getType());
ArrayList<T> instanceList = new ArrayList<>();
try {
switch (data.type) {
Expand Down Expand Up @@ -210,12 +214,7 @@ private void init() {
mGson = new GsonBuilder().setPrettyPrinting().create();

// 启动 MMKV
MMKV.initialize(mmkvPath, new MMKV.LibLoader() {
@Override
public void loadLibrary(String libName) {
System.loadLibrary(libName);
}
});
MMKV.initialize(mmkvPath, libName -> System.loadLibrary(libName));
mMMKV = MMKV.defaultMMKV();
int version = mMMKV.getInt("version", 0);
if (version != 0 && version != mVersion) {
Expand Down Expand Up @@ -262,4 +261,14 @@ public MemberData(String type, ArrayList<String> serializeList) {
this.serializeList = serializeList;
}
}

public static void deleteAllCache(Context context) {
String[] folderNames = context.getResources().getStringArray(R.array.xposed_scope);
for (String folderName : folderNames) {
String folderPath = "/data/data/" + folderName + MMKV_PATH;
if (safeExecCommandWithRoot("ls " + folderPath).contains("mmkv")) {
safeExecCommandWithRoot("rm -rf " + folderPath);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@
import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.base.BaseData;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;

public class DisableWatermark extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Method method = (Method) DexKit.findMember("DisableWatermark", new IDexKit() {
Method method = DexKit.findMember("DisableWatermark", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("userId", "add watermark")
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
hookMethod(method, new MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,24 @@
import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.base.BaseData;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;

public class DebugMode extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Method method1 = (Method) DexKit.findMember("EnvironmentFlag", new IDexKit() {
Method method1 = DexKit.findMember("EnvironmentFlag", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("environment_flag")
.returnType(String.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
hookMethod(method1, new MethodHook() {
Expand All @@ -55,15 +55,15 @@ protected void before(XC_MethodHook.MethodHookParam param) throws Throwable {
}
});

Method method2 = (Method) DexKit.findMember("DebugMode1", new IDexKit() {
Method method2 = DexKit.findMember("DebugMode1", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("pref_key_debug_mode_new")
.returnType(boolean.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
hookMethod(method2, new MethodHook() {
Expand All @@ -73,15 +73,15 @@ protected void before(XC_MethodHook.MethodHookParam param) throws Throwable {
}
});

Method method3 = (Method) DexKit.findMember("DebugMode2", new IDexKit() {
Method method3 = DexKit.findMember("DebugMode2", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("pref_key_debug_mode")
.returnType(boolean.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
hookMethod(method3, new MethodHook() {
Expand All @@ -91,15 +91,15 @@ protected void before(XC_MethodHook.MethodHookParam param) throws Throwable {
}
});

Method method4 = (Method) DexKit.findMember("DebugMode3", new IDexKit() {
Method method4 = DexKit.findMember("DebugMode3", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("pref_key_debug_mode_" + getPackageVersionCode(lpparam))
.returnType(boolean.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
hookMethod(method4, new MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@
import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.base.BaseData;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;

import de.robv.android.xposed.XC_MethodHook;

public class EnableDebugEnvironment extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Method method = (Method) DexKit.findMember("DebugMode", new IDexKit() {
Method method = DexKit.findMember("DebugMode", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.usingStrings("pref_key_debug_mode_" + getPackageVersionCode(lpparam))
.name("getDebugMode")
.returnType(boolean.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
hookMethod(method, new MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.luckypray.dexkit.query.matchers.ClassMatcher;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.base.BaseData;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Method;
import java.util.Objects;

Expand All @@ -37,17 +37,17 @@
public class UnlockSubscription extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Method method = (Method) DexKit.findMember("CalendarApplication", new IDexKit() {
Method method = DexKit.findMember("CalendarApplication", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("Cal:D:CalendarApplicationDelegate"))
.usingStrings("key_subscription_display", "key_import_todo", "key_chinese_almanac_pref", "key_weather_display", "key_ai_time_parse")
.paramCount(0)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
logD(TAG, lpparam.packageName, "method is "+method);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.luckypray.dexkit.result.ClassData;
import org.luckypray.dexkit.result.FieldData;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.base.BaseData;

import java.lang.reflect.AnnotatedElement;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

Expand All @@ -48,84 +48,84 @@
public class BlackLeica extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Class<?> clazz2 = (Class<?>) DexKit.findMember("TextColorMakerClazz", new IDexKit() {
Class<?> clazz2 = DexKit.findMember("TextColorMakerClazz", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
ClassData clazzData = bridge.findClass(FindClass.create()
.matcher(ClassMatcher.create()
.usingStrings("get(ColorSpace.Named.SRGB)", "bitmap")
)).singleOrNull();
return clazzData.getInstance(lpparam.classLoader);
return clazzData;
}
});
Method method1 = (Method) DexKit.findMember("WaterMakerLeica", new IDexKit() {
Method method1 = DexKit.findMember("WaterMakerLeica", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.paramTypes(int.class, int.class, float.class, String.class, String.class, String.class, boolean.class, String.class, boolean.class, Drawable.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
Class<?> clazz1 = (Class<?>) DexKit.findMember("DescStringColorMakerClazz", new IDexKit() {
Class<?> clazz1 = DexKit.findMember("DescStringColorMakerClazz", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
ClassData clazzData = bridge.findClass(FindClass.create()
.matcher(ClassMatcher.create()
.addMethod(MethodMatcher.create()
.paramTypes(int.class, int.class, float.class, String.class, String.class, String.class, boolean.class, String.class, boolean.class, Drawable.class)
)
)).singleOrNull();
return clazzData.getInstance(lpparam.classLoader);
return clazzData;
}
});
// Class<?> clazz1 = method1.getClass();
Method method2 = (Method) DexKit.findMember("TextPainter", new IDexKit() {
Method method2 = DexKit.findMember("TextPainter", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.paramTypes(Typeface.class, float.class, int.class)
.returnType(TextPaint.class)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
Method method3 = (Method) DexKit.findMember("TextColorMaker", new IDexKit() {
Method method3 = DexKit.findMember("TextColorMaker", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
MethodData methodData = bridge.findMethod(FindMethod.create()
.matcher(MethodMatcher.create()
.declaredClass(clazz2)
.paramTypes(int.class)
.returnType(clazz2)
)).singleOrNull();
return methodData.getMethodInstance(lpparam.classLoader);
return methodData;
}
});
Field field1 = (Field) DexKit.findMember("DescStringColor", new IDexKit() {
Field field1 = DexKit.findMember("DescStringColor", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
FieldData fieldData = bridge.findField(FindField.create()
.matcher(FieldMatcher.create()
.declaredClass(clazz1)
.type(int.class)
)).singleOrNull();
return fieldData.getFieldInstance(lpparam.classLoader);
return fieldData;
}
});
Field field2 = (Field) DexKit.findMember("LeicaPendantColor", new IDexKit() {
Field field2 = DexKit.findMember("LeicaPendantColor", new IDexKit() {
@Override
public AnnotatedElement dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
public BaseData dexkit(DexKitBridge bridge) throws ReflectiveOperationException {
FieldData fieldData = bridge.findField(FindField.create()
.matcher(FieldMatcher.create()
.declaredClass(ClassMatcher.create()
.usingStrings("#33000000", "ISWN")
)
.type(int.class)
)).singleOrNull();
return fieldData.getFieldInstance(lpparam.classLoader);
return fieldData;
}
});

Expand Down
Loading

0 comments on commit ffbc20b

Please sign in to comment.