From 7b18d3a3a85ee030da59438436b8d7012796341a Mon Sep 17 00:00:00 2001 From: Ahmed Ashour Date: Mon, 8 Apr 2019 12:04:45 +0200 Subject: [PATCH] fix: ignore not generated insns in CodeShrinker visitor (PR #560) --- .../src/main/java/jadx/core/dex/nodes/InsnNode.java | 12 ++++++++++-- .../tests/integration/trycatch/TestFinally2.java | 10 +--------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java b/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java index 64a95fbe1..1a8ee51c2 100644 --- a/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java +++ b/jadx-core/src/main/java/jadx/core/dex/nodes/InsnNode.java @@ -6,10 +6,12 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import com.android.dx.io.instructions.DecodedInstruction; -import com.rits.cloning.Cloner; import org.jetbrains.annotations.Nullable; +import com.android.dx.io.instructions.DecodedInstruction; +import com.rits.cloning.Cloner; + +import jadx.core.dex.attributes.AFlag; import jadx.core.dex.attributes.nodes.LineAttrNode; import jadx.core.dex.instructions.InsnType; import jadx.core.dex.instructions.args.ArgType; @@ -195,6 +197,12 @@ public class InsnNode extends LineAttrNode { } public boolean canReorder() { + if (contains(AFlag.DONT_GENERATE)) { + if (getType() == InsnType.MONITOR_EXIT) { + return false; + } + return true; + } switch (getType()) { case CONST: case CONST_STR: diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java index 22daaf9ad..b7d1d288e 100644 --- a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestFinally2.java @@ -6,7 +6,6 @@ import java.io.InputStream; import org.junit.jupiter.api.Test; -import jadx.NotYetImplemented; import jadx.core.dex.nodes.ClassNode; import jadx.tests.api.IntegrationTest; @@ -59,14 +58,7 @@ public class TestFinally2 extends IntegrationTest { String code = cls.getCode().toString(); assertThat(code, containsOne("decode(inputStream);")); - } - - @Test - @NotYetImplemented - public void test2() { - ClassNode cls = getClassNode(TestCls.class); - String code = cls.getCode().toString(); - + assertThat(code, containsOne("return new Result(400);")); assertThat(code, not(containsOne("result ="))); } }