Search in sources :

Example 36 with Constant

use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.

the class Form4rcc method isCompatible.

/**
 * {@inheritDoc}
 */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof MultiCstInsn)) {
        return false;
    }
    MultiCstInsn mci = (MultiCstInsn) insn;
    int methodIdx = mci.getIndex(0);
    int protoIdx = mci.getIndex(1);
    if (!unsignedFitsInShort(methodIdx) || !unsignedFitsInShort(protoIdx)) {
        return false;
    }
    Constant methodRef = mci.getConstant(0);
    if (!(methodRef instanceof CstMethodRef)) {
        return false;
    }
    Constant protoRef = mci.getConstant(1);
    if (!(protoRef instanceof CstProtoRef)) {
        return false;
    }
    RegisterSpecList regs = mci.getRegisters();
    int sz = regs.size();
    if (sz == 0) {
        return true;
    }
    return (unsignedFitsInByte(regs.getWordCount()) && unsignedFitsInShort(sz) && unsignedFitsInShort(regs.get(0).getReg()) && isRegListSequential(regs));
}
Also used : CstProtoRef(com.android.dx.rop.cst.CstProtoRef) Constant(com.android.dx.rop.cst.Constant) MultiCstInsn(com.android.dx.dex.code.MultiCstInsn) CstMethodRef(com.android.dx.rop.cst.CstMethodRef) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 37 with Constant

use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.

the class AnnotationItem method annotateTo.

/**
 * Write a (listing file) annotation for this instance to the given
 * output, that consumes no bytes of output. This is for annotating
 * a reference to this instance at the point of the reference.
 *
 * @param out {@code non-null;} where to output to
 * @param prefix {@code non-null;} prefix for each line of output
 */
public void annotateTo(AnnotatedOutput out, String prefix) {
    out.annotate(0, prefix + "visibility: " + annotation.getVisibility().toHuman());
    out.annotate(0, prefix + "type: " + annotation.getType().toHuman());
    for (NameValuePair pair : annotation.getNameValuePairs()) {
        CstString name = pair.getName();
        Constant value = pair.getValue();
        out.annotate(0, prefix + name.toHuman() + ": " + ValueEncoder.constantToHuman(value));
    }
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) CstString(com.android.dx.rop.cst.CstString)

Example 38 with Constant

use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.

the class ClassDataItem method makeStaticValuesConstant.

/**
 * Gets a {@link CstArray} corresponding to {@link #staticValues} if
 * it contains any non-zero non-{@code null} values.
 *
 * @return {@code null-ok;} the corresponding constant or {@code null} if
 * there are no values to encode
 */
private CstArray makeStaticValuesConstant() {
    // First sort the statics into their final order.
    Collections.sort(staticFields);
    /*
         * Get the size of staticValues minus any trailing zeros/nulls (both
         * nulls per se as well as instances of CstKnownNull).
         */
    int size = staticFields.size();
    while (size > 0) {
        EncodedField field = staticFields.get(size - 1);
        Constant cst = staticValues.get(field);
        if (cst instanceof CstLiteralBits) {
            // Note: CstKnownNull extends CstLiteralBits.
            if (((CstLiteralBits) cst).getLongBits() != 0) {
                break;
            }
        } else if (cst != null) {
            break;
        }
        size--;
    }
    if (size == 0) {
        return null;
    }
    // There is something worth encoding, so build up a result.
    CstArray.List list = new CstArray.List(size);
    for (int i = 0; i < size; i++) {
        EncodedField field = staticFields.get(i);
        Constant cst = staticValues.get(field);
        if (cst == null) {
            cst = Zeroes.zeroFor(field.getRef().getType());
        }
        list.set(i, cst);
    }
    list.setImmutable();
    return new CstArray(list);
}
Also used : CstArray(com.android.dx.rop.cst.CstArray) CstLiteralBits(com.android.dx.rop.cst.CstLiteralBits) Constant(com.android.dx.rop.cst.Constant) ArrayList(java.util.ArrayList)

