skylot / jadx

Dex to Java decompiler
Apache License 2.0
41.67k stars 4.88k forks source link

java.lang.NullPointerException #1575

Closed Luffitys closed 2 years ago

Luffitys commented 2 years ago

Please describe what you did before the error occurred. Trying to debug the app, during the launch jadx had this issue. IMPORTANT! If the error occurs with a specific APK file please attach or provide link to apk file! https://www.celsoazevedo.com/files/android/google-camera/dev-bsg/f/dl92/

java.lang.NullPointerException
    at jadx.gui.device.debugger.smali.Smali.fmtSwitchPayload(Smali.java:766)
    at jadx.gui.device.debugger.smali.Smali.fmtPayloadInsn(Smali.java:736)
    at jadx.gui.device.debugger.smali.Smali.formatInsn(Smali.java:344)
    at jadx.gui.device.debugger.smali.Smali.decodeInsn(Smali.java:336)
    at jadx.gui.device.debugger.smali.Smali.lambda$writeMethod$2(Smali.java:292)
    at jadx.plugins.input.dex.sections.DexCodeReader.visitInstructions(DexCodeReader.java:85)
    at jadx.gui.device.debugger.smali.Smali.writeMethod(Smali.java:291)
    at jadx.gui.device.debugger.smali.Smali.lambda$writeClass$1(Smali.java:219)
    at jadx.plugins.input.dex.sections.DexClassData.readMethods(DexClassData.java:170)
    at jadx.plugins.input.dex.sections.DexClassData.visitMethods(DexClassData.java:145)
    at jadx.plugins.input.dex.sections.DexClassData.visitFieldsAndMethods(DexClassData.java:112)
    at jadx.gui.device.debugger.smali.Smali.writeClass(Smali.java:203)
    at jadx.gui.device.debugger.smali.Smali.disassemble(Smali.java:86)
    at jadx.gui.device.debugger.DbgUtils.lambda$getSmali$0(DbgUtils.java:32)
    at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1134)
    at jadx.gui.device.debugger.DbgUtils.getSmali(DbgUtils.java:31)
    at jadx.gui.device.debugger.DebugController.openMainActivityTab(DebugController.java:109)
    at jadx.gui.device.debugger.DebugController.lambda$stopAtOnCreate$0(DebugController.java:121)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
    at java.base/java.lang.Thread.run(Thread.java:829)
jpstotz commented 2 years ago

Thanks for reporting.

The problematic code line that throws NullPointerException is:

int opcodeOffset = line.payloadOffsetMap.get(curOffset);

line and payloadOffsetMap seem to be always not null, so the exception should be caused by a conversion from Integer to int of a null value (the map has no entry for curOffset).

@Luffitys Can you please tell use which of the linked APK files you were viewing (and which class) when the error occurred?

Luffitys commented 2 years ago

@jpstotz All the APKs are fundamentally the same, but with a different package name. In this case, I used “MGC_8.4.600_A10_V13_snap.apk”. In my settings, I have auto decompilation turned on, so the APK was already decompiled. I attached the debugger to my phone and started launched the app, without opening any classes.

skylot commented 2 years ago

Fixed. Issue was in code generator for debug smali, it expects switch payload after switch instruction, but this is not correct and order can be reversed. I add another instructions pass to collect this data before actual code generation.