fix package id to unsigned byte

This commit is contained in:
REAndroid 2022-12-30 05:58:34 -05:00
parent c2a9ebd7e9
commit 4f715d04ab
6 changed files with 33 additions and 25 deletions

View File

@ -31,9 +31,9 @@ import java.io.IOException;
import java.util.*;
public class StringPoolBuilder {
private final Map<Byte, Set<String>> mSpecNameMap;
private final Map<Integer, Set<String>> mSpecNameMap;
private final Set<String> mTableStrings;
private byte mCurrentPackageId;
private int mCurrentPackageId;
private JSONArray mStyledStrings;
public StringPoolBuilder(){
this.mSpecNameMap = new HashMap<>();
@ -41,7 +41,7 @@ public class StringPoolBuilder {
}
public void apply(TableBlock tableBlock){
applyTableString(tableBlock.getTableStringPool());
for(byte pkgId:mSpecNameMap.keySet()){
for(int pkgId:mSpecNameMap.keySet()){
PackageBlock packageBlock=tableBlock.getPackageArray().getOrCreate(pkgId);
applySpecString(packageBlock.getSpecStringPool());
}
@ -52,7 +52,7 @@ public class StringPoolBuilder {
stringPool.refresh();
}
private void applySpecString(SpecStringPool stringPool){
byte pkgId= (byte) stringPool.getPackageBlock().getId();
int pkgId = stringPool.getPackageBlock().getId();
stringPool.addStrings(getSpecString(pkgId));
stringPool.refresh();
}
@ -86,7 +86,7 @@ public class StringPoolBuilder {
public Set<String> getTableString(){
return mTableStrings;
}
public Set<String> getSpecString(byte pkgId){
public Set<String> getSpecString(int pkgId){
return mSpecNameMap.get(pkgId);
}
private void scan(JSONObject jsonObject){
@ -100,7 +100,7 @@ public class StringPoolBuilder {
}
return;
}else if(jsonObject.has(PackageBlock.NAME_package_id)){
mCurrentPackageId= (byte) jsonObject.getInt(PackageBlock.NAME_package_id);
mCurrentPackageId = jsonObject.getInt(PackageBlock.NAME_package_id);
}
Set<String> keyList = jsonObject.keySet();
for(String key:keyList){
@ -143,7 +143,7 @@ public class StringPoolBuilder {
if(name==null){
return;
}
byte pkgId=mCurrentPackageId;
int pkgId=mCurrentPackageId;
if(pkgId==0){
throw new IllegalArgumentException("Current package id is 0");
}

View File

@ -58,10 +58,9 @@ public class TableBlockJsonBuilder {
}
FileInputStream inputStream=new FileInputStream(pkgFile);
JSONObject jsonObject=new JSONObject(inputStream);
int id = jsonObject.getInt(PackageBlock.NAME_package_id);
String name=jsonObject.optString(PackageBlock.NAME_package_name);
PackageBlock pkg=tableBlock.getPackageArray().getOrCreate((byte) id);
pkg.setName(name);
PackageBlock pkg=tableBlock.getPackageArray()
.getOrCreate(jsonObject.getInt(PackageBlock.NAME_package_id));
pkg.setName(jsonObject.optString(PackageBlock.NAME_package_name));
if(jsonObject.has(PackageBlock.NAME_staged_aliases)){
JSONArray stagedJson = jsonObject.getJSONArray(PackageBlock.NAME_staged_aliases);
StagedAlias stagedAlias = new StagedAlias();
@ -78,11 +77,12 @@ public class TableBlockJsonBuilder {
private void loadType(PackageBlock packageBlock, File typeJsonFile) throws IOException{
FileInputStream inputStream=new FileInputStream(typeJsonFile);
JSONObject jsonObject=new JSONObject(inputStream);
int id= jsonObject.getInt("id");
// TODO: change json names to use from static field
JSONObject configObj=jsonObject.getJSONObject("config");
ResConfig resConfig=new ResConfig();
resConfig.fromJson(configObj);
TypeBlock typeBlock=packageBlock.getSpecTypePairArray().getOrCreate((byte) id, resConfig);
TypeBlock typeBlock=packageBlock.getSpecTypePairArray()
.getOrCreate(((byte)(0xff & jsonObject.getInt("id"))), resConfig);
typeBlock.fromJson(jsonObject);
}
}

View File

@ -43,6 +43,9 @@ public class PackageArray extends BlockArray<PackageBlock>
sort(this);
}
public PackageBlock getOrCreate(byte pkgId){
return getOrCreate(0xff & pkgId);
}
public PackageBlock getOrCreate(int pkgId){
PackageBlock packageBlock=getPackageBlockById(pkgId);
if(packageBlock!=null){
return packageBlock;
@ -53,6 +56,9 @@ public class PackageArray extends BlockArray<PackageBlock>
return packageBlock;
}
public PackageBlock getPackageBlockById(byte pkgId){
return getPackageBlockById(0xff & pkgId);
}
public PackageBlock getPackageBlockById(int pkgId){
Iterator<PackageBlock> itr=iterator(true);
while (itr.hasNext()){
PackageBlock packageBlock=itr.next();

View File

@ -156,6 +156,9 @@ package com.reandroid.lib.arsc.chunk;
public int getId(){
return mPackageId.get();
}
public void setId(byte id){
setId(0xff & id);
}
public void setId(int id){
mPackageId.set(id);
}

View File

@ -54,7 +54,7 @@ public class TableBlock extends BaseChunk implements JSONConvert<JSONObject> {
public TableStringPool getTableStringPool(){
return mTableStringPool;
}
public PackageBlock getPackageBlockById(byte pkgId){
public PackageBlock getPackageBlockById(int pkgId){
return getPackageArray().getPackageBlockById(pkgId);
}
public PackageArray getPackageArray(){
@ -112,7 +112,7 @@ public class TableBlock extends BaseChunk implements JSONConvert<JSONObject> {
}
int pkgId=resourceId>>24;
pkgId=pkgId&0xff;
PackageBlock packageBlock=getPackageBlockById((byte) pkgId);
PackageBlock packageBlock=getPackageBlockById(pkgId);
if(packageBlock!=null){
EntryGroup entryGroup=packageBlock.getEntryGroup(resourceId);
if(entryGroup!=null){

View File

@ -24,7 +24,7 @@ import com.reandroid.lib.arsc.value.EntryBlock;
import java.util.*;
public class TableEntryStore implements EntryStore{
private final Map<Byte, Set<PackageBlock>> mPackagesMap;
private final Map<Integer, Set<PackageBlock>> mPackagesMap;
public TableEntryStore(){
this.mPackagesMap = new HashMap<>();
}
@ -58,15 +58,14 @@ public class TableEntryStore implements EntryStore{
if(packageBlock==null){
return;
}
byte pkgId= (byte) packageBlock.getId();
Set<PackageBlock> packageBlockSet=getOrCreate(pkgId);
Set<PackageBlock> packageBlockSet=getOrCreate(packageBlock.getId());
if(packageBlockSet.contains(packageBlock)){
return;
}
packageBlockSet.add(packageBlock);
}
private Set<PackageBlock> getOrCreate(byte packageId){
Byte id=packageId;
private Set<PackageBlock> getOrCreate(int packageId){
Integer id=packageId;
Set<PackageBlock> packageBlockSet=mPackagesMap.get(id);
if(packageBlockSet==null){
packageBlockSet=new HashSet<>();
@ -78,7 +77,7 @@ public class TableEntryStore implements EntryStore{
public EntryGroup searchEntryGroup(String packageName, String type, String name) {
return null;
}
private Set<TableBlock> getTableBlocks(byte packageId) {
private Set<TableBlock> getTableBlocks(int packageId) {
Set<TableBlock> results=new HashSet<>();
Set<PackageBlock> packageBlockSet = mPackagesMap.get(packageId);
if(packageBlockSet!=null){
@ -92,7 +91,7 @@ public class TableEntryStore implements EntryStore{
@Override
public List<EntryGroup> getEntryGroups(int resourceId) {
List<EntryGroup> results=new ArrayList<>();
byte pkgId= (byte) ((resourceId>>24)&0xff);
int pkgId = (resourceId>>24)&0xff;
Set<PackageBlock> packageBlockSet = mPackagesMap.get(pkgId);
if(packageBlockSet==null){
return results;
@ -107,7 +106,7 @@ public class TableEntryStore implements EntryStore{
}
@Override
public EntryGroup getEntryGroup(int resourceId) {
byte pkgId= (byte) ((resourceId>>24)&0xff);
int pkgId = (resourceId>>24)&0xff;
Set<PackageBlock> packageBlockSet = mPackagesMap.get(pkgId);
if(packageBlockSet==null){
return null;
@ -123,7 +122,7 @@ public class TableEntryStore implements EntryStore{
@Override
public List<PackageBlock> getPackageBlocks(byte packageId) {
List<PackageBlock> results=new ArrayList<>();
Set<PackageBlock> packageBlockSet = mPackagesMap.get(packageId);
Set<PackageBlock> packageBlockSet = mPackagesMap.get(0xff & packageId);
if(packageBlockSet!=null){
results.addAll(packageBlockSet);
}
@ -132,7 +131,7 @@ public class TableEntryStore implements EntryStore{
@Override
public List<TableString> getTableStrings(byte packageId, int stringReference) {
List<TableString> results=new ArrayList<>();
Set<TableBlock> tableBlockSet=getTableBlocks(packageId);
Set<TableBlock> tableBlockSet=getTableBlocks(0xff & packageId);
for(TableBlock tableBlock:tableBlockSet){
TableString tableString=tableBlock.getTableStringPool().get(stringReference);
if(tableString!=null){