Example 39 with Constant

use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.

the class CodeItem method addContents.

/**
 * {@inheritDoc}
 */
public void addContents(DexFile file) {
    MixedItemSection byteData = file.getByteData();
    TypeIdsSection typeIds = file.getTypeIds();
    if (code.hasPositions() || code.hasLocals()) {
        debugInfo = new DebugInfoItem(code, isStatic, ref);
        byteData.add(debugInfo);
    }
    if (code.hasAnyCatches()) {
        for (Type type : code.getCatchTypes()) {
            typeIds.intern(type);
        }
        catches = new CatchStructs(code);
    }
    for (Constant c : code.getInsnConstants()) {
        file.internIfAppropriate(c);
    }
}
Also used : Type(com.android.dx.rop.type.Type) Constant(com.android.dx.rop.cst.Constant)

Example 40 with Constant

use of com.android.dx.rop.cst.Constant in project J2ME-Loader by nikita36078.

the class ValueEncoder method writeAnnotation.

/**
 * Writes out the encoded form of the given annotation, that is,
 * as an {@code encoded_annotation} and not including a
 * {@code value_type} prefix. If the output stream keeps
 * (debugging) annotations and {@code topLevel} is
 * {@code true}, then this method will write (debugging)
 * annotations.
 *
 * @param annotation {@code non-null;} annotation instance to write
 * @param topLevel {@code true} iff the given annotation is the
 * top-level annotation or {@code false} if it is a sub-annotation
 * of some other annotation
 */
public void writeAnnotation(Annotation annotation, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    StringIdsSection stringIds = file.getStringIds();
    TypeIdsSection typeIds = file.getTypeIds();
    CstType type = annotation.getType();
    int typeIdx = typeIds.indexOf(type);
    if (annotates) {
        out.annotate("  type_idx: " + Hex.u4(typeIdx) + " // " + type.toHuman());
    }
    out.writeUleb128(typeIds.indexOf(annotation.getType()));
    Collection<NameValuePair> pairs = annotation.getNameValuePairs();
    int size = pairs.size();
    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }
    out.writeUleb128(size);
    int at = 0;
    for (NameValuePair pair : pairs) {
        CstString name = pair.getName();
        int nameIdx = stringIds.indexOf(name);
        Constant value = pair.getValue();
        if (annotates) {
            out.annotate(0, "  elements[" + at + "]:");
            at++;
            out.annotate("    name_idx: " + Hex.u4(nameIdx) + " // " + name.toHuman());
        }
        out.writeUleb128(nameIdx);
        if (annotates) {
            out.annotate("    value: " + constantToHuman(value));
        }
        writeConstant(value);
    }
    if (annotates) {
        out.endAnnotation();
    }
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstString(com.android.dx.rop.cst.CstString)

Aggregations

Constant (com.android.dx.rop.cst.Constant)91 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)36 CstType (com.android.dx.rop.cst.CstType)30 CstString (com.android.dx.rop.cst.CstString)27 CstInsn (com.android.dx.dex.code.CstInsn)24 RegisterSpec (com.android.dx.rop.code.RegisterSpec)20 TypedConstant (com.android.dx.rop.cst.TypedConstant)20 CstLiteralBits (com.android.dx.rop.cst.CstLiteralBits)18 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)17 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)14 CstInteger (com.android.dx.rop.cst.CstInteger)12 NameValuePair (com.android.dx.rop.annotation.NameValuePair)8 Insn (com.android.dx.rop.code.Insn)8 PlainInsn (com.android.dx.rop.code.PlainInsn)8 Type (com.android.dx.rop.type.Type)8 TypeBearer (com.android.dx.rop.type.TypeBearer)8 Rop (com.android.dx.rop.code.Rop)6 ThrowingCstInsn (com.android.dx.rop.code.ThrowingCstInsn)6 ArrayList (java.util.ArrayList)6 ParseException (com.android.dx.cf.iface.ParseException)4