mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-05-08 09:44:26 +02:00
read Spec and Type separately
This commit is contained in:
parent
dc911e861e
commit
b8fd031bc1
@ -22,6 +22,7 @@ import com.reandroid.arsc.chunk.SpecBlock;
|
|||||||
import com.reandroid.arsc.chunk.TypeBlock;
|
import com.reandroid.arsc.chunk.TypeBlock;
|
||||||
import com.reandroid.arsc.container.SpecTypePair;
|
import com.reandroid.arsc.container.SpecTypePair;
|
||||||
import com.reandroid.arsc.header.HeaderBlock;
|
import com.reandroid.arsc.header.HeaderBlock;
|
||||||
|
import com.reandroid.arsc.header.TypeHeader;
|
||||||
import com.reandroid.arsc.io.BlockReader;
|
import com.reandroid.arsc.io.BlockReader;
|
||||||
import com.reandroid.arsc.item.TypeString;
|
import com.reandroid.arsc.item.TypeString;
|
||||||
import com.reandroid.arsc.value.Entry;
|
import com.reandroid.arsc.value.Entry;
|
||||||
@ -243,6 +244,11 @@ public class TypeBlockArray extends BlockArray<TypeBlock>
|
|||||||
if(chunkType!=ChunkType.TYPE){
|
if(chunkType!=ChunkType.TYPE){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
TypeHeader typeHeader = reader.readTypeHeader();
|
||||||
|
int id = getTypeId();
|
||||||
|
if(id!=0 && typeHeader.getId().unsignedInt() != id){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
int pos=reader.getPosition();
|
int pos=reader.getPosition();
|
||||||
TypeBlock typeBlock=createNext();
|
TypeBlock typeBlock=createNext();
|
||||||
typeBlock.readBytes(reader);
|
typeBlock.readBytes(reader);
|
||||||
|
@ -18,6 +18,8 @@ package com.reandroid.arsc.container;
|
|||||||
import com.reandroid.arsc.chunk.*;
|
import com.reandroid.arsc.chunk.*;
|
||||||
import com.reandroid.arsc.array.SpecTypePairArray;
|
import com.reandroid.arsc.array.SpecTypePairArray;
|
||||||
import com.reandroid.arsc.header.HeaderBlock;
|
import com.reandroid.arsc.header.HeaderBlock;
|
||||||
|
import com.reandroid.arsc.header.SpecHeader;
|
||||||
|
import com.reandroid.arsc.header.TypeHeader;
|
||||||
import com.reandroid.arsc.io.BlockReader;
|
import com.reandroid.arsc.io.BlockReader;
|
||||||
import com.reandroid.arsc.list.OverlayableList;
|
import com.reandroid.arsc.list.OverlayableList;
|
||||||
import com.reandroid.arsc.list.StagedAliasList;
|
import com.reandroid.arsc.list.StagedAliasList;
|
||||||
@ -83,6 +85,8 @@ public class PackageBody extends FixedBlockContainer {
|
|||||||
ChunkType chunkType=headerBlock.getChunkType();
|
ChunkType chunkType=headerBlock.getChunkType();
|
||||||
if(chunkType==ChunkType.SPEC){
|
if(chunkType==ChunkType.SPEC){
|
||||||
readSpecBlock(reader);
|
readSpecBlock(reader);
|
||||||
|
}else if(chunkType==ChunkType.TYPE){
|
||||||
|
readTypeBlock(reader);
|
||||||
}else if(chunkType==ChunkType.LIBRARY){
|
}else if(chunkType==ChunkType.LIBRARY){
|
||||||
readLibraryBlock(reader);
|
readLibraryBlock(reader);
|
||||||
}else if(chunkType==ChunkType.OVERLAYABLE){
|
}else if(chunkType==ChunkType.OVERLAYABLE){
|
||||||
@ -97,8 +101,15 @@ public class PackageBody extends FixedBlockContainer {
|
|||||||
return pos!=reader.getPosition();
|
return pos!=reader.getPosition();
|
||||||
}
|
}
|
||||||
private void readSpecBlock(BlockReader reader) throws IOException{
|
private void readSpecBlock(BlockReader reader) throws IOException{
|
||||||
SpecTypePair specTypePair=mSpecTypePairArray.createNext();
|
SpecHeader specHeader = reader.readSpecHeader();
|
||||||
specTypePair.readBytes(reader);
|
SpecTypePair specTypePair = mSpecTypePairArray.getOrCreate(specHeader.getId().get());
|
||||||
|
specTypePair.getSpecBlock().readBytes(reader);
|
||||||
|
}
|
||||||
|
private void readTypeBlock(BlockReader reader) throws IOException{
|
||||||
|
TypeHeader typeHeader = reader.readTypeHeader();
|
||||||
|
SpecTypePair specTypePair = mSpecTypePairArray.getOrCreate(typeHeader.getId().get());
|
||||||
|
TypeBlock typeBlock = specTypePair.getTypeBlockArray().createNext();
|
||||||
|
typeBlock.readBytes(reader);
|
||||||
}
|
}
|
||||||
private void readLibraryBlock(BlockReader reader) throws IOException{
|
private void readLibraryBlock(BlockReader reader) throws IOException{
|
||||||
LibraryBlock libraryBlock=new LibraryBlock();
|
LibraryBlock libraryBlock=new LibraryBlock();
|
||||||
|
@ -173,11 +173,14 @@ public class SpecTypePair extends BlockContainer<Block>
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ChunkType chunkType=headerBlock.getChunkType();
|
ChunkType chunkType=headerBlock.getChunkType();
|
||||||
|
if(chunkType == ChunkType.TYPE){
|
||||||
|
mTypeBlockArray.readBytes(reader);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(chunkType!=ChunkType.SPEC){
|
if(chunkType!=ChunkType.SPEC){
|
||||||
readUnexpectedNonSpecBlock(reader, headerBlock);
|
readUnexpectedNonSpecBlock(reader, headerBlock);
|
||||||
}
|
}
|
||||||
mSpecBlock.readBytes(reader);
|
mSpecBlock.readBytes(reader);
|
||||||
mTypeBlockArray.readBytes(reader);
|
|
||||||
}
|
}
|
||||||
private void readUnexpectedNonSpecBlock(BlockReader reader, HeaderBlock headerBlock) throws IOException{
|
private void readUnexpectedNonSpecBlock(BlockReader reader, HeaderBlock headerBlock) throws IOException{
|
||||||
throw new IOException("Unexpected block: "+headerBlock.toString()+", Should be: "+ChunkType.SPEC);
|
throw new IOException("Unexpected block: "+headerBlock.toString()+", Should be: "+ChunkType.SPEC);
|
||||||
|
@ -15,8 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package com.reandroid.arsc.io;
|
package com.reandroid.arsc.io;
|
||||||
|
|
||||||
import com.reandroid.arsc.header.HeaderBlock;
|
|
||||||
import com.reandroid.arsc.header.InfoHeader;
|
import com.reandroid.arsc.header.InfoHeader;
|
||||||
|
import com.reandroid.arsc.header.SpecHeader;
|
||||||
|
import com.reandroid.arsc.header.TypeHeader;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
|
|
||||||
@ -56,6 +57,26 @@ import java.io.*;
|
|||||||
readFully(bts);
|
readFully(bts);
|
||||||
seek(pos);
|
seek(pos);
|
||||||
return toShort(bts, 0);
|
return toShort(bts, 0);
|
||||||
|
}
|
||||||
|
public SpecHeader readSpecHeader() throws IOException{
|
||||||
|
SpecHeader specHeader = new SpecHeader();
|
||||||
|
if(available() < specHeader.countBytes()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int pos = getPosition();
|
||||||
|
specHeader.readBytes(this);
|
||||||
|
seek(pos);
|
||||||
|
return specHeader;
|
||||||
|
}
|
||||||
|
public TypeHeader readTypeHeader() throws IOException{
|
||||||
|
TypeHeader typeHeader = new TypeHeader();
|
||||||
|
if(available() < typeHeader.countBytes()){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
int pos = getPosition();
|
||||||
|
typeHeader.readBytes(this);
|
||||||
|
seek(pos);
|
||||||
|
return typeHeader;
|
||||||
}
|
}
|
||||||
public InfoHeader readHeaderBlock() throws IOException {
|
public InfoHeader readHeaderBlock() throws IOException {
|
||||||
InfoHeader infoHeader = new InfoHeader();
|
InfoHeader infoHeader = new InfoHeader();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user