mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 06:14:25 +02:00
write signature block with alignment
This commit is contained in:
parent
fb7e41c638
commit
f0c2ebb97d
@ -28,6 +28,10 @@ public class ZipFileInput extends ZipInput {
|
|||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public File getFile(){
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long position() throws IOException {
|
public long position() throws IOException {
|
||||||
FileChannel fileChannel = this.fileChannel;
|
FileChannel fileChannel = this.fileChannel;
|
||||||
|
@ -26,11 +26,13 @@ import com.reandroid.archive2.io.ZipFileOutput;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ApkWriter extends ZipFileOutput {
|
public class ApkWriter extends ZipFileOutput {
|
||||||
|
private final Object mLock = new Object();
|
||||||
private final Collection<? extends InputSource> sourceList;
|
private final Collection<? extends InputSource> sourceList;
|
||||||
private ZipAligner zipAligner;
|
private ZipAligner zipAligner;
|
||||||
private ApkSignatureBlock apkSignatureBlock;
|
private ApkSignatureBlock apkSignatureBlock;
|
||||||
@ -42,18 +44,21 @@ public class ApkWriter extends ZipFileOutput {
|
|||||||
this.zipAligner = ZipAligner.apkAligner();
|
this.zipAligner = ZipAligner.apkAligner();
|
||||||
}
|
}
|
||||||
public void write()throws IOException {
|
public void write()throws IOException {
|
||||||
List<OutputSource> outputList = buildOutputEntry();
|
synchronized (mLock){
|
||||||
logMessage("Buffering compress changed files ...");
|
List<OutputSource> outputList = buildOutputEntry();
|
||||||
BufferFileInput buffer = writeBuffer(outputList);
|
logMessage("Buffering compress changed files ...");
|
||||||
buffer.unlock();
|
BufferFileInput buffer = writeBuffer(outputList);
|
||||||
align(outputList);
|
buffer.unlock();
|
||||||
writeApk(outputList);
|
align(outputList);
|
||||||
buffer.close();
|
writeApk(outputList);
|
||||||
|
buffer.close();
|
||||||
|
|
||||||
writeSignatureBlock();
|
writeSignatureBlock();
|
||||||
|
|
||||||
writeCEH(outputList);
|
writeCEH(outputList);
|
||||||
this.close();
|
this.close();
|
||||||
|
logMessage("Written to: " + getFile().getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public void setApkSignatureBlock(ApkSignatureBlock apkSignatureBlock) {
|
public void setApkSignatureBlock(ApkSignatureBlock apkSignatureBlock) {
|
||||||
this.apkSignatureBlock = apkSignatureBlock;
|
this.apkSignatureBlock = apkSignatureBlock;
|
||||||
@ -92,7 +97,16 @@ public class ApkWriter extends ZipFileOutput {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
logMessage("Writing signature block ...");
|
logMessage("Writing signature block ...");
|
||||||
signatureBlock.writeBytes(getOutputStream());
|
long offset = position();
|
||||||
|
int alignment = 4096;
|
||||||
|
int padding = (int) ((alignment - (offset % alignment)) % alignment);
|
||||||
|
OutputStream outputStream = getOutputStream();
|
||||||
|
if(padding > 0){
|
||||||
|
outputStream.write(new byte[padding]);
|
||||||
|
}
|
||||||
|
signatureBlock.refresh();
|
||||||
|
logVerbose("padding = " + padding + ", signatures = " + signatureBlock.countBytes());
|
||||||
|
signatureBlock.writeBytes(outputStream);
|
||||||
}
|
}
|
||||||
private BufferFileInput writeBuffer(List<OutputSource> outputList) throws IOException {
|
private BufferFileInput writeBuffer(List<OutputSource> outputList) throws IOException {
|
||||||
File bufferFile = getBufferFile();
|
File bufferFile = getBufferFile();
|
||||||
|
@ -38,4 +38,15 @@ public class BufferFileInput extends ZipFileInput {
|
|||||||
}
|
}
|
||||||
throw new IOException("File locked!");
|
throw new IOException("File locked!");
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
super.close();
|
||||||
|
if(unlocked){
|
||||||
|
File file = super.getFile();
|
||||||
|
if(file.isFile()){
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
unlocked = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user