Search in sources :

Example 6 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class BasicBlockList method catchesEqual.

/**
     * Compares the catches of two blocks for equality. This includes
     * both the catch types and target labels.
     *
     * @param block1 {@code non-null;} one block to compare
     * @param block2 {@code non-null;} the other block to compare
     * @return {@code true} if the two blocks' non-primary successors
     * are identical
     */
public boolean catchesEqual(BasicBlock block1, BasicBlock block2) {
    TypeList catches1 = block1.getExceptionHandlerTypes();
    TypeList catches2 = block2.getExceptionHandlerTypes();
    if (!StdTypeList.equalContents(catches1, catches2)) {
        return false;
    }
    IntList succ1 = block1.getSuccessors();
    IntList succ2 = block2.getSuccessors();
    // Both are guaranteed to be the same size.
    int size = succ1.size();
    int primary1 = block1.getPrimarySuccessor();
    int primary2 = block2.getPrimarySuccessor();
    if (((primary1 == -1) || (primary2 == -1)) && (primary1 != primary2)) {
        /*
             * For the current purpose, both blocks in question must
             * either both have a primary or both not have a primary to
             * be considered equal, and it turns out here that that's not
             * the case.
             */
        return false;
    }
    for (int i = 0; i < size; i++) {
        int label1 = succ1.get(i);
        int label2 = succ2.get(i);
        if (label1 == primary1) {
            /*
                 * It should be the case that block2's primary is at the
                 * same index. If not, we consider the blocks unequal for
                 * the current purpose.
                 */
            if (label2 != primary2) {
                return false;
            }
            continue;
        }
        if (label1 != label2) {
            return false;
        }
    }
    return true;
}
Also used : StdTypeList(com.android.dx.rop.type.StdTypeList) TypeList(com.android.dx.rop.type.TypeList) IntList(com.android.dx.util.IntList)

Example 7 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class TypeListItem method compareTo0.

/** {@inheritDoc} */
@Override
protected int compareTo0(OffsettedItem other) {
    TypeList thisList = this.list;
    TypeList otherList = ((TypeListItem) other).list;
    return StdTypeList.compareContents(thisList, otherList);
}
Also used : StdTypeList(com.android.dx.rop.type.StdTypeList) TypeList(com.android.dx.rop.type.TypeList)

Example 8 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class Ropper method addReturnBlock.

/**
     * Constructs and adds the return block, if necessary. The return
     * block merely contains an appropriate {@code return}
     * instruction.
     */
