Search in sources :

Example 51 with ClassNode

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

the class TestSwitchReturnFromCase method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsString("switch (a % 4) {"));
    assertEquals(5, count(code, "case "));
    assertEquals(3, count(code, "break;"));
    assertThat(code, containsOne("s = \"1\";"));
    assertThat(code, containsOne("s = \"2\";"));
    assertThat(code, containsOne("s = \"4\";"));
    assertThat(code, containsOne("s = \"5\";"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 52 with ClassNode

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

the class TestSwitchWithFallThroughCase2 method test.

@Test
public void test() {
    ClassNode cls = getClassNode(TestCls.class);
    String code = cls.getCode().toString();
    assertThat(code, containsOne("switch (a % 4) {"));
    assertThat(code, containsOne("if (a == 5 && b) {"));
    assertThat(code, containsOne("if (b) {"));
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) IntegrationTest(jadx.tests.api.IntegrationTest) Test(org.junit.Test)

Example 53 with ClassNode

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

the class ClassGen method searchCollision.

private static boolean searchCollision(DexNode dex, ClassInfo useCls, ClassInfo searchCls) {
    if (useCls == null) {
        return false;
    }
    String shortName = searchCls.getShortName();
    if (useCls.getShortName().equals(shortName)) {
        return true;
    }
    ClassNode classNode = dex.resolveClass(useCls);
    if (classNode != null) {
        for (ClassNode inner : classNode.getInnerClasses()) {
            if (inner.getShortName().equals(shortName) && !inner.getAlias().equals(searchCls)) {
                return true;
            }
        }
    }
    return searchCollision(dex, useCls.getParentClass(), searchCls);
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode)

Example 54 with ClassNode

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

the class ClassGen method addInnerClasses.

private void addInnerClasses(CodeWriter code, ClassNode cls) throws CodegenException {
    for (ClassNode innerCls : cls.getInnerClasses()) {
        if (innerCls.contains(AFlag.DONT_GENERATE) || innerCls.contains(AFlag.ANONYMOUS_CLASS)) {
            continue;
        }
        ClassGen inClGen = new ClassGen(innerCls, getParentGen());
        code.newLine();
        inClGen.addClassCode(code);
        imports.addAll(inClGen.getImports());
    }
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode)

Example 55 with ClassNode

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

the class InsnGen method makeConstructor.

private void makeConstructor(ConstructorInsn insn, CodeWriter code) throws CodegenException {
    ClassNode cls = mth.dex().resolveClass(insn.getClassType());
    if (cls != null && cls.contains(AFlag.ANONYMOUS_CLASS) && !fallback) {
        inlineAnonymousConstr(code, cls, insn);
        return;
    }
    if (insn.isSelf()) {
        throw new JadxRuntimeException("Constructor 'self' invoke must be removed!");
    }
    if (insn.isSuper()) {
        code.add("super");
    } else if (insn.isThis()) {
        code.add("this");
    } else {
        code.add("new ");
        useClass(code, insn.getClassType());
    }
    MethodNode callMth = mth.dex().resolveMethod(insn.getCallMth());
    generateMethodArguments(code, insn, 0, callMth);
}
Also used : ClassNode(jadx.core.dex.nodes.ClassNode) ConstClassNode(jadx.core.dex.instructions.ConstClassNode) MethodNode(jadx.core.dex.nodes.MethodNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

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