This commit is contained in:
REAndroid 2022-12-21 06:32:17 -05:00
parent fc22b9531d
commit 6aeaf09656
14 changed files with 99 additions and 203 deletions

View File

@ -22,10 +22,11 @@ repositories {
} }
dependencies { dependencies {
//No dependency
} }
processResources { processResources {
filesMatching('lib.properties') { filesMatching('arsclib.properties') {
expand('version': version) expand('version': version)
} }
} }

View File

@ -654,9 +654,9 @@ public class ResourceIds {
String name=null; String name=null;
Matcher matcher=pattern.matcher(element); Matcher matcher=pattern.matcher(element);
while (matcher.find()){ while (matcher.find()){
String attr=matcher.group("Attr").toLowerCase(); String attr=matcher.group(1).toLowerCase();
String value=matcher.group("Value"); String value=matcher.group(2);
element=matcher.group("Next"); element=matcher.group(3);
if(attr.equals("id")){ if(attr.equals("id")){
id=Integer.decode(value); id=Integer.decode(value);
}else if(attr.equals("name")){ }else if(attr.equals("name")){
@ -674,7 +674,7 @@ public class ResourceIds {
} }
return new Entry(id, type, name); return new Entry(id, type, name);
} }
private static final Pattern PATTERN=Pattern.compile("^\\s*(?<Attr>[^\\s=\"]+)\\s*=\\s*\"(?<Value>[^\"]+)\"(?<Next>.*)$"); private static final Pattern PATTERN=Pattern.compile("^\\s*([^\\s=\"]+)\\s*=\\s*\"([^\"]+)\"(.*)$");
} }
} }

View File

