Search in sources :

Example 61 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class JavaClass method load.

private void load() {
    JadxDecompiler rootDecompiler = getRootDecompiler();
    int inClsCount = cls.getInnerClasses().size();
    if (inClsCount != 0) {
        List<JavaClass> list = new ArrayList<JavaClass>(inClsCount);
        for (ClassNode inner : cls.getInnerClasses()) {
            if (!inner.contains(AFlag.DONT_GENERATE)) {
                JavaClass javaClass = new JavaClass(inner, this);
                javaClass.load();
                list.add(javaClass);
                rootDecompiler.getClassesMap().put(inner, javaClass);
            }
        }
        this.innerClasses = Collections.unmodifiableList(list);
    }
    int fieldsCount = cls.getFields().size();
    if (fieldsCount != 0) {
        List<JavaField> flds = new ArrayList<JavaField>(fieldsCount);
        for (FieldNode f : cls.getFields()) {
            if (!f.contains(AFlag.DONT_GENERATE)) {
                JavaField javaField = new JavaField(f, this);
                flds.add(javaField);
                rootDecompiler.getFieldsMap().put(f, javaField);
            }
        }
        this.fields = Collections.unmodifiableList(flds);
    }
    int methodsCount = cls.getMethods().size();
    if (methodsCount != 0) {
        List<JavaMethod> mths = new ArrayList<JavaMethod>(methodsCount);
        for (MethodNode m : cls.getMethods()) {
            if (!m.contains(AFlag.DONT_GENERATE)) {
                JavaMethod javaMethod = new JavaMethod(this, m);
                mths.add(javaMethod);
                rootDecompiler.getMethodsMap().put(m, javaMethod);
            }
        }
        Collections.sort(mths, new Comparator<JavaMethod>() {

            @Override
            public int compare(JavaMethod o1, JavaMethod o2) {
                return o1.getName().compareTo(o2.getName());
            }
        });
        this.methods = Collections.unmodifiableList(mths);
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) FieldNode(jadx.core.dex.nodes.FieldNode) ArrayList(java.util.ArrayList) MethodNode(jadx.core.dex.nodes.MethodNode)

Example 62 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestArgInline method test.

@Test
public void test() {
    noDebugInfo();
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsString("i++;"));
    assertThat(code, not(containsString("i = i + 1;")));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 63 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestClassGen method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsString("public interface I {"));
    assertThat(code, containsString(indent(2) + "int test();"));
    assertThat(code, not(containsString("public int test();")));
    assertThat(code, containsString(indent(2) + "int test3();"));
    assertThat(code, containsString("public static abstract class A {"));
    assertThat(code, containsString(indent(2) + "public abstract int test2();"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 64 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestFloatValue method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, not(containsString("1073741824")));
    assertThat(code, containsString("0.55f"));
    assertThat(code, containsString("fa[0] = fa[0] / 2.0f;"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 65 with ClassNode

use of jadx.core.dex.nodes.ClassNode in project jadx by skylot.

the class TestRedundantBrackets method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, not(containsString("(-1)")));
    assertThat(code, not(containsString("return;")));
    assertThat(code, containsString("return obj instanceof String ? ((String) obj).length() : 0;"));
    assertThat(code, containsString("a + b < 10"));
    assertThat(code, containsString("(a & b) != 0"));
    assertThat(code, containsString("if (num == 4 || num == 6 || num == 8 || num == 10)"));
    assertThat(code, containsString("a[1] = n * 2;"));
    assertThat(code, containsString("a[n - 1] = 1;"));
    // argument type not changed to String
    assertThat(code, containsString("public int method2(Object obj) {"));
    // cast not eliminated
    assertThat(code, containsString("((String) obj).length()"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Aggregations

ClassNode (jadx.core.dex.nodes.ClassNode)236 Test (org.junit.Test)201 IntegrationTest (jadx.tests.api.IntegrationTest)197 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)93 JadxMatchers.countString (jadx.tests.api.utils.JadxMatchers.countString)17 MethodNode (jadx.core.dex.nodes.MethodNode)12 FieldNode (jadx.core.dex.nodes.FieldNode)10 Matchers.containsString (org.hamcrest.Matchers.containsString)10 ConstClassNode (jadx.core.dex.instructions.ConstClassNode)7 InsnNode (jadx.core.dex.nodes.InsnNode)7 ClassInfo (jadx.core.dex.info.ClassInfo)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)6 DexNode (jadx.core.dex.nodes.DexNode)5 InsnArg (jadx.core.dex.instructions.args.InsnArg)4 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)4 SmaliTest (jadx.tests.api.SmaliTest)4 ArrayList (java.util.ArrayList)4 FieldReplaceAttr (jadx.core.dex.attributes.nodes.FieldReplaceAttr)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 MethodInfo (jadx.core.dex.info.MethodInfo)3