Skip to content

Commit

Permalink
Merge branch 'LSPosed:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
aguys123 authored Mar 2, 2024
2 parents 8e2daae + 7ffaf46 commit f1aaff4
Show file tree
Hide file tree
Showing 11 changed files with 298 additions and 62 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ android {
applicationId = "com.coderstory.toolkit"
minSdk = 28
targetSdk = 34
versionCode = 2016
versionName = "4.4"
versionCode = 2019
versionName = "4.5"
}

signingConfigs {
Expand Down
6 changes: 0 additions & 6 deletions app/src/main/java/toolkit/coderstory/CorePatchForQ.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ public void handleLoadPackage(XC_LoadPackage.LoadPackageParam loadPackageParam)
Class<?> packageClazz = XposedHelpers.findClass("android.content.pm.PackageParser.Package", loadPackageParam.classLoader);
hookAllMethods("com.android.server.pm.PackageManagerService", loadPackageParam.classLoader, "checkDowngrade", new XC_MethodHook() {
public void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
super.beforeHookedMethod(methodHookParam);
if (prefs.getBoolean("downgrade", true)) {
Object packageInfoLite = methodHookParam.args[0];

Expand Down Expand Up @@ -65,7 +64,6 @@ public void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable
final Object newInstance = findConstructorExact.newInstance(signingDetailsArgs);
hookAllMethods("android.util.apk.ApkSignatureVerifier", loadPackageParam.classLoader, "verifyV1Signature", new XC_MethodHook() {
public void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable {
super.afterHookedMethod(methodHookParam);
if (prefs.getBoolean("authcreak", false)) {
Throwable throwable = methodHookParam.getThrowable();
if (throwable != null) {
Expand All @@ -90,7 +88,6 @@ public void afterHookedMethod(MethodHookParam methodHookParam) throws Throwable
hookAllMethods(signingDetails, "checkCapability", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
if (prefs.getBoolean("digestCreak", true)) {
if ((Integer) param.args[1] != 4 && prefs.getBoolean("authcreak", false)) {
param.setResult(Boolean.TRUE);
Expand All @@ -102,7 +99,6 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
if (prefs.getBoolean("digestCreak", true)) {
if ((Integer) param.args[1] != 4 && prefs.getBoolean("authcreak", false)) {
param.setResult(Boolean.TRUE);
Expand All @@ -115,7 +111,6 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
findAndHookMethod("android.content.pm.ApplicationInfo", loadPackageParam.classLoader, "isPackageWhitelistedForHiddenApis", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
if (prefs.getBoolean("digestCreak", true)) {
ApplicationInfo info = (ApplicationInfo) param.thisObject;
if ((info.flags & ApplicationInfo.FLAG_SYSTEM) != 0
Expand Down Expand Up @@ -159,7 +154,6 @@ public void initZygote(StartupParam startupParam) {
hookAllConstructors("android.util.jar.StrictJarVerifier", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
if (prefs.getBoolean("enhancedMode", false)) {
param.args[3] = Boolean.FALSE;
}
Expand Down
283 changes: 254 additions & 29 deletions app/src/main/java/toolkit/coderstory/CorePatchForR.java

Large diffs are not rendered by default.

47 changes: 28 additions & 19 deletions app/src/main/java/toolkit/coderstory/CorePatchForT.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package toolkit.coderstory;

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

import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;

import de.robv.android.xposed.XC_MethodHook;
Expand Down Expand Up @@ -38,23 +39,6 @@ protected void beforeHookedMethod(MethodHookParam param) {
}
});

// Package " + packageName + " signatures do not match previously installed version; ignoring!"
// public boolean checkCapability(String sha256String, @CertCapabilities int flags) {
// public boolean checkCapability(SigningDetails oldDetails, @CertCapabilities int flags)
hookAllMethods("android.content.pm.PackageParser", loadPackageParam.classLoader, "checkCapability", new XC_MethodHook() {
@Override
protected void beforeHookedMethod(MethodHookParam param) {
// Don't handle PERMISSION (grant SIGNATURE permissions to pkgs with this cert)
// Or applications will have all privileged permissions
// https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/content/pm/PackageParser.java;l=5947?q=CertCapabilities
if (prefs.getBoolean("authcreak", false)) {
if ((Integer) param.args[1] != 4) {
param.setResult(true);
}
}
}
});

findAndHookMethod("com.android.server.pm.InstallPackageHelper", loadPackageParam.classLoader,
"doesSignatureMatchForPermissions", String.class,
"com.android.server.pm.parsing.pkg.ParsedPackage", int.class, new XC_MethodHook() {
Expand Down Expand Up @@ -97,10 +81,35 @@ protected void afterHookedMethod(MethodHookParam param) {
}
});
}

// ensure verifySignatures success
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/services/core/java/com/android/server/pm/PackageManagerServiceUtils.java;l=621;drc=2e50991320cbef77d3e8504a4b284adae8c2f4d2
var utils = XposedHelpers.findClassIfExists("com.android.server.pm.PackageManagerServiceUtils", loadPackageParam.classLoader);
if (utils != null) {
deoptimizeMethod(utils, "canJoinSharedUserId");
}
}

@Override
Class<?> getSigningDetails(ClassLoader classLoader) {
return XposedHelpers.findClassIfExists("android.content.pm.SigningDetails", classLoader);
}

@Override
protected void dumpSigningDetails(Object signingDetails, PrintWriter pw) {
var i = 0;
for (var sign : (Signature[]) XposedHelpers.callMethod(signingDetails, "getSignatures")) {
i++;
pw.println(i + ": " + sign.toCharsString());
}
}

@Override
protected Object SharedUserSetting_packages(Object sharedUser) {
return XposedHelpers.getObjectField(sharedUser, "mPackages");
}

@Override
protected Object SigningDetails_mergeLineageWith(Object self, Object other) {
return XposedHelpers.callMethod(self, "mergeLineageWith", other, 2 /*MERGE_RESTRICTED_CAPABILITY*/);
}
}
1 change: 0 additions & 1 deletion app/src/main/java/toolkit/coderstory/ReturnConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public ReturnConstant(XSharedPreferences prefs, String prefsKey, Object value) {

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
super.beforeHookedMethod(param);
prefs.reload();
if (prefs.getBoolean(prefsKey, true)) {
param.setResult(value);
Expand Down
4 changes: 0 additions & 4 deletions app/src/main/java/toolkit/coderstory/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,13 @@
import android.app.AlertDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Insets;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowInsetsController;

import com.coderstory.toolkit.R;

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/toolkit/coderstory/XposedHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public static void findAndHookMethod(String className, ClassLoader classLoader,
XposedBridge.log("E/" + MainHook.TAG + " " + Log.getStackTraceString(e));
}
}

public static void findAndHookMethod(Class<?> clazz, String methodName, Object... parameterTypesAndCallback) {
try {
if (clazz != null) {
Expand All @@ -31,6 +32,7 @@ public static void findAndHookMethod(Class<?> clazz, String methodName, Object..
XposedBridge.log("E/" + MainHook.TAG + " " + Log.getStackTraceString(e));
}
}

public static void hookAllMethods(String className, ClassLoader classLoader, String methodName, XC_MethodHook callback) {
try {
Class<?> packageParser = findClass(className, classLoader);
Expand All @@ -39,7 +41,6 @@ public static void hookAllMethods(String className, ClassLoader classLoader, Str
if (BuildConfig.DEBUG)
XposedBridge.log("E/" + MainHook.TAG + " " + Log.getStackTraceString(e));
}

}

public void hookAllMethods(Class<?> hookClass, String methodName, XC_MethodHook callback) {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
<string name="bypassBlock_summary">Ignore a lista de bloqueio em alguns dispositivos como Nothing Phone</string>
<string name="miui_usepresig_warn">Usar assinaturas instaladas não funcionará na MIUI porque sua estrutura muda muito.\nNão temos tempo para acompanhar o caso.</string>
<string name="usepresig_warn">!! Qualquer apk pode substituir o instalado !!\nTenha cuidado ao instalar apk desconhecido.</string>
<string name="shared_user_title">Ignorar verificação de usuário compartilhado</string>
<string name="shared_user_summary">Permite instalar apps com assinaturas diferentes do usuário compartilhado. (<b>\'Desativar comparação de assinaturas\' também deve estar ativado.</b>)</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
<string name="bypassBlock">绕过黑名单</string>
<string name="bypassBlock_summary">绕过某些设备如 Nothing Phone 上的黑名单</string>
<string name="config_error">配置初始化失败</string>
<string name="shared_user_title">绕过共享用户签名验证</string>
<string name="shared_user_summary">允许安装与其共享用户签名不同的 app(<b>需要同时打开“禁用APK签名验证”</b>)</string>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@
<string name="bypassBlock_summary">Bypass blocklist in some devices like Nothing Phone</string>
<string name="miui_usepresig_warn">UsePreSig won\'t work on MiUI because its framework changes too much.\nWe don\'t have time to track the case.</string>
<string name="usepresig_warn">!! Any apk can override the installed one !!\nBe carefully when installing unknown apk</string>
<string name="shared_user_title">Bypass shared user verify</string>
<string name="shared_user_summary">Allow install app with signature differ from its shared user (<b>\'Disable compare signatures\' must be enabled too</b>)</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
android:title="@string/bypassBlock"
android:summary="@string/bypassBlock_summary"
android:defaultValue="true" />

<SwitchPreference
android:key="sharedUser"
android:title="@string/shared_user_title"
android:summary="@string/shared_user_summary"
android:defaultValue="false" />
</PreferenceCategory>

</PreferenceScreen>

0 comments on commit f1aaff4

Please sign in to comment.