core: refactor fill-array instruction processing and constants replace (fix #48)
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
package jadx.tests.integration.arrays;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestArrayFillConstReplace extends IntegrationTest {
|
||||
|
||||
public static class TestCls {
|
||||
public static final int CONST_INT = 0xffff;
|
||||
|
||||
public int[] test() {
|
||||
return new int[]{127, 129, CONST_INT};
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("return new int[]{127, 129, CONST_INT};"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package jadx.tests.integration.arrays;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.IntegrationTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.hamcrest.CoreMatchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestArrays2 extends IntegrationTest {
|
||||
public static class TestCls {
|
||||
|
||||
private static Object test4(int type) {
|
||||
if (type == 1) {
|
||||
return new int[]{1, 2};
|
||||
} else if (type == 2) {
|
||||
return new float[]{1, 2};
|
||||
} else if (type == 3) {
|
||||
return new short[]{1, 2};
|
||||
} else if (type == 4) {
|
||||
return new byte[]{1, 2};
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void check() {
|
||||
assertThat(test4(4), instanceOf(byte[].class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
noDebugInfo();
|
||||
ClassNode cls = getClassNode(TestCls.class);
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("new int[]{1, 2}"));
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ public class TestFallbackMode extends IntegrationTest {
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsString("public int test(int r2) {"));
|
||||
assertThat(code, containsString("r1_this = this;"));
|
||||
assertThat(code, containsString("r1 = this;"));
|
||||
assertThat(code, containsString("L_0x0004:"));
|
||||
assertThat(code, not(containsString("throw new UnsupportedOperationException")));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package jadx.tests.smali;
|
||||
|
||||
import jadx.core.dex.nodes.ClassNode;
|
||||
import jadx.tests.api.SmaliTest;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static jadx.tests.api.utils.JadxMatchers.containsOne;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class TestArithConst extends SmaliTest {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
noDebugInfo();
|
||||
ClassNode cls = getClassNodeFromSmali("TestArithConst");
|
||||
String code = cls.getCode().toString();
|
||||
|
||||
assertThat(code, containsOne("return i + CONST_INT;"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
.class public LTestArithConst;
|
||||
.super Ljava/lang/Object;
|
||||
|
||||
.field public static final CONST_INT:I = 0xff
|
||||
|
||||
.method private test(I)I
|
||||
.registers 2
|
||||
|
||||
add-int/lit16 v0, p1, 0xff
|
||||
|
||||
return v0
|
||||
.end method
|
||||
Reference in New Issue
Block a user