From 8f7d1a897df243a8fafcaec6c193477e73f54ef3 Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Sun, 23 Oct 2016 13:15:32 -0700 Subject: [PATCH] Fix null start/end locations in SmaliCodeFragmentFactory.evaluateRegister --- .../debugging/SmaliCodeFragmentFactory.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/smalidea/src/main/java/org/jf/smalidea/debugging/SmaliCodeFragmentFactory.java b/smalidea/src/main/java/org/jf/smalidea/debugging/SmaliCodeFragmentFactory.java index 94a5076d..82a190b7 100644 --- a/smalidea/src/main/java/org/jf/smalidea/debugging/SmaliCodeFragmentFactory.java +++ b/smalidea/src/main/java/org/jf/smalidea/debugging/SmaliCodeFragmentFactory.java @@ -61,6 +61,7 @@ import org.jf.smalidea.psi.impl.SmaliMethod; import org.jf.smalidea.util.NameUtils; import org.jf.smalidea.util.PsiUtil; +import javax.annotation.Nullable; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.List; @@ -274,6 +275,7 @@ public class SmaliCodeFragmentFactory extends DefaultCodeFragmentFactory { return originalContext; } + @Nullable public static Value evaluateRegister(EvaluationContext context, final SmaliMethod smaliMethod, final int registerNum, final String type) throws EvaluateException { @@ -308,12 +310,21 @@ public class SmaliCodeFragmentFactory extends DefaultCodeFragmentFactory { for (SmaliInstruction instruction: smaliMethod.getInstructions()) { methodSize += instruction.getInstructionSize(); } - Location endLocation = method.locationOfCodeIndex((methodSize/2) - 1); + Location endLocation = null; + for (int endCodeIndex = (methodSize/2) - 1; endCodeIndex >= 0; endCodeIndex--) { + endLocation = method.locationOfCodeIndex(endCodeIndex); + if (endLocation != null) { + break; + } + } + if (endLocation == null) { + return null; + } LocalVariable localVariable = localVariableConstructor.newInstance(vm, method, mapRegister(frameProxy.getStackFrame().virtualMachine(), smaliMethod, registerNum), - method.locationOfCodeIndex(0), + method.location(), endLocation, String.format("v%d", registerNum), type, null);