Search in sources :

Example 16 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class DexNode method deepResolveMethod.

@Nullable
private MethodNode deepResolveMethod(@NotNull ClassNode cls, String signature) {
    for (MethodNode m : cls.getMethods()) {
        if (m.getMethodInfo().getShortId().startsWith(signature)) {
            return m;
        }
    }
    MethodNode found;
    ArgType superClass = cls.getSuperClass();
    if (superClass != null) {
        ClassNode superNode = resolveClass(superClass);
        if (superNode != null) {
            found = deepResolveMethod(superNode, signature);
            if (found != null) {
                return found;
            }
        }
    }
    for (ArgType iFaceType : cls.getInterfaces()) {
        ClassNode iFaceNode = resolveClass(iFaceType);
        if (iFaceNode != null) {
            found = deepResolveMethod(iFaceNode, signature);
            if (found != null) {
                return found;
            }
        }
    }
    return null;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class MethodInfo method makeSignature.

public String makeSignature(boolean includeRetType) {
    StringBuilder signature = new StringBuilder();
    signature.append(name);
    signature.append('(');
    for (ArgType arg : args) {
        signature.append(TypeGen.signature(arg));
    }
    signature.append(')');
    if (includeRetType) {
        signature.append(TypeGen.signature(retType));
    }
    return signature.toString();
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType)

Example 18 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class AnnotationGen method encodeValue.

// TODO: refactor this boilerplate code
public void encodeValue(CodeWriter code, Object val) {
    if (val == null) {
        code.add("null");
        return;
    }
    if (val instanceof String) {
        code.add(getStringUtils().unescapeString((String) val));
    } else if (val instanceof Integer) {
        code.add(TypeGen.formatInteger((Integer) val));
    } else if (val instanceof Character) {
        code.add(getStringUtils().unescapeChar((Character) val));
    } else if (val instanceof Boolean) {
        code.add(Boolean.TRUE.equals(val) ? "true" : "false");
    } else if (val instanceof Float) {
        code.add(TypeGen.formatFloat((Float) val));
    } else if (val instanceof Double) {
        code.add(TypeGen.formatDouble((Double) val));
    } else if (val instanceof Long) {
        code.add(TypeGen.formatLong((Long) val));
    } else if (val instanceof Short) {
        code.add(TypeGen.formatShort((Short) val));
    } else if (val instanceof Byte) {
        code.add(TypeGen.formatByte((Byte) val));
    } else if (val instanceof ArgType) {
        classGen.useType(code, (ArgType) val);
        code.add(".class");
    } else if (val instanceof FieldInfo) {
        // must be a static field
        FieldInfo field = (FieldInfo) val;
        InsnGen.makeStaticFieldAccess(code, field, classGen);
    } else if (val instanceof Iterable) {
        code.add('{');
        Iterator<?> it = ((Iterable) val).iterator();
        while (it.hasNext()) {
            Object obj = it.next();
            encodeValue(code, obj);
            if (it.hasNext()) {
                code.add(", ");
            }
        }
        code.add('}');
    } else if (val instanceof Annotation) {
        formatAnnotation(code, (Annotation) val);
    } else {
        // TODO: also can be method values
        throw new JadxRuntimeException("Can't decode value: " + val + " (" + val.getClass() + ")");
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) Annotation(jadx.core.dex.attributes.annotations.Annotation) Iterator(java.util.Iterator) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) FieldInfo(jadx.core.dex.info.FieldInfo)

Example 19 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class TypeMergeTest method testMerge.

@Test
public void testMerge() throws IOException, DecodeException {
    first(INT, INT);
    first(BOOLEAN, INT);
    reject(INT, LONG);
    first(INT, UNKNOWN);
    reject(INT, UNKNOWN_OBJECT);
    first(INT, NARROW);
    first(CHAR, INT);
    check(unknown(PrimitiveType.INT, PrimitiveType.BOOLEAN, PrimitiveType.FLOAT), unknown(PrimitiveType.INT, PrimitiveType.BOOLEAN), unknown(PrimitiveType.INT, PrimitiveType.BOOLEAN));
    check(unknown(PrimitiveType.INT, PrimitiveType.FLOAT), unknown(PrimitiveType.INT, PrimitiveType.BOOLEAN), INT);
    check(unknown(PrimitiveType.INT, PrimitiveType.OBJECT), unknown(PrimitiveType.OBJECT, PrimitiveType.ARRAY), unknown(PrimitiveType.OBJECT));
    ArgType objExc = object("java.lang.Exception");
    ArgType objThr = object("java.lang.Throwable");
    ArgType objIO = object("java.io.IOException");
    ArgType objArr = object("java.lang.ArrayIndexOutOfBoundsException");
    ArgType objList = object("java.util.List");
    first(objExc, objExc);
    check(objExc, objList, OBJECT);
    first(objExc, OBJECT);
    check(objExc, objThr, objThr);
    check(objIO, objArr, objExc);
    ArgType generic = genericType("T");
    first(generic, objExc);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) Test(org.junit.Test)

Example 20 with ArgType

use of jadx.core.dex.instructions.args.ArgType in project jadx by skylot.

the class TypeMergeTest method merge.

private void merge(ArgType t1, ArgType t2, ArgType exp) {
    ArgType res = ArgType.merge(dex, t1, t2);
    String msg = format(t1, t2, exp, res);
    if (exp == null) {
        assertNull("Incorrect accept: " + msg, res);
    } else {
        assertNotNull("Incorrect reject: " + msg, res);
        assertTrue("Incorrect result: " + msg, exp.equals(res));
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType)

Aggregations

ArgType (jadx.core.dex.instructions.args.ArgType)48 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)12 InsnNode (jadx.core.dex.nodes.InsnNode)11 InsnArg (jadx.core.dex.instructions.args.InsnArg)9 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)8 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)6 SSAVar (jadx.core.dex.instructions.args.SSAVar)6 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)5 ArrayList (java.util.ArrayList)5 FieldNode (jadx.core.dex.nodes.FieldNode)4 MethodNode (jadx.core.dex.nodes.MethodNode)4 Annotation (jadx.core.dex.attributes.annotations.Annotation)3 FieldInfo (jadx.core.dex.info.FieldInfo)3 FilledNewArrayNode (jadx.core.dex.instructions.FilledNewArrayNode)3 InvokeNode (jadx.core.dex.instructions.InvokeNode)3 BlockNode (jadx.core.dex.nodes.BlockNode)3 ClassNode (jadx.core.dex.nodes.ClassNode)3 DexNode (jadx.core.dex.nodes.DexNode)3 List (java.util.List)3 MethodInfo (jadx.core.dex.info.MethodInfo)2