2929import java .util .Arrays ;
3030import java .util .List ;
3131
32+ import io .github .libxposed .api .XposedInterface ;
33+
3234public class ModulePackageTrust extends BaseHook {
3335 private final ArrayList <String > systemPackages = new ArrayList <>();
3436
@@ -39,63 +41,78 @@ public void init() {
3941
4042 chainAllMethods ("com.android.server.pm.permission.PermissionManagerServiceImpl" ,
4143 "shouldGrantPermissionBySignature" ,
42- chain -> {
43- String packageName = (String ) callMethod (chain .getArg (0 ), "getPackageName" );
44- if (systemPackages .contains (packageName )) {
45- return true ;
44+ new XposedInterface .Hooker () {
45+ @ Override
46+ public Object intercept (XposedInterface .Chain chain ) throws Throwable {
47+ String packageName = (String ) callMethod (chain .getArg (0 ), "getPackageName" );
48+ if (systemPackages .contains (packageName )) {
49+ return true ;
50+ }
51+ return chain .proceed ();
4652 }
47- return chain .proceed ();
4853 });
4954
5055 chainAllMethods ("com.android.server.pm.PackageManagerServiceUtils" ,
5156 "verifySignatures" ,
52- chain -> {
53- String packageName = (String ) callMethod (chain .getArg (0 ), "getName" );
54- if (systemPackages .contains (packageName )) {
55- return true ;
57+ new XposedInterface .Hooker () {
58+ @ Override
59+ public Object intercept (XposedInterface .Chain chain ) throws Throwable {
60+ String packageName = (String ) callMethod (chain .getArg (0 ), "getName" );
61+ if (systemPackages .contains (packageName )) {
62+ return true ;
63+ }
64+ return chain .proceed ();
5665 }
57- return chain .proceed ();
5866 });
5967
6068 chainAllMethods ("com.android.server.pm.ComputerEngine" ,
6169 "queryIntentActivitiesInternal" ,
62- chain -> {
63- Object result = chain .proceed ();
64- if (chain .getArgs ().size () < 6 || !(result instanceof List <?>)) {
65- return result ;
66- }
67- List <?> infos = (List <?>) result ;
68- for (Object item : infos ) {
69- if (!(item instanceof ResolveInfo )) {
70- continue ;
70+ new XposedInterface .Hooker () {
71+ @ Override
72+ public Object intercept (XposedInterface .Chain chain ) throws Throwable {
73+ Object result = chain .proceed ();
74+ if (chain .getArgs ().size () < 6 || !(result instanceof List <?>)) {
75+ return result ;
7176 }
72- ResolveInfo info = (ResolveInfo ) item ;
73- if (info .activityInfo == null ) {
74- continue ;
75- }
76- if (systemPackages .contains (info .activityInfo .packageName )) {
77- setObjectField (info , "system" , true );
77+ List <?> infos = (List <?>) result ;
78+ for (Object item : infos ) {
79+ if (!(item instanceof ResolveInfo )) {
80+ continue ;
81+ }
82+ ResolveInfo info = (ResolveInfo ) item ;
83+ if (info .activityInfo == null ) {
84+ continue ;
85+ }
86+ if (systemPackages .contains (info .activityInfo .packageName )) {
87+ setObjectField (info , "system" , true );
88+ }
7889 }
90+ return result ;
7991 }
80- return result ;
8192 });
8293
83- findAndChainMethod ("android.content.pm.ApplicationInfo" , "isSystemApp" , chain -> {
84- Object result = chain .proceed ();
85- ApplicationInfo applicationInfo = (ApplicationInfo ) chain .getThisObject ();
86- if (applicationInfo != null && systemPackages .contains (applicationInfo .packageName )) {
87- return true ;
94+ findAndChainMethod ("android.content.pm.ApplicationInfo" , "isSystemApp" , new XposedInterface .Hooker () {
95+ @ Override
96+ public Object intercept (XposedInterface .Chain chain ) throws Throwable {
97+ Object result = chain .proceed ();
98+ ApplicationInfo applicationInfo = (ApplicationInfo ) chain .getThisObject ();
99+ if (applicationInfo != null && systemPackages .contains (applicationInfo .packageName )) {
100+ return true ;
101+ }
102+ return result ;
88103 }
89- return result ;
90104 });
91105
92- findAndChainMethod ("android.content.pm.ApplicationInfo" , "isSignedWithPlatformKey" , chain -> {
93- Object result = chain .proceed ();
94- ApplicationInfo applicationInfo = (ApplicationInfo ) chain .getThisObject ();
95- if (applicationInfo != null && systemPackages .contains (applicationInfo .packageName )) {
96- return true ;
106+ findAndChainMethod ("android.content.pm.ApplicationInfo" , "isSignedWithPlatformKey" , new XposedInterface .Hooker () {
107+ @ Override
108+ public Object intercept (XposedInterface .Chain chain ) throws Throwable {
109+ Object result = chain .proceed ();
110+ ApplicationInfo applicationInfo = (ApplicationInfo ) chain .getThisObject ();
111+ if (applicationInfo != null && systemPackages .contains (applicationInfo .packageName )) {
112+ return true ;
113+ }
114+ return result ;
97115 }
98- return result ;
99116 });
100117
101118 try {
0 commit comments