Search in sources :

Example 81 with Constant

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

the class Form45cc method isCompatible.

/**
 * {@inheritDoc}
 */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof MultiCstInsn)) {
        return false;
    }
    MultiCstInsn mci = (MultiCstInsn) insn;
    if (mci.getNumberOfConstants() != 2) {
        return false;
    }
    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();
    return (wordCount(regs) >= 0);
}
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 82 with Constant

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

the class Form51l method isCompatible.

/**
 * {@inheritDoc}
 */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    if (!((insn instanceof CstInsn) && (regs.size() == 1) && unsignedFitsInByte(regs.get(0).getReg()))) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    Constant cst = ci.getConstant();
    return (cst instanceof CstLiteral64);
}
Also used : CstInsn(com.android.dx.dex.code.CstInsn) Constant(com.android.dx.rop.cst.Constant) CstLiteral64(com.android.dx.rop.cst.CstLiteral64) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList)

Example 83 with Constant

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

the class AnnotationUtils method makeInnerClass.

/**
 * Constructs a standard {@code InnerClass} annotation.
 *
 * @param name {@code null-ok;} the original name of the class, or
 * {@code null} to represent an anonymous class
 * @param accessFlags the original access flags
 * @return {@code non-null;} the annotation
 */
public static Annotation makeInnerClass(CstString name, int accessFlags) {
    Annotation result = new Annotation(INNER_CLASS_TYPE, SYSTEM);
    Constant nameCst = (name != null) ? name : CstKnownNull.THE_ONE;
    result.put(new NameValuePair(NAME_STRING, nameCst));
    result.put(new NameValuePair(ACCESS_FLAGS_STRING, CstInteger.make(accessFlags)));
    result.setImmutable();
    return result;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) Constant(com.android.dx.rop.cst.Constant) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Example 84 with Constant

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

the class ValueEncoder method writeArray.

/**
 * Writes out the encoded form of the given array, that is, as
 * an {@code encoded_array} 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 array {@code non-null;} array 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 writeArray(CstArray array, boolean topLevel) {
    boolean annotates = topLevel && out.annotates();
    CstArray.List list = ((CstArray) array).getList();
    int size = list.size();
    if (annotates) {
        out.annotate("  size: " + Hex.u4(size));
    }
    out.writeUleb128(size);
    for (int i = 0; i < size; i++) {
        Constant cst = list.get(i);
        if (annotates) {
            out.annotate("  [" + Integer.toHexString(i) + "] " + constantToHuman(cst));
        }
        writeConstant(cst);
    }
    if (annotates) {
        out.endAnnotation();
    }
}
Also used : CstArray(com.android.dx.rop.cst.CstArray) Constant(com.android.dx.rop.cst.Constant)

Example 85 with Constant

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

the class PlainInsn method withSourceLiteral.

/**
 * {@inheritDoc}
 */
@Override
public Insn withSourceLiteral() {
    RegisterSpecList sources = getSources();
    int szSources = sources.size();
    if (szSources == 0) {
        return this;
    }
    TypeBearer lastType = sources.get(szSources - 1).getTypeBearer();
    if (!lastType.isConstant()) {
        // Check for reverse subtraction, where first source is constant
        TypeBearer firstType = sources.get(0).getTypeBearer();
        if (szSources == 2 && firstType.isConstant()) {
            Constant cst = (Constant) firstType;
            RegisterSpecList newSources = sources.withoutFirst();
            Rop newRop = Rops.ropFor(getOpcode().getOpcode(), getResult(), newSources, cst);
            return new PlainCstInsn(newRop, getPosition(), getResult(), newSources, cst);
        }
        return this;
    } else {
        Constant cst = (Constant) lastType;
        RegisterSpecList newSources = sources.withoutLast();
        Rop newRop;
        try {
            // Check for constant subtraction and flip it to be addition
            int opcode = getOpcode().getOpcode();
            if (opcode == RegOps.SUB && cst instanceof CstInteger) {
                opcode = RegOps.ADD;
                cst = CstInteger.make(-((CstInteger) cst).getValue());
            }
            newRop = Rops.ropFor(opcode, getResult(), newSources, cst);
        } catch (IllegalArgumentException ex) {
            // There's no rop for this case
            return this;
        }
        return new PlainCstInsn(newRop, getPosition(), getResult(), newSources, cst);
    }
}
Also used : Constant(com.android.dx.rop.cst.Constant) CstInteger(com.android.dx.rop.cst.CstInteger) TypeBearer(com.android.dx.rop.type.TypeBearer)

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