private void addReturnBlock() {
    Rop returnOp = machine.getReturnOp();
    if (returnOp == null) {
        /*
             * The method being converted never returns normally, so there's
             * no need for a return block.
             */
        return;
    }
    SourcePosition returnPos = machine.getReturnPosition();
    int label = getSpecialLabel(RETURN);
    if (isSynchronized()) {
        InsnList insns = new InsnList(1);
        Insn insn = new ThrowingInsn(Rops.MONITOR_EXIT, returnPos, RegisterSpecList.make(getSynchReg()), StdTypeList.EMPTY);
        insns.set(0, insn);
        insns.setImmutable();
        int nextLabel = getSpecialLabel(SYNCH_RETURN);
        BasicBlock bb = new BasicBlock(label, insns, IntList.makeImmutable(nextLabel), nextLabel);
        addBlock(bb, IntList.EMPTY);
        label = nextLabel;
    }
    InsnList insns = new InsnList(1);
    TypeList sourceTypes = returnOp.getSources();
    RegisterSpecList sources;
    if (sourceTypes.size() == 0) {
        sources = RegisterSpecList.EMPTY;
    } else {
        RegisterSpec source = RegisterSpec.make(0, sourceTypes.getType(0));
        sources = RegisterSpecList.make(source);
    }
    Insn insn = new PlainInsn(returnOp, returnPos, null, sources);
    insns.set(0, insn);
    insns.setImmutable();
    BasicBlock bb = new BasicBlock(label, insns, IntList.EMPTY, -1);
    addBlock(bb, IntList.EMPTY);
}
Also used : PlainInsn(com.android.dx.rop.code.PlainInsn) Rop(com.android.dx.rop.code.Rop) ThrowingCstInsn(com.android.dx.rop.code.ThrowingCstInsn) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) PlainInsn(com.android.dx.rop.code.PlainInsn) Insn(com.android.dx.rop.code.Insn) PlainCstInsn(com.android.dx.rop.code.PlainCstInsn) SourcePosition(com.android.dx.rop.code.SourcePosition) BasicBlock(com.android.dx.rop.code.BasicBlock) InsnList(com.android.dx.rop.code.InsnList) ThrowingInsn(com.android.dx.rop.code.ThrowingInsn) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) TypeList(com.android.dx.rop.type.TypeList) StdTypeList(com.android.dx.rop.type.StdTypeList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 9 with TypeList

use of com.android.dx.rop.type.TypeList in project RocooFix by dodola.

the class ClassReferenceListBuilder method addClassWithHierachy.

private void addClassWithHierachy(String classBinaryName) {
    if (classNames.contains(classBinaryName) || !refcname.equals(classBinaryName + CLASS_EXTENSION)) {
        return;
    }
    try {
        DirectClassFile classFile = path.getClass(currentName);
        classNames.add(currentName);
        File entryFile = new File(patchDir + "/" + currentName);
        entryFile.getParentFile().mkdirs();
        if (!entryFile.exists()) {
            entryFile.createNewFile();
            //                Iterable<ClassPathElement> elements = path.getElements();
            //                for (ClassPathElement element : elements) {
            //                    InputStream in = element.open(currentName);
            byte[] bytes = NuwaProcessor.referHackWhenInit(classFile.getBytes().makeDataInputStream());
            //                    System.out.println(classFile.getFilePath() + ",size:" + bytes.length);
            FileUtils.writeByteArrayToFile(entryFile, bytes);
        //                }
        }
        //            NuwaProcessor.referHackWhenInit();
        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) {
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) CstType(com.android.dx.rop.cst.CstType) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) StdTypeList(com.android.dx.rop.type.StdTypeList) TypeList(com.android.dx.rop.type.TypeList)

Example 10 with TypeList

use of com.android.dx.rop.type.TypeList in project buck by facebook.

the class ClassReferenceListBuilder method addClassWithHierarchy.

private void addClassWithHierarchy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }
    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        if (CLASS_TO_CHECK != null && classBinaryName.contains(CLASS_TO_CHECK)) {
            found();
        }
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierarchy(superClass.getClassType().getClassName());
        }
        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierarchy(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)

Aggregations

TypeList (com.android.dx.rop.type.TypeList)14 StdTypeList (com.android.dx.rop.type.StdTypeList)8 CstType (com.android.dx.rop.cst.CstType)7 DirectClassFile (com.android.dx.cf.direct.DirectClassFile)3 BasicBlock (com.android.dx.rop.code.BasicBlock)3 Type (com.android.dx.rop.type.Type)3 FileNotFoundException (java.io.FileNotFoundException)3 Annotations (com.android.dx.rop.annotation.Annotations)2 BasicBlockList (com.android.dx.rop.code.BasicBlockList)2 IntList (com.android.dx.util.IntList)2 AttExceptions (com.android.dx.cf.attrib.AttExceptions)1 AttRuntimeInvisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleAnnotations)1 AttRuntimeInvisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeInvisibleParameterAnnotations)1 AttRuntimeVisibleAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleAnnotations)1 AttRuntimeVisibleParameterAnnotations (com.android.dx.cf.attrib.AttRuntimeVisibleParameterAnnotations)1 ConcreteMethod (com.android.dx.cf.code.ConcreteMethod)1 Method (com.android.dx.cf.iface.Method)1 MethodList (com.android.dx.cf.iface.MethodList)1 DalvCode (com.android.dx.dex.code.DalvCode)1 EncodedMethod (com.android.dx.dex.file.EncodedMethod)1