Search in sources :

Example 1 with CstType

use of com.android.dx.rop.cst.CstType in project RocooFix by dodola.

the class ClassReferenceListBuilder method addDependencies.

private void addDependencies(ConstantPool pool) {
    for (Constant constant : pool.getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType());
        } else if (constant instanceof CstMethodRef) {
            Prototype proto = ((CstMethodRef) constant).getPrototype();
            checkDescriptor(proto.getReturnType());
            StdTypeList args = proto.getParameterTypes();
            for (int i = 0; i < args.size(); i++) {
                checkDescriptor(args.get(i));
            }
        }
    }
}
Also used : Prototype(com.android.dx.rop.type.Prototype) StdTypeList(com.android.dx.rop.type.StdTypeList) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstMethodRef(com.android.dx.rop.cst.CstMethodRef)

Example 2 with CstType

use of com.android.dx.rop.cst.CstType in project RocooFix by dodola.

the class ClassReferenceListBuilder method addClassWithHierachy.

private void addClassWithHierachy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }
    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierachy(superClass.getClassType().getClassName());
        }
        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierachy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
    // Ignore: The referenced type is not in the path it must be part of the libraries.
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) CstType(com.android.dx.rop.cst.CstType) FileNotFoundException(java.io.FileNotFoundException) StdTypeList(com.android.dx.rop.type.StdTypeList) TypeList(com.android.dx.rop.type.TypeList)

Example 3 with CstType

use of com.android.dx.rop.cst.CstType in project RocooFix by dodola.

the class ClassReferenceListBuilder method addSupperClass.

public void addSupperClass(String name) {
    if (name.endsWith(CLASS_EXTENSION)) {
        classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
    }
    if (name.endsWith(CLASS_EXTENSION)) {
        DirectClassFile classFile;
        try {
            classFile = path.getClass(name);
            CstType superClass = classFile.getSuperclass();
            if (superClass != null) {
                String superClassName = superClass.getClassType().getClassName();
                classNames.add(superClassName);
            }
        } catch (FileNotFoundException e) {
        //                throw new IOException("Class " + name +
        //                        " is missing form original class path " + path, e);
        }
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) CstType(com.android.dx.rop.cst.CstType) FileNotFoundException(java.io.FileNotFoundException)

Example 4 with CstType

use of com.android.dx.rop.cst.CstType in project buck by facebook.

the class AttributeTranslator method getClassAnnotations.

/**
     * Gets the annotations out of a given class, similar to {@link
     * #getAnnotations}, also including annotations for translations
     * of class-level attributes {@code EnclosingMethod} and
     * {@code InnerClasses}, if present. Additionally, if the
     * class is an annotation class, then this also includes a
     * representation of all the {@code AnnotationDefault}
     * values.
     *
     * @param cf {@code non-null;} the class in question
     * @param args {@code non-null;} the high-level options
     * @return {@code non-null;} the set of annotations, which may be empty
     */
public static Annotations getClassAnnotations(DirectClassFile cf, CfOptions args) {
    CstType thisClass = cf.getThisClass();
    AttributeList attribs = cf.getAttributes();
    Annotations result = getAnnotations(attribs);
    Annotation enclosingMethod = translateEnclosingMethod(attribs);
    try {
        Annotations innerClassAnnotations = translateInnerClasses(thisClass, attribs, enclosingMethod == null);
        if (innerClassAnnotations != null) {
            result = Annotations.combine(result, innerClassAnnotations);
        }
    } catch (Warning warn) {
        args.warn.println("warning: " + warn.getMessage());
    }
    if (enclosingMethod != null) {
        result = Annotations.combine(result, enclosingMethod);
    }
    if (AccessFlags.isAnnotation(cf.getAccessFlags())) {
        Annotation annotationDefault = translateAnnotationDefaults(cf);
        if (annotationDefault != null) {
            result = Annotations.combine(result, annotationDefault);
        }
    }
    return result;
}
Also used : Warning(com.android.dx.util.Warning) AttRuntimeVisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations) AttRuntimeVisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations) Annotations(com.android.dx.rop.annotation.Annotations) AttRuntimeInvisibleAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations) AttRuntimeInvisibleParameterAnnotations(com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations) AttributeList(com.android.dx.cf.iface.AttributeList) CstType(com.android.dx.rop.cst.CstType) Annotation(com.android.dx.rop.annotation.Annotation)

Example 5 with CstType

use of com.android.dx.rop.cst.CstType in project buck by facebook.

the class RopToDop method dopFor.

/**
     * Returns the dalvik opcode appropriate for the given register-based
     * instruction.
     *
     * @param insn {@code non-null;} the original instruction
     * @return the corresponding dalvik opcode; one of the constants in
     * {@link Dops}
     */
