Search in sources :

Example 1 with CstProtoRef

use of com.android.dx.rop.cst.CstProtoRef 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 2 with CstProtoRef

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

the class DalvInsnList method getOutsSize.

/**
 * Gets the size of the outgoing arguments area required by this
 * method. This is equal to the largest argument word count of any
 * method referred to by this instance.
 *
 * @return {@code >= 0;} the required outgoing arguments size
 */
public int getOutsSize() {
    int sz = size();
    int result = 0;
    for (int i = 0; i < sz; i++) {
        DalvInsn insn = (DalvInsn) get0(i);
        int count = 0;
        if (insn instanceof CstInsn) {
            Constant cst = ((CstInsn) insn).getConstant();
            if (cst instanceof CstBaseMethodRef) {
                CstBaseMethodRef methodRef = (CstBaseMethodRef) cst;
                boolean isStatic = (insn.getOpcode().getFamily() == Opcodes.INVOKE_STATIC);
                count = methodRef.getParameterWordCount(isStatic);
            }
        } else if (insn instanceof MultiCstInsn) {
            if (insn.getOpcode().getFamily() != Opcodes.INVOKE_POLYMORPHIC) {
                throw new RuntimeException("Expecting invoke-polymorphic");
            }
            MultiCstInsn mci = (MultiCstInsn) insn;
            // Invoke-polymorphic has two constants: [0] method-ref and
            // [1] call site prototype. The number of arguments is based
            // on the call site prototype since these are the arguments
            // presented. The method-ref is always MethodHandle.invoke(Object[])
            // or MethodHandle.invokeExact(Object[]).
            CstProtoRef proto = (CstProtoRef) mci.getConstant(1);
            count = proto.getPrototype().getParameterTypes().getWordCount();
            // And one for receiver (method handle).
            count = count + 1;
        } else {
            continue;
        }
        if (count > result) {
            result = count;
        }
    }
    return result;
}
Also used : CstProtoRef(com.android.dx.rop.cst.CstProtoRef) CstBaseMethodRef(com.android.dx.rop.cst.CstBaseMethodRef) Constant(com.android.dx.rop.cst.Constant)

Example 3 with CstProtoRef

use of com.android.dx.rop.cst.CstProtoRef 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 4 with CstProtoRef

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

the class ProtoIdsSection method get.

/**
 * {@inheritDoc}
 */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }
    if (!(cst instanceof CstProtoRef)) {
        throw new IllegalArgumentException("cst not instance of CstProtoRef");
    }
    throwIfNotPrepared();
    CstProtoRef protoRef = (CstProtoRef) cst;
    IndexedItem result = protoIds.get(protoRef.getPrototype());
    if (result == null) {
        throw new IllegalArgumentException("not found");
    }
    return result;
}
Also used : CstProtoRef(com.android.dx.rop.cst.CstProtoRef)

Aggregations

CstProtoRef (com.android.dx.rop.cst.CstProtoRef)4 Constant (com.android.dx.rop.cst.Constant)3 MultiCstInsn (com.android.dx.dex.code.MultiCstInsn)2 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)2 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)2 CstBaseMethodRef (com.android.dx.rop.cst.CstBaseMethodRef)1