Skip to content

Commit

Permalink
opt: 更新版本号 & 优化工具代码
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Jan 27, 2025
1 parent 45fca81 commit 9f50fe7
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 91 deletions.
10 changes: 5 additions & 5 deletions README-en.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ dependencyResolutionManagement {
dependencies {
// Choose one of these options; jitpack is recommended as maven might not update as frequently.
// Tip: Replace v.*.*.* with the latest release version.
implementation 'com.github.HChenX:HookTool:v.1.1.7' // jitpack
implementation 'io.github.hchenx:hooktool:v.1.1.7'
implementation 'com.github.HChenX:HookTool:v.1.2.0' // jitpack
// implementation 'io.github.hchenx:hooktool:v.1.2.0'
// maven Tip: Almost abandoned, please do not use!
}
```
Expand Down Expand Up @@ -110,7 +110,7 @@ public static class MainActivity {
public class MainTest {
public void test() {
CoreTool.hookMethod(/* content */); // Hook method
CoreTool.findClass().get(); // Find class
CoreTool.findClass(); // Find class
CoreTool.callMethod(); // Call method
ChainTool.chain("com.hchen.demo", new ChainTool()
.method("method")
Expand Down Expand Up @@ -141,7 +141,7 @@ public class MainTest extends BaseHC {
// Be sure to initialize HCInit.initStartupParam(startupParam) at the hook entry point.
@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) {
Class<?> c = findClass("com.hchen.demo.Main").get();
Class<?> c = findClass("com.hchen.demo.Main");
hookMethod(c, "test", new IHook() {
/* content */
});
Expand Down Expand Up @@ -221,7 +221,7 @@ public class MainTest extends BaseHC {
```java
public class MainTest extends BaseHC {
public void init() {
Class<?> c = findClass("com.hchen.demo.Demo").get(); // If the class cannot be retrieved, an error log is recorded and null is returned.
Class<?> c = findClass("com.hchen.demo.Demo"); // If the class cannot be retrieved, an error log is recorded and null is returned.
hookMethod(c, "test", new IHook() { // If c is null, an error log is recorded and the hook is skipped, allowing the rest of the code to continue.
@Override
public void before() {
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ dependencyResolutionManagement {
dependencies {
// 二选一即可,推荐使用 jitpack,maven 可能不会同步更新!
// Tip: v.*.*.* 填写当前最新发行版版本号即可!
implementation 'com.github.HChenX:HookTool:v.1.1.7' // jitpack
implementation 'io.github.hchenx:hooktool:v.1.1.7' // maven Tip: 几乎废弃,请不要使用!
implementation 'com.github.HChenX:HookTool:v.1.2.0' // jitpack
// implementation 'io.github.hchenx:hooktool:v.1.2.0' // maven Tip: 几乎废弃,请不要使用!
}
```

Expand Down Expand Up @@ -108,7 +108,7 @@ public static class MainActivity {
public class MainTest {
public void test() {
CoreTool.hookMethod(/* 内容 */); // 即可 hook
CoreTool.findClass().get(); // 查找类
CoreTool.findClass(); // 查找类
CoreTool.callMethod(); // 调用方法
ChainTool.chain("com.hchen.demo", new ChainTool()
.method("method")
Expand Down Expand Up @@ -139,7 +139,7 @@ public class MainTest extends BaseHC {
// 请务必在 hook 入口处初始化 HCInit.initStartupParam(startupParam);
@Override
public void initZygote(IXposedHookZygoteInit.StartupParam startupParam) {
Class<?> c = findClass("com.hchen.demo.Main").get();
Class<?> c = findClass("com.hchen.demo.Main");
hookMethod(c, "test", new IHook() {
/* 内容 */
});
Expand Down Expand Up @@ -220,7 +220,7 @@ public class MainTest extends BaseHC {
```java
public class MainTest extends BaseHC {
public void init() {
Class<?> c = findClass("com.hchen.demo.Demo").get(); // 如果无法获取 class 则会记录 Error 日志并返回 null。
Class<?> c = findClass("com.hchen.demo.Demo"); // 如果无法获取 class 则会记录 Error 日志并返回 null。
hookMethod(c, "test", new IHook() { // c 为 null 也会记录 Error 日志,并跳过 hook 继续执行后面逻辑。
@Override
public void before() {
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
id 'maven-publish'
}

def defVersion = 'v.1.1.8'
int defVersionCode = 2025012100
def defVersion = 'v.1.2.0'
int defVersionCode = 2025012700

group = 'com.github.HChenX'
version = defVersion
Expand Down
1 change: 0 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
#-renamesourcefileattribute SourceFile

-keep class * extends com.hchen.hooktool.BaseHC
-keep class com.hchen.hooktool.HCEntrance
-keep class com.hchen.hooktool.HCState {
static boolean isEnabled;
static java.lang.String mFramework;
Expand Down
77 changes: 0 additions & 77 deletions app/src/main/java/com/hchen/hooktool/helper/ConvertHelper.java

This file was deleted.

46 changes: 45 additions & 1 deletion app/src/main/java/com/hchen/hooktool/tool/CoreBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,29 @@
*/
package com.hchen.hooktool.tool;

import static com.hchen.hooktool.helper.ConvertHelper.arrayToClass;
import static com.hchen.hooktool.helper.TryHelper.run;
import static com.hchen.hooktool.hook.HookFactory.createHook;
import static com.hchen.hooktool.log.LogExpand.getStackTrace;
import static com.hchen.hooktool.log.LogExpand.getTag;
import static com.hchen.hooktool.log.XposedLog.logE;
import static com.hchen.hooktool.log.XposedLog.logI;
import static com.hchen.hooktool.log.XposedLog.logW;
import static com.hchen.hooktool.tool.CoreBase.ConvertHelper.arrayToClass;
import static com.hchen.hooktool.tool.CoreTool.callStaticMethod;
import static com.hchen.hooktool.tool.SingleMember.createSingleMember;

import androidx.annotation.Nullable;

import com.hchen.hooktool.HCData;
import com.hchen.hooktool.hook.IHook;
import com.hchen.hooktool.log.LogExpand;
import com.hchen.hooktool.tool.itool.IMemberFilter;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -362,4 +366,44 @@ private static Method baseGetSuperPrivateMethod(Class<?> clz, String name, Objec
return method;
}).orErrorMag(null, "Failed to get super private method!");
}

static final class ConvertHelper {
/**
* 泛型转换为数组。
*/
public static <T> Object[] genericToArray(T ts) {
if (ts instanceof Object[] objects) return objects;
return new Object[]{ts};
}

@Nullable
public static Class<?>[] arrayToClass(Object... objs) {
return arrayToClass(HCData.getClassLoader(), objs);
}

/**
* 数组参数转为类。
*/
@Nullable
public static Class<?>[] arrayToClass(ClassLoader classLoader, Object... objs) {
if (classLoader == null || objs == null) return null;
if (objs.length == 0) return new Class<?>[]{};
List<Class<?>> classes = new ArrayList<>();
for (Object o : objs) {
if (o instanceof Class<?> c) {
classes.add(c);
} else if (o instanceof String s) {
Class<?> ct = baseFindClass(s, classLoader).getNotReport();
if (ct == null) return null;
classes.add(ct);
} else if (o instanceof IHook) {
break; // 一定为最后一个参数
} else {
logW(LogExpand.getTag(), "Unknown type: " + o + getStackTrace());
return null;
}
}
return classes.toArray(new Class<?>[0]);
}
}
}

0 comments on commit 9f50fe7

Please sign in to comment.