Ensure optimizedDirectory for rish dex is readable and writable

This commit is contained in:
RikkaW
2023-07-19 15:05:34 +08:00
parent 4dcdd992fe
commit c281276422
2 changed files with 17 additions and 1 deletions

View File

@ -23,6 +23,9 @@ android {
lint { lint {
checkReleaseBuilds false checkReleaseBuilds false
} }
buildFeatures {
buildConfig = true
}
} }
android.applicationVariants.all { variant -> android.applicationVariants.all { variant ->

View File

@ -12,6 +12,7 @@ import android.os.Looper;
import android.os.Parcel; import android.os.Parcel;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.ServiceManager; import android.os.ServiceManager;
import android.system.ErrnoException;
import android.system.Os; import android.system.Os;
import android.text.TextUtils; import android.text.TextUtils;
@ -100,9 +101,21 @@ public class ShizukuShellLoader {
if (!TextUtils.isEmpty(systemLibrarySearchPath)) { if (!TextUtils.isEmpty(systemLibrarySearchPath)) {
librarySearchPath += File.pathSeparatorChar + systemLibrarySearchPath; librarySearchPath += File.pathSeparatorChar + systemLibrarySearchPath;
} }
String optimizedDirectory = ".";
File optimizedDirectoryFile = new File(optimizedDirectory);
if (!optimizedDirectoryFile.exists() || !optimizedDirectoryFile.isDirectory() || !optimizedDirectoryFile.canWrite() || !optimizedDirectoryFile.canExecute()) {
optimizedDirectory = "/data/local/tmp/rish-shizuku-" + BuildConfig.VERSION_CODE;
optimizedDirectoryFile = new File(optimizedDirectory);
optimizedDirectoryFile.mkdirs();
try {
Os.chmod(optimizedDirectory, 00711);
} catch (ErrnoException e) {
System.err.println(e.getMessage());
}
}
try { try {
DexClassLoader classLoader = new DexClassLoader(sourceDir, ".", librarySearchPath, ClassLoader.getSystemClassLoader()); DexClassLoader classLoader = new DexClassLoader(sourceDir, optimizedDirectory, librarySearchPath, ClassLoader.getSystemClassLoader());
Class<?> cls = classLoader.loadClass("moe.shizuku.manager.shell.Shell"); Class<?> cls = classLoader.loadClass("moe.shizuku.manager.shell.Shell");
cls.getDeclaredMethod("main", String[].class, String.class, IBinder.class, Handler.class) cls.getDeclaredMethod("main", String[].class, String.class, IBinder.class, Handler.class)
.invoke(null, args, callingPackage, binder, handler); .invoke(null, args, callingPackage, binder, handler);