Skip to content

Commit 3de1a2c

Browse files
committed
opt: synchronize changes from the corepatch upstream
1 parent 4d9dfd0 commit 3de1a2c

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

  • library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/systemframework/corepatch

library/libhook/src/main/java/com/sevtinge/hyperceiler/libhook/rules/systemframework/corepatch/SharedUserPatch.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,19 @@
33
import static com.sevtinge.hyperceiler.libhook.utils.api.DeviceHelper.System.isMoreAndroidVersion;
44
import static com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.EzxHelpUtils.deoptimizeMethods;
55
import static com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.EzxHelpUtils.findClassIfExists;
6+
import static com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.EzxHelpUtils.findField;
7+
import static com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.EzxHelpUtils.getIntField;
8+
import static com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.EzxHelpUtils.setIntField;
69

710
import android.content.pm.ApplicationInfo;
11+
import android.util.Log;
812

913
import com.sevtinge.hyperceiler.common.log.XposedLog;
1014
import com.sevtinge.hyperceiler.libhook.callback.IMethodHook;
1115
import com.sevtinge.hyperceiler.libhook.utils.hookapi.tool.EzxHelpUtils;
1216

17+
import java.lang.reflect.Method;
18+
import java.lang.reflect.Modifier;
1319
import java.util.Arrays;
1420

1521
import io.github.kyuubiran.ezxhelper.xposed.common.HookParam;
@@ -29,7 +35,15 @@ public void init(XposedModuleInterface.SystemServerStartingParam lpparam) {
2935

3036
// https://cs.android.com/android/platform/superproject/+/android-14.0.0_r60:frameworks/base/services/core/java/com/android/server/pm/ReconcilePackageUtils.java;l=61;bpv=1;bpt=0
3137
if (CorePatchHelper.isSharedUserEnabled()) {
32-
setStaticBooleanField(utilClass, "ALLOW_NON_PRELOADS_SYSTEM_SHAREDUIDS", true);
38+
try {
39+
var field = findField(utilClass, "ALLOW_NON_PRELOADS_SYSTEM_SHAREDUIDS");
40+
int accessFlags = (int) getIntField(field, "accessFlags");
41+
42+
setIntField(field, "accessFlags", accessFlags & ~Modifier.FINAL);
43+
field.set(null, true);
44+
} catch (Throwable e) {
45+
XposedLog.e(TAG, "system", "ALLOW_NON_PRELOADS_SYSTEM_SHAREDUIDS failed" + Log.getStackTraceString(e));
46+
}
3347
}
3448
} catch (Throwable t) {
3549
XposedLog.e(TAG, "system", "Android 14+ hook failed, crash: " + t);
@@ -55,6 +69,7 @@ public void before(HookParam param) {
5569
var utilClass = findClass("com.android.server.pm.PackageManagerServiceUtils", lpparam.getClassLoader());
5670
if (utilClass != null) {
5771
deoptimizeMethods(utilClass, "verifySignatures");
72+
hookVerifySignatures(utilClass);
5873
}
5974

6075
// choose a signature after all old signed packages are removed
@@ -187,4 +202,20 @@ protected Object SigningDetails_mergeLineageWith(Object self, Object other) {
187202
}
188203
return EzxHelpUtils.callMethod(self, "mergeLineageWith", other);
189204
}
205+
206+
private void hookVerifySignatures(Class<?> utilClass) {
207+
for (Method method : utilClass.getDeclaredMethods()) {
208+
if (!"verifySignatures".equals(method.getName()) || method.getReturnType() != Boolean.TYPE) {
209+
continue;
210+
}
211+
EzxHelpUtils.hookMethod(method, new IMethodHook() {
212+
@Override
213+
public void before(HookParam param) {
214+
if (CorePatchHelper.isFeatureEnabled(CorePatchHelper.PREF_AUTH_CREAK, false)) {
215+
param.setResult(false);
216+
}
217+
}
218+
});
219+
}
220+
}
190221
}

0 commit comments

Comments
 (0)