public static Dop dopFor(Insn insn) {
    Rop rop = insn.getOpcode();
    /*
         * First, just try looking up the rop in the MAP of easy
         * cases.
         */
    Dop result = MAP.get(rop);
    if (result != null) {
        return result;
    }
    switch(rop.getOpcode()) {
        case RegOps.MOVE_EXCEPTION:
            return Dops.MOVE_EXCEPTION;
        case RegOps.INVOKE_STATIC:
            return Dops.INVOKE_STATIC;
        case RegOps.INVOKE_VIRTUAL:
            return Dops.INVOKE_VIRTUAL;
        case RegOps.INVOKE_SUPER:
            return Dops.INVOKE_SUPER;
        case RegOps.INVOKE_DIRECT:
            return Dops.INVOKE_DIRECT;
        case RegOps.INVOKE_INTERFACE:
            return Dops.INVOKE_INTERFACE;
        case RegOps.NEW_ARRAY:
            return Dops.NEW_ARRAY;
        case RegOps.FILLED_NEW_ARRAY:
            return Dops.FILLED_NEW_ARRAY;
        case RegOps.FILL_ARRAY_DATA:
            return Dops.FILL_ARRAY_DATA;
        case RegOps.MOVE_RESULT:
            {
                RegisterSpec resultReg = insn.getResult();
                if (resultReg == null) {
                    return Dops.NOP;
                } else {
                    switch(resultReg.getBasicType()) {
                        case Type.BT_INT:
                        case Type.BT_FLOAT:
                        case Type.BT_BOOLEAN:
                        case Type.BT_BYTE:
                        case Type.BT_CHAR:
                        case Type.BT_SHORT:
                            return Dops.MOVE_RESULT;
                        case Type.BT_LONG:
                        case Type.BT_DOUBLE:
                            return Dops.MOVE_RESULT_WIDE;
                        case Type.BT_OBJECT:
                            return Dops.MOVE_RESULT_OBJECT;
                        default:
                            {
                                throw new RuntimeException("Unexpected basic type");
                            }
                    }
                }
            }
        case RegOps.GET_FIELD:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.IGET_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.IGET_BYTE;
                    case Type.BT_CHAR:
                        return Dops.IGET_CHAR;
                    case Type.BT_SHORT:
                        return Dops.IGET_SHORT;
                    case Type.BT_INT:
                        return Dops.IGET;
                }
                break;
            }
        case RegOps.PUT_FIELD:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.IPUT_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.IPUT_BYTE;
                    case Type.BT_CHAR:
                        return Dops.IPUT_CHAR;
                    case Type.BT_SHORT:
                        return Dops.IPUT_SHORT;
                    case Type.BT_INT:
                        return Dops.IPUT;
                }
                break;
            }
        case RegOps.GET_STATIC:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.SGET_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.SGET_BYTE;
                    case Type.BT_CHAR:
                        return Dops.SGET_CHAR;
                    case Type.BT_SHORT:
                        return Dops.SGET_SHORT;
                    case Type.BT_INT:
                        return Dops.SGET;
                }
                break;
            }
        case RegOps.PUT_STATIC:
            {
                CstFieldRef ref = (CstFieldRef) ((ThrowingCstInsn) insn).getConstant();
                int basicType = ref.getBasicType();
                switch(basicType) {
                    case Type.BT_BOOLEAN:
                        return Dops.SPUT_BOOLEAN;
                    case Type.BT_BYTE:
                        return Dops.SPUT_BYTE;
                    case Type.BT_CHAR:
                        return Dops.SPUT_CHAR;
                    case Type.BT_SHORT:
                        return Dops.SPUT_SHORT;
                    case Type.BT_INT:
                        return Dops.SPUT;
                }
                break;
            }
        case RegOps.CONST:
            {
                Constant cst = ((ThrowingCstInsn) insn).getConstant();
                if (cst instanceof CstType) {
                    return Dops.CONST_CLASS;
                } else if (cst instanceof CstString) {
                    return Dops.CONST_STRING;
                }
                break;
            }
    }
    throw new RuntimeException("unknown rop: " + rop);
}
Also used : Rop(com.android.dx.rop.code.Rop) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstString(com.android.dx.rop.cst.CstString) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Aggregations

CstType (com.android.dx.rop.cst.CstType)42 Constant (com.android.dx.rop.cst.Constant)15 CstString (com.android.dx.rop.cst.CstString)15 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)11 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)10 Type (com.android.dx.rop.type.Type)8 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)6 StdTypeList (com.android.dx.rop.type.StdTypeList)6 TypeList (com.android.dx.rop.type.TypeList)6 CstInsn (com.android.dx.dex.code.CstInsn)5 Annotations (com.android.dx.rop.annotation.Annotations)5 RegisterSpec (com.android.dx.rop.code.RegisterSpec)5 CstNat (com.android.dx.rop.cst.CstNat)5 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)4 Annotation (com.android.dx.rop.annotation.Annotation)4 ByteArray (com.android.dx.util.ByteArray)4 IntList (com.android.dx.util.IntList)4 FileNotFoundException (java.io.FileNotFoundException)4 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)3 MethodList (com.android.dx.cf.iface.MethodList)3