Bypass DexFile's security check for RootService (#5911)

Old Android (pre 8.0) enforces `optimizedDirectory` to have the same uid with the process. If repackaged, root service (uid=0) will crash when trying to load current.apk. So we set `optimizedDirectory` to null to bypass the check.
This commit is contained in:
残页 2022-06-04 19:21:57 +08:00 committed by GitHub
parent 351e094440
commit a3381da7ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,18 +5,19 @@ import java.io.IOException;
import java.net.URL;
import java.util.Enumeration;
import dalvik.system.DexClassLoader;
import dalvik.system.BaseDexClassLoader;
public class DynamicClassLoader extends DexClassLoader {
public class DynamicClassLoader extends BaseDexClassLoader {
private static final ClassLoader base = Object.class.getClassLoader();
public DynamicClassLoader(File apk) {
super(apk.getPath(), apk.getParent(), null, base);
this(apk, base);
}
public DynamicClassLoader(File apk, ClassLoader parent) {
super(apk.getPath(), apk.getParent(), null, parent);
// Set optimizedDirectory to null to bypass DexFile's security checks
super(apk.getPath(), null, null, parent);
}
@Override