Skip to content

Commit

Permalink
优化: dexkit cache
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Jun 15, 2024
1 parent c6cefb0 commit 609665e
Show file tree
Hide file tree
Showing 26 changed files with 204 additions and 322 deletions.
389 changes: 133 additions & 256 deletions app/src/main/java/com/sevtinge/hyperceiler/module/base/dexkit/DexKit.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,32 @@ object DexKitTool {
* 将 ClassData 列表快捷转为 List<AnnotatedElement>
* 使用时在查找后调用 .toElementList(EzXHelper.safeClassLoader) 即可
*/
fun ClassDataList.toElementList(classLoader: ClassLoader): List<AnnotatedElement> {
return DexKit.toElementList(this, classLoader)
fun ClassDataList.toElementList(): List<AnnotatedElement> {
return DexKit.toElementList(this)
}

/**
* 将 MethodData 列表快捷转为 List<AnnotatedElement>
* 使用时在查找后调用 .toElementList(EzXHelper.safeClassLoader) 即可
*/
fun MethodDataList.toElementList(classLoader: ClassLoader): List<AnnotatedElement> {
return DexKit.toElementList(this, classLoader)
fun MethodDataList.toElementList(): List<AnnotatedElement> {
return DexKit.toElementList(this)
}

/**
* 将 FieldData 列表快捷转为 List<AnnotatedElement>
* 使用时在查找后调用 .toElementList(EzXHelper.safeClassLoader) 即可
*/
fun FieldDataList.toElementList(classLoader: ClassLoader): List<AnnotatedElement> {
return DexKit.toElementList(this, classLoader)
fun FieldDataList.toElementList(): List<AnnotatedElement> {
return DexKit.toElementList(this)
}

fun List<*>.toElementList(): List<AnnotatedElement> {
return DexKit.toElementList(this)
}

fun BaseDataList<*>.toElementList(): List<AnnotatedElement> {
return DexKit.toElementList(this)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public List<AnnotatedElement> dexkit(DexKitBridge bridge) throws ReflectiveOpera
)
)
);
return DexKit.toElementList(methodData, lpparam.classLoader);
return DexKit.toElementList(methodData);
}
}).toMethodList();
for (Method method : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.sevtinge.hyperceiler.module.hook.mediaeditor

import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
Expand All @@ -38,7 +37,7 @@ object UnlockCustomPhotoFrames : BaseHook() {
private val isPOCO by lazy { frames == 3 }

private val publicA by lazy {
DexKit.useDexKitIfNoCache(arrayOf("PA", "PC")) { bridge ->
DexKit.useDexkitIfNoCache(arrayOf("PC", "PA")) { bridge ->
bridge.findMethod {
matcher {
// 真是妹想到啊,1.5 和 1.6 版本还以为不会套回去了
Expand Down Expand Up @@ -67,19 +66,28 @@ object UnlockCustomPhotoFrames : BaseHook() {
modifiers = Modifier.STATIC or Modifier.FINAL
}
}
}.toElementList(EzXHelper.classLoader)
}.toElementList()
}.toMethodList()
}

override fun init() {
// 为了减少查询次数,这玩意写得好懵圈.png
val publicC = DexKit.createCache("PC", publicA?.toMethodDataList()?.filter { methodData ->
methodData.usingFields.any {
it.field.typeName == "boolean" // 1.6.3.5 通过此条件应该只会返回 b() 方法
}
}, lpparam.classLoader).toMethodList().toSet()
// val publicC = DexKit.getDexKitBridge("PC", publicA?.toMethodDataList()?.filter { methodData ->
// methodData.usingFields.any {
// it.field.typeName == "boolean" // 1.6.3.5 通过此条件应该只会返回 b() 方法
// }
// }, lpparam.classLoader).toMethodList().toSet()
val publicC = DexKit.getDexKitBridgeList("PC") { _ ->
publicA?.toMethodDataList()?.filter { methodData ->
methodData.usingFields.any {
it.field.typeName == "boolean" // 1.6.3.5 通过此条件应该只会返回 b() 方法
}
}?.toElementList()
}.toMethodList()
val actions = listOf<(Method) -> Unit>(::xiaomi, ::poco, ::redmi, ::other)
val orderedPublicA = DexKit.createCache("PA", publicA, lpparam.classLoader).toMethodList()
val orderedPublicA = DexKit.getDexKitBridgeList("PA") { _ ->
publicA?.toElementList()
}.toMethodList()
val differentItems = orderedPublicA.subtract(publicC)
var index = 0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ object UnlockLeicaFilter : BaseHook() {
returnType = "boolean"
paramCount = 0
}
}.toElementList(classLoader)
}.toElementList()
}.toMethodList()
}
private val leicaNew by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<AnnotatedElement> dexkit(DexKitBridge bridge) throws ReflectiveOpera
.usingNumbers(0.5f, 200)
)
);
return DexKit.toElementList(methodData, lpparam.classLoader);
return DexKit.toElementList(methodData);
}
}).toMethodList();
for (Method method : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object NoAutoTurnOff : BaseHook() {
paramTypes = listOf("android.content.Context", "java.lang.String")
paramCount = 2
}
}.toElementList(safeClassLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,11 @@

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKitList;

import org.luckypray.dexkit.DexKitBridge;
import org.luckypray.dexkit.query.FindMethod;
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.MethodDataList;

import java.lang.reflect.AnnotatedElement;
Expand Down Expand Up @@ -57,7 +54,7 @@ public List<AnnotatedElement> dexkit(DexKitBridge bridge) throws ReflectiveOpera
.name("setHideButton")
)
);
return DexKit.toElementList(methodData, lpparam.classLoader);
return DexKit.toElementList(methodData);
}
}).toMethodList();
for (Method method2 : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.sevtinge.hyperceiler.module.hook.packageinstaller

import android.content.pm.*
import com.github.kyuubiran.ezxhelper.EzXHelper.safeClassLoader
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
Expand All @@ -33,7 +32,7 @@ object AllAsSystemApp : BaseHook() {
paramTypes = listOf("android.content.pm.ApplicationInfo")
returnType = "boolean"
}
}.toElementList(safeClassLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package com.sevtinge.hyperceiler.module.hook.packageinstaller

import android.content.*
import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.sevtinge.hyperceiler.*
import com.sevtinge.hyperceiler.module.base.*
Expand Down Expand Up @@ -60,7 +59,7 @@ object DisableAppInfoUpload : BaseHook() {
returnType(Void::class.javaPrimitiveType as Class<*>)
modifiers(AccessFlagsMatcher.create(Modifier.STATIC))
}
}.toElementList(EzXHelper.safeClassLoader)
}.toElementList()
}.toMethodList()

