mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-06-13 05:37:41 +02:00
simplify getParent methods
This commit is contained in:
@ -59,6 +59,7 @@ public class ResXmlAttributeArray extends BlockArray<ResXmlAttribute>
|
|||||||
}
|
}
|
||||||
private void refreshStart(){
|
private void refreshStart(){
|
||||||
Block parent=getParent();
|
Block parent=getParent();
|
||||||
|
clearChildes();
|
||||||
if(parent==null){
|
if(parent==null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -87,6 +88,23 @@ public class ResXmlAttributeArray extends BlockArray<ResXmlAttribute>
|
|||||||
super.onReadBytes(reader);
|
super.onReadBytes(reader);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
|
public void clearChildes(){
|
||||||
|
ResXmlAttribute[] childes = getChildes();
|
||||||
|
if(childes==null || childes.length==0){
|
||||||
|
super.clearChildes();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int length = childes.length;
|
||||||
|
for(int i=0;i<length;i++){
|
||||||
|
ResXmlAttribute child = childes[i];
|
||||||
|
if(child==null){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
child.onRemoved();
|
||||||
|
}
|
||||||
|
super.clearChildes();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
public int compare(ResXmlAttribute attr1, ResXmlAttribute attr2) {
|
public int compare(ResXmlAttribute attr1, ResXmlAttribute attr2) {
|
||||||
return attr1.compareTo(attr2);
|
return attr1.compareTo(attr2);
|
||||||
}
|
}
|
||||||
|
@ -90,6 +90,16 @@ public abstract class Block {
|
|||||||
public final Block getParent(){
|
public final Block getParent(){
|
||||||
return mParent;
|
return mParent;
|
||||||
}
|
}
|
||||||
|
public final <T> T getParent(Class<T> parentClass){
|
||||||
|
Block parent = getParent();
|
||||||
|
while (parent!=null){
|
||||||
|
if(parent.getClass() == parentClass){
|
||||||
|
return (T) parent;
|
||||||
|
}
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected static byte[] addBytes(byte[] bts1, byte[] bts2){
|
protected static byte[] addBytes(byte[] bts1, byte[] bts2){
|
||||||
|
@ -60,14 +60,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
SpecTypePair getSpecTypePair(){
|
SpecTypePair getSpecTypePair(){
|
||||||
Block parent=getParent();
|
return getParent(SpecTypePair.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof SpecTypePair){
|
|
||||||
return (SpecTypePair)parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public int getEntryCount() {
|
public int getEntryCount() {
|
||||||
return specFlagsArray.size();
|
return specFlagsArray.size();
|
||||||
|
@ -137,14 +137,7 @@ public class TypeBlock extends Chunk<TypeHeader>
|
|||||||
return getEntryArray().countNonNull();
|
return getEntryArray().countNonNull();
|
||||||
}
|
}
|
||||||
public SpecTypePair getParentSpecTypePair(){
|
public SpecTypePair getParentSpecTypePair(){
|
||||||
Block parent=getParent();
|
return getParent(SpecTypePair.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof SpecTypePair){
|
|
||||||
return (SpecTypePair)parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public void cleanEntries(){
|
public void cleanEntries(){
|
||||||
PackageBlock packageBlock=getPackageBlock();
|
PackageBlock packageBlock=getPackageBlock();
|
||||||
|
@ -72,7 +72,6 @@
|
|||||||
if(xmlString!=null){
|
if(xmlString!=null){
|
||||||
xmlString.removeReference(item);
|
xmlString.removeReference(item);
|
||||||
}
|
}
|
||||||
return xmlString;
|
|
||||||
}
|
}
|
||||||
public void setLineNumber(int val){
|
public void setLineNumber(int val){
|
||||||
getHeaderBlock().getLineNumber().set(val);
|
getHeaderBlock().getLineNumber().set(val);
|
||||||
@ -181,14 +180,7 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
public ResXmlElement getParentResXmlElement(){
|
public ResXmlElement getParentResXmlElement(){
|
||||||
Block parent=getParent();
|
return getParent(ResXmlElement.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof ResXmlElement){
|
|
||||||
return (ResXmlElement)parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
protected void onChunkRefreshed() {
|
protected void onChunkRefreshed() {
|
||||||
|
@ -15,154 +15,40 @@
|
|||||||
*/
|
*/
|
||||||
package com.reandroid.arsc.chunk.xml;
|
package com.reandroid.arsc.chunk.xml;
|
||||||
|
|
||||||
import com.reandroid.arsc.array.ResXmlAttributeArray;
|
|
||||||
import com.reandroid.arsc.array.ResXmlIDArray;
|
import com.reandroid.arsc.array.ResXmlIDArray;
|
||||||
import com.reandroid.arsc.base.Block;
|
|
||||||
import com.reandroid.arsc.container.FixedBlockContainer;
|
|
||||||
import com.reandroid.arsc.decoder.ValueDecoder;
|
import com.reandroid.arsc.decoder.ValueDecoder;
|
||||||
import com.reandroid.arsc.group.EntryGroup;
|
import com.reandroid.arsc.group.EntryGroup;
|
||||||
|
import com.reandroid.arsc.io.BlockReader;
|
||||||
import com.reandroid.arsc.item.*;
|
import com.reandroid.arsc.item.*;
|
||||||
import com.reandroid.arsc.pool.ResXmlStringPool;
|
import com.reandroid.arsc.pool.ResXmlStringPool;
|
||||||
import com.reandroid.arsc.value.Value;
|
import com.reandroid.arsc.pool.StringPool;
|
||||||
|
import com.reandroid.arsc.value.ValueItem;
|
||||||
import com.reandroid.arsc.value.ValueType;
|
import com.reandroid.arsc.value.ValueType;
|
||||||
import com.reandroid.common.EntryStore;
|
import com.reandroid.common.EntryStore;
|
||||||
import com.reandroid.json.JSONConvert;
|
|
||||||
import com.reandroid.json.JSONObject;
|
import com.reandroid.json.JSONObject;
|
||||||
import com.reandroid.xml.XMLAttribute;
|
import com.reandroid.xml.XMLAttribute;
|
||||||
import com.reandroid.xml.XMLException;
|
import com.reandroid.xml.XMLException;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.io.IOException;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
public class ResXmlAttribute extends FixedBlockContainer
|
public class ResXmlAttribute extends ValueItem implements Comparable<ResXmlAttribute>{
|
||||||
implements Value, Comparable<ResXmlAttribute>, JSONConvert<JSONObject> {
|
private ReferenceItem mNSReference;
|
||||||
private final IntegerItem mNamespaceReference;
|
private ReferenceItem mNameReference;
|
||||||
private final IntegerItem mNameReference;
|
private ReferenceItem mStringReference;
|
||||||
private final IntegerItem mValueStringReference;
|
public ResXmlAttribute(int attributeUnitSize) {
|
||||||
private final ShortItem mNameType;
|
super(attributeUnitSize, OFFSET_SIZE);
|
||||||
private final ByteItem mReserved;
|
byte[] bts = getBytesInternal();
|
||||||
private final ByteItem mValueTypeByte;
|
putInteger(bts, OFFSET_NS, -1);
|
||||||
private final IntegerItem mData;
|
putInteger(bts, OFFSET_NAME, -1);
|
||||||
private final ByteArray extraBytes;
|
putInteger(bts, OFFSET_STRING, -1);
|
||||||
public ResXmlAttribute(int size) {
|
|
||||||
super(8);
|
|
||||||
mNamespaceReference = new IntegerItem(-1);
|
|
||||||
mNameReference = new IntegerItem(-1);
|
|
||||||
mValueStringReference = new IntegerItem(-1);
|
|
||||||
mNameType = new ShortItem((short) 0x0008);
|
|
||||||
mReserved = new ByteItem();
|
|
||||||
mValueTypeByte = new ByteItem();
|
|
||||||
mData = new IntegerItem();
|
|
||||||
extraBytes = new ByteArray();
|
|
||||||
addChild(0, mNamespaceReference);
|
|
||||||
addChild(1, mNameReference);
|
|
||||||
addChild(2, mValueStringReference);
|
|
||||||
addChild(3, mNameType);
|
|
||||||
addChild(4, mReserved);
|
|
||||||
addChild(5, mValueTypeByte);
|
|
||||||
addChild(6, mData);
|
|
||||||
addChild(7, extraBytes);
|
|
||||||
|
|
||||||
extraBytes.setSize(size-20);
|
|
||||||
}
|
}
|
||||||
public ResXmlAttribute(){
|
public ResXmlAttribute() {
|
||||||
this(20);
|
this(20);
|
||||||
}
|
}
|
||||||
public void setAttributesUnitSize(int size){
|
|
||||||
extraBytes.setSize(size-20);
|
|
||||||
IntegerItem integerItem = new IntegerItem(this.hashCode());
|
|
||||||
extraBytes.putByteArray(0, integerItem.getBytes());
|
|
||||||
}
|
|
||||||
|
|
||||||
Set<ResXmlString> clearStringReferences(){
|
|
||||||
Set<ResXmlString> results= new HashSet<>();
|
|
||||||
ResXmlString xmlString;
|
|
||||||
xmlString=unLinkStringReference(mNamespaceReference);
|
|
||||||
if(xmlString!=null){
|
|
||||||
results.add(xmlString);
|
|
||||||
}
|
|
||||||
xmlString=unLinkStringReference(mNameReference);
|
|
||||||
if(xmlString!=null){
|
|
||||||
results.add(xmlString);
|
|
||||||
}
|
|
||||||
xmlString=unLinkStringReference(mValueStringReference);
|
|
||||||
if(xmlString!=null){
|
|
||||||
results.add(xmlString);
|
|
||||||
}
|
|
||||||
xmlString=unLinkStringReference(mData);
|
|
||||||
if(xmlString!=null){
|
|
||||||
results.add(xmlString);
|
|
||||||
}
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
public void linkStringReferences(){
|
|
||||||
linkStringReference(mNamespaceReference);
|
|
||||||
linkStringReference(mNameReference);
|
|
||||||
linkStringReference(mValueStringReference);
|
|
||||||
if(getValueType()==ValueType.STRING){
|
|
||||||
linkStringReference(mData);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void linkStringReference(IntegerItem item){
|
|
||||||
ResXmlString xmlString = getResXmlString(item.get());
|
|
||||||
if(xmlString!=null){
|
|
||||||
xmlString.addReferenceIfAbsent(item);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private ResXmlString unLinkStringReference(IntegerItem item){
|
|
||||||
ResXmlString xmlString = getResXmlString(item.get());
|
|
||||||
if(xmlString!=null){
|
|
||||||
xmlString.removeReference(item);
|
|
||||||
}
|
|
||||||
return xmlString;
|
|
||||||
}
|
|
||||||
public String getUri(){
|
public String getUri(){
|
||||||
return getString(getNamespaceReference());
|
return getString(getNamespaceReference());
|
||||||
}
|
}
|
||||||
int getNamespaceReference(){
|
|
||||||
return mNamespaceReference.get();
|
|
||||||
}
|
|
||||||
public void setNamespaceReference(int ref){
|
|
||||||
mNamespaceReference.set(ref);
|
|
||||||
}
|
|
||||||
int getNameReference(){
|
|
||||||
return mNameReference.get();
|
|
||||||
}
|
|
||||||
void setNameReference(int ref){
|
|
||||||
mNameReference.set(ref);
|
|
||||||
}
|
|
||||||
int getValueStringReference(){
|
|
||||||
return mValueStringReference.get();
|
|
||||||
}
|
|
||||||
void setValueStringReference(int ref){
|
|
||||||
mValueStringReference.set(ref);
|
|
||||||
}
|
|
||||||
byte getValueTypeByte(){
|
|
||||||
return mValueTypeByte.get();
|
|
||||||
}
|
|
||||||
void setValueTypeByte(byte b){
|
|
||||||
mValueTypeByte.set(b);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public int getData(){
|
|
||||||
return mData.get();
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void setData(int val){
|
|
||||||
mData.set(val);
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public ValueType getValueType(){
|
|
||||||
return ValueType.valueOf(getValueTypeByte());
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void setValueType(ValueType valueType){
|
|
||||||
byte b=0;
|
|
||||||
if(valueType!=null){
|
|
||||||
b=valueType.getByte();
|
|
||||||
}
|
|
||||||
setValueTypeByte(b);
|
|
||||||
}
|
|
||||||
public String getFullName(){
|
public String getFullName(){
|
||||||
String name=getName();
|
String name=getName();
|
||||||
if(name==null){
|
if(name==null){
|
||||||
@ -188,13 +74,6 @@
|
|||||||
}
|
}
|
||||||
return startNamespace.getPrefix();
|
return startNamespace.getPrefix();
|
||||||
}
|
}
|
||||||
public ResXmlStartNamespace getStartNamespace(){
|
|
||||||
ResXmlElement xmlElement=getParentResXmlElement();
|
|
||||||
if(xmlElement==null){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return xmlElement.getStartNamespaceByUriRef(getNamespaceReference());
|
|
||||||
}
|
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public String getValueString(){
|
public String getValueString(){
|
||||||
return getString(getValueStringReference());
|
return getString(getValueStringReference());
|
||||||
@ -218,14 +97,39 @@
|
|||||||
if(name==null){
|
if(name==null){
|
||||||
name="";
|
name="";
|
||||||
}
|
}
|
||||||
ResXmlIDMap xmlIDMap=getResXmlIDMap();
|
ResXmlIDMap xmlIDMap = getResXmlIDMap();
|
||||||
ResXmlStringPool stringPool=getStringPool();
|
StringPool<?> stringPool = getStringPool();
|
||||||
if(stringPool==null || xmlIDMap==null){
|
if(stringPool==null || xmlIDMap==null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ResXmlString xmlString = stringPool.getOrCreateAttributeName(xmlIDMap.getResXmlIDArray().childesCount(), name);
|
ResXmlStringPool resXmlStringPool = (ResXmlStringPool) stringPool;
|
||||||
|
ResXmlString xmlString = resXmlStringPool.getOrCreateAttributeName(xmlIDMap.getResXmlIDArray().childesCount(), name);
|
||||||
setNameReference(xmlString.getIndex());
|
setNameReference(xmlString.getIndex());
|
||||||
}
|
}
|
||||||
|
public ResXmlElement getParentResXmlElement(){
|
||||||
|
return getParent(ResXmlElement.class);
|
||||||
|
}
|
||||||
|
public int getAttributesUnitSize(){
|
||||||
|
return OFFSET_SIZE + super.getSize();
|
||||||
|
}
|
||||||
|
public void setAttributesUnitSize(int size){
|
||||||
|
int eight = size - OFFSET_SIZE;
|
||||||
|
super.setSize(eight);
|
||||||
|
}
|
||||||
|
private String getString(int ref){
|
||||||
|
if(ref<0){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
StringPool<?> stringPool = getStringPool();
|
||||||
|
if(stringPool == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
StringItem stringItem = stringPool.get(ref);
|
||||||
|
if(stringItem == null){
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return stringItem.getHtml();
|
||||||
|
}
|
||||||
private int getResourceId(int ref){
|
private int getResourceId(int ref){
|
||||||
if(ref<0){
|
if(ref<0){
|
||||||
return 0;
|
return 0;
|
||||||
@ -241,38 +145,6 @@
|
|||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getString(int ref){
|
|
||||||
if(ref<0){
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ResXmlString xmlString=getResXmlString(ref);
|
|
||||||
if(xmlString!=null){
|
|
||||||
return xmlString.getHtml();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
private ResXmlString getResXmlString(int ref){
|
|
||||||
ResXmlStringPool stringPool=getStringPool();
|
|
||||||
if(stringPool!=null){
|
|
||||||
return stringPool.get(ref);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
private ResXmlString getOrCreateResXmlString(String str){
|
|
||||||
ResXmlStringPool stringPool=getStringPool();
|
|
||||||
if(stringPool!=null){
|
|
||||||
return stringPool.getOrCreate(str);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
private ResXmlStringPool getStringPool(){
|
|
||||||
ResXmlElement xmlElement=getParentResXmlElement();
|
|
||||||
if(xmlElement!=null){
|
|
||||||
return xmlElement.getStringPool();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
private ResXmlIDMap getResXmlIDMap(){
|
private ResXmlIDMap getResXmlIDMap(){
|
||||||
ResXmlElement xmlElement=getParentResXmlElement();
|
ResXmlElement xmlElement=getParentResXmlElement();
|
||||||
if(xmlElement!=null){
|
if(xmlElement!=null){
|
||||||
@ -280,118 +152,112 @@
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public ResXmlElement getParentResXmlElement(){
|
|
||||||
Block parent=getParent();
|
int getNamespaceReference(){
|
||||||
while (parent!=null){
|
return getInteger(getBytesInternal(), OFFSET_NS);
|
||||||
if(parent instanceof ResXmlElement){
|
|
||||||
return (ResXmlElement)parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public String getValueAsString(){
|
public void setNamespaceReference(int ref){
|
||||||
int ref= getData();
|
if(ref == getNamespaceReference()){
|
||||||
ResXmlString xmlString=getResXmlString(ref);
|
return;
|
||||||
if(xmlString==null){
|
}
|
||||||
|
unlink(mNSReference);
|
||||||
|
putInteger(getBytesInternal(), OFFSET_NS, ref);
|
||||||
|
mNSReference = link(OFFSET_NS);
|
||||||
|
}
|
||||||
|
int getNameReference(){
|
||||||
|
return getInteger(getBytesInternal(), OFFSET_NAME);
|
||||||
|
}
|
||||||
|
void setNameReference(int ref){
|
||||||
|
if(ref == getNameReference()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unlink(mNameReference);
|
||||||
|
putInteger(getBytesInternal(), OFFSET_NAME, ref);
|
||||||
|
mNameReference = link(OFFSET_NAME);
|
||||||
|
}
|
||||||
|
int getValueStringReference(){
|
||||||
|
return getInteger(getBytesInternal(), OFFSET_STRING);
|
||||||
|
}
|
||||||
|
void setValueStringReference(int ref){
|
||||||
|
if(ref == getValueStringReference()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
unlink(mStringReference);
|
||||||
|
putInteger(getBytesInternal(), OFFSET_STRING, ref);
|
||||||
|
mStringReference = link(OFFSET_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReadBytes(BlockReader reader) throws IOException {
|
||||||
|
super.onReadBytes(reader);
|
||||||
|
linkAll();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
public void onRemoved(){
|
||||||
|
super.onRemoved();
|
||||||
|
unlinkAll();
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onUnlinkDataString(StringItem stringItem){
|
||||||
|
if(stringItem.getReferencedList().size()==0){
|
||||||
|
stringItem.set("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@Override
|
||||||
|
protected void onDataChanged(){
|
||||||
|
if(getValueType()!=ValueType.STRING){
|
||||||
|
setValueStringReference(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private void linkAll(){
|
||||||
|
unlink(mNSReference);
|
||||||
|
mNSReference = link(OFFSET_NS);
|
||||||
|
unlink(mNameReference);
|
||||||
|
mNameReference = link(OFFSET_NAME);
|
||||||
|
unlink(mStringReference);
|
||||||
|
mStringReference = link(OFFSET_STRING);
|
||||||
|
}
|
||||||
|
private void unlinkAll(){
|
||||||
|
unlink(mNSReference);
|
||||||
|
unlink(mNameReference);
|
||||||
|
unlink(mStringReference);
|
||||||
|
}
|
||||||
|
private ReferenceItem link(int offset){
|
||||||
|
if(offset<0){
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return xmlString.getHtml();
|
StringPool<?> stringPool = getStringPool();
|
||||||
}
|
if(stringPool == null){
|
||||||
public boolean getValueAsBoolean(){
|
return null;
|
||||||
int ref= getData();
|
|
||||||
return ref!=0;
|
|
||||||
}
|
|
||||||
public void setValueAsString(String str){
|
|
||||||
setValueType(ValueType.STRING);
|
|
||||||
ResXmlString xmlString=getOrCreateResXmlString(str);
|
|
||||||
if(xmlString==null){
|
|
||||||
throw new IllegalStateException("ResXmlString is null, attribute must be added to parent element first");
|
|
||||||
}
|
}
|
||||||
int ref=xmlString.getIndex();
|
int ref = getInteger(getBytesInternal(), offset);
|
||||||
setData(ref);
|
StringItem stringItem = stringPool.get(ref);
|
||||||
setValueStringReference(ref);
|
if(stringItem == null){
|
||||||
}
|
return null;
|
||||||
public void setValueAsBoolean(boolean val){
|
|
||||||
setValueType(ValueType.INT_BOOLEAN);
|
|
||||||
int ref=val?0xffffffff:0;
|
|
||||||
setData(ref);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public boolean hasIntegerValue(){
|
|
||||||
ValueType valueType=getValueType();
|
|
||||||
return valueType==ValueType.INT_DEC;
|
|
||||||
}
|
|
||||||
public Integer getValueAsInteger(){
|
|
||||||
if(hasIntegerValue()){
|
|
||||||
return getData();
|
|
||||||
}
|
}
|
||||||
return null;
|
ReferenceItem referenceItem = new ReferenceBlock<>(this, offset);
|
||||||
|
stringItem.addReference(referenceItem);
|
||||||
|
return referenceItem;
|
||||||
}
|
}
|
||||||
public void setValueAsInteger(int val){
|
private void unlink(ReferenceItem reference){
|
||||||
setValueType(ValueType.INT_DEC);
|
if(reference == null){
|
||||||
setData(val);
|
return;
|
||||||
setValueStringReference(-1);
|
}
|
||||||
}
|
StringPool<?> stringPool = getStringPool();
|
||||||
private ResXmlAttributeArray getParentResXmlAttributeArray(){
|
if(stringPool==null){
|
||||||
Block parent=this;
|
return;
|
||||||
while(parent!=null){
|
}
|
||||||
if(parent instanceof ResXmlAttributeArray){
|
StringItem stringItem = stringPool.get(reference.get());
|
||||||
return (ResXmlAttributeArray)parent;
|
if(stringItem==null){
|
||||||
}
|
return;
|
||||||
parent=parent.getParent();
|
}
|
||||||
|
stringItem.removeReference(reference);
|
||||||
|
if(stringItem.getReferencedList().size()==0){
|
||||||
|
stringItem.set("");
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
|
||||||
public void setValueAsIntegerDec(int val){
|
|
||||||
setValueType(ValueType.INT_DEC);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsHex(int val){
|
|
||||||
setValueType(ValueType.INT_HEX);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsFraction(float fraction){
|
|
||||||
int val=Float.floatToIntBits(fraction);
|
|
||||||
setValueAsFraction(val);
|
|
||||||
}
|
|
||||||
public void setValueAsFraction(int val){
|
|
||||||
setValueType(ValueType.FRACTION);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsResourceId(int resId){
|
|
||||||
setValueType(ValueType.REFERENCE);
|
|
||||||
setData(resId);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsAttributeId(int attrId){
|
|
||||||
setValueType(ValueType.ATTRIBUTE);
|
|
||||||
setData(attrId);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsColorRGB4(int val){
|
|
||||||
setValueType(ValueType.INT_COLOR_RGB4);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsColorRGB8(int val){
|
|
||||||
setValueType(ValueType.INT_COLOR_RGB8);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsColorARGB4(int val){
|
|
||||||
setValueType(ValueType.INT_COLOR_ARGB4);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
|
||||||
public void setValueAsColorARGB8(int val){
|
|
||||||
setValueType(ValueType.INT_COLOR_ARGB8);
|
|
||||||
setData(val);
|
|
||||||
setValueStringReference(-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(ResXmlAttribute other) {
|
public int compareTo(ResXmlAttribute other) {
|
||||||
int id1=getNameResourceID();
|
int id1=getNameResourceID();
|
||||||
@ -472,8 +338,8 @@
|
|||||||
if(prefix!=null){
|
if(prefix!=null){
|
||||||
name=prefix+":"+name;
|
name=prefix+":"+name;
|
||||||
}
|
}
|
||||||
ValueType valueType=getValueType();
|
ValueType valueType = getValueType();
|
||||||
int raw= getData();
|
int raw = getData();
|
||||||
String value;
|
String value;
|
||||||
if(valueType==ValueType.STRING){
|
if(valueType==ValueType.STRING){
|
||||||
value = ValueDecoder.escapeSpecialCharacter(getValueAsString());
|
value = ValueDecoder.escapeSpecialCharacter(getValueAsString());
|
||||||
@ -493,10 +359,10 @@
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public String toString(){
|
public String toString(){
|
||||||
String fullName=getFullName();
|
String fullName = getFullName();
|
||||||
if(fullName!=null ){
|
if(fullName!=null ){
|
||||||
int id=getNameResourceID();
|
int id=getNameResourceID();
|
||||||
if(id>0){
|
if(id!=0){
|
||||||
fullName=fullName+"(@"+String.format("0x%08x",id)+")";
|
fullName=fullName+"(@"+String.format("0x%08x",id)+")";
|
||||||
}
|
}
|
||||||
String valStr;
|
String valStr;
|
||||||
@ -504,9 +370,11 @@
|
|||||||
if(valueType==ValueType.STRING){
|
if(valueType==ValueType.STRING){
|
||||||
valStr=getValueAsString();
|
valStr=getValueAsString();
|
||||||
}else if (valueType==ValueType.INT_BOOLEAN){
|
}else if (valueType==ValueType.INT_BOOLEAN){
|
||||||
valStr=String.valueOf(getValueAsBoolean());
|
valStr = String.valueOf(getValueAsBoolean());
|
||||||
|
}else if (valueType==ValueType.INT_DEC){
|
||||||
|
valStr = String.valueOf(getData());
|
||||||
}else {
|
}else {
|
||||||
valStr="["+valueType+"] "+ getData();
|
valStr = "["+valueType+"] " + String.format("0x%08x",getData());
|
||||||
}
|
}
|
||||||
if(valStr!=null){
|
if(valStr!=null){
|
||||||
return fullName+"=\""+valStr+"\"";
|
return fullName+"=\""+valStr+"\"";
|
||||||
@ -520,16 +388,22 @@
|
|||||||
builder.append("{NamespaceReference=").append(getNamespaceReference());
|
builder.append("{NamespaceReference=").append(getNamespaceReference());
|
||||||
builder.append(", NameReference=").append(getNameReference());
|
builder.append(", NameReference=").append(getNameReference());
|
||||||
builder.append(", ValueStringReference=").append(getValueStringReference());
|
builder.append(", ValueStringReference=").append(getValueStringReference());
|
||||||
builder.append(", NameType=").append(mNameType.unsignedInt());
|
builder.append(", ValueSize=").append(getSize());
|
||||||
builder.append(", ReservedByte=").append(mReserved.unsignedInt());
|
builder.append(", ValueTypeByte=").append(getType() & 0xff);
|
||||||
builder.append(", ValueTypeByte=").append(getValueTypeByte());
|
builder.append(", Data=").append(getData());
|
||||||
builder.append(", RawValue=").append(getData());
|
|
||||||
builder.append("}");
|
builder.append("}");
|
||||||
return builder.toString();
|
return builder.toString();
|
||||||
}
|
}
|
||||||
static final String NAME_id = "id";
|
|
||||||
public static final String NAME_value_type = "value_type";
|
|
||||||
|
|
||||||
|
public static final String NAME_id = "id";
|
||||||
public static final String NAME_name = "name";
|
public static final String NAME_name = "name";
|
||||||
public static final String NAME_namespace_uri = "namespace_uri";
|
public static final String NAME_namespace_uri = "namespace_uri";
|
||||||
public static final String NAME_data= "data";
|
|
||||||
|
private static final int OFFSET_NS = 0;
|
||||||
|
private static final int OFFSET_NAME = 4;
|
||||||
|
private static final int OFFSET_STRING = 8;
|
||||||
|
|
||||||
|
private static final int OFFSET_SIZE = 12;
|
||||||
}
|
}
|
||||||
|
@ -125,14 +125,7 @@ public class SpecTypePair extends BlockContainer<Block>
|
|||||||
return mTypeBlockArray;
|
return mTypeBlockArray;
|
||||||
}
|
}
|
||||||
public PackageBlock getPackageBlock(){
|
public PackageBlock getPackageBlock(){
|
||||||
Block parent=getParent();
|
return getParent(PackageBlock.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof PackageBlock){
|
|
||||||
return (PackageBlock)parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public List<Entry> listEntries(int entryId){
|
public List<Entry> listEntries(int entryId){
|
||||||
List<Entry> results=new ArrayList<>();
|
List<Entry> results=new ArrayList<>();
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
package com.reandroid.arsc.item;
|
package com.reandroid.arsc.item;
|
||||||
|
|
||||||
|
|
||||||
import com.reandroid.arsc.base.Block;
|
|
||||||
import com.reandroid.arsc.pool.TypeStringPool;
|
import com.reandroid.arsc.pool.TypeStringPool;
|
||||||
|
|
||||||
public class TypeString extends StringItem {
|
public class TypeString extends StringItem {
|
||||||
@ -24,7 +23,7 @@ package com.reandroid.arsc.item;
|
|||||||
super(utf8);
|
super(utf8);
|
||||||
}
|
}
|
||||||
public int getId(){
|
public int getId(){
|
||||||
TypeStringPool stringPool=getTypeStringPool();
|
TypeStringPool stringPool = getParent(TypeStringPool.class);
|
||||||
if(stringPool!=null){
|
if(stringPool!=null){
|
||||||
return stringPool.idOf(this);
|
return stringPool.idOf(this);
|
||||||
}
|
}
|
||||||
@ -36,14 +35,4 @@ package com.reandroid.arsc.item;
|
|||||||
// Type don't have style unless to obfuscate/confuse other decompilers
|
// Type don't have style unless to obfuscate/confuse other decompilers
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
private TypeStringPool getTypeStringPool(){
|
|
||||||
Block parent=this;
|
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof TypeStringPool){
|
|
||||||
return (TypeStringPool) parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -160,14 +160,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public TypeBlock getTypeBlock(){
|
public TypeBlock getTypeBlock(){
|
||||||
Block parent = getParent();
|
return getParent(TypeBlock.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof TypeBlock){
|
|
||||||
return (TypeBlock) parent;
|
|
||||||
}
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
private String getPackageName(){
|
private String getPackageName(){
|
||||||
PackageBlock packageBlock = getPackageBlock();
|
PackageBlock packageBlock = getPackageBlock();
|
||||||
@ -177,14 +170,7 @@
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public PackageBlock getPackageBlock(){
|
public PackageBlock getPackageBlock(){
|
||||||
Block parent = getParent();
|
return getParent(PackageBlock.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof PackageBlock){
|
|
||||||
return (PackageBlock) parent;
|
|
||||||
}
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
private TableEntry<?, ?> ensureTableEntry(boolean is_complex){
|
private TableEntry<?, ?> ensureTableEntry(boolean is_complex){
|
||||||
TableEntry<?, ?> tableEntry = getTableEntry();
|
TableEntry<?, ?> tableEntry = getTableEntry();
|
||||||
|
@ -40,14 +40,7 @@ public abstract class TableEntry<HEADER extends Header, VALUE extends Block> ext
|
|||||||
this.resValue.setIndex(1);
|
this.resValue.setIndex(1);
|
||||||
}
|
}
|
||||||
public Entry getParentEntry(){
|
public Entry getParentEntry(){
|
||||||
Block parent = getParent();
|
return getParent(Entry.class);
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof Entry){
|
|
||||||
return (Entry) parent;
|
|
||||||
}
|
|
||||||
parent=parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
}
|
}
|
||||||
|
@ -31,58 +31,49 @@ import java.io.IOException;
|
|||||||
public abstract class ValueItem extends BlockItem implements Value,
|
public abstract class ValueItem extends BlockItem implements Value,
|
||||||
JSONConvert<JSONObject>{
|
JSONConvert<JSONObject>{
|
||||||
private ReferenceItem mStringReference;
|
private ReferenceItem mStringReference;
|
||||||
public ValueItem(int bytesLength) {
|
private final int sizeOffset;
|
||||||
|
public ValueItem(int bytesLength, int sizeOffset) {
|
||||||
super(bytesLength);
|
super(bytesLength);
|
||||||
|
this.sizeOffset = sizeOffset;
|
||||||
|
|
||||||
writeSize();
|
writeSize();
|
||||||
}
|
}
|
||||||
public void onRemoved(){
|
public void onRemoved(){
|
||||||
unLinkStringReference();
|
unLinkStringReference();
|
||||||
}
|
}
|
||||||
public Entry getParentEntry(){
|
protected void onDataChanged(){
|
||||||
Block parent=getParent();
|
|
||||||
while (parent!=null){
|
|
||||||
if(parent instanceof Entry){
|
|
||||||
return (Entry) parent;
|
|
||||||
}
|
|
||||||
parent = parent.getParent();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
public void refresh(){
|
public void refresh(){
|
||||||
writeSize();
|
writeSize();
|
||||||
}
|
}
|
||||||
public ReferenceItem getTableStringReference(){
|
|
||||||
return mStringReference;
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract int getSizeOffset();
|
|
||||||
|
|
||||||
byte getRes0(){
|
byte getRes0(){
|
||||||
return getBytesInternal()[getSizeOffset()+OFFSET_RES0];
|
return getBytesInternal()[this.sizeOffset + OFFSET_RES0];
|
||||||
}
|
}
|
||||||
public byte getType(){
|
public byte getType(){
|
||||||
return getBytesInternal()[getSizeOffset()+OFFSET_TYPE];
|
return getBytesInternal()[this.sizeOffset + OFFSET_TYPE];
|
||||||
}
|
}
|
||||||
public void setType(byte type){
|
public void setType(byte type){
|
||||||
if(type == getType()){
|
if(type == getType()){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
byte[] bts = getBytesInternal();
|
byte[] bts = getBytesInternal();
|
||||||
int offset = getSizeOffset()+OFFSET_TYPE;
|
int offset = this.sizeOffset + OFFSET_TYPE;
|
||||||
byte old = bts[offset];
|
byte old = bts[offset];
|
||||||
bts[offset] = type;
|
bts[offset] = type;
|
||||||
onTypeChanged(old, type);
|
onTypeChanged(old, type);
|
||||||
|
onDataChanged();
|
||||||
}
|
}
|
||||||
public int getSize(){
|
public int getSize(){
|
||||||
return 0xffff & getShort(getBytesInternal(), getSizeOffset()+OFFSET_SIZE);
|
return 0xffff & getShort(getBytesInternal(), this.sizeOffset + OFFSET_SIZE);
|
||||||
}
|
}
|
||||||
public void setSize(int size){
|
public void setSize(int size){
|
||||||
size = getSizeOffset() + size;
|
size = this.sizeOffset + size;
|
||||||
setBytesLength(size, false);
|
setBytesLength(size, false);
|
||||||
writeSize();
|
writeSize();
|
||||||
}
|
}
|
||||||
private void writeSize(){
|
private void writeSize(){
|
||||||
int offset = getSizeOffset();
|
int offset = this.sizeOffset;
|
||||||
int size = countBytes() - offset;
|
int size = countBytes() - offset;
|
||||||
putShort(getBytesInternal(), offset + OFFSET_SIZE, (short) size);
|
putShort(getBytesInternal(), offset + OFFSET_SIZE, (short) size);
|
||||||
}
|
}
|
||||||
@ -107,20 +98,21 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public int getData(){
|
public int getData(){
|
||||||
return getInteger(getBytesInternal(), getSizeOffset()+OFFSET_DATA);
|
return getInteger(getBytesInternal(), this.sizeOffset + OFFSET_DATA);
|
||||||
}
|
}
|
||||||
@Override
|
@Override
|
||||||
public void setData(int data){
|
public void setData(int data){
|
||||||
byte[] bts = getBytesInternal();
|
byte[] bts = getBytesInternal();
|
||||||
int old = getInteger(bts, getSizeOffset()+OFFSET_DATA);
|
int old = getInteger(bts, this.sizeOffset + OFFSET_DATA);
|
||||||
if(old == data){
|
if(old == data){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
unLinkStringReference();
|
unLinkStringReference();
|
||||||
putInteger(bts, getSizeOffset()+OFFSET_DATA, data);
|
putInteger(bts, this.sizeOffset + OFFSET_DATA, data);
|
||||||
if(ValueType.STRING==getValueType()){
|
if(ValueType.STRING==getValueType()){
|
||||||
linkStringReference();
|
linkStringReference();
|
||||||
}
|
}
|
||||||
|
onDataChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -148,7 +140,7 @@ import java.io.IOException;
|
|||||||
if(stringReference!=null){
|
if(stringReference!=null){
|
||||||
unLinkStringReference();
|
unLinkStringReference();
|
||||||
}
|
}
|
||||||
stringReference = new ReferenceBlock<>(this, getSizeOffset()+OFFSET_DATA);
|
stringReference = new ReferenceBlock<>(this, this.sizeOffset + OFFSET_DATA);
|
||||||
mStringReference = stringReference;
|
mStringReference = stringReference;
|
||||||
tableString.addReference(stringReference);
|
tableString.addReference(stringReference);
|
||||||
}
|
}
|
||||||
@ -162,9 +154,14 @@ import java.io.IOException;
|
|||||||
if(stringPool == null){
|
if(stringPool == null){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
stringPool.removeReference(stringReference);
|
StringItem stringItem = stringPool.removeReference(stringReference);
|
||||||
|
if(stringItem!=null){
|
||||||
|
onUnlinkDataString(stringItem);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
private StringPool<?> getStringPool(){
|
protected void onUnlinkDataString(StringItem stringItem){
|
||||||
|
}
|
||||||
|
public StringPool<?> getStringPool(){
|
||||||
Block parent = getParent();
|
Block parent = getParent();
|
||||||
while (parent!=null){
|
while (parent!=null){
|
||||||
if(parent instanceof MainChunk){
|
if(parent instanceof MainChunk){
|
||||||
@ -182,7 +179,7 @@ import java.io.IOException;
|
|||||||
}
|
}
|
||||||
private void initializeBytes(BlockReader reader) throws IOException {
|
private void initializeBytes(BlockReader reader) throws IOException {
|
||||||
int position = reader.getPosition();
|
int position = reader.getPosition();
|
||||||
int offset = getSizeOffset();
|
int offset = this.sizeOffset;
|
||||||
reader.offset(offset);
|
reader.offset(offset);
|
||||||
int size = reader.readUnsignedShort();
|
int size = reader.readUnsignedShort();
|
||||||
reader.seek(position);
|
reader.seek(position);
|
||||||
@ -290,6 +287,6 @@ import java.io.IOException;
|
|||||||
private static final int OFFSET_DATA = 4;
|
private static final int OFFSET_DATA = 4;
|
||||||
|
|
||||||
|
|
||||||
static final String NAME_data = "data";
|
public static final String NAME_data = "data";
|
||||||
static final String NAME_value_type = "value_type";
|
public static final String NAME_value_type = "value_type";
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user