mirror of
https://github.com/revanced/ARSCLib.git
synced 2025-04-30 14:24:25 +02:00
re-struct Value to include ResXmlAttribute
This commit is contained in:
parent
8023a75ae8
commit
a48537a20e
@ -180,7 +180,7 @@ public class ApkModule {
|
||||
continue;
|
||||
}
|
||||
for(TableString tableString:groupTableString.listItems()){
|
||||
List<Entry> entryList = tableString.listReferencedEntries(true);
|
||||
List<Entry> entryList = tableString.listReferencedEntries();
|
||||
if(entryList.size()==0){
|
||||
continue;
|
||||
}
|
||||
|
@ -250,7 +250,7 @@ public class AndroidManifestBlock extends ResXmlDocument {
|
||||
ResXmlElement manifestElement=getOrCreateManifestElement();
|
||||
ResXmlAttribute attribute = manifestElement
|
||||
.getOrCreateAndroidAttribute(attributeName, resourceId);
|
||||
attribute.setValueAsInteger(value);
|
||||
attribute.setTypeAndData(ValueType.INT_DEC, value);
|
||||
}
|
||||
private Integer getManifestAttributeInt(int resourceId){
|
||||
ResXmlElement manifestElement=getManifestElement();
|
||||
@ -258,10 +258,10 @@ public class AndroidManifestBlock extends ResXmlDocument {
|
||||
return null;
|
||||
}
|
||||
ResXmlAttribute attribute= manifestElement.searchAttributeByResourceId(resourceId);
|
||||
if(attribute==null || !attribute.hasIntegerValue()){
|
||||
if(attribute==null || attribute.getValueType()!=ValueType.INT_DEC){
|
||||
return null;
|
||||
}
|
||||
return attribute.getValueAsInteger();
|
||||
return attribute.getData();
|
||||
}
|
||||
public ResXmlElement getApplicationElement(){
|
||||
ResXmlElement manifestElement=getManifestElement();
|
||||
|
@ -39,22 +39,10 @@
|
||||
addChild(mNamespaceReference);
|
||||
addChild(mStringReference);
|
||||
}
|
||||
Set<ResXmlString> clearStringReferences(){
|
||||
Set<ResXmlString> results=new HashSet<>();
|
||||
ResXmlString xmlString;
|
||||
xmlString=unLinkStringReference(getHeaderBlock().getCommentReference());
|
||||
if(xmlString!=null){
|
||||
results.add(xmlString);
|
||||
}
|
||||
xmlString=unLinkStringReference(mNamespaceReference);
|
||||
if(xmlString!=null){
|
||||
results.add(xmlString);
|
||||
}
|
||||
xmlString=unLinkStringReference(mStringReference);
|
||||
if(xmlString!=null){
|
||||
results.add(xmlString);
|
||||
}
|
||||
return results;
|
||||
void onRemoved(){
|
||||
unLinkStringReference(getHeaderBlock().getCommentReference());
|
||||
unLinkStringReference(mNamespaceReference);
|
||||
unLinkStringReference(mStringReference);
|
||||
}
|
||||
void linkStringReferences(){
|
||||
linkStringReference(getHeaderBlock().getCommentReference());
|
||||
@ -67,7 +55,7 @@
|
||||
xmlString.addReferenceIfAbsent(item);
|
||||
}
|
||||
}
|
||||
ResXmlString unLinkStringReference(IntegerItem item){
|
||||
void unLinkStringReference(IntegerItem item){
|
||||
ResXmlString xmlString = getResXmlString(item.get());
|
||||
if(xmlString!=null){
|
||||
xmlString.removeReference(item);
|
||||
|
@ -21,7 +21,6 @@
|
||||
import com.reandroid.arsc.container.SingleBlockContainer;
|
||||
import com.reandroid.arsc.header.HeaderBlock;
|
||||
import com.reandroid.arsc.io.BlockReader;
|
||||
import com.reandroid.arsc.item.ResXmlString;
|
||||
import com.reandroid.arsc.pool.ResXmlStringPool;
|
||||
import com.reandroid.common.EntryStore;
|
||||
import com.reandroid.json.JSONConvert;
|
||||
@ -77,23 +76,21 @@
|
||||
public ResXmlAttribute newAttribute(){
|
||||
return getStartElement().newAttribute();
|
||||
}
|
||||
Set<ResXmlString> clearStringReferences(){
|
||||
Set<ResXmlString> results=new HashSet<>();
|
||||
void onRemoved(){
|
||||
for(ResXmlStartNamespace startNamespace:getStartNamespaceList()){
|
||||
results.addAll(startNamespace.clearStringReferences());
|
||||
startNamespace.onRemoved();
|
||||
}
|
||||
ResXmlStartElement start = getStartElement();
|
||||
if(start!=null){
|
||||
results.addAll(start.clearStringReferences());
|
||||
start.onRemoved();
|
||||
}
|
||||
ResXmlText resXmlText=getResXmlText();
|
||||
if(resXmlText!=null){
|
||||
results.addAll(resXmlText.clearStringReferences());
|
||||
resXmlText.onRemoved();
|
||||
}
|
||||
for(ResXmlElement child:listElements()){
|
||||
results.addAll(child.clearStringReferences());
|
||||
child.onRemoved();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
void linkStringReferences(){
|
||||
for(ResXmlStartNamespace startNamespace:getStartNamespaceList()){
|
||||
@ -284,18 +281,14 @@
|
||||
mBody.add(element);
|
||||
}
|
||||
public boolean removeAttribute(ResXmlAttribute resXmlAttribute){
|
||||
if(resXmlAttribute != null){
|
||||
resXmlAttribute.onRemoved();
|
||||
}
|
||||
return getStartElement().getResXmlAttributeArray().remove(resXmlAttribute);
|
||||
}
|
||||
public boolean removeElement(ResXmlElement element){
|
||||
if(element.getParent()!=null){
|
||||
// TODO: Find a way to remove properly from StringPool
|
||||
Set<ResXmlString> removedStrings = element.clearStringReferences();
|
||||
for(ResXmlString xmlString:removedStrings){
|
||||
if(xmlString.getReferencedList().size()!=0){
|
||||
continue;
|
||||
}
|
||||
xmlString.set("");
|
||||
}
|
||||
element.onRemoved();
|
||||
}
|
||||
return mBody.remove(element);
|
||||
}
|
||||
|
@ -66,21 +66,17 @@
|
||||
if(end!=null){
|
||||
end.linkStringReferences();
|
||||
}
|
||||
for(ResXmlAttribute attr:listResXmlAttributes()){
|
||||
attr.linkStringReferences();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
Set<ResXmlString> clearStringReferences(){
|
||||
Set<ResXmlString> results=super.clearStringReferences();
|
||||
void onRemoved(){
|
||||
super.onRemoved();
|
||||
ResXmlEndElement end = getResXmlEndElement();
|
||||
if(end!=null){
|
||||
results.addAll(end.clearStringReferences());
|
||||
end.onRemoved();
|
||||
}
|
||||
for(ResXmlAttribute attr:listResXmlAttributes()){
|
||||
results.addAll(attr.clearStringReferences());
|
||||
attr.onRemoved();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
@Override
|
||||
protected void onPreRefreshRefresh(){
|
||||
|
@ -41,13 +41,11 @@
|
||||
}
|
||||
}
|
||||
@Override
|
||||
Set<ResXmlString> clearStringReferences(){
|
||||
Set<ResXmlString> results=super.clearStringReferences();
|
||||
void onRemoved(){
|
||||
ResXmlEndNamespace end = getEnd();
|
||||
if(end!=null){
|
||||
results.addAll(end.clearStringReferences());
|
||||
end.onRemoved();
|
||||
}
|
||||
return results;
|
||||
}
|
||||
public XMLAttribute decodeToXml(){
|
||||
String uri=getUri();
|
||||
|
@ -15,7 +15,9 @@
|
||||
*/
|
||||
package com.reandroid.arsc.item;
|
||||
|
||||
import com.reandroid.arsc.base.Block;
|
||||
import com.reandroid.arsc.value.Entry;
|
||||
import com.reandroid.arsc.value.ResValue;
|
||||
import com.reandroid.arsc.value.ResValueMap;
|
||||
import com.reandroid.arsc.value.ValueItem;
|
||||
|
||||
@ -26,20 +28,21 @@ public class TableString extends StringItem {
|
||||
public TableString(boolean utf8) {
|
||||
super(utf8);
|
||||
}
|
||||
public List<Entry> listReferencedEntries(boolean ignoreBagEntries){
|
||||
public List<Entry> listReferencedEntries(){
|
||||
List<Entry> results=new ArrayList<>();
|
||||
for(ReferenceItem ref:getReferencedList()){
|
||||
if(!(ref instanceof ReferenceBlock)){
|
||||
continue;
|
||||
}
|
||||
ValueItem valueItem = (ValueItem) ((ReferenceBlock)ref).getBlock();
|
||||
if(valueItem ==null){
|
||||
Block block = ((ReferenceBlock<?>)ref).getBlock();
|
||||
if(block ==null){
|
||||
continue;
|
||||
}
|
||||
if(ignoreBagEntries && (valueItem instanceof ResValueMap)){
|
||||
if(!(block instanceof ResValue)){
|
||||
continue;
|
||||
}
|
||||
results.add(valueItem.getParentEntry());
|
||||
ResValue resValue = (ResValue) block;
|
||||
results.add(resValue.getEntry());
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
@ -163,15 +163,16 @@ package com.reandroid.arsc.pool;
|
||||
removeReference(ref);
|
||||
}
|
||||
}
|
||||
public boolean removeReference(ReferenceItem ref){
|
||||
public T removeReference(ReferenceItem ref){
|
||||
if(ref==null){
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
T item=get(ref.get());
|
||||
if(item!=null){
|
||||
return item.removeReference(ref);
|
||||
item.removeReference(ref);
|
||||
return item;
|
||||
}
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
public void addReference(ReferenceItem ref){
|
||||
if(ref==null){
|
||||
|
@ -15,29 +15,14 @@
|
||||
*/
|
||||
package com.reandroid.arsc.value;
|
||||
|
||||
import com.reandroid.arsc.base.Block;
|
||||
|
||||
public class ResValue extends ValueItem {
|
||||
public ResValue() {
|
||||
super(8);
|
||||
super(8, OFFSET_SIZE);
|
||||
}
|
||||
|
||||
public Entry getEntry(){
|
||||
Block parent = getParent();
|
||||
while (parent!=null){
|
||||
if(parent instanceof Entry){
|
||||
return (Entry) parent;
|
||||
return getParent(Entry.class);
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
int getSizeOffset(){
|
||||
return OFFSET_SIZE;
|
||||
}
|
||||
|
||||
|
||||
private static final int OFFSET_SIZE = 0;
|
||||
|
||||
}
|
||||
|
@ -21,18 +21,11 @@ import com.reandroid.json.JSONObject;
|
||||
public class ResValueMap extends ValueItem{
|
||||
|
||||
public ResValueMap() {
|
||||
super(12);
|
||||
super(12, OFFSET_SIZE);
|
||||
}
|
||||
|
||||
public Entry getEntry(){
|
||||
Block parent = getParent();
|
||||
while (parent!=null){
|
||||
if(parent instanceof Entry){
|
||||
return (Entry) parent;
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
return null;
|
||||
return getParent(Entry.class);
|
||||
}
|
||||
|
||||
public ResTableMapEntry getParentMapEntry(){
|
||||
@ -53,10 +46,6 @@ public class ResValueMap extends ValueItem{
|
||||
putInteger(getBytesInternal(), OFFSET_NAME, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
int getSizeOffset(){
|
||||
return OFFSET_SIZE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONObject toJson() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user