Search in sources :

Example 6 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class StdAttributeFactory method innerClasses.

/**
     * Parses an {@code InnerClasses} attribute.
     */
private Attribute innerClasses(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length < 2) {
        return throwSeverelyTruncated();
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    // number_of_classes
    int count = bytes.getUnsignedShort(offset);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "number_of_classes: " + Hex.u2(count));
    }
    offset += 2;
    length -= 2;
    if (length != (count * 8)) {
        throwBadLength((count * 8) + 2);
    }
    InnerClassList list = new InnerClassList(count);
    for (int i = 0; i < count; i++) {
        int innerClassIdx = bytes.getUnsignedShort(offset);
        int outerClassIdx = bytes.getUnsignedShort(offset + 2);
        int nameIdx = bytes.getUnsignedShort(offset + 4);
        int accessFlags = bytes.getUnsignedShort(offset + 6);
        CstType innerClass = (CstType) pool.get(innerClassIdx);
        CstType outerClass = (CstType) pool.get0Ok(outerClassIdx);
        CstString name = (CstString) pool.get0Ok(nameIdx);
        list.set(i, innerClass, outerClass, name, accessFlags);
        if (observer != null) {
            observer.parsed(bytes, offset, 2, "inner_class: " + DirectClassFile.stringOrNone(innerClass));
            observer.parsed(bytes, offset + 2, 2, "  outer_class: " + DirectClassFile.stringOrNone(outerClass));
            observer.parsed(bytes, offset + 4, 2, "  name: " + DirectClassFile.stringOrNone(name));
            observer.parsed(bytes, offset + 6, 2, "  access_flags: " + AccessFlags.innerClassString(accessFlags));
        }
        offset += 8;
    }
    list.setImmutable();
    return new AttInnerClasses(list);
}
Also used : ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString) ByteArray(com.taobao.android.dx.util.ByteArray) InnerClassList(com.taobao.android.dx.cf.attrib.InnerClassList) AttInnerClasses(com.taobao.android.dx.cf.attrib.AttInnerClasses)

Example 7 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class StdAttributeFactory method sourceFile.

/**
     * Parses a {@code SourceFile} attribute.
     */
private Attribute sourceFile(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSourceFile(cst);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "source: " + cst);
    }
    return result;
}
Also used : Attribute(com.taobao.android.dx.cf.iface.Attribute) ConstantPool(com.taobao.android.dx.rop.cst.ConstantPool) CstString(com.taobao.android.dx.rop.cst.CstString) AttSourceFile(com.taobao.android.dx.cf.attrib.AttSourceFile) ByteArray(com.taobao.android.dx.util.ByteArray)

Example 8 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class StdAttributeFactory method parseLocalVariables.

/**
     * Parse the table part of either a {@code LocalVariableTable}
     * or a {@code LocalVariableTypeTable}.
     *
     * @param bytes {@code non-null;} bytes to parse, which should <i>only</i>
     * contain the table data (no header)
     * @param pool {@code non-null;} constant pool to use
     * @param count {@code >= 0;} the number of entries
     * @param typeTable {@code true} iff this is for a type table
     * @return {@code non-null;} the constructed list
     */
private LocalVariableList parseLocalVariables(ByteArray bytes, ConstantPool pool, ParseObserver observer, int count, boolean typeTable) {
    if (bytes.size() != (count * 10)) {
        // "+ 2" is for the count.
        throwBadLength((count * 10) + 2);
    }
    ByteArray.MyDataInputStream in = bytes.makeDataInputStream();
    LocalVariableList list = new LocalVariableList(count);
    try {
        for (int i = 0; i < count; i++) {
            int startPc = in.readUnsignedShort();
            int length = in.readUnsignedShort();
            int nameIdx = in.readUnsignedShort();
            int typeIdx = in.readUnsignedShort();
            int index = in.readUnsignedShort();
            CstString name = (CstString) pool.get(nameIdx);
            CstString type = (CstString) pool.get(typeIdx);
            CstString descriptor = null;
            CstString signature = null;
            if (typeTable) {
                signature = type;
            } else {
                descriptor = type;
            }
            list.set(i, startPc, length, name, descriptor, signature, index);
            if (observer != null) {
                observer.parsed(bytes, i * 10, 10, Hex.u2(startPc) + ".." + Hex.u2(startPc + length) + " " + Hex.u2(index) + " " + name.toHuman() + " " + type.toHuman());
            }
        }
    } catch (IOException ex) {
        throw new RuntimeException("shouldn't happen", ex);
    }
    list.setImmutable();
    return list;
}
Also used : LocalVariableList(com.taobao.android.dx.cf.code.LocalVariableList) CstString(com.taobao.android.dx.rop.cst.CstString) ByteArray(com.taobao.android.dx.util.ByteArray) IOException(java.io.IOException)

Example 9 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class Form21c method isCompatible.

