mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-06-12 05:07:45 +02:00
Rewrite zip signing
This commit is contained in:
@ -14,7 +14,6 @@ import com.topjohnwu.magisk.utils.ZipUtils;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
|
||||
@ -38,51 +37,33 @@ public class ProcessRepoZip extends ParallelTask<Void, Void, Boolean> {
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
|
||||
FileInputStream in;
|
||||
FileOutputStream out;
|
||||
|
||||
try {
|
||||
|
||||
// Create temp file
|
||||
File temp1 = new File(magiskManager.getCacheDir(), "1.zip");
|
||||
File temp2 = new File(magiskManager.getCacheDir(), "2.zip");
|
||||
if (magiskManager.getCacheDir().mkdirs()) {
|
||||
temp1.createNewFile();
|
||||
temp2.createNewFile();
|
||||
}
|
||||
|
||||
out = new FileOutputStream(temp1);
|
||||
magiskManager.getCacheDir().mkdirs();
|
||||
temp1.createNewFile();
|
||||
temp2.createNewFile();
|
||||
|
||||
// First remove top folder in Github source zip, Uri -> temp1
|
||||
ZipUtils.removeTopFolder(activity.getContentResolver().openInputStream(mUri), out);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
out = new FileOutputStream(temp2);
|
||||
ZipUtils.removeTopFolder(activity.getContentResolver().openInputStream(mUri), temp1);
|
||||
|
||||
// Then sign the zip for the first time, temp1 -> temp2
|
||||
ZipUtils.signZip(activity, temp1, out, false);
|
||||
out.flush();
|
||||
out.close();
|
||||
ZipUtils.signZip(activity, temp1, temp2, false);
|
||||
|
||||
// Adjust the zip to prevent unzip issues, temp2 -> temp2
|
||||
ZipUtils.adjustZip(temp2);
|
||||
// Adjust the zip to prevent unzip issues, temp2 -> temp1
|
||||
ZipUtils.zipAdjust(temp2.getPath(), temp1.getPath());
|
||||
|
||||
out = new FileOutputStream(temp1);
|
||||
// Finally, sign the whole zip file again, temp1 -> temp2
|
||||
ZipUtils.signZip(activity, temp1, temp2, true);
|
||||
|
||||
// Finally, sign the whole zip file again, temp2 -> temp1
|
||||
ZipUtils.signZip(activity, temp2, out, true);
|
||||
out.flush();
|
||||
out.close();
|
||||
|
||||
in = new FileInputStream(temp1);
|
||||
|
||||
// Write it back to the downloaded zip, temp1 -> Uri
|
||||
// Write it back to the downloaded zip, temp2 -> Uri
|
||||
FileInputStream in = new FileInputStream(temp2);
|
||||
try (OutputStream target = activity.getContentResolver().openOutputStream(mUri)) {
|
||||
byte[] buffer = new byte[4096];
|
||||
int length;
|
||||
if (target == null) throw new FileNotFoundException();
|
||||
if (target == null) throw new FileNotFoundException();
|
||||
while ((length = in.read(buffer)) > 0)
|
||||
target.write(buffer, 0, length);
|
||||
}
|
||||
|
@ -7,7 +7,6 @@ import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.support.v4.content.FileProvider;
|
||||
|
||||
import com.topjohnwu.magisk.MagiskManager;
|
||||
import com.topjohnwu.magisk.utils.Utils;
|
||||
|
||||
import java.io.File;
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user