Skip to content

Commit

Permalink
Update ARSCLib
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Nov 15, 2024
1 parent 10749cd commit eafe39f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 57 deletions.
Binary file modified libs/ARSCLib.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public static void removeAttributeFromManifestByName(AndroidManifestBlock androi
}
return;
}
int removed = manifestElement.removeAttributesWithName(resourceName);
if (removed > 0 && logger != null) {
logger.logMessage("Removed-attribute : " + resourceName);
boolean removed = manifestElement.removeAttributesWithName(resourceName);
if (removed && logger != null) {
logger.logMessage("Removed-attribute : " + resourceName);
}
}
public static void removeAttributeFromManifestById(AndroidManifestBlock androidManifestBlock,
Expand All @@ -85,8 +85,8 @@ public static void removeAttributeFromManifestById(AndroidManifestBlock androidM
}
return;
}
int removed = manifestElement.removeAttributesWithId(resourceId);
if (removed > 0 && logger != null) {
boolean removed = manifestElement.removeAttributesWithId(resourceId);
if (removed && logger != null) {
logger.logMessage("Removed-attribute : " + HexUtil.toHex8("@0x", resourceId));
}
}
Expand All @@ -104,50 +104,22 @@ public static void removeAttributeFromManifestAndApplication(AndroidManifestBloc
}
return;
}
int removed = manifestElement.removeAttributesWithId(resourceId);
boolean removed = manifestElement.removeAttributesWithId(resourceId);
ResXmlElement applicationElement = manifestElement.getElement(
AndroidManifest.TAG_application);
if(removed > 1){
if(logger != null){
logger.logMessage("Duplicate attributes on <manifest> removed: "
+ HexUtil.toHex8("0x", resourceId));
}

if(removed && logger != null) {
logger.logMessage("Attributes on <manifest> removed: "
+ HexUtil.toHex8("0x", resourceId) + " (" + nameForLogging + ")");
}
if(applicationElement == null){
return;
}
removed = applicationElement.removeAttributesWithId(resourceId);
if(removed > 1){
if(logger != null){
logger.logMessage("Duplicate attributes on <application> removed: "
+ HexUtil.toHex8("0x", resourceId));
}
}
if(removed > 0){
if(logger != null){
logger.logMessage("Removed-attribute " + (removed > 1? "(" + removed + "): " : ": ") +
nameForLogging);
}
}
}
@Deprecated
public static int removeApplicationAttribute(AndroidManifestBlock manifestBlock, int resourceId){
if(resourceId == 0){
return 0;
}
ResXmlElement applicationElement = manifestBlock.getApplicationElement();
if(applicationElement == null){
return 0;
}
return applicationElement.removeAttributesWithId(resourceId);
}
public static String getNamedValue(ResXmlElement element) {
ResXmlAttribute attribute = CollectionUtil.getFirst(element.getAttributes(
AndroidManifestHelper::isNameResourceId));
if(attribute == null){
return "<not name attribute>";
if(removed && logger != null) {
logger.logMessage("Attributes on <application> removed: "
+ HexUtil.toHex8("0x", resourceId) + " (" + nameForLogging + ")");
}
return attribute.decodeValue();
}
static boolean isNameResourceId(ResXmlAttribute attribute){
int resourceId = attribute.getNameId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public void writeStringPool(String source, StringPool<?> stringPool) throws IOEx
@Override
public void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) throws IOException {
writeNameValue("source-path", sourcePath);
for (ResXmlNode node : xmlDocument) {
Iterator<ResXmlNode> iterator = xmlDocument.iterator();
while (iterator.hasNext()) {
ResXmlNode node = iterator.next();
if (node instanceof ResXmlElement) {
writeElement((ResXmlElement) node);
} else if (node instanceof ResXmlTextNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ public void writeXmlDocument(String sourcePath, ResXmlDocument xmlDocument) thro
serializer.startTag(null, name);
serializer.attribute(null, "source-path", sourcePath);
XmlSerializer documentSerializer = newSerializer();
for (ResXmlNode xmlNode : xmlDocument) {
Iterator<ResXmlNode> iterator = xmlDocument.iterator();
while (iterator.hasNext()) {
ResXmlNode xmlNode = iterator.next();
xmlNode.serialize(documentSerializer, false);
}
documentSerializer.flush();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/reandroid/apkeditor/merge/Merger.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ private void sanitizeManifest(ApkModule apkModule) {
splits_removed = removeSplitsTableEntry(meta, apkModule);
}
logMessage("Removed-element : <" + meta.getName() + "> name=\""
+ AndroidManifestHelper.getNamedValue(meta) + "\"");
+ AndroidManifestBlock.getAndroidNameValue(meta) + "\"");
application.remove(meta);
}
manifest.refresh();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.arsc.chunk.xml.ResXmlAttribute;
import com.reandroid.arsc.chunk.xml.ResXmlElement;
import com.reandroid.arsc.chunk.xml.UnknownResXmlNode;
import com.reandroid.arsc.io.BlockReader;
import com.reandroid.utils.collection.CollectionUtil;

import java.io.IOException;
import java.util.List;
import java.util.Random;

Expand Down Expand Up @@ -62,7 +65,11 @@ private void placeBadChunk(AndroidManifestBlock manifestBlock) {
badManifest.setVersionCode(1);
badManifest.setVersionName("1.0");
badManifest.refreshFull();
manifestBlock.getUnexpectedBlockContainer()
.setItem(badManifest);
UnknownResXmlNode unknown = manifestBlock.newUnknown();
try {
unknown.readBytes(new BlockReader(badManifest.getBytes()));
} catch (IOException ignored) {
}
manifestBlock.moveTo(unknown, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -515,22 +515,16 @@ private boolean isPreferenceScreen(ResXmlElement root){
if(!"PreferenceScreen".equals(root.getName())){
return false;
}
for(ResXmlElement element:root.listElements()){
String tag = element.getName();
if("PreferenceCategory".equals(tag)){
return true;
}
if("CheckBoxPreference".equals(tag)){
return true;
}
}
return false;
return root.getElement("PreferenceCategory") != null ||
root.getElement("CheckBoxPreference") != null;
}
private boolean isPaths(ResXmlElement root){
if(!"paths".equals(root.getName())){
return false;
}
for(ResXmlElement element:root.listElements()){
Iterator<ResXmlElement> iterator = root.getElements();
while(iterator.hasNext()){
ResXmlElement element = iterator.next();
String tag = element.getName();
if("files-path".equals(tag) || "cache-path".equals(tag)){
return true;
Expand Down

0 comments on commit eafe39f

Please sign in to comment.