From 26a4f1e6033941fd3b309f7c50423ed8559a848d Mon Sep 17 00:00:00 2001 From: Ben Gruver Date: Sun, 11 Sep 2016 11:14:27 -0700 Subject: [PATCH] Fix an issue with instance-of type inference We should only infer the register type after an if-eqz/nez if it has a single predecessor that is the instance-of instruction. --- .../java/org/jf/dexlib2/analysis/AnalyzedInstruction.java | 3 ++- .../main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dexlib2/src/main/java/org/jf/dexlib2/analysis/AnalyzedInstruction.java b/dexlib2/src/main/java/org/jf/dexlib2/analysis/AnalyzedInstruction.java index be7b20f5..111913cc 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/analysis/AnalyzedInstruction.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/analysis/AnalyzedInstruction.java @@ -368,7 +368,8 @@ public class AnalyzedInstruction implements Comparable { return false; } - if (instruction.getOpcode() == Opcode.IF_EQZ || instruction.getOpcode() == Opcode.IF_NEZ) { + if (getPredecessorCount() == 1 && (instruction.getOpcode() == Opcode.IF_EQZ || + instruction.getOpcode() == Opcode.IF_NEZ)) { AnalyzedInstruction previousInstruction = getPreviousInstruction(); if (previousInstruction != null && previousInstruction.instruction.getOpcode() == Opcode.INSTANCE_OF && diff --git a/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java b/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java index 6c99db38..64275402 100644 --- a/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java +++ b/dexlib2/src/main/java/org/jf/dexlib2/analysis/MethodAnalyzer.java @@ -1206,7 +1206,10 @@ public class MethodAnalyzer { private void analyzeIfEqzNez(@Nonnull AnalyzedInstruction analyzedInstruction) { int instructionIndex = analyzedInstruction.getInstructionIndex(); if (instructionIndex > 0) { - AnalyzedInstruction prevAnalyzedInstruction = analyzedInstructions.valueAt(instructionIndex - 1); + if (analyzedInstruction.getPredecessorCount() != 1) { + return; + } + AnalyzedInstruction prevAnalyzedInstruction = analyzedInstruction.getPredecessors().first(); if (prevAnalyzedInstruction.instruction.getOpcode() == Opcode.INSTANCE_OF) { if (canNarrowAfterInstanceOf(prevAnalyzedInstruction, analyzedInstruction, classPath)) { List narrowingRegisters = Lists.newArrayList();