@ -45,7 +45,7 @@ public class BuildInfo {
return sProperties; return sProperties;
} }
private static Properties loadProperties(){ private static Properties loadProperties(){
InputStream inputStream=BuildInfo.class.getResourceAsStream("/lib.properties"); InputStream inputStream=BuildInfo.class.getResourceAsStream("/arsclib.properties");
Properties properties=new Properties(); Properties properties=new Properties();
try{ try{
properties.load(inputStream); properties.load(inputStream);

View File

@ -43,15 +43,6 @@ public abstract class BlockItem extends Block {
mBytes=bts; mBytes=bts;
onBytesChanged(); onBytesChanged();
} }
final void ensureMinLength(int minLen){
int len=mBytes.length;
if(minLen<=len){
return;
}
byte[] bts=new byte[minLen];
System.arraycopy(bts, 0, mBytes, 0, mBytes.length);
mBytes=bts;
}
final void setBytesLength(int length){ final void setBytesLength(int length){
setBytesLength(length, true); setBytesLength(length, true);
} }
@ -104,8 +95,7 @@ public abstract class BlockItem extends Block {
} }
@Override @Override
public void onReadBytes(BlockReader reader) throws IOException{ public void onReadBytes(BlockReader reader) throws IOException{
byte[] bts=getBytesInternal(); reader.readFully(getBytesInternal());
reader.readFully(bts);
onBytesChanged(); onBytesChanged();
} }
@Override @Override

View File

@ -15,8 +15,6 @@
*/ */
package com.reandroid.lib.arsc.value; package com.reandroid.lib.arsc.value;
import java.util.*; import java.util.*;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -427,6 +425,9 @@ public class ResConfigHelper {
} }
return ret.toString(); return ret.toString();
} }
/*
* Encodes density to value
* densityName is full name like: mdpi, xxxdpi, 580dpi ... */
public static short encodeDensity(String densityName){ public static short encodeDensity(String densityName){
short density=0; short density=0;
if(densityName==null){ if(densityName==null){
@ -436,29 +437,31 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
return density; return density;
} }
String d=matcher.group("A"); return encodeDensityName(matcher.group(1));
if("l".equals(d)){ }
density = DENSITY_LOW; private static short encodeDensityName(String name){
}else if("m".equals(d)){ if("l".equals(name)){
density = DENSITY_MEDIUM; return DENSITY_LOW;
}else if("h".equals(d)){ }else if("m".equals(name)){
density = DENSITY_HIGH; return DENSITY_MEDIUM;
}else if("tv".equals(d)){ }else if("h".equals(name)){
density = DENSITY_TV; return DENSITY_HIGH;
}else if("xh".equals(d)){ }else if("tv".equals(name)){
density = DENSITY_XHIGH; return DENSITY_TV;
}else if("xxh".equals(d)){ }else if("xh".equals(name)){
density = DENSITY_XXHIGH; return DENSITY_XHIGH;
}else if("xxxh".equals(d)){ }else if("xxh".equals(name)){
density = DENSITY_XXXHIGH; return DENSITY_XXHIGH;
}else if("any".equals(d)){ }else if("xxxh".equals(name)){
density = DENSITY_ANY; return DENSITY_XXXHIGH;
}else if("no".equals(d)){ }else if("any".equals(name)){
density = DENSITY_NONE; return DENSITY_ANY;
}else if(isDecimal(d)){ }else if("no".equals(name)){
density = (short) Integer.parseInt(d); return DENSITY_NONE;
}else if(isDecimal(name)){
return (short) Integer.parseInt(name);
} }
return density; return 0;
} }
private static void encodeDensity(ResConfig resConfig, String[] split){ private static void encodeDensity(ResConfig resConfig, String[] split){
int density=0; int density=0;
@ -471,28 +474,8 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
String d=matcher.group("A"); density=encodeDensityName(matcher.group(1));
if("l".equals(d)){ if(density==0){
density = DENSITY_LOW;
}else if("m".equals(d)){
density = DENSITY_MEDIUM;
}else if("h".equals(d)){
density = DENSITY_HIGH;
}else if("tv".equals(d)){
density = DENSITY_TV;
}else if("xh".equals(d)){
density = DENSITY_XHIGH;
}else if("xxh".equals(d)){
density = DENSITY_XXHIGH;
}else if("xxxh".equals(d)){
density = DENSITY_XXXHIGH;
}else if("any".equals(d)){
density = DENSITY_ANY;
}else if("no".equals(d)){
density = DENSITY_NONE;
}else if(isDecimal(d)){
density = Integer.parseInt(d);
}else {
continue; continue;
} }
split[i]=null; split[i]=null;
@ -840,50 +823,28 @@ public class ResConfigHelper {
return ret.toString(); return ret.toString();
} }
private static void encodeOrientation(ResConfig resConfig, String[] split){ private static void encodeOrientation(ResConfig resConfig, String[] split){
byte orientation=0; byte orientationByte=0;
for(int i=0;i<split.length;i++){ for(int i=0;i<split.length;i++){
String s=split[i]; String s=split[i];
if(s==null){ if(s==null){
continue; continue;
} }
if("port".equals(s)){ ResConfig.Orientation orientation= ResConfig.Orientation.fromName(s);
orientation = ORIENTATION_PORT; if(orientation==null){
}else if("land".equals(s)){
orientation = ORIENTATION_LAND;
}else {
continue; continue;
} }
orientationByte=orientation.getByteValue();
split[i]=null; split[i]=null;
break; break;
} }
resConfig.setOrientation(orientation); resConfig.setOrientation(orientationByte);
} }
private static String decodeOrientation(ResConfig resConfig){ private static String decodeOrientation(ResConfig resConfig){
StringBuilder ret=new StringBuilder(); ResConfig.Orientation orientation=resConfig.getOrientation();
byte orientation=resConfig.getOrientationByte(); if(orientation==null){
switch (orientation) { return null;
case ORIENTATION_PORT:
ret.append("-port");
break;
case ORIENTATION_LAND:
ret.append("-land");
break;
case ORIENTATION_SQUARE:
ret.append("-square");
break;
} }
return ret.toString(); return "-"+orientation.toString();
}
public static String decodeOrientation(byte orientation){
switch (orientation) {
case ORIENTATION_PORT:
return "port";
case ORIENTATION_LAND:
return "land";
case ORIENTATION_SQUARE:
return "square";
}
return null;
} }
private static void encodeScreenLayout(ResConfig resConfig, String[] split){ private static void encodeScreenLayout(ResConfig resConfig, String[] split){
int screenLayout=0; int screenLayout=0;
@ -1085,8 +1046,8 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
String mccMnc=matcher.group("A"); String mccMnc=matcher.group(1);
int val=Integer.parseInt(matcher.group("B")); int val=Integer.parseInt(matcher.group(2));
if(val==0){ if(val==0){
val=-1; val=-1;
} }
@ -1110,8 +1071,8 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
String mccMnc=matcher.group("A"); String mccMnc=matcher.group(1);
int val=Integer.parseInt(matcher.group("B")); int val=Integer.parseInt(matcher.group(2));
sh=(short)val; sh=(short)val;
if(!"mnc".equals(mccMnc)){ if(!"mnc".equals(mccMnc)){
continue; continue;
@ -1162,11 +1123,7 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
String pre=matcher.group("A"); val=Integer.parseInt(matcher.group(1));
if(!pre.equals("sw")){
continue;
}
val=Integer.parseInt(matcher.group("B"));
split[i]=null; split[i]=null;
break; break;
} }
@ -1193,11 +1150,11 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
String pre=matcher.group("A"); String pre=matcher.group(1);
if(!pre.equals("h")){ if(!pre.equals("h")){
continue; continue;
} }
val=Integer.parseInt(matcher.group("B")); val=Integer.parseInt(matcher.group(2));
split[i]=null; split[i]=null;
break; break;
} }
@ -1224,11 +1181,11 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
String pre=matcher.group("A"); String pre=matcher.group(1);
if(!pre.equals("w")){ if(!pre.equals("w")){
continue; continue;
} }
val=Integer.parseInt(matcher.group("B")); val=Integer.parseInt(matcher.group(2));
split[i]=null; split[i]=null;
break; break;
} }
@ -1255,7 +1212,7 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
val=Integer.parseInt(matcher.group("A")); val=Integer.parseInt(matcher.group(1));
split[i]=null; split[i]=null;
break; break;
} }
@ -1292,8 +1249,8 @@ public class ResConfigHelper {
if(!matcher.find()){ if(!matcher.find()){
continue; continue;
} }
int a=Integer.parseInt(matcher.group("A")); int a=Integer.parseInt(matcher.group(1));
int b=Integer.parseInt(matcher.group("B")); int b=Integer.parseInt(matcher.group(2));
short w; short w;
short h; short h;
if(a>b){ if(a>b){
@ -1359,23 +1316,23 @@ public class ResConfigHelper {
return matcher.find(); return matcher.find();
} }
private static final Pattern PATTERN_SDK_VERSION=Pattern.compile("^-?v(?<A>[0-9]+)$"); private static final Pattern PATTERN_SDK_VERSION=Pattern.compile("^-?v([0-9]+)$");
private static final Pattern PATTERN_SCREEN_DP=Pattern.compile("^(?<A>[wh])(?<B>[0-9]+)dp$"); private static final Pattern PATTERN_SCREEN_DP=Pattern.compile("^([wh])([0-9]+)dp$");
private static final Pattern PATTERN_SCREEN_SMALLEST_DP=Pattern.compile("^(?<A>(sw)|(sh))(?<B>[0-9]+)dp$"); private static final Pattern PATTERN_SCREEN_SMALLEST_DP=Pattern.compile("^sw([0-9]+)dp$");
private static final Pattern PATTERN_LANG_NAME=Pattern.compile("^[a-z]{2}$"); private static final Pattern PATTERN_LANG_NAME=Pattern.compile("^[a-z]{2}$");
private static final Pattern PATTERN_COUNTRY_NAME=Pattern.compile("^[a-zA-Z]{2,3}$"); private static final Pattern PATTERN_COUNTRY_NAME=Pattern.compile("^[a-zA-Z]{2,3}$");
private static final Pattern PATTERN_MCC_MNC=Pattern.compile("^(?<A>m[cn]c)(?<B>[0-9]{2,3})$"); private static final Pattern PATTERN_MCC_MNC=Pattern.compile("^(m[cn]c)([0-9]{2,3})$");
private static final Pattern PATTERN_DENSITY=Pattern.compile("^(?<A>[^\\s]+)dpi$"); private static final Pattern PATTERN_DENSITY=Pattern.compile("^([^\\s]+)dpi$");
private static final Pattern PATTERN_NUMBER=Pattern.compile("^[0-9]+$"); private static final Pattern PATTERN_NUMBER=Pattern.compile("^[0-9]+$");
private static final Pattern PATTERN_SCREEN_SIZE=Pattern.compile("^-?(?<A>[0-9]+)x(?<B>[0-9]+)$"); private static final Pattern PATTERN_SCREEN_SIZE=Pattern.compile("^-?([0-9]+)x([0-9]+)$");
public final static short MASK_LAYOUTDIR = 0xc0; public final static short MASK_LAYOUTDIR = 0xc0;
@ -1404,11 +1361,6 @@ public class ResConfigHelper {
public final static short SCREENLAYOUT_ROUND_YES = 0x2; public final static short SCREENLAYOUT_ROUND_YES = 0x2;
public final static byte ORIENTATION_ANY = 0;
public final static byte ORIENTATION_PORT = 1;
public final static byte ORIENTATION_LAND = 2;
public final static byte ORIENTATION_SQUARE = 3;
public final static byte MASK_UI_MODE_TYPE = 0x0f; public final static byte MASK_UI_MODE_TYPE = 0x0f;
public final static byte UI_MODE_TYPE_ANY = 0x00; public final static byte UI_MODE_TYPE_ANY = 0x00;
public final static byte UI_MODE_TYPE_NORMAL = 0x01; public final static byte UI_MODE_TYPE_NORMAL = 0x01;

View File

@ -15,8 +15,6 @@
*/ */
package com.reandroid.lib.arsc.value.array; package com.reandroid.lib.arsc.value.array;
import com.reandroid.lib.arsc.item.SpecString;
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.attribute.AttributeBag; import com.reandroid.lib.arsc.value.attribute.AttributeBag;
@ -34,22 +32,14 @@ public class ArrayBag {
if(entryBlock==null){ if(entryBlock==null){
return null; return null;
} }
SpecString spec = entryBlock.getSpecString(); return entryBlock.getName();
if(spec==null){
return null;
}
return spec.get();
} }
public String getTypeName(){ public String getTypeName(){
EntryBlock entryBlock=getBagItems()[0].getBagItem().getEntryBlock(); EntryBlock entryBlock=getBagItems()[0].getBagItem().getEntryBlock();
if(entryBlock==null){ if(entryBlock==null){
return null; return null;
} }
TypeString typeString = entryBlock.getTypeString(); return entryBlock.getTypeName();
if(typeString==null){
return null;
}
return typeString.get();
} }
@Override @Override
public String toString() { public String toString() {
@ -81,11 +71,11 @@ public class ArrayBag {
if(entryBlock==null){ if(entryBlock==null){
return false; return false;
} }
TypeString typeString = entryBlock.getTypeString(); String type = entryBlock.getTypeName();
if(typeString==null){ if(type==null){
return false; return false;
} }
if(!NAME.equals(typeString.get())){ if(!type.startsWith(NAME)){
return false; return false;
} }
return ArrayBagItem.create(resValueBag.getBagItems()) != null; return ArrayBagItem.create(resValueBag.getBagItems()) != null;

View File

@ -45,8 +45,7 @@ public enum AttributeItemType {
return null; return null;
} }
name=name.toUpperCase(); name=name.toUpperCase();
AttributeItemType[] all=values(); for(AttributeItemType bagType:values()){
for(AttributeItemType bagType:all){
if(name.equals(bagType.name())){ if(name.equals(bagType.name())){
return bagType; return bagType;
} }

View File

@ -15,8 +15,6 @@
*/ */
package com.reandroid.lib.arsc.value.plurals; package com.reandroid.lib.arsc.value.plurals;
import com.reandroid.lib.arsc.item.SpecString;
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.attribute.AttributeBag; import com.reandroid.lib.arsc.value.attribute.AttributeBag;
@ -34,22 +32,14 @@ public class PluralsBag {
if(entryBlock==null){ if(entryBlock==null){
return null; return null;
} }
SpecString spec = entryBlock.getSpecString(); return entryBlock.getName();
if(spec==null){
return null;
}
return spec.get();
} }
public String getTypeName(){ public String getTypeName(){
EntryBlock entryBlock=getBagItems()[0].getBagItem().getEntryBlock(); EntryBlock entryBlock=getBagItems()[0].getBagItem().getEntryBlock();
if(entryBlock==null){ if(entryBlock==null){
return null; return null;
} }
TypeString typeString = entryBlock.getTypeString(); return entryBlock.getTypeName();
if(typeString==null){
return null;
}
return typeString.get();
} }
@Override @Override
@ -82,11 +72,11 @@ public class PluralsBag {
if(entryBlock==null){ if(entryBlock==null){
return false; return false;
} }
TypeString typeString = entryBlock.getTypeString(); String type = entryBlock.getTypeName();
if(typeString==null){ if(type==null){
return false; return false;
} }
if(!NAME.equals(typeString.get())){ if(!type.startsWith(NAME)){
return false; return false;
} }
return PluralsBagItem.create(resValueBag.getBagItems()) != null; return PluralsBagItem.create(resValueBag.getBagItems()) != null;

View File

@ -109,6 +109,7 @@ public class PluralsBagItem {
for(int i=0;i<len;i++){ for(int i=0;i<len;i++){
PluralsBagItem item=create(resValueBagItems[i]); PluralsBagItem item=create(resValueBagItems[i]);
if(item==null){ if(item==null){
// If it reaches here type name is obfuscated
return null; return null;
} }
PluralsQuantity quantity=item.getQuantity(); PluralsQuantity quantity=item.getQuantity();

View File

@ -117,11 +117,11 @@ public class StyleBag {
if(entryBlock==null){ if(entryBlock==null){
return false; return false;
} }
TypeString typeString = entryBlock.getTypeString(); String type = entryBlock.getTypeName();
if(typeString==null){ if(type==null){
return false; return false;
} }
if(!NAME.equals(typeString.get())){ if(!type.startsWith(NAME)){
return false; return false;
} }
return ArrayBagItem.create(resValueBag.getBagItems()) != null; return ArrayBagItem.create(resValueBag.getBagItems()) != null;

View File

@ -15,12 +15,6 @@
*/ */
package com.reandroid.lib.arsc.value.style; package com.reandroid.lib.arsc.value.style;
import com.reandroid.lib.arsc.chunk.PackageBlock;
import com.reandroid.lib.arsc.chunk.TableBlock;
import com.reandroid.lib.arsc.item.SpecString;
import com.reandroid.lib.arsc.item.TableString;
import com.reandroid.lib.arsc.pool.SpecStringPool;
import com.reandroid.lib.arsc.pool.TableStringPool;
import com.reandroid.lib.arsc.value.EntryBlock; import com.reandroid.lib.arsc.value.EntryBlock;
import com.reandroid.lib.arsc.value.ResValueBagItem; import com.reandroid.lib.arsc.value.ResValueBagItem;
import com.reandroid.lib.arsc.value.ValueType; import com.reandroid.lib.arsc.value.ValueType;
@ -76,20 +70,7 @@ public class StyleBagItem {
return entryBlock.buildResourceName(id, prefix, includeType); return entryBlock.buildResourceName(id, prefix, includeType);
} }
public String getStringValue(){ public String getStringValue(){
ValueType valueType=getValueType(); return mBagItem.getValueAsString();
if(valueType!=ValueType.STRING){
throw new IllegalArgumentException("Not STRING ValueType="+valueType);
}
TableStringPool stringPool=getStringPool();
if(stringPool==null){
return null;
}
int ref=getValue();
TableString tableString = stringPool.get(ref);
if(tableString==null){
return null;
}
return tableString.getHtml();
} }
public ValueType getValueType(){ public ValueType getValueType(){
return getBagItem().getValueType(); return getBagItem().getValueType();
@ -97,21 +78,6 @@ public class StyleBagItem {
public int getValue(){ public int getValue(){
return getBagItem().getData(); return getBagItem().getData();
} }
private TableStringPool getStringPool(){
EntryBlock entryBlock=getBagItem().getEntryBlock();
if(entryBlock==null){
return null;
}
PackageBlock pkg = entryBlock.getPackageBlock();
if(pkg==null){
return null;
}
TableBlock tableBlock= pkg.getTableBlock();
if(tableBlock==null){
return null;
}
return tableBlock.getTableStringPool();
}
@Override @Override
public String toString() { public String toString() {
StringBuilder builder=new StringBuilder(); StringBuilder builder=new StringBuilder();
@ -158,7 +124,6 @@ public class StyleBagItem {
if(resValueBagItem==null){ if(resValueBagItem==null){
return null; return null;
} }
StyleBagItem item=new StyleBagItem(resValueBagItem); return new StyleBagItem(resValueBagItem);
return item;
} }
} }

View File

@ -15,7 +15,6 @@
*/ */
package com.reandroid.lib.common; package com.reandroid.lib.common;
import com.reandroid.lib.arsc.io.BlockReader;
import com.reandroid.lib.arsc.util.FrameworkTable; import com.reandroid.lib.arsc.util.FrameworkTable;
import java.io.IOException; import java.io.IOException;
@ -31,7 +30,7 @@ public class Frameworks {
load_once=true; load_once=true;
FrameworkTable frameworkTable=null; FrameworkTable frameworkTable=null;
try { try {
frameworkTable = loadFramework(ANDROID_FRAMEWORK); frameworkTable = loadFramework(ANDROID_FRAMEWORK_30);
} catch (IOException e) { } catch (IOException e) {
} }
android_table=frameworkTable; android_table=frameworkTable;
@ -42,11 +41,10 @@ public class Frameworks {
if(inputStream==null){ if(inputStream==null){
return null; return null;
} }
BlockReader reader=new BlockReader(inputStream);
FrameworkTable frameworkTable=new FrameworkTable(); FrameworkTable frameworkTable=new FrameworkTable();
frameworkTable.readBytes(reader); frameworkTable.readBytes(inputStream);
return frameworkTable; return frameworkTable;
} }
private static final String ANDROID_FRAMEWORK= "/fwk/android_resources_30.arsc"; private static final String ANDROID_FRAMEWORK_30 = "/fwk/android_resources_30.arsc";
} }

View File

@ -1,8 +1,18 @@
/* /*
* Copyright (c) 2002 JSON.org (now "Public Domain") * Copyright (C) 2022 github.com/REAndroid
* This is NOT property of REAndroid *
* This package is renamed from org.json.* to avoid class conflict when used on anroid platforms * Licensed under the Apache License, Version 2.0 (the "License");
*/ * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reandroid.lib.json; package com.reandroid.lib.json;
import java.io.*; import java.io.*;