From 17cbb3eab0a725b7c9946ceda54dbeb9c639b29d Mon Sep 17 00:00:00 2001 From: S-trace Date: Fri, 3 Jan 2020 04:16:22 +0300 Subject: [PATCH] core: Fix possible NPE in DebugInfoParser.addrChange() This may happen because MethodNode.unloadInsnArr() call from BlockSplitter.visit() - after it instructions[] become null. So, try to reload method before processing its instructions array and bail if insnArr still null even after reloading method. --- .../java/jadx/core/dex/nodes/MethodNode.java | 18 +++++++++++------- .../debuginfo/DebugInfoParseVisitor.java | 9 +++++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java index 14c287b4e..889f2ff2c 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/MethodNode.java @@ -155,13 +155,8 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode { public void checkInstructions() { List list = new ArrayList<>(); if (instructions == null) { - LOG.debug("Instructions == null, reloading method {}.{}", getClass().getName(), getName()); - unload(); - try { - load(); - } catch (DecodeException e) { - throw new JadxRuntimeException("Failed to reload method " + getClass().getName() + "." + getName()); - } + LOG.debug("instructions == null, reloading method {}.{}", getClass().getName(), getName()); + reload(); } for (InsnNode insnNode : instructions) { if (insnNode == null) { @@ -182,6 +177,15 @@ public class MethodNode extends LineAttrNode implements ILoadable, ICodeNode { } } + public void reload() { + unload(); + try { + load(); + } catch (DecodeException e) { + throw new JadxRuntimeException("Failed to reload method " + getClass().getName() + "." + getName()); + } + } + public void initMethodTypes() { List types = parseSignature(); if (types == null) { diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java b/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java index 3bc4368ae..e21b5734d 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/debuginfo/DebugInfoParseVisitor.java @@ -48,6 +48,15 @@ public class DebugInfoParseVisitor extends AbstractVisitor { private void processDebugInfo(MethodNode mth, int debugOffset) { InsnNode[] insnArr = mth.getInstructions(); + if (insnArr == null) { + LOG.debug("insnArr == null, reloading method {}.{}", getClass().getName(), mth.getName()); + mth.reload(); + insnArr = mth.getInstructions(); + } + if (insnArr == null) { + LOG.error("insnArr == null even after reloading method {}.{} - bailing", getClass().getName(), mth.getName()); + return; + } DebugInfoParser debugInfoParser = new DebugInfoParser(mth, debugOffset, insnArr); List localVars = debugInfoParser.process(); attachDebugInfo(mth, localVars, insnArr);