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 {
//No dependency
}
processResources {
filesMatching('lib.properties') {
filesMatching('arsclib.properties') {
expand('version': version)
}
}

View File

@ -654,9 +654,9 @@ public class ResourceIds {
String name=null;
Matcher matcher=pattern.matcher(element);
while (matcher.find()){
String attr=matcher.group("Attr").toLowerCase();
String value=matcher.group("Value");
element=matcher.group("Next");
String attr=matcher.group(1).toLowerCase();
String value=matcher.group(2);
element=matcher.group(3);
if(attr.equals("id")){
id=Integer.decode(value);
}else if(attr.equals("name")){
@ -674,7 +674,7 @@ public class ResourceIds {
}
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;
}
private static Properties loadProperties(){
InputStream inputStream=BuildInfo.class.getResourceAsStream("/lib.properties");
InputStream inputStream=BuildInfo.class.getResourceAsStream("/arsclib.properties");
Properties properties=new Properties();
try{
properties.load(inputStream);

View File

@ -43,15 +43,6 @@ public abstract class BlockItem extends Block {
mBytes=bts;
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){
setBytesLength(length, true);
}
@ -104,8 +95,7 @@ public abstract class BlockItem extends Block {
}
@Override
public void onReadBytes(BlockReader reader) throws IOException{
byte[] bts=getBytesInternal();
reader.readFully(bts);
reader.readFully(getBytesInternal());
onBytesChanged();
}
@Override

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -15,12 +15,6 @@
*/
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.ResValueBagItem;
import com.reandroid.lib.arsc.value.ValueType;
@ -76,20 +70,7 @@ public class StyleBagItem {
return entryBlock.buildResourceName(id, prefix, includeType);
}
public String getStringValue(){
ValueType valueType=getValueType();
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();
return mBagItem.getValueAsString();
}
public ValueType getValueType(){
return getBagItem().getValueType();
@ -97,21 +78,6 @@ public class StyleBagItem {
public int getValue(){
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
public String toString() {
StringBuilder builder=new StringBuilder();
@ -158,7 +124,6 @@ public class StyleBagItem {
if(resValueBagItem==null){
return null;
}
StyleBagItem item=new StyleBagItem(resValueBagItem);
return item;
return new StyleBagItem(resValueBagItem);
}
}

View File

@ -15,7 +15,6 @@
*/
package com.reandroid.lib.common;
import com.reandroid.lib.arsc.io.BlockReader;
import com.reandroid.lib.arsc.util.FrameworkTable;
import java.io.IOException;
@ -31,7 +30,7 @@ public class Frameworks {
load_once=true;
FrameworkTable frameworkTable=null;
try {
frameworkTable = loadFramework(ANDROID_FRAMEWORK);
frameworkTable = loadFramework(ANDROID_FRAMEWORK_30);
} catch (IOException e) {
}
android_table=frameworkTable;
@ -42,11 +41,10 @@ public class Frameworks {
if(inputStream==null){
return null;
}
BlockReader reader=new BlockReader(inputStream);
FrameworkTable frameworkTable=new FrameworkTable();
frameworkTable.readBytes(reader);
frameworkTable.readBytes(inputStream);
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")
* This is NOT property of REAndroid
* This package is renamed from org.json.* to avoid class conflict when used on anroid platforms
*/
/*
* Copyright (C) 2022 github.com/REAndroid
*
* 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;
import java.io.*;