Skip to content

Commit

Permalink
fix: 可能的空指针 & 设备判断失败 & 日志输出
Browse files Browse the repository at this point in the history
  • Loading branch information
HChenX committed Dec 2, 2024
1 parent b100537 commit 99edf3e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.0.8'
int defVersionCode = 2024112600
def defVersion = 'v.1.0.9'
int defVersionCode = 2024120100

group = 'com.github.HChenX'
version = defVersion
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hchen/hooktool/BaseHC.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
public abstract class BaseHC extends CoreTool {
public String TAG = getClass().getSimpleName(); // 快捷获取类的简单名称作为 TAG, 为了效果建议配置相应的混淆规则。
private final ChainTool mChainTool = new ChainTool();
public static XC_LoadPackage.LoadPackageParam lpparam = ToolData.mLpparam;
public static ClassLoader classLoader = ToolData.mClassLoader;
public static XC_LoadPackage.LoadPackageParam lpparam; // onZygote 状态下为 null。
public static ClassLoader classLoader;

/**
* 一般阶段。
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/hchen/hooktool/HCInit.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ public static void initLoadPackageParam(XC_LoadPackage.LoadPackageParam loadPack
}
ToolData.isXposed = true;
ToolData.mLpparam = loadPackageParam;
ClassLoader classLoader = loadPackageParam.classLoader;
ToolData.mClassLoader = classLoader;
ToolData.mClassLoader = loadPackageParam.classLoader;
BaseHC.lpparam = loadPackageParam;
BaseHC.classLoader = loadPackageParam.classLoader;
String packageName = loadPackageParam.packageName;
logI("Init classloader: [" + classLoader + "], pkg: " + packageName);
logI("Init classloader: [" + loadPackageParam.classLoader + "], pkg: " + packageName);
}

/**
Expand All @@ -96,6 +97,7 @@ public static void initStartupParam(IXposedHookZygoteInit.StartupParam startupPa
ToolData.isXposed = true;
ToolData.mStartupParam = startupParam;
ToolData.mClassLoader = startupParam.getClass().getClassLoader();
BaseHC.classLoader = startupParam.getClass().getClassLoader();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/hchen/hooktool/tool/ChainTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
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.logD;
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.CoreTool.existsConstructor;
import static com.hchen.hooktool.tool.CoreTool.existsMethod;
Expand Down Expand Up @@ -191,7 +191,7 @@ public void doChainHook() {
for (ChainData memberData : chainData.members) {
try {
XposedBridge.hookMethod(memberData.member, createHook(getTag(), chainData.iHook));
logD(getTag(), "Success to hook: " + memberData.member);
logI(getTag(), "Success to hook: " + memberData.member);
} catch (Throwable e) {
logE(getTag(), "Failed to hook: " + memberData.member, e);
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/com/hchen/hooktool/tool/CoreBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
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.logD;
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.CoreTool.findConstructor;
import static com.hchen.hooktool.tool.CoreTool.findMethod;
Expand All @@ -52,7 +52,7 @@
* @author 焕晨HChen
* @noinspection unchecked
*/
public final class CoreBase {
final class CoreBase {
private CoreBase() {
}

Expand Down Expand Up @@ -136,7 +136,7 @@ static CoreTool.UnHook baseHook(MemberData<Class<?>> clazz, String method, Objec

return run(() -> {
CoreTool.UnHook unHook = new CoreTool.UnHook(XposedBridge.hookMethod(((MemberData<Member>) member).getNoReport(), createHook(tag, iHook)));
logD(tag, "Success to hook: " + member.getNoReport());
logI(tag, "Success to hook: " + member.getNoReport());
return unHook;
}).orErrMag(new CoreTool.UnHook(null), "Failed to hook! \ndebug: " + debug);
}
Expand Down
5 changes: 2 additions & 3 deletions app/src/main/java/com/hchen/hooktool/tool/CoreTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static com.hchen.hooktool.helper.TryHelper.run;
import static com.hchen.hooktool.hook.HookFactory.createHook;
import static com.hchen.hooktool.log.LogExpand.getTag;
import static com.hchen.hooktool.log.XposedLog.logD;
import static com.hchen.hooktool.log.XposedLog.logI;
import static com.hchen.hooktool.log.XposedLog.logW;
import static com.hchen.hooktool.tool.CoreBase.baseCallStaticMethod;
Expand Down Expand Up @@ -260,7 +259,7 @@ public static UnHook hook(Member member, IHook iHook) {
String tag = getTag();
return run(() -> {
UnHook unhook = new UnHook(XposedBridge.hookMethod(member, createHook(tag, iHook)));
logD(tag, "Success to hook: " + member);
logI(tag, "Success to hook: " + member);
return unhook;
}).orErrMag(new UnHook(null), "Failed to hook: " + member);
}
Expand All @@ -273,7 +272,7 @@ public static UnHookList hookAll(MemberListData<Member> members, IHook iHook) {
}
return members.stream().map(member -> run(() -> {
UnHook unHook = new UnHook(XposedBridge.hookMethod(member, createHook(tag, iHook)));
logD(tag, "Success to hook: " + member);
logI(tag, "Success to hook: " + member);
return unHook;
}).orErrMag(new UnHook(null), "Failed to hook: " + member)).collect(Collectors.toCollection(UnHookList::new));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ public static boolean isMagicOs() {
public static boolean isRightRom(final String... names) {
if (names == null) return false;
for (String name : names) {
if (Build.BRAND.toLowerCase().contains(name) || Build.MANUFACTURER.toLowerCase().contains(name)) {
if (Build.BRAND.toLowerCase().contains(name.toLowerCase())
|| Build.MANUFACTURER.toLowerCase().contains(name.toLowerCase())) {
return true;
}
}
Expand Down

0 comments on commit 99edf3e

Please sign in to comment.