mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-24 12:27:37 +00:00
Fix stub resource loading on Android 9, 10
They can only load resources from zip files Co-authored-by: canyie <a1364259@163.com> Co-authored-by: 南宫雪珊 <vvb2060@gmail.com>
This commit is contained in:
parent
606d97ae4d
commit
75ba62d588
@ -35,7 +35,9 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import javax.crypto.CipherInputStream;
|
||||
@ -183,19 +185,17 @@ public class DownloadActivity extends Activity {
|
||||
Os.close(fd);
|
||||
}
|
||||
} else {
|
||||
File dir = new File(getCodeCacheDir(), "res");
|
||||
dir.mkdirs();
|
||||
|
||||
// addAssetPath requires a directory containing AndroidManifest.xml on Android 6.0
|
||||
try (var stubApk = new ZipFile(getPackageCodePath());
|
||||
var manifest = new FileOutputStream(new File(dir, "AndroidManifest.xml"))) {
|
||||
var stubManifest = stubApk.getInputStream(
|
||||
stubApk.getEntry("AndroidManifest.xml"));
|
||||
APKInstall.transfer(stubManifest, manifest);
|
||||
File res = new File(getCodeCacheDir(), "res.apk");
|
||||
try (var out = new ZipOutputStream(new FileOutputStream(res))) {
|
||||
// AndroidManifest.xml is reuqired on Android 6-, and directory support is broken on Android 9-10
|
||||
out.putNextEntry(new ZipEntry("AndroidManifest.xml"));
|
||||
try (var stubApk = new ZipFile(getPackageCodePath())) {
|
||||
APKInstall.transfer(stubApk.getInputStream(stubApk.getEntry("AndroidManifest.xml")), out);
|
||||
}
|
||||
out.putNextEntry(new ZipEntry("resources.arsc"));
|
||||
decryptResources(out);
|
||||
}
|
||||
|
||||
decryptResources(new FileOutputStream(new File(dir, "resources.arsc")));
|
||||
StubApk.addAssetPath(getResources(), dir.getPath());
|
||||
StubApk.addAssetPath(getResources(), res.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user