mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 14:24:25 +02:00
Parse StagedAlias block & fix -ve typeId
This commit is contained in:
parent
94b66c9efc
commit
2cb28532bf
@ -45,12 +45,15 @@ abstract class BaseTypeBlock extends BaseChunk {
|
||||
public byte getTypeId(){
|
||||
return mTypeId.get();
|
||||
}
|
||||
public int getTypeIdInt(){
|
||||
return (0xff & mTypeId.get());
|
||||
}
|
||||
public void setTypeId(byte id){
|
||||
mTypeId.set(id);
|
||||
}
|
||||
public void setTypeName(String name){
|
||||
TypeStringPool typeStringPool=getTypeStringPool();
|
||||
byte id=getTypeId();
|
||||
int id=getTypeIdInt();
|
||||
TypeString typeString=typeStringPool.getById(id);
|
||||
if(typeString==null){
|
||||
typeString=typeStringPool.getOrCreate(id, name);
|
||||
@ -96,7 +99,7 @@ abstract class BaseTypeBlock extends BaseChunk {
|
||||
return null;
|
||||
}
|
||||
TypeStringPool typeStringPool=packageBlock.getTypeStringPool();
|
||||
mTypeString=typeStringPool.getById(getTypeId());
|
||||
mTypeString=typeStringPool.getById(getTypeIdInt());
|
||||
return mTypeString;
|
||||
}
|
||||
SpecTypePair getSpecTypePair(){
|
||||
|
@ -57,6 +57,7 @@ public class PackageBlock extends BaseChunk
|
||||
|
||||
private final SpecTypePairArray mSpecTypePairArray;
|
||||
private final LibraryBlock mLibraryBlock;
|
||||
private final StagedAlias mStagedAlias;
|
||||
|
||||
private final PackageLastBlocks mPackageLastBlocks;
|
||||
|
||||
@ -82,7 +83,11 @@ public class PackageBlock extends BaseChunk
|
||||
|
||||
this.mSpecTypePairArray=new SpecTypePairArray();
|
||||
this.mLibraryBlock=new LibraryBlock();
|
||||
this.mPackageLastBlocks=new PackageLastBlocks(mSpecTypePairArray, mLibraryBlock);
|
||||
this.mStagedAlias=new StagedAlias();
|
||||
this.mPackageLastBlocks = new PackageLastBlocks(
|
||||
mSpecTypePairArray,
|
||||
mLibraryBlock,
|
||||
mStagedAlias);
|
||||
|
||||
this.mEntriesGroup=new HashMap<>();
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class SpecBlock extends BaseTypeBlock implements BlockLoad , JSONConvert<
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("id", getTypeId());
|
||||
jsonObject.put("id", getTypeIdInt());
|
||||
return jsonObject;
|
||||
}
|
||||
|
||||
|
@ -151,7 +151,7 @@ public class TypeBlock extends BaseTypeBlock
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("id", getTypeId());
|
||||
jsonObject.put("id", getTypeIdInt());
|
||||
TypeString typeString=getTypeString();
|
||||
if(typeString!=null){
|
||||
jsonObject.put("name", typeString.get());
|
||||
@ -183,8 +183,8 @@ public class TypeBlock extends BaseTypeBlock
|
||||
}
|
||||
@Override
|
||||
public int compareTo(TypeBlock typeBlock) {
|
||||
int id1=getTypeId();
|
||||
int id2=typeBlock.getTypeId();
|
||||
int id1=getTypeIdInt();
|
||||
int id2=typeBlock.getTypeIdInt();
|
||||
if(id1!=id2){
|
||||
return Integer.compare(id1, id2);
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ package com.reandroid.lib.arsc.container;
|
||||
import com.reandroid.lib.arsc.chunk.ChunkType;
|
||||
import com.reandroid.lib.arsc.array.SpecTypePairArray;
|
||||
import com.reandroid.lib.arsc.chunk.LibraryBlock;
|
||||
import com.reandroid.lib.arsc.chunk.StagedAlias;
|
||||
import com.reandroid.lib.arsc.header.HeaderBlock;
|
||||
import com.reandroid.lib.arsc.io.BlockReader;
|
||||
|
||||
@ -27,12 +28,17 @@ public class PackageLastBlocks extends FixedBlockContainer {
|
||||
|
||||
private final SpecTypePairArray mSpecTypePairArray;
|
||||
private final LibraryBlock mLibraryBlock;
|
||||
public PackageLastBlocks(SpecTypePairArray specTypePairArray, LibraryBlock libraryBlock){
|
||||
super(2);
|
||||
private final StagedAlias mStagedAlias;
|
||||
public PackageLastBlocks(SpecTypePairArray specTypePairArray,
|
||||
LibraryBlock libraryBlock,
|
||||
StagedAlias stagedAlias){
|
||||
super(3);
|
||||
this.mSpecTypePairArray=specTypePairArray;
|
||||
this.mLibraryBlock=libraryBlock;
|
||||
this.mStagedAlias=stagedAlias;
|
||||
addChild(0, mSpecTypePairArray);
|
||||
addChild(1, mLibraryBlock);
|
||||
addChild(2, mStagedAlias);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -53,6 +59,8 @@ public class PackageLastBlocks extends FixedBlockContainer {
|
||||
readSpecBlock(reader);
|
||||
}else if(chunkType==ChunkType.LIBRARY){
|
||||
readLibraryBlock(reader);
|
||||
}else if(chunkType==ChunkType.STAGED_ALIAS){
|
||||
readStagedAlias(reader);
|
||||
}else {
|
||||
readUnexpectedBlock(reader, headerBlock);
|
||||
}
|
||||
@ -67,6 +75,11 @@ public class PackageLastBlocks extends FixedBlockContainer {
|
||||
libraryBlock.readBytes(reader);
|
||||
mLibraryBlock.addLibraryInfo(libraryBlock);
|
||||
}
|
||||
private void readStagedAlias(BlockReader reader) throws IOException{
|
||||
StagedAlias stagedAlias = new StagedAlias();
|
||||
stagedAlias.readBytes(reader);
|
||||
mStagedAlias.addStagedAliasEntries(stagedAlias);
|
||||
}
|
||||
private void readUnexpectedBlock(BlockReader reader, HeaderBlock headerBlock) throws IOException{
|
||||
throw new IOException(reader.getActualPosition()+", Unexpected block: "+headerBlock.toString());
|
||||
}
|
||||
|
@ -180,7 +180,7 @@ public class SpecTypePair extends BlockContainer<Block>
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
JSONObject jsonObject=new JSONObject();
|
||||
jsonObject.put("id", getSpecBlock().getTypeId());
|
||||
jsonObject.put("id", getSpecBlock().getTypeIdInt());
|
||||
jsonObject.put("types", getTypeBlockArray().toJson());
|
||||
return jsonObject;
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ public class EntryBlock extends Block implements JSONConvert<JSONObject> {
|
||||
return 0;
|
||||
}
|
||||
int pkgId=packageBlock.getId();
|
||||
int typeId=typeBlock.getTypeId();
|
||||
int typeId=typeBlock.getTypeIdInt();
|
||||
int entryId=getIndex();
|
||||
return ((pkgId << 24) | (typeId << 16) | entryId);
|
||||
}
|
||||
|
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.reandroid.lib.arsc.value;
|
||||
|
||||
import com.reandroid.lib.arsc.array.LibraryInfoArray;
|
||||
import com.reandroid.lib.arsc.base.Block;
|
||||
import com.reandroid.lib.arsc.base.BlockCounter;
|
||||
import com.reandroid.lib.arsc.io.BlockReader;
|
||||
|
Loading…
x
Reference in New Issue
Block a user