From d74f73aff7e2025cc18c760a6eecb504acc899eb Mon Sep 17 00:00:00 2001 From: kooritea Date: Mon, 18 Jul 2022 14:52:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=82=E9=85=8D12L=20202207=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kooritea/fcmfix/xposed/BroadcastFix.java | 69 +++++++++++++------ .../kooritea/fcmfix/xposed/XposedModule.java | 1 + 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/com/kooritea/fcmfix/xposed/BroadcastFix.java b/app/src/main/java/com/kooritea/fcmfix/xposed/BroadcastFix.java index 0271503..b4089aa 100644 --- a/app/src/main/java/com/kooritea/fcmfix/xposed/BroadcastFix.java +++ b/app/src/main/java/com/kooritea/fcmfix/xposed/BroadcastFix.java @@ -3,6 +3,7 @@ import android.content.Intent; import android.os.Build; import java.lang.reflect.Method; +import java.lang.reflect.Parameter; import de.robv.android.xposed.XC_MethodHook; import de.robv.android.xposed.XposedBridge; import de.robv.android.xposed.XposedHelpers; @@ -31,28 +32,54 @@ protected void startHook(){ } } if(targetMethod != null){ + int intent_args_index = 0; + int appOp_args_index = 0; + Parameter[] parameters = targetMethod.getParameters(); + if(Build.VERSION.SDK_INT == Build.VERSION_CODES.P){ + intent_args_index = 2; + appOp_args_index = 9; + }else if(Build.VERSION.SDK_INT == Build.VERSION_CODES.Q){ + intent_args_index = 2; + appOp_args_index = 9; + }else if(Build.VERSION.SDK_INT == Build.VERSION_CODES.R){ + intent_args_index = 3; + appOp_args_index = 10; + }else if(Build.VERSION.SDK_INT == 31){ + intent_args_index = 3; + appOp_args_index = 11; + }else if(Build.VERSION.SDK_INT == 32){ + intent_args_index = 3; + if(parameters[11].getType() == int.class){ + appOp_args_index = 11; + } + if(parameters[12].getType() == int.class){ + appOp_args_index = 12; + } + } + if(intent_args_index == 0 || appOp_args_index == 0){ + for(int i = 0; i < parameters.length; i++){ + if(parameters[i].getName() == "appOp" && parameters[i].getType() == int.class){ + appOp_args_index = i; + } + if(parameters[i].getName() == "intent" && parameters[i].getType() == Intent.class){ + intent_args_index = i; + } + } + } + printLog("Android API: " + Build.VERSION.SDK_INT); + printLog("appOp_args_index: " + appOp_args_index); + printLog("intent_args_index: " + intent_args_index); + if(intent_args_index == 0 || appOp_args_index == 0){ + printLog("broadcastIntentLocked hook 位置查找失败,fcmfix将不会工作。"); + return; + } + final int finalIntent_args_index = intent_args_index; + final int finalAppOp_args_index = appOp_args_index; + XposedBridge.hookMethod(targetMethod,new XC_MethodHook() { @Override protected void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable { - int intent_args_index = 0; - int appOp_args_index = 0; - if(Build.VERSION.SDK_INT == Build.VERSION_CODES.Q){ - intent_args_index = 2; - appOp_args_index = 9; - }else if(Build.VERSION.SDK_INT == Build.VERSION_CODES.R){ - intent_args_index = 3; - appOp_args_index = 10; - }else if(Build.VERSION.SDK_INT == 31){ - intent_args_index = 3; - appOp_args_index = 11; - }else if(Build.VERSION.SDK_INT == 32){ - intent_args_index = 3; - appOp_args_index = 11; - }else{ - sendUpdateNotification("未适配的安卓版本: " + Build.VERSION.SDK_INT, "fcmfix将不会工作"); - return; - } - Intent intent = (Intent) methodHookParam.args[intent_args_index]; + Intent intent = (Intent) methodHookParam.args[finalIntent_args_index]; if(intent != null && intent.getPackage() != null && intent.getFlags() != Intent.FLAG_INCLUDE_STOPPED_PACKAGES && "com.google.android.c2dm.intent.RECEIVE".equals(intent.getAction())){ String target; if (intent.getComponent() != null) { @@ -61,9 +88,9 @@ protected void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwa target = intent.getPackage(); } if(targetIsAllow(target)){ - int i = ((Integer)methodHookParam.args[appOp_args_index]).intValue(); + int i = ((Integer)methodHookParam.args[finalAppOp_args_index]).intValue(); if (i == -1) { - methodHookParam.args[appOp_args_index] = Integer.valueOf(11); + methodHookParam.args[finalAppOp_args_index] = Integer.valueOf(11); } intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); printLog("Send Forced Start Broadcast: " + target); diff --git a/app/src/main/java/com/kooritea/fcmfix/xposed/XposedModule.java b/app/src/main/java/com/kooritea/fcmfix/xposed/XposedModule.java index a325546..df9fbf8 100644 --- a/app/src/main/java/com/kooritea/fcmfix/xposed/XposedModule.java +++ b/app/src/main/java/com/kooritea/fcmfix/xposed/XposedModule.java @@ -84,6 +84,7 @@ private static void callAllOnCanReadConfig(){ protected static void printLog(String text){ Intent log = new Intent("com.kooritea.fcmfix.log"); log.putExtra("text",text); + XposedBridge.log("[fcmfix] "+ text); try{ context.sendBroadcast(log); }catch (Exception e){