Skip to content

Commit

Permalink
allow system app use hidden api
Browse files Browse the repository at this point in the history
  • Loading branch information
coderstory committed Jun 1, 2021
1 parent 6784770 commit 81b90a1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions app/src/main/java/toolkit/coderstory/CorePatchForQ.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package toolkit.coderstory;


import android.content.pm.ApplicationInfo;
import android.content.pm.Signature;

import com.coderstory.toolkit.BuildConfig;
Expand All @@ -17,6 +18,8 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;

public class CorePatchForQ extends XposedHelper implements IXposedHookLoadPackage, IXposedHookZygoteInit {
XSharedPreferences prefs = new XSharedPreferences(BuildConfig.APPLICATION_ID, "conf");

Expand Down Expand Up @@ -109,6 +112,19 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
}
}
});

// if app is system app, allow to use hidden api, even if app not using a system signature
findAndHookMethod("android.content.pm.ApplicationInfo", loadPackageParam.classLoader, "isPackageWhitelistedForHiddenApis", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
ApplicationInfo info = (ApplicationInfo) param.thisObject;
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0
|| (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
param.setResult(true);
}
}
});
}
}

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/toolkit/coderstory/CorePatchForR.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package toolkit.coderstory;


import android.content.pm.ApplicationInfo;
import android.content.pm.Signature;
import android.util.Log;

Expand All @@ -18,6 +19,8 @@
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;

import static android.content.pm.ApplicationInfo.FLAG_SYSTEM;

public class CorePatchForR extends XposedHelper implements IXposedHookLoadPackage, IXposedHookZygoteInit {
XSharedPreferences prefs = new XSharedPreferences(BuildConfig.APPLICATION_ID, "conf");

Expand Down Expand Up @@ -102,6 +105,19 @@ public void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable
//处理覆盖安装但签名不一致
Class<?> signingDetails = XposedHelpers.findClass("android.content.pm.PackageParser.SigningDetails", loadPackageParam.classLoader);
hookAllMethods(signingDetails, "checkCapability", XC_MethodReplacement.returnConstant(true));

// if app is system app, allow to use hidden api, even if app not using a system signature
findAndHookMethod("android.content.pm.ApplicationInfo", loadPackageParam.classLoader, "isPackageWhitelistedForHiddenApis", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
ApplicationInfo info = (ApplicationInfo) param.thisObject;
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0
|| (info.flags & ApplicationInfo.FLAG_UPDATED_SYSTEM_APP) != 0) {
param.setResult(true);
}
}
});
}
}

Expand Down

0 comments on commit 81b90a1

Please sign in to comment.