Skip to content

Commit

Permalink
适配12L 202207 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
kooritea committed Jul 18, 2022
1 parent 7bc477c commit d74f73a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 21 deletions.
69 changes: 48 additions & 21 deletions app/src/main/java/com/kooritea/fcmfix/xposed/BroadcastFix.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down

0 comments on commit d74f73a

Please sign in to comment.