REAndroid / APKEditor

Powerful android apk editor - aapt/aapt2 independent
Apache License 2.0
647 stars 95 forks source link

Apk decompilation error (xml type) #31

Closed kiber-io closed 1 year ago

kiber-io commented 1 year ago

hi!

I use the latest version - 1.2.1. previously I used the json type for decompilation, now I switched to xml and immediately caught an error where it was not on json. if you try to disassemble the attached apk using the json type, then everything happens correctly. but if you try to parse it in xml, the utility crashes with an error at the moment of decompilation

here is the decompilation log in xml:

java -jar .\bin\apkeditor.jar d -t xml -i .\app.apk
00.000 I: [DECOMPILE] Decompiling ...
   Input: .\app.apk
 Output: .\app_decompile_xml
 Type: xml
 ----------------------------
00.019 I: [DECOMPILE] Loading ...
00.244 I: [DECOMPILE] Initializing android framework ...
00.244 I: [DECOMPILE] Loading android framework for version: 31
00.299 I: [DECOMPILE] Initialized framework: android-31
00.299 I: [DECOMPILE] Decompiling to XML ...
00.322 I: [DECOMPILE] [SANITIZE]: Sanitizing paths ...
00.327 I: [DECOMPILE] [SANITIZE]: DONE = 1703
00.328 I: [DECOMPILE] Decoding ...
00.328 I: [DECOMPILE] Validating resource names ...
00.397 I: [DECOMPILE] Decoding: AndroidManifest.xml
00.452 I: [DECOMPILE] Decoding public.xml: 0-com.perm.kate
00.477 I: [DECOMPILE] Decoding resource files ...
06.384 [DECOMPILE] Decoding: res\layout\sticker_preview.xml
06.390 I: [DECOMPILE] Decoding values: 0-com.perm.kate

ERROR:
Cannot invoke "String.indexOf(int)" because "value" is null
java.io.IOException: Cannot invoke "String.indexOf(int)" because "value" is null
        at com.reandroid.apkeditor.decompile.Decompiler.run(Decompiler.java:72)
        at com.reandroid.apkeditor.decompile.Decompiler.execute(Decompiler.java:131)
        at com.reandroid.apkeditor.Main.execute(Main.java:61)
        at com.reandroid.apkeditor.Main.main(Main.java:38)
Caused by: java.lang.NullPointerException: Cannot invoke "String.indexOf(int)" because "value" is null
        at com.android.org.kxml2.io.KXmlSerializer.attribute(KXmlSerializer.java:432)
        at com.reandroid.apk.xmldecoder.EntryWriterSerializer.attribute(EntryWriterSerializer.java:52)
        at com.reandroid.apk.xmldecoder.EntryWriterSerializer.attribute(EntryWriterSerializer.java:23)
        at com.reandroid.apk.xmldecoder.BagDecoderAttr.decode(BagDecoderAttr.java:58)
        at com.reandroid.apk.xmldecoder.BagDecoderAttr.decode(BagDecoderAttr.java:27)
        at com.reandroid.apk.xmldecoder.DecoderResTableEntryMap.decode(DecoderResTableEntryMap.java:40)
        at com.reandroid.apk.xmldecoder.XMLEntryDecoder.decode(XMLEntryDecoder.java:61)
        at com.reandroid.apk.xmldecoder.XMLEntryDecoder.decode(XMLEntryDecoder.java:92)
        at com.reandroid.apk.xmldecoder.XMLEntryDecoderSerializer.decode(XMLEntryDecoderSerializer.java:86)
        at com.reandroid.apk.xmldecoder.XMLEntryDecoderSerializer.decodeUniqueConfigs(XMLEntryDecoderSerializer.java:73)
        at com.reandroid.apk.xmldecoder.XMLEntryDecoderSerializer.decode(XMLEntryDecoderSerializer.java:51)
        at com.reandroid.apk.ApkModuleXmlDecoder.decodeValues(ApkModuleXmlDecoder.java:296)
        at com.reandroid.apk.ApkModuleXmlDecoder.decodeValues(ApkModuleXmlDecoder.java:292)
        at com.reandroid.apk.ApkModuleXmlDecoder.decodeValues(ApkModuleXmlDecoder.java:279)
        at com.reandroid.apk.ApkModuleXmlDecoder.onDecodeTo(ApkModuleXmlDecoder.java:100)
        at com.reandroid.apk.ApkDecoder.decodeTo(ApkDecoder.java:37)
        at com.reandroid.apkeditor.decompile.Decompiler.run(Decompiler.java:70)
        ... 3 more

and here is the decompilation in json:

java -jar .\bin\apkeditor.jar d -t json -i .\app.apk
00.000 I: [DECOMPILE] Decompiling ...
   Input: .\app.apk
 Output: .\app_decompile_json
 Type: json
 Split: false
 ---------------------------- 
00.022 I: [DECOMPILE] Loading ...
00.222 I: [DECOMPILE] Initializing android framework ...
00.223 I: [DECOMPILE] Loading android framework for version: 31
00.272 I: [DECOMPILE] Initialized framework: android-31
00.272 I: [DECOMPILE] Decompiling to JSON ...
00.289 I: [DECOMPILE] [SANITIZE]: Sanitizing paths ...
00.291 I: [DECOMPILE] [SANITIZE]: DONE = 1703
01.958 I: [DECOMPILE] Dumping signatures ...
01.961 I: [DECOMPILE] Saved to: .\app_decompile_json
01.961 I: [DECOMPILE] Done

APK: https://drive.google.com/file/d/1Uc6-C3WrHgNDp_6DsfR3oyOy17gsq0NC/view?usp=sharing

REAndroid commented 1 year ago

Obfuscated apk decoding/encoding to XML is not fully supported (check README). Use instead JSON format for obfuscated apk files.

This issue is solved as on refereed commits and the release is also updated.