mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-02 23:24:26 +02:00
read HeaderBlock properly & fix bug #8
This commit is contained in:
parent
b628d6540f
commit
8d786b2844
@ -129,7 +129,7 @@ package com.reandroid.lib.arsc.chunk;
|
|||||||
public void onBlockLoaded(BlockReader reader, Block sender) throws IOException {
|
public void onBlockLoaded(BlockReader reader, Block sender) throws IOException {
|
||||||
if(sender==mPackageId){
|
if(sender==mPackageId){
|
||||||
int headerSize=getHeaderBlock().getHeaderSize();
|
int headerSize=getHeaderBlock().getHeaderSize();
|
||||||
if(headerSize!=288){
|
if(headerSize<288){
|
||||||
mTypeIdOffset.set(0);
|
mTypeIdOffset.set(0);
|
||||||
mTypeIdOffsetContainer.setItem(null);
|
mTypeIdOffsetContainer.setItem(null);
|
||||||
}
|
}
|
||||||
|
@ -90,12 +90,12 @@ package com.reandroid.lib.arsc.chunk.xml;
|
|||||||
if(headerBlock==null){
|
if(headerBlock==null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ChunkType chunkType=headerBlock.getChunkType();
|
|
||||||
if(chunkType!=ChunkType.XML){
|
|
||||||
throw new IOException("Not ResXmlBlock: "+headerBlock);
|
|
||||||
}
|
|
||||||
BlockReader chunkReader=reader.create(reader.getPosition(), headerBlock.getChunkSize());
|
BlockReader chunkReader=reader.create(reader.getPosition(), headerBlock.getChunkSize());
|
||||||
getHeaderBlock().readBytes(chunkReader);
|
headerBlock=getHeaderBlock();
|
||||||
|
headerBlock.readBytes(chunkReader);
|
||||||
|
// android/aapt2 accepts 0x0000 (NULL) chunk type as XML, it could
|
||||||
|
// be android's bug and might be fixed in the future until then lets fix it ourselves
|
||||||
|
headerBlock.setType(ChunkType.XML);
|
||||||
while (chunkReader.isAvailable()){
|
while (chunkReader.isAvailable()){
|
||||||
boolean readOk=readNext(chunkReader);
|
boolean readOk=readNext(chunkReader);
|
||||||
if(!readOk){
|
if(!readOk){
|
||||||
|
@ -24,25 +24,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class AnyHeader extends HeaderBlock{
|
public class AnyHeader extends HeaderBlock{
|
||||||
private final ByteArray extraBytes;
|
|
||||||
public AnyHeader() {
|
public AnyHeader() {
|
||||||
super(ChunkType.NULL.ID);
|
super(ChunkType.NULL.ID);
|
||||||
this.extraBytes = new ByteArray();
|
|
||||||
super.addChild(extraBytes);
|
|
||||||
}
|
|
||||||
public ByteArray getExtraBytes() {
|
|
||||||
return extraBytes;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
void onHeaderSizeLoaded(int size){
|
|
||||||
int max = 0x0000ffff;
|
|
||||||
if(size > max){
|
|
||||||
size=max;
|
|
||||||
}else if(size<0){
|
|
||||||
size=0;
|
|
||||||
}
|
|
||||||
extraBytes.setSize(size-8);
|
|
||||||
super.onHeaderSizeLoaded(size);
|
|
||||||
}
|
}
|
||||||
public int readBytes(InputStream inputStream) throws IOException {
|
public int readBytes(InputStream inputStream) throws IOException {
|
||||||
int result=0;
|
int result=0;
|
||||||
|
@ -20,6 +20,7 @@ import com.reandroid.lib.arsc.base.Block;
|
|||||||
import com.reandroid.lib.arsc.container.ExpandableBlockContainer;
|
import com.reandroid.lib.arsc.container.ExpandableBlockContainer;
|
||||||
import com.reandroid.lib.arsc.io.BlockLoad;
|
import com.reandroid.lib.arsc.io.BlockLoad;
|
||||||
import com.reandroid.lib.arsc.io.BlockReader;
|
import com.reandroid.lib.arsc.io.BlockReader;
|
||||||
|
import com.reandroid.lib.arsc.item.ByteArray;
|
||||||
import com.reandroid.lib.arsc.item.IntegerItem;
|
import com.reandroid.lib.arsc.item.IntegerItem;
|
||||||
import com.reandroid.lib.arsc.item.ShortItem;
|
import com.reandroid.lib.arsc.item.ShortItem;
|
||||||
|
|
||||||
@ -30,11 +31,13 @@ import java.io.IOException;
|
|||||||
private final ShortItem mHeaderSize;
|
private final ShortItem mHeaderSize;
|
||||||
private final IntegerItem mChunkSize;
|
private final IntegerItem mChunkSize;
|
||||||
private HeaderLoaded mHeaderLoaded;
|
private HeaderLoaded mHeaderLoaded;
|
||||||
|
private final ByteArray extraBytes;
|
||||||
public HeaderBlock(short type){
|
public HeaderBlock(short type){
|
||||||
super(3);
|
super(3);
|
||||||
this.mType=new ShortItem(type);
|
this.mType=new ShortItem(type);
|
||||||
this.mHeaderSize=new ShortItem();
|
this.mHeaderSize=new ShortItem();
|
||||||
this.mChunkSize=new IntegerItem();
|
this.mChunkSize=new IntegerItem();
|
||||||
|
this.extraBytes=new ByteArray();
|
||||||
addChild(mType);
|
addChild(mType);
|
||||||
addChild(mHeaderSize);
|
addChild(mHeaderSize);
|
||||||
addChild(mChunkSize);
|
addChild(mChunkSize);
|
||||||
@ -42,6 +45,9 @@ import java.io.IOException;
|
|||||||
this.mHeaderSize.setBlockLoad(this);
|
this.mHeaderSize.setBlockLoad(this);
|
||||||
this.mChunkSize.setBlockLoad(this);
|
this.mChunkSize.setBlockLoad(this);
|
||||||
}
|
}
|
||||||
|
public ByteArray getExtraBytes() {
|
||||||
|
return extraBytes;
|
||||||
|
}
|
||||||
public void setHeaderLoaded(HeaderLoaded headerLoaded){
|
public void setHeaderLoaded(HeaderLoaded headerLoaded){
|
||||||
this.mHeaderLoaded=headerLoaded;
|
this.mHeaderLoaded=headerLoaded;
|
||||||
}
|
}
|
||||||
@ -94,6 +100,21 @@ import java.io.IOException;
|
|||||||
setChunkSize(count);
|
setChunkSize(count);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
public void onReadBytes(BlockReader reader) throws IOException {
|
||||||
|
int start=reader.getPosition();
|
||||||
|
super.onReadBytes(reader);
|
||||||
|
int readActual=reader.getPosition() - start;
|
||||||
|
int difference=getHeaderSize()-readActual;
|
||||||
|
if(difference==0){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(extraBytes.getParent()==null){
|
||||||
|
addChild(extraBytes);
|
||||||
|
}
|
||||||
|
extraBytes.setSize(difference);
|
||||||
|
extraBytes.readBytes(reader);
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public void onBlockLoaded(BlockReader reader, Block sender) throws IOException {
|
public void onBlockLoaded(BlockReader reader, Block sender) throws IOException {
|
||||||
if(sender==this.mType){
|
if(sender==this.mType){
|
||||||
onChunkTypeLoaded(mType.get());
|
onChunkTypeLoaded(mType.get());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user