core: fix 'break' detection in loops
This commit is contained in:
@@ -10,16 +10,15 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestReturnWrapping extends InternalJadxTest {
|
||||
public static class TestCls {
|
||||
/**/
|
||||
|
||||
public static int f1(int arg0) {
|
||||
switch (arg0) {
|
||||
case 1:
|
||||
return 255;
|
||||
}
|
||||
return arg0 + 1;
|
||||
}/**/
|
||||
}
|
||||
|
||||
/**/
|
||||
public static Object f2(Object arg0, int arg1) {
|
||||
Object ret = null;
|
||||
int i = arg1;
|
||||
@@ -34,9 +33,8 @@ public class TestReturnWrapping extends InternalJadxTest {
|
||||
}
|
||||
return i > 128 ? arg0.toString() + ret.toString() : i;
|
||||
}
|
||||
}/**/
|
||||
}
|
||||
|
||||
/**/
|
||||
public static int f3(int arg0) {
|
||||
while (arg0 > 10) {
|
||||
int abc = 951;
|
||||
@@ -46,7 +44,7 @@ public class TestReturnWrapping extends InternalJadxTest {
|
||||
arg0 -= abc;
|
||||
}
|
||||
return arg0;
|
||||
}/**/
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -56,7 +54,6 @@ public class TestReturnWrapping extends InternalJadxTest {
|
||||
|
||||
assertThat(code, containsString("return 255;"));
|
||||
assertThat(code, containsString("return arg0 + 1;"));
|
||||
//assertThat(code, containsString("return Integer.toHexString(i);"));
|
||||
assertThat(code, containsString("return i > 128 ? arg0.toString() + ret.toString() : Integer.valueOf(i);"));
|
||||
assertThat(code, containsString("return arg0 + 2;"));
|
||||
assertThat(code, containsString("arg0 -= 951;"));
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package jadx.tests.internal.loops;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestBreakInLoop extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
private int f;
|
||||
|
||||
private void test(int[] a, int b) {
|
||||
int i = 0;
|
||||
while (i < a.length) {
|
||||
a[i]++;
|
||||
if (i < b) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
this.f++;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertEquals(count(code, "this.f++;"), 1);
|
||||
assertThat(code, containsString("if (i < b) {"));
|
||||
assertThat(code, containsString("break;"));
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,7 @@ import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestLoopCondition extends InternalJadxTest {
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class TestCls extends Exception {
|
||||
public static class TestCls {
|
||||
public String f;
|
||||
|
||||
private void setEnabled(boolean r1z) {
|
||||
@@ -32,14 +31,6 @@ public class TestLoopCondition extends InternalJadxTest {
|
||||
setEnabled(false);
|
||||
}
|
||||
|
||||
public int testComplexIfInLoop(boolean a) {
|
||||
int i = 0;
|
||||
while (a && i < 10) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
private void testMoreComplexIfInLoop(java.util.ArrayList<String> list) throws Exception {
|
||||
for (int i = 0; i != 16 && i < 255; i++) {
|
||||
list.set(i, "ABC");
|
||||
@@ -55,9 +46,9 @@ public class TestLoopCondition extends InternalJadxTest {
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("i < this.f.length()"));
|
||||
assertThat(code, containsString("while (a && i < 10) {"));
|
||||
assertThat(code, containsString("list.set(i, \"ABC\")"));
|
||||
assertThat(code, containsString("list.set(i, \"DEF\")"));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
package jadx.tests.internal.loops;
|
||||
|
||||
import jadx.api.InternalJadxTest;
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestLoopCondition2 extends InternalJadxTest {
|
||||
|
||||
public static class TestCls {
|
||||
|
||||
public int test(boolean a) {
|
||||
int i = 0;
|
||||
while (a && i < 10) {
|
||||
i++;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
System.out.println(code);
|
||||
|
||||
assertThat(code, containsString("while (a && i < 10) {"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user