Search in sources :

Example 51 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class JNodeCache method convert.

private JNode convert(JavaNode node) {
    if (node == null) {
        return null;
    }
    if (node instanceof JavaClass) {
        return convert(((JavaClass) node));
    }
    if (node instanceof JavaMethod) {
        return new JMethod((JavaMethod) node, makeFrom(node.getDeclaringClass()));
    }
    if (node instanceof JavaField) {
        return new JField((JavaField) node, makeFrom(node.getDeclaringClass()));
    }
    if (node instanceof JavaVariable) {
        JavaVariable javaVar = (JavaVariable) node;
        JMethod jMth = (JMethod) makeFrom(javaVar.getMth());
        return new JVariable(jMth, javaVar);
    }
    throw new JadxRuntimeException("Unknown type for JavaNode: " + node.getClass());
}
Also used : JVariable(jadx.gui.treemodel.JVariable) JField(jadx.gui.treemodel.JField) JavaField(jadx.api.JavaField) JavaClass(jadx.api.JavaClass) JavaVariable(jadx.api.JavaVariable) JavaMethod(jadx.api.JavaMethod) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) JMethod(jadx.gui.treemodel.JMethod)

Example 52 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class ClassNode method addSyntheticClass.

public static ClassNode addSyntheticClass(RootNode root, String name, int accessFlags) {
    ClassInfo clsInfo = ClassInfo.fromName(root, name);
    ClassNode existCls = root.resolveClass(clsInfo);
    if (existCls != null) {
        throw new JadxRuntimeException("Class already exist: " + name);
    }
    return addSyntheticClass(root, clsInfo, accessFlags);
}
Also used : JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) ClassInfo(jadx.core.dex.info.ClassInfo)

Example 53 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class SignatureParser method consumeMethodArgs.

public List<ArgType> consumeMethodArgs(int argsCount) {
    consume('(');
    if (lookAhead(')')) {
        consume(')');
        return Collections.emptyList();
    }
    List<ArgType> args = new ArrayList<>(argsCount);
    // just prevent endless loop, args count can be different for synthetic methods
    int limit = argsCount + 10;
    do {
        ArgType type = consumeType();
        if (type == null) {
            throw new JadxRuntimeException("Unexpected end of signature");
        }
        args.add(type);
        if (args.size() > limit) {
            throw new JadxRuntimeException("Arguments count limit reached: " + args.size());
        }
    } while (!lookAhead(')'));
    consume(')');
    return args;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) ArrayList(java.util.ArrayList) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 54 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class SignatureParser method consumeObjectType.

private ArgType consumeObjectType(boolean innerType) {
    mark();
    int ch;
    do {
        if (innerType && lookAhead('.')) {
            // stop before next nested inner class
            return ArgType.object(inclusiveSlice());
        }
        ch = next();
        if (ch == STOP_CHAR) {
            return null;
        }
    } while (ch != '<' && ch != ';');
    if (ch == ';') {
        String obj;
        if (innerType) {
            obj = slice().replace('/', '.');
        } else {
            obj = inclusiveSlice();
        }
        return ArgType.object(obj);
    }
    // generic type start ('<')
    String obj = slice();
    if (!innerType) {
        obj += ';';
    } else {
        obj = obj.replace('/', '.');
    }
    List<ArgType> typeVars = consumeGenericArgs();
    consume('>');
    ArgType genericType = ArgType.generic(obj, typeVars);
    if (!lookAhead('.')) {
        consume(';');
        return genericType;
    }
    consume('.');
    next();
    // type parsing not completed, proceed to inner class
    ArgType inner = consumeObjectType(true);
    if (inner == null) {
        throw new JadxRuntimeException("No inner type found: " + debugString());
    }
    // for every nested inner type create nested type object
    while (lookAhead('.')) {
        genericType = ArgType.outerGeneric(genericType, inner);
        consume('.');
        next();
        inner = consumeObjectType(true);
        if (inner == null) {
            throw new JadxRuntimeException("Unexpected inner type found: " + debugString());
        }
    }
    return ArgType.outerGeneric(genericType, inner);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Example 55 with JadxRuntimeException

use of jadx.core.utils.exceptions.JadxRuntimeException in project jadx by skylot.

the class SignatureParser method consumeType.

public ArgType consumeType() {
    char ch = next();
    switch(ch) {
        case 'L':
            ArgType obj = consumeObjectType(false);
            if (obj != null) {
                return obj;
            }
            break;
        case 'T':
            next();
            mark();
            String typeVarName = consumeUntil(';');
            if (typeVarName != null) {
                consume(';');
                if (typeVarName.contains(")")) {
                    throw new JadxRuntimeException("Bad name for type variable: " + typeVarName);
                }
                return ArgType.genericType(typeVarName);
            }
            break;
        case '[':
            return ArgType.array(consumeType());
        case STOP_CHAR:
            return null;
        default:
            // primitive type (one char)
            ArgType type = ArgType.parse(ch);
            if (type != null) {
                return type;
            }
            break;
    }
    throw new JadxRuntimeException("Can't parse type: " + debugString() + ", unexpected: " + ch);
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Aggregations

JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)115 BlockNode (jadx.core.dex.nodes.BlockNode)25 ArrayList (java.util.ArrayList)25 InsnNode (jadx.core.dex.nodes.InsnNode)24 ArgType (jadx.core.dex.instructions.args.ArgType)20 RegisterArg (jadx.core.dex.instructions.args.RegisterArg)17 BitSet (java.util.BitSet)11 ClassNode (jadx.core.dex.nodes.ClassNode)10 MethodNode (jadx.core.dex.nodes.MethodNode)9 InsnArg (jadx.core.dex.instructions.args.InsnArg)8 SSAVar (jadx.core.dex.instructions.args.SSAVar)8 IOException (java.io.IOException)8 List (java.util.List)8 File (java.io.File)7 IRegion (jadx.core.dex.nodes.IRegion)6 Path (java.nio.file.Path)6 IndexInsnNode (jadx.core.dex.instructions.IndexInsnNode)5 PhiInsn (jadx.core.dex.instructions.PhiInsn)5 LiteralArg (jadx.core.dex.instructions.args.LiteralArg)5 FieldNode (jadx.core.dex.nodes.FieldNode)5