Skip to content

Commit

Permalink
Fix for compatibility API 33 (Android 13)
Browse files Browse the repository at this point in the history
  • Loading branch information
ElJaviLuki committed May 23, 2023
1 parent 9af7382 commit a532b99
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 69 deletions.
12 changes: 6 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ android {
dataBinding {
enabled true
}
compileSdkVersion 31
compileSdkVersion 33
buildToolsVersion "30.0.2"

defaultConfig {
applicationId "tw.idv.palatis.xappdebug"
minSdkVersion 24
targetSdkVersion 31
versionCode 100005
versionName "1.0.5"
targetSdkVersion 33
versionCode 100006
versionName "1.0.6"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
project.ext.set("archivesBaseName", applicationId + "-" + versionName + "-" + versionCode)
Expand All @@ -31,8 +31,8 @@ android {
versionNameSuffix "-dbg"
}
release {
signingConfig signingConfigs.release
aaptOptions.cruncherEnabled = true
// signingConfig signingConfigs.release
// aaptOptions.cruncherEnabled = true
shrinkResources true
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
<meta-data
android:name="xposedminversion"
android:value="82" />
<meta-data
android:name="xposedscope"
android:value="android"
/>
</application>

</manifest>
188 changes: 125 additions & 63 deletions app/src/main/java/tw/idv/palatis/xappdebug/xposed/HookMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.annotation.SuppressLint;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.os.Build;
import android.os.StrictMode;
import android.os.UserHandle;

Expand All @@ -31,82 +32,137 @@ public class HookMain implements IXposedHookLoadPackage {
// https://android.googlesource.com/platform/frameworks/base.git/+/master/core/java/com/android/internal/os/Zygote.java
private static final int DEBUG_ENABLE_JDWP = 1;

private static final String PACKAGE_MANAGER_SERVICE_CLASS = "com.android.server.pm.PackageManagerService";

public static final boolean IS_TIRAMISU_OR_LATER = android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU;

private static final String PM_CLASS = "com.android.server.pm." +
(IS_TIRAMISU_OR_LATER ? "ComputerEngine" : "PackageManagerService");

@Override
public void handleLoadPackage(final XC_LoadPackage.LoadPackageParam lpparam) throws Throwable {
if (!"android".equals(lpparam.packageName))
return;

findAndHookMethod(
PACKAGE_MANAGER_SERVICE_CLASS,
lpparam.classLoader,
"getPackageInfo",
String.class, int.class, int.class, /* packageName, flags, userId */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
final int userId = (int) param.args[2];
final PackageInfo info = (PackageInfo) param.getResult();
if (info == null)
return;
if (!isDebuggable(info.packageName, userId))
return;
info.applicationInfo.flags |= FLAG_DEBUGGABLE;
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
if (IS_TIRAMISU_OR_LATER) {
findAndHookMethod(
PM_CLASS,
lpparam.classLoader,
"getPackageInfo",
String.class, long.class, int.class, /* packageName, flags, userId */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
if (((PackageInfo) param.getResult()).applicationInfo != null)
checkAndMakeDebuggable(((PackageInfo) param.getResult()).applicationInfo, ((PackageInfo) param.getResult()).packageName, (int) param.args[2]);
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
}
}
}
);

findAndHookMethod(
PACKAGE_MANAGER_SERVICE_CLASS,
lpparam.classLoader,
"getApplicationInfo",
String.class, int.class, int.class, /* packageName, flags, userId */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
final int userId = (int) param.args[2];
final ApplicationInfo appInfo = (ApplicationInfo) param.getResult();
if (appInfo == null)
return;
if (!isDebuggable(appInfo.packageName, userId))
return;
appInfo.flags |= FLAG_DEBUGGABLE;
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
);

findAndHookMethod(
PM_CLASS,
lpparam.classLoader,
"getApplicationInfo",
String.class, long.class, int.class, /* packageName, flags, userId */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
ApplicationInfo appInfo = (ApplicationInfo) param.getResult();
if (appInfo != null)
checkAndMakeDebuggable(appInfo, ((ApplicationInfo) param.getResult()).packageName, (int) param.args[2]);
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
}
}
}
);

findAndHookMethod(
PACKAGE_MANAGER_SERVICE_CLASS,
lpparam.classLoader,
"getInstalledApplicationsListInternal",
int.class, int.class, int.class, /* flags, userId, callingUid */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
final int userId = (int) param.args[1];
final List<ApplicationInfo> infos = (List<ApplicationInfo>) param.getResult();
if (infos == null)
return;
for (ApplicationInfo info : infos) {
if (isDebuggable(info.packageName, userId))
info.flags |= FLAG_DEBUGGABLE;
);

findAndHookMethod(
PM_CLASS,
lpparam.classLoader,
"getInstalledApplications",
long.class, int.class, int.class, /* flags, userId, callingUid */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
List<ApplicationInfo> infos = (List<ApplicationInfo>) param.getResult();
if (infos != null) {
for (ApplicationInfo info : infos) {
checkAndMakeDebuggable(info, info.packageName, (int) param.args[1]);
}
}
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
}
}
);
);
}else{
findAndHookMethod(
PM_CLASS,
lpparam.classLoader,
"getPackageInfo",
String.class, int.class, int.class, /* packageName, flags, userId */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
if (((PackageInfo) param.getResult()).applicationInfo != null)
checkAndMakeDebuggable(((PackageInfo) param.getResult()).applicationInfo, ((PackageInfo) param.getResult()).packageName, (int) param.args[2]);
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
}
}
);

findAndHookMethod(
PM_CLASS,
lpparam.classLoader,
"getApplicationInfo",
String.class, int.class, int.class, /* packageName, flags, userId */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
ApplicationInfo appInfo = (ApplicationInfo) param.getResult();
if (appInfo != null)
checkAndMakeDebuggable(appInfo, ((ApplicationInfo) param.getResult()).packageName, (int) param.args[2]);
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
}
}
);

findAndHookMethod(
PM_CLASS,
lpparam.classLoader,
"getInstalledApplicationsListInternal",
int.class, int.class, int.class, /* flags, userId, callingUid */
new XC_MethodHook() {
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable {
try {
List<ApplicationInfo> infos = (List<ApplicationInfo>) param.getResult();
if (infos != null) {
for (ApplicationInfo info : infos) {
checkAndMakeDebuggable(info, info.packageName, (int) param.args[1]);
}
}
} catch (Exception e) {
XposedBridge.log(LOG_TAG + ": " + getStackTraceString(e));
}
}
}
);
}


hookAllMethods(
android.os.Process.class,
Expand All @@ -126,6 +182,12 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
);
}

private void checkAndMakeDebuggable(ApplicationInfo appInfo, String packageName, int user) {
if (isDebuggable(packageName, user)) {
appInfo.flags |= FLAG_DEBUGGABLE;
}
}

@SuppressLint("SdCardPath")
private static boolean isDebuggable(final String packageName, int user) {
final String path = String.format(
Expand Down

0 comments on commit a532b99

Please sign in to comment.