This commit is contained in:
REAndroid
2022-12-10 11:42:50 -05:00
parent 0b2f3815db
commit 661073d9b4
6 changed files with 62 additions and 5 deletions

View File

@ -1,9 +1,6 @@
package com.reandroid.lib.apk;
import com.reandroid.archive.APKArchive;
import com.reandroid.archive.InputSource;
import com.reandroid.archive.ZipArchive;
import com.reandroid.archive.ZipSerializer;
import com.reandroid.archive.*;
import com.reandroid.lib.arsc.array.PackageArray;
import com.reandroid.lib.arsc.chunk.PackageBlock;
import com.reandroid.lib.arsc.chunk.TableBlock;
@ -47,10 +44,12 @@ public class ApkModule {
return moduleName;
}
public void writeApk(File file) throws IOException {
writeApk(file, null);
}
public void writeApk(File file, WriteProgress progress) throws IOException {
ZipArchive archive=new ZipArchive();
archive.addAll(getApkArchive().listInputSources());
UncompressedFiles uf=getUncompressedFiles();
uf.setResRawDir("res/raw/");
uf.apply(archive);
int i=1;
for(InputSource inputSource:archive.listInputSources()){
@ -64,6 +63,7 @@ public class ApkModule {
manifest.setSort(0);
}
ZipSerializer serializer=new ZipSerializer(archive.listInputSources(), false);
serializer.setWriteProgress(progress);
serializer.writeZip(file);
}
public UncompressedFiles getUncompressedFiles(){

View File

@ -27,6 +27,13 @@ public class BlockInputSource<T extends BaseChunk> extends ByteInputSource{
return block.countBytes();
}
@Override
public long getCrc() throws IOException{
Block block = getBlock();
CrcOutputStream outputStream=new CrcOutputStream();
block.writeBytes(outputStream);
return outputStream.getCrcValue();
}
@Override
public long write(OutputStream outputStream) throws IOException {
return getBlock().writeBytes(outputStream);
}

View File

@ -0,0 +1,38 @@
package com.reandroid.lib.apk;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.CRC32;
public class CrcOutputStream extends OutputStream {
private final CRC32 crc;
private long length;
private long mCheckSum;
public CrcOutputStream() {
super();
this.crc = new CRC32();
}
public long getLength(){
return length;
}
public long getCrcValue(){
if(mCheckSum==0){
mCheckSum=crc.getValue();
}
return mCheckSum;
}
@Override
public void write(int b) throws IOException {
this.crc.update(b);
length=length+1;
}
@Override
public void write(byte[] b) throws IOException {
this.write(b, 0, b.length);
}
@Override
public void write(byte[] b, int off, int len) throws IOException {
this.crc.update(b, off, len);
length=length+len;
}
}

View File

@ -29,6 +29,12 @@ public class SingleJsonTableInputSource extends InputSource {
TableBlock tableBlock = getTableBlock();
return tableBlock.countBytes();
}
@Override
public long getCrc() throws IOException {
CrcOutputStream outputStream=new CrcOutputStream();
this.write(outputStream);
return outputStream.getCrcValue();
}
public TableBlock getTableBlock() throws IOException{
if(mCache!=null){
return mCache;

View File

@ -26,6 +26,12 @@ public class SplitJsonTableInputSource extends InputSource {
TableBlock tableBlock = getTableBlock();
return tableBlock.countBytes();
}
@Override
public long getCrc() throws IOException {
CrcOutputStream outputStream=new CrcOutputStream();
this.write(outputStream);
return outputStream.getCrcValue();
}
public TableBlock getTableBlock() throws IOException {
if(mCache!=null){
return mCache;