/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }
    RegisterSpecList regs = insn.getRegisters();
    RegisterSpec reg;
    switch(regs.size()) {
        case 1:
            {
                reg = regs.get(0);
                break;
            }
        case 2:
            {
                /*
                 * This format is allowed for ops that are effectively
                 * 2-arg but where the two args are identical.
                 */
                reg = regs.get(0);
                if (reg.getReg() != regs.get(1).getReg()) {
                    return false;
                }
                break;
            }
        default:
            {
                return false;
            }
    }
    if (!unsignedFitsInByte(reg.getReg())) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();
    Constant cst = ci.getConstant();
    if (!unsignedFitsInShort(cpi)) {
        return false;
    }
    return (cst instanceof CstType) || (cst instanceof CstFieldRef) || (cst instanceof CstString);
}
Also used : CstInsn(com.taobao.android.dx.dex.code.CstInsn) Constant(com.taobao.android.dx.rop.cst.Constant) CstType(com.taobao.android.dx.rop.cst.CstType) CstFieldRef(com.taobao.android.dx.rop.cst.CstFieldRef) CstString(com.taobao.android.dx.rop.cst.CstString) RegisterSpecList(com.taobao.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Example 10 with CstString

use of com.taobao.android.dx.rop.cst.CstString in project atlas by alibaba.

the class EscapeAnalysis method insertExceptionThrow.

/**
     * Replaces instructions that trigger an ArrayIndexOutofBounds exception
     * with an actual throw of the exception.
     *
     * @param insn {@code non-null;} instruction causing the exception
     * @param index {@code non-null;} index value that is out of bounds
     * @param deletedInsns {@code non-null;} set of instructions marked for
     * deletion
     */
private void insertExceptionThrow(SsaInsn insn, RegisterSpec index, HashSet<SsaInsn> deletedInsns) {
    // Create a new ArrayIndexOutOfBoundsException
    CstType exception = new CstType(Exceptions.TYPE_ArrayIndexOutOfBoundsException);
    insertThrowingInsnBefore(insn, RegisterSpecList.EMPTY, null, RegOps.NEW_INSTANCE, exception);
    // Add a successor block with a move result pseudo for the exception
    SsaBasicBlock currBlock = insn.getBlock();
    SsaBasicBlock newBlock = currBlock.insertNewSuccessor(currBlock.getPrimarySuccessor());
    SsaInsn newInsn = newBlock.getInsns().get(0);
    RegisterSpec newReg = RegisterSpec.make(ssaMeth.makeNewSsaReg(), exception);
    insertPlainInsnBefore(newInsn, RegisterSpecList.EMPTY, newReg, RegOps.MOVE_RESULT_PSEUDO, null);
    // Add another successor block to initialize the exception
    SsaBasicBlock newBlock2 = newBlock.insertNewSuccessor(newBlock.getPrimarySuccessor());
    SsaInsn newInsn2 = newBlock2.getInsns().get(0);
    CstNat newNat = new CstNat(new CstString("<init>"), new CstString("(I)V"));
    CstMethodRef newRef = new CstMethodRef(exception, newNat);
    insertThrowingInsnBefore(newInsn2, RegisterSpecList.make(newReg, index), null, RegOps.INVOKE_DIRECT, newRef);
    deletedInsns.add(newInsn2);
    // Add another successor block to throw the new exception
    SsaBasicBlock newBlock3 = newBlock2.insertNewSuccessor(newBlock2.getPrimarySuccessor());
    SsaInsn newInsn3 = newBlock3.getInsns().get(0);
    insertThrowingInsnBefore(newInsn3, RegisterSpecList.make(newReg), null, RegOps.THROW, null);
    newBlock3.replaceSuccessor(newBlock3.getPrimarySuccessorIndex(), ssaMeth.getExitBlock().getIndex());
    deletedInsns.add(newInsn3);
}
Also used : CstNat(com.taobao.android.dx.rop.cst.CstNat) CstType(com.taobao.android.dx.rop.cst.CstType) CstString(com.taobao.android.dx.rop.cst.CstString) CstMethodRef(com.taobao.android.dx.rop.cst.CstMethodRef) RegisterSpec(com.taobao.android.dx.rop.code.RegisterSpec)

Aggregations

CstString (com.taobao.android.dx.rop.cst.CstString)33 CstType (com.taobao.android.dx.rop.cst.CstType)14 Constant (com.taobao.android.dx.rop.cst.Constant)12 ConstantPool (com.taobao.android.dx.rop.cst.ConstantPool)6 ByteArray (com.taobao.android.dx.util.ByteArray)6 NameValuePair (com.taobao.android.dx.rop.annotation.NameValuePair)5 RegisterSpec (com.taobao.android.dx.rop.code.RegisterSpec)5 Annotation (com.taobao.android.dx.rop.annotation.Annotation)4 CstFieldRef (com.taobao.android.dx.rop.cst.CstFieldRef)4 CstNat (com.taobao.android.dx.rop.cst.CstNat)4 Type (com.taobao.android.dx.rop.type.Type)4 ParseException (com.taobao.android.dx.cf.iface.ParseException)3 ClassDefItem (com.taobao.android.dx.dex.file.ClassDefItem)3 CstAnnotation (com.taobao.android.dx.rop.cst.CstAnnotation)3 Attribute (com.taobao.android.dx.cf.iface.Attribute)2 CstInsn (com.taobao.android.dx.dex.code.CstInsn)2 Annotations (com.taobao.android.dx.rop.annotation.Annotations)2 AnnotationsList (com.taobao.android.dx.rop.annotation.AnnotationsList)2 LocalItem (com.taobao.android.dx.rop.code.LocalItem)2 RegisterSpecList (com.taobao.android.dx.rop.code.RegisterSpecList)2