if (avlUploadInvokerList.isEmpty()) {
Expand Down Expand Up @@ -94,7 +93,7 @@ object DisableAppInfoUpload : BaseHook() {
returnType(Object::class.java)
usingStrings("device_type", "packageName", "installationMode", "apk_bit")
}
}.toElementList(EzXHelper.safeClassLoader)
}.toElementList()
}.toMethodList()

if (interceptCheckInvokerList.isEmpty()) {
Expand Down Expand Up @@ -127,7 +126,7 @@ object DisableAppInfoUpload : BaseHook() {
null
)
}
}.toElementList(EzXHelper.safeClassLoader)
}.toElementList()
}.toMethodList()

if (infoLayoutInvokerList.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.sevtinge.hyperceiler.module.hook.packageinstaller

import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
Expand All @@ -41,7 +40,7 @@ object InstallRiskDisable : BaseHook() {
addUsingString("android.provider.MiuiSettings\$Ad", StringMatchType.Equals)
returnType = "boolean"
}
}.toElementList(EzXHelper.safeClassLoader)
}.toElementList()
}.toMethodList().createHooks {
returnConstant(false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package com.sevtinge.hyperceiler.module.hook.personalassistant

import android.graphics.drawable.*
import android.view.*
import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createAfterHook
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
Expand All @@ -45,7 +44,7 @@ object BlurPersonalAssistant : BaseHook() {
matcher {
addUsingStringsEquals("ScrollStateManager")
}
}.toElementList(EzXHelper.safeClassLoader)
}.toElementList()
}.toMethodList().forEach { methodData ->
methodData.createAfterHook {
val scrollX = it.args[0] as Float
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object UnlockMoreVolumeFromNew : BaseHook() {
declaredClass(getClass)
type = "boolean"
}
}.toElementList(safeClassLoader)
}.toElementList()
}.toFieldList()

findAndHookConstructor(getClass, object : MethodHook() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public List<AnnotatedElement> dexkit(DexKitBridge bridge) throws ReflectiveOpera
.usingNumbers(0.5f, 200)
)
);
return DexKit.toElementList(methodData, lpparam.classLoader);
return DexKit.toElementList(methodData);
}
}).toMethodList();
for (Method method : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createAfterHook
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
import com.sevtinge.hyperceiler.module.base.dexkit.DexKitTool.toElementList
import com.sevtinge.hyperceiler.module.base.dexkit.DexKitTool.toMethod
import com.sevtinge.hyperceiler.utils.*
import de.robv.android.xposed.*
Expand All @@ -41,7 +42,7 @@ object BatteryHealth : BaseHook() {
}

private val cc by lazy {
DexKit.useDexKitIfNoCache(arrayOf("SecurityBatteryHealthClass")) {
DexKit.useDexkitIfNoCache(arrayOf("SecurityBatteryHealthClass")) {
it.findClass {
searchPackages("com.miui.powercenter.nightcharge")
findFirst = true
Expand Down Expand Up @@ -77,7 +78,9 @@ object BatteryHealth : BaseHook() {
}
)

val nameClass = DexKit.createCache("SecurityBatteryHealthClass", cc, lpparam.classLoader).toClassList().first().name
val nameClass = DexKit.getDexKitBridgeList("SecurityBatteryHealthClass") { _ ->
cc?.toElementList()
}.toClassList().first().name
findAndHookMethod(
nameClass,
"handleMessage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ object ScreenUsedTime : BaseHook() {
returnType = "boolean"
paramCount = 0
}
}.toElementList(safeClassLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,19 @@

import static com.sevtinge.hyperceiler.module.base.tool.HookTool.MethodHook.returnConstant;

import android.util.SparseArray;

import com.sevtinge.hyperceiler.module.base.BaseHook;
import com.sevtinge.hyperceiler.module.base.dexkit.DexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKit;
import com.sevtinge.hyperceiler.module.base.dexkit.IDexKitList;

import org.luckypray.dexkit.DexKitBridge;
import org.luckypray.dexkit.query.FindMethod;
import org.luckypray.dexkit.query.matchers.AnnotationMatcher;
import org.luckypray.dexkit.query.matchers.AnnotationsMatcher;
import org.luckypray.dexkit.query.matchers.MethodMatcher;
import org.luckypray.dexkit.result.MethodData;
import org.luckypray.dexkit.result.MethodDataList;

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

import de.robv.android.xposed.XC_MethodHook;

public class UnlockSmartCharge extends BaseHook {
@Override
public void init() throws NoSuchMethodException {
Expand All @@ -52,7 +44,7 @@ public List<AnnotatedElement> dexkit(DexKitBridge bridge) throws ReflectiveOpera
.usingStrings("persist.vendor.smartchg")
)
);
return DexKit.toElementList(methodData, lpparam.classLoader);
return DexKit.toElementList(methodData);
}
}).toMethodList();
for (Method method : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ object BeautyLightAuto : BaseHook() {
addUsingStringsEquals("taoyao")
returnType = "boolean"
}
}.toElementList(EzXHelper.classLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ object BeautyPrivacy : BaseHook() {
paramTypes = listOf(R0.parameterTypes[0].name)
}
}
}.toElementList(EzXHelper.classLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.sevtinge.hyperceiler.module.hook.securitycenter.lab

import com.github.kyuubiran.ezxhelper.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
import com.sevtinge.hyperceiler.module.base.dexkit.DexKitTool.addUsingStringsEquals
import com.sevtinge.hyperceiler.module.base.dexkit.DexKitTool.toElementList
Expand All @@ -30,7 +29,7 @@ object LabUtilsClass {
matcher {
addUsingStringsEquals("mi_lab_ai_clipboard_enable", "mi_lab_blur_location_enable")
}
}.toElementList(EzXHelper.classLoader)
}.toElementList()
}.toClassList()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.sevtinge.hyperceiler.module.hook.securitycenter.other

import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHook
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
Expand All @@ -40,7 +39,7 @@ object BypassSimLockMiAccountAuth : BaseHook() {
paramTypes("android.content.Context")
returnType = "boolean"
}
}.toElementList(EzXHelper.classLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package com.sevtinge.hyperceiler.module.hook.securitycenter.other

import com.github.kyuubiran.ezxhelper.*
import com.github.kyuubiran.ezxhelper.HookFactory.`-Static`.createHooks
import com.sevtinge.hyperceiler.module.base.*
import com.sevtinge.hyperceiler.module.base.dexkit.*
Expand All @@ -34,7 +33,7 @@ object FuckRiskPkg : BaseHook() {
"riskPkgList", "key_virus_pkg_list", "show_virus_notification"
)
}
}.toElementList(EzXHelper.classLoader)
}.toElementList()
}.toMethodList()
}

Expand Down
Loading

0 comments on commit 609665e

Please sign in to comment.