avoid literal type name usage for entry bag detection

This commit is contained in:
REAndroid 2023-01-14 11:01:31 -05:00
parent c39d3d8ad5
commit 0c8762bc64
4 changed files with 29 additions and 35 deletions

View File

@ -17,7 +17,7 @@ package com.reandroid.lib.arsc.value.array;
import com.reandroid.lib.arsc.value.EntryBlock; import com.reandroid.lib.arsc.value.EntryBlock;
import com.reandroid.lib.arsc.value.ResValueBag; import com.reandroid.lib.arsc.value.ResValueBag;
import com.reandroid.lib.arsc.value.attribute.AttributeBag; import com.reandroid.lib.arsc.value.ResValueBagItem;
public class ArrayBag { public class ArrayBag {
private final ArrayBagItem[] mBagItems; private final ArrayBagItem[] mBagItems;
@ -61,8 +61,8 @@ public class ArrayBag {
return builder.toString(); return builder.toString();
} }
/** TODO: find another method to check instead of checking type name (plurals), /** The result of this is not always 100% accurate,
* just like {@link AttributeBag} **/ * in addition to this use your methods to cross check like type-name == "array"**/
public static boolean isArray(ResValueBag resValueBag){ public static boolean isArray(ResValueBag resValueBag){
if(resValueBag==null){ if(resValueBag==null){
return false; return false;
@ -71,14 +71,24 @@ public class ArrayBag {
if(entryBlock==null){ if(entryBlock==null){
return false; return false;
} }
String type = entryBlock.getTypeName(); if(resValueBag.getParentId()!=0){
if(type==null){
return false; return false;
} }
if(!type.startsWith(NAME)){ ArrayBagItem[] arrayBagItems = ArrayBagItem.create(resValueBag.getBagItems());
if(arrayBagItems==null || arrayBagItems.length==0){
return false; return false;
} }
return ArrayBagItem.create(resValueBag.getBagItems()) != null; for(int i=0;i< arrayBagItems.length; i++){
ArrayBagItem arrayBagItem = arrayBagItems[i];
ResValueBagItem resValueBagItem = arrayBagItem.getBagItem();
if(resValueBagItem.getIdHigh()!=0x0100){
return false;
}
if(resValueBagItem.getIdLow() != (i+1)){
return false;
}
}
return true;
} }
public static ArrayBag create(ResValueBag resValueBag){ public static ArrayBag create(ResValueBag resValueBag){
@ -91,5 +101,4 @@ public class ArrayBag {
} }
return new ArrayBag(bagItems); return new ArrayBag(bagItems);
} }
public static final String NAME="array";
} }

View File

@ -17,7 +17,6 @@ package com.reandroid.lib.arsc.value.plurals;
import com.reandroid.lib.arsc.value.EntryBlock; import com.reandroid.lib.arsc.value.EntryBlock;
import com.reandroid.lib.arsc.value.ResValueBag; import com.reandroid.lib.arsc.value.ResValueBag;
import com.reandroid.lib.arsc.value.attribute.AttributeBag;
public class PluralsBag { public class PluralsBag {
private final PluralsBagItem[] mBagItems; private final PluralsBagItem[] mBagItems;
@ -62,8 +61,8 @@ public class PluralsBag {
return builder.toString(); return builder.toString();
} }
/** TODO: find another method to check instead of checking type name (plurals), /** The result of this is not always 100% accurate,
* just like {@link AttributeBag} **/ * in addition to this use your methods to cross check like type-name == "plurals"**/
public static boolean isPlurals(ResValueBag resValueBag){ public static boolean isPlurals(ResValueBag resValueBag){
if(resValueBag==null){ if(resValueBag==null){
return false; return false;
@ -72,13 +71,6 @@ public class PluralsBag {
if(entryBlock==null){ if(entryBlock==null){
return false; return false;
} }
String type = entryBlock.getTypeName();
if(type==null){
return false;
}
if(!type.startsWith(NAME)){
return false;
}
return PluralsBagItem.create(resValueBag.getBagItems()) != null; return PluralsBagItem.create(resValueBag.getBagItems()) != null;
} }
@ -92,5 +84,4 @@ public class PluralsBag {
} }
return new PluralsBag(bagItems); return new PluralsBag(bagItems);
} }
public static final String NAME="plurals";
} }

View File

@ -107,7 +107,11 @@ public class PluralsBagItem {
Set<PluralsQuantity> duplicates=new HashSet<>(); Set<PluralsQuantity> duplicates=new HashSet<>();
List<PluralsBagItem> results=new ArrayList<>(); List<PluralsBagItem> results=new ArrayList<>();
for(int i=0;i<len;i++){ for(int i=0;i<len;i++){
PluralsBagItem item=create(resValueBagItems[i]); ResValueBagItem resValueBagItem = resValueBagItems[i];
if(resValueBagItem.getIdHigh() != 0x0100){
return null;
}
PluralsBagItem item=create(resValueBagItem);
if(item==null){ if(item==null){
// If it reaches here type name is obfuscated // If it reaches here type name is obfuscated
return null; return null;

View File

@ -19,8 +19,6 @@ import com.reandroid.lib.arsc.item.SpecString;
import com.reandroid.lib.arsc.item.TypeString; import com.reandroid.lib.arsc.item.TypeString;
import com.reandroid.lib.arsc.value.EntryBlock; import com.reandroid.lib.arsc.value.EntryBlock;
import com.reandroid.lib.arsc.value.ResValueBag; import com.reandroid.lib.arsc.value.ResValueBag;
import com.reandroid.lib.arsc.value.array.ArrayBagItem;
import com.reandroid.lib.arsc.value.attribute.AttributeBag;
public class StyleBag { public class StyleBag {
private final StyleBagItem[] mBagItems; private final StyleBagItem[] mBagItems;
@ -107,8 +105,8 @@ public class StyleBag {
return builder.toString(); return builder.toString();
} }
/** TODO: find another method to check instead of checking type name (plurals), /** The result of this is not always 100% accurate,
* just like {@link AttributeBag} **/ * in addition to this use your methods to cross check like type-name == "plurals"**/
public static boolean isStyle(ResValueBag resValueBag){ public static boolean isStyle(ResValueBag resValueBag){
if(resValueBag==null){ if(resValueBag==null){
return false; return false;
@ -117,14 +115,7 @@ public class StyleBag {
if(entryBlock==null){ if(entryBlock==null){
return false; return false;
} }
String type = entryBlock.getTypeName(); return StyleBag.create(resValueBag) != null;
if(type==null){
return false;
}
if(!type.startsWith(NAME)){
return false;
}
return ArrayBagItem.create(resValueBag.getBagItems()) != null;
} }
public static StyleBag create(ResValueBag resValueBag){ public static StyleBag create(ResValueBag resValueBag){
@ -137,5 +128,4 @@ public class StyleBag {
} }
return new StyleBag(bagItems); return new StyleBag(bagItems);
} }
public static final String NAME="style";
} }