Skip to content

Commit eafe39f

Browse files
committed
Update ARSCLib
1 parent 10749cd commit eafe39f

File tree

7 files changed

+34
-57
lines changed

7 files changed

+34
-57
lines changed

libs/ARSCLib.jar

20 KB
Binary file not shown.

src/main/java/com/reandroid/apkeditor/common/AndroidManifestHelper.java

Lines changed: 13 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public static void removeAttributeFromManifestByName(AndroidManifestBlock androi
7171
}
7272
return;
7373
}
74-
int removed = manifestElement.removeAttributesWithName(resourceName);
75-
if (removed > 0 && logger != null) {
76-
logger.logMessage("Removed-attribute : " + resourceName);
74+
boolean removed = manifestElement.removeAttributesWithName(resourceName);
75+
if (removed && logger != null) {
76+
logger.logMessage("Removed-attribute : " + resourceName);
7777
}
7878
}
7979
public static void removeAttributeFromManifestById(AndroidManifestBlock androidManifestBlock,
@@ -85,8 +85,8 @@ public static void removeAttributeFromManifestById(AndroidManifestBlock androidM
8585
}
8686
return;
8787
}
88-
int removed = manifestElement.removeAttributesWithId(resourceId);
89-
if (removed > 0 && logger != null) {
88+
boolean removed = manifestElement.removeAttributesWithId(resourceId);
89+
if (removed && logger != null) {
9090
logger.logMessage("Removed-attribute : " + HexUtil.toHex8("@0x", resourceId));
9191
}
9292
}
@@ -104,50 +104,22 @@ public static void removeAttributeFromManifestAndApplication(AndroidManifestBloc
104104
}
105105
return;
106106
}
107-
int removed = manifestElement.removeAttributesWithId(resourceId);
107+
boolean removed = manifestElement.removeAttributesWithId(resourceId);
108108
ResXmlElement applicationElement = manifestElement.getElement(
109109
AndroidManifest.TAG_application);
110-
if(removed > 1){
111-
if(logger != null){
112-
logger.logMessage("Duplicate attributes on <manifest> removed: "
113-
+ HexUtil.toHex8("0x", resourceId));
114-
}
110+
111+
if(removed && logger != null) {
112+
logger.logMessage("Attributes on <manifest> removed: "
113+
+ HexUtil.toHex8("0x", resourceId) + " (" + nameForLogging + ")");
115114
}
116115
if(applicationElement == null){
117116
return;
118117
}
119118
removed = applicationElement.removeAttributesWithId(resourceId);
120-
if(removed > 1){
121-
if(logger != null){
122-
logger.logMessage("Duplicate attributes on <application> removed: "
123-
+ HexUtil.toHex8("0x", resourceId));
124-
}
125-
}
126-
if(removed > 0){
127-
if(logger != null){
128-
logger.logMessage("Removed-attribute " + (removed > 1? "(" + removed + "): " : ": ") +
129-
nameForLogging);
130-
}
131-
}
132-
}
133-
@Deprecated
134-
public static int removeApplicationAttribute(AndroidManifestBlock manifestBlock, int resourceId){
135-
if(resourceId == 0){
136-
return 0;
137-
}
138-
ResXmlElement applicationElement = manifestBlock.getApplicationElement();
139-
if(applicationElement == null){
140-
return 0;
141-
}
142-
return applicationElement.removeAttributesWithId(resourceId);
143-
}
144-
public static String getNamedValue(ResXmlElement element) {
145-
ResXmlAttribute attribute = CollectionUtil.getFirst(element.getAttributes(
146-
AndroidManifestHelper::isNameResourceId));
147-
if(attribute == null){
148-
return "<not name attribute>";
119+
if(removed && logger != null) {
120+
logger.logMessage("Attributes on <application> removed: "
121+
+ HexUtil.toHex8("0x", resourceId) + " (" + nameForLogging + ")");
149122
}
150-
return attribute.decodeValue();
151123
}
152124
static boolean isNameResourceId(ResXmlAttribute attribute){
153125
int resourceId = attribute.getNameId();

src/main/java/com/reandroid/apkeditor/info/InfoWriterText.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ public void writeStringPool(String source, StringPool<?> stringPool) throws IOEx
8585
@Override
8686
public void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) throws IOException {
8787
writeNameValue("source-path", sourcePath);
88-
for (ResXmlNode node : xmlDocument) {
88+
Iterator<ResXmlNode> iterator = xmlDocument.iterator();
89+
while (iterator.hasNext()) {
90+
ResXmlNode node = iterator.next();
8991
if (node instanceof ResXmlElement) {
9092
writeElement((ResXmlElement) node);
9193
} else if (node instanceof ResXmlTextNode) {

src/main/java/com/reandroid/apkeditor/info/InfoWriterXml.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ public void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) thro
9494
serializer.startTag(null, name);
9595
serializer.attribute(null, "source-path", sourcePath);
9696
XmlSerializer documentSerializer = newSerializer();
97-
for (ResXmlNode xmlNode : xmlDocument) {
97+
Iterator<ResXmlNode> iterator = xmlDocument.iterator();
98+
while (iterator.hasNext()) {
99+
ResXmlNode xmlNode = iterator.next();
98100
xmlNode.serialize(documentSerializer, false);
99101
}
100102
documentSerializer.flush();

src/main/java/com/reandroid/apkeditor/merge/Merger.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private void sanitizeManifest(ApkModule apkModule) {
170170
splits_removed = removeSplitsTableEntry(meta, apkModule);
171171
}
172172
logMessage("Removed-element : <" + meta.getName() + "> name=\""
173-
+ AndroidManifestHelper.getNamedValue(meta) + "\"");
173+
+ AndroidManifestBlock.getAndroidNameValue(meta) + "\"");
174174
application.remove(meta);
175175
}
176176
manifest.refresh();

src/main/java/com/reandroid/apkeditor/protect/ManifestConfuser.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
2121
import com.reandroid.arsc.chunk.xml.ResXmlAttribute;
2222
import com.reandroid.arsc.chunk.xml.ResXmlElement;
23+
import com.reandroid.arsc.chunk.xml.UnknownResXmlNode;
24+
import com.reandroid.arsc.io.BlockReader;
2325
import com.reandroid.utils.collection.CollectionUtil;
2426

27+
import java.io.IOException;
2528
import java.util.List;
2629
import java.util.Random;
2730

@@ -62,7 +65,11 @@ private void placeBadChunk(AndroidManifestBlock manifestBlock) {
6265
badManifest.setVersionCode(1);
6366
badManifest.setVersionName("1.0");
6467
badManifest.refreshFull();
65-
manifestBlock.getUnexpectedBlockContainer()
66-
.setItem(badManifest);
68+
UnknownResXmlNode unknown = manifestBlock.newUnknown();
69+
try {
70+
unknown.readBytes(new BlockReader(badManifest.getBytes()));
71+
} catch (IOException ignored) {
72+
}
73+
manifestBlock.moveTo(unknown, 0);
6774
}
6875
}

src/main/java/com/reandroid/apkeditor/refactor/TypeNameRefactor.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -515,22 +515,16 @@ private boolean isPreferenceScreen(ResXmlElement root){
515515
if(!"PreferenceScreen".equals(root.getName())){
516516
return false;
517517
}
518-
for(ResXmlElement element:root.listElements()){
519-
String tag = element.getName();
520-
if("PreferenceCategory".equals(tag)){
521-
return true;
522-
}
523-
if("CheckBoxPreference".equals(tag)){
524-
return true;
525-
}
526-
}
527-
return false;
518+
return root.getElement("PreferenceCategory") != null ||
519+
root.getElement("CheckBoxPreference") != null;
528520
}
529521
private boolean isPaths(ResXmlElement root){
530522
if(!"paths".equals(root.getName())){
531523
return false;
532524
}
533-
for(ResXmlElement element:root.listElements()){
525+
Iterator<ResXmlElement> iterator = root.getElements();
526+
while(iterator.hasNext()){
527+
ResXmlElement element = iterator.next();
534528
String tag = element.getName();
535529
if("files-path".equals(tag) || "cache-path".equals(tag)){
536530
return true;

0 commit comments

Comments
 (0)