diff --git a/jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfInfo.java b/jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfInfo.java index 7142be80f..e0a18cf2b 100644 --- a/jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfInfo.java +++ b/jadx-core/src/main/java/jadx/core/dex/regions/conditions/IfInfo.java @@ -3,8 +3,6 @@ package jadx.core.dex.regions.conditions; import jadx.core.dex.nodes.BlockNode; import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; import java.util.Set; public final class IfInfo { @@ -12,13 +10,13 @@ public final class IfInfo { private final Set mergedBlocks; private final BlockNode thenBlock; private final BlockNode elseBlock; - private final List skipBlocks; + private final Set skipBlocks; private BlockNode outBlock; @Deprecated private BlockNode ifBlock; public IfInfo(IfCondition condition, BlockNode thenBlock, BlockNode elseBlock) { - this(condition, thenBlock, elseBlock, new HashSet(), new LinkedList()); + this(condition, thenBlock, elseBlock, new HashSet(), new HashSet()); } public IfInfo(IfCondition condition, IfInfo info) { @@ -30,7 +28,7 @@ public final class IfInfo { } private IfInfo(IfCondition condition, BlockNode thenBlock, BlockNode elseBlock, - Set mergedBlocks, List skipBlocks) { + Set mergedBlocks, Set skipBlocks) { this.condition = condition; this.thenBlock = thenBlock; this.elseBlock = elseBlock; @@ -47,6 +45,13 @@ public final class IfInfo { return tmpIf; } + public void merge(IfInfo... arr) { + for (IfInfo info : arr) { + mergedBlocks.addAll(info.getMergedBlocks()); + skipBlocks.addAll(info.getSkipBlocks()); + } + } + public IfCondition getCondition() { return condition; } @@ -55,6 +60,10 @@ public final class IfInfo { return mergedBlocks; } + public Set getSkipBlocks() { + return skipBlocks; + } + public BlockNode getThenBlock() { return thenBlock; } @@ -71,10 +80,6 @@ public final class IfInfo { this.outBlock = outBlock; } - public List getSkipBlocks() { - return skipBlocks; - } - public BlockNode getIfBlock() { return ifBlock; } diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IfMakerHelper.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IfMakerHelper.java index 33cc43306..b1106ca22 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IfMakerHelper.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/IfMakerHelper.java @@ -190,12 +190,7 @@ public class IfMakerHelper { nextThen.getCondition(), nextElse.getCondition()); IfInfo result = new IfInfo(newCondition, nextThen.getThenBlock(), nextThen.getElseBlock()); result.setIfBlock(currentIf.getIfBlock()); - result.getMergedBlocks().addAll(currentIf.getMergedBlocks()); - result.getMergedBlocks().addAll(nextThen.getMergedBlocks()); - result.getMergedBlocks().addAll(nextElse.getMergedBlocks()); - result.getSkipBlocks().addAll(currentIf.getSkipBlocks()); - result.getSkipBlocks().addAll(nextThen.getSkipBlocks()); - result.getSkipBlocks().addAll(nextElse.getSkipBlocks()); + result.merge(currentIf, nextThen, nextElse); confirmMerge(result); return result; } @@ -215,10 +210,7 @@ public class IfMakerHelper { IfCondition condition = IfCondition.merge(mergeOperation, first.getCondition(), second.getCondition()); IfInfo result = new IfInfo(condition, second); result.setIfBlock(first.getIfBlock()); - result.getMergedBlocks().addAll(first.getMergedBlocks()); - result.getMergedBlocks().addAll(second.getMergedBlocks()); - result.getSkipBlocks().addAll(first.getSkipBlocks()); - result.getSkipBlocks().addAll(second.getSkipBlocks()); + result.merge(first, second); BlockNode otherPathBlock = followThenBranch ? first.getElseBlock() : first.getThenBlock(); skipSimplePath(otherPathBlock, result.getSkipBlocks()); @@ -303,7 +295,7 @@ public class IfMakerHelper { return null; } - private static void skipSimplePath(BlockNode block, List skipped) { + private static void skipSimplePath(BlockNode block, Set skipped) { while (block != null && block.getCleanSuccessors().size() < 2 && block.getPredecessors().size() == 1) { diff --git a/jadx-core/src/test/java/jadx/tests/internal/conditions/TestConditions15.java b/jadx-core/src/test/java/jadx/tests/internal/conditions/TestConditions15.java new file mode 100644 index 000000000..b268d8424 --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/internal/conditions/TestConditions15.java @@ -0,0 +1,70 @@ +package jadx.tests.internal.conditions; + +import jadx.api.InternalJadxTest; +import jadx.core.dex.nodes.ClassNode; + +import org.junit.Test; + +import static jadx.tests.utils.JadxMatchers.containsOne; +import static org.junit.Assert.assertThat; + +public class TestConditions15 extends InternalJadxTest { + + public static class TestCls { + + private static boolean test(final String name) { + if (isEmpty(name)) { + return false; + } + if ("1".equals(name) + || "2".equals(name) + || "3".equals(name) + || "4".equals(name) + || "5".equals(name) + || "6".equals(name) + || "7".equals(name) + || "8".equals(name) + || "9".equals(name) + || "10".equals(name) + || "11".equals(name) + || "12".equals(name) + || "13".equals(name) + || "14".equals(name) + || "15".equals(name) + || "16".equals(name) + || "17".equals(name) + || "18".equals(name) + || "19".equals(name) + || "20".equals(name) + || "22".equals(name) + || "22".equals(name) + || "23".equals(name) + || "24".equals(name) + || "25".equals(name) + || "26".equals(name) + || "27".equals(name) + || "28".equals(name) + || "29".equals(name) + || "30".equals(name)) { + return false; + } else { + return true; + } + } + + private static boolean isEmpty(String name) { + return name.isEmpty(); + } + } + + @Test + public void test() { + ClassNode cls = getClassNode(TestCls.class); + String code = cls.getCode().toString(); + System.out.println(code); + + assertThat(code, containsOne("\"1\".equals(name)")); + assertThat(code, containsOne("\"30\".equals(name)")); + + } +}