Skip to content

Commit

Permalink
添加异常捕获防止影响其他hooker执行
Browse files Browse the repository at this point in the history
  • Loading branch information
kooritea committed Jun 13, 2024
1 parent 6f1bb2b commit 71ee631
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions app/src/main/java/com/kooritea/fcmfix/util/XposedUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,23 @@ public static XC_MethodHook.Unhook findAndHookMethodAnyParam(Class<?> clazz, Str
return XposedBridge.hookMethod(XposedHelpers.findMethodExact(clazz,methodName,bestMatch.getParameterTypes()), callbacks);
}

public static XC_MethodHook.Unhook tryFindAndHookMethod(Class<?> clazz, String methodName, int parameterCount, XC_MethodHook callbacks) {
try{
return findAndHookMethod(clazz,methodName,parameterCount,callbacks);
}catch (NoSuchMethodError e) {
return null;
}
}
public static XC_MethodHook.Unhook findAndHookMethod(Class<?> clazz, String methodName, int parameterCount, XC_MethodHook callbacks) {
Method method = null;
for (Method m : clazz.getDeclaredMethods()) {
if (m.getName().equals(methodName) && m.getParameterTypes().length == parameterCount) {
method = m;
}
}
if (method == null) {
throw new NoSuchMethodError(clazz.getName() + '#' + methodName);
}
return XposedBridge.hookMethod(XposedHelpers.findMethodExact(clazz,methodName, method.getParameterTypes()), callbacks);
}

Expand Down
15 changes: 11 additions & 4 deletions app/src/main/java/com/kooritea/fcmfix/xposed/AutoStartFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ public class AutoStartFix extends XposedModule {

public AutoStartFix(XC_LoadPackage.LoadPackageParam loadPackageParam){
super(loadPackageParam);
this.startHook();
this.startHookRemovePowerPolicy();
try{
this.startHook();
this.startHookRemovePowerPolicy();
}catch (Exception e) {
printLog("hook error AutoStartFix:" + e.getMessage());
}
}

protected void startHook(){
Expand Down Expand Up @@ -122,8 +126,11 @@ protected void beforeHookedMethod(MethodHookParam methodHookParam) {
};

printLog("[fcmfix] start hook com.android.server.am.AutoStartManagerServiceStubImpl.isAllowStartService");
XposedUtils.findAndHookMethod(AutoStartManagerServiceStubImpl, "isAllowStartService", 3, methodHook);
XposedUtils.findAndHookMethod(AutoStartManagerServiceStubImpl, "isAllowStartService", 4, methodHook);
XC_MethodHook.Unhook unhook1 = XposedUtils.tryFindAndHookMethod(AutoStartManagerServiceStubImpl, "isAllowStartService", 3, methodHook);
XC_MethodHook.Unhook unhook2 = XposedUtils.tryFindAndHookMethod(AutoStartManagerServiceStubImpl, "isAllowStartService", 4, methodHook);
if(unhook1 == null && unhook2 == null){
throw new NoSuchMethodError();
}
} catch (XposedHelpers.ClassNotFoundError | NoSuchMethodError e){
printLog("No Such Class com.android.server.am.AutoStartManagerServiceStubImpl.isAllowStartService");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ public BroadcastFix(XC_LoadPackage.LoadPackageParam loadPackageParam) {

@Override
protected void onCanReadConfig() {
this.startHook();
try{
this.startHook();
}catch (Exception e) {
printLog("hook error com.android.server.am.ActivityManagerService.broadcastIntentLocked:" + e.getMessage());
}
}

protected void startHook(){
Expand Down

0 comments on commit 71ee631

Please sign in to comment.