REAndroid / ARSCLib

Android binary resources read/write library
Apache License 2.0
220 stars 44 forks source link

`ResXmlDocument#decodeToXml()` is not processing namespaces correctly #60

Closed MuntashirAkon closed 1 year ago

MuntashirAkon commented 1 year ago
ResXmlDocument xmlBlock = new ResXmlDocument();
try (BlockReader reader = new BlockReader(byteBuffer.array())) {
    xmlBlock.readBytes(reader);
    xmlBlock.setPackageBlock(getFrameworkPackageBlock());
    return xmlBlock.decodeToXml();
}

For Google Play Services, it's throwing an IllegalArgumentException.

java.lang.IllegalArgumentException: Namespace not found for prefix: ns2
    at com.reandroid.xml.XMLElement.setName(XMLElement.java:397)
    at com.reandroid.xml.XMLElement.setName(XMLElement.java:377)
    at com.reandroid.xml.XMLElement.<init>(XMLElement.java:42)
    at com.reandroid.arsc.chunk.xml.ResXmlElement.decodeToXml(ResXmlElement.java:1430)
    at com.reandroid.arsc.chunk.xml.ResXmlElement.decodeToXml(ResXmlElement.java:1452)
    at com.reandroid.arsc.chunk.xml.ResXmlDocument.decodeToXml(ResXmlDocument.java:488)
    at io.github.muntashirakon.AppManager.apk.parser.AndroidBinXmlDecoder.decodeToXml(AndroidBinXmlDecoder.java:5)
MuntashirAkon commented 1 year ago

Related issue: https://github.com/MuntashirAkon/AppManager/issues/1164

ResXmlPullParser is working correctly as expected.

REAndroid commented 1 year ago

Try ResXmlDocument#autoSetAttributeNamespaces just before decoding, this will automatically fixes any errors on namespaces. Maybe you need to do the same for attribute names autoSetAttributeNames

MuntashirAkon commented 1 year ago

Try ResXmlDocument#autoSetAttributeNamespaces just before decoding, this will automatically fixes any errors on namespaces. Maybe you need to do the same for attribute names autoSetAttributeNames

Didn't work. The issue persists.

REAndroid commented 1 year ago

You are right, i didn't test but fixed with : https://github.com/REAndroid/ARSCLib/commit/d20b0a8ee2dffb63912cfd923eac932f7a7e323c

MuntashirAkon commented 1 year ago

Thanks.