mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-06-13 05:37:41 +02:00
V1.0.3
This commit is contained in:
@ -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(){
|
||||
|
@ -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);
|
||||
}
|
||||
|
38
src/main/java/com/reandroid/lib/apk/CrcOutputStream.java
Normal file
38
src/main/java/com/reandroid/lib/apk/CrcOutputStream.java
Normal 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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user