From 66e6613d3c3ebbec49e74e0652329a994c2ede62 Mon Sep 17 00:00:00 2001 From: Skylot Date: Tue, 1 Dec 2020 16:20:50 +0300 Subject: [PATCH] wip: handle empty loop body (#1040) --- .../dex/visitors/regions/RegionMaker.java | 7 +++- .../trycatch/TestLoopInTryCatch.java | 16 +++++++++ .../smali/trycatch/TestLoopInTryCatch.smali | 34 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 jadx-core/src/test/java/jadx/tests/integration/trycatch/TestLoopInTryCatch.java create mode 100644 jadx-core/src/test/smali/trycatch/TestLoopInTryCatch.smali diff --git a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java index b937cc33..d2b21932 100644 --- a/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java +++ b/jadx-core/src/main/java/jadx/core/dex/visitors/regions/RegionMaker.java @@ -224,7 +224,12 @@ public class RegionMaker { } stack.addExit(out); BlockNode loopBody = condInfo.getThenBlock(); - Region body = makeRegion(loopBody, stack); + Region body; + if (loopBody.contains(AFlag.LOOP_START)) { + body = new Region(loopRegion); + } else { + body = makeRegion(loopBody, stack); + } // add blocks from loop start to first condition block BlockNode conditionBlock = condInfo.getIfBlock(); if (loopStart != conditionBlock) { diff --git a/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestLoopInTryCatch.java b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestLoopInTryCatch.java new file mode 100644 index 00000000..56164b8f --- /dev/null +++ b/jadx-core/src/test/java/jadx/tests/integration/trycatch/TestLoopInTryCatch.java @@ -0,0 +1,16 @@ +package jadx.tests.integration.trycatch; + +import jadx.tests.api.SmaliTest; + +import org.junit.jupiter.api.Test; + +import static jadx.tests.api.utils.assertj.JadxAssertions.assertThat; + +public class TestLoopInTryCatch extends SmaliTest { + @Test + public void test() { + assertThat(getClassNodeFromSmali()) + .code() + .containsOne("while ("); + } +} diff --git a/jadx-core/src/test/smali/trycatch/TestLoopInTryCatch.smali b/jadx-core/src/test/smali/trycatch/TestLoopInTryCatch.smali new file mode 100644 index 00000000..b616cadc --- /dev/null +++ b/jadx-core/src/test/smali/trycatch/TestLoopInTryCatch.smali @@ -0,0 +1,34 @@ +.class public Ltrycatch/TestLoopInTryCatch; +.super Ljava/lang/Object; +.source "SourceFile" + +.method public static test()V + .registers 6 + + :try_start + + :loop + + const/4 v1, 0x0 + + const/4 v2, 0x1 + + if-eq v1, v2, :cond + + const/4 v3, 0x2 + + if-eq v1, v3, :cond + + goto :loop + + :cond + if-eq v1, v2, :end + + return-void + + :try_end + .catch Ljava/io/IOException; {:try_start .. :try_end} :end + + :end + return-void +.end method -- GitLab