com.android.dx.dex.code.DalvInsn Java Examples

The following examples show how to use com.android.dx.dex.code.DalvInsn. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Form21h.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits cb = (CstLiteralBits) ((CstInsn) insn).getConstant();
    short bits;

    // Where the high bits are depends on the category of the target.
    if (regs.get(0).getCategory() == 1) {
        bits = (short) (cb.getIntBits() >>> 16);
    } else {
        bits = (short) (cb.getLongBits() >>> 48);
    }

    write(out, opcodeUnit(insn, regs.get(0).getReg()), bits);
}
 
Example #2
Source File: Form31i.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@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();

    if (!(cst instanceof CstLiteralBits)) {
        return false;
    }

    return ((CstLiteralBits) cst).fitsInInt();
}
 
Example #3
Source File: Form45cc.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    MultiCstInsn mci = (MultiCstInsn) insn;
    short regB = (short) mci.getIndex(0);  // B is the method index
    short regH = (short) mci.getIndex(1);  // H is the call site proto index

    RegisterSpecList regs = explicitize(insn.getRegisters());
    int regA = regs.size();
    int regC = (regA > 0) ? regs.get(0).getReg() : 0;
    int regD = (regA > 1) ? regs.get(1).getReg() : 0;
    int regE = (regA > 2) ? regs.get(2).getReg() : 0;
    int regF = (regA > 3) ? regs.get(3).getReg() : 0;
    int regG = (regA > 4) ? regs.get(4).getReg() : 0;

    // The output format is: A|G|op BBBB F|E|D|C HHHHH
    write(out,
          opcodeUnit(insn, makeByte(regG, regA)),
          regB,
          codeUnit(regC, regD, regE, regF),
          regH);
}
 
Example #4
Source File: Form45cc.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);

    for (int i = 0; i < sz; i++) {
        RegisterSpec reg = regs.get(i);
        /*
         * The check below adds (category - 1) to the register, to
         * account for the fact that the second half of a
         * category-2 register has to be represented explicitly in
         * the result.
         */
        bits.set(i, unsignedFitsInNibble(reg.getReg() +
                                         reg.getCategory() - 1));
    }

    return bits;
}
 
Example #5
Source File: Form35c.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();
    return (wordCount(regs) >= 0);
}
 
Example #6
Source File: Form35c.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    Constant cst = ci.getConstant();
    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType) ||
          (cst instanceof CstCallSiteRef))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();
    return (wordCount(regs) >= 0);
}
 
Example #7
Source File: Form45cc.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    MultiCstInsn mci = (MultiCstInsn) insn;
    short regB = (short) mci.getIndex(0);  // B is the method index
    short regH = (short) mci.getIndex(1);  // H is the call site proto index

    RegisterSpecList regs = explicitize(insn.getRegisters());
    int regA = regs.size();
    int regC = (regA > 0) ? regs.get(0).getReg() : 0;
    int regD = (regA > 1) ? regs.get(1).getReg() : 0;
    int regE = (regA > 2) ? regs.get(2).getReg() : 0;
    int regF = (regA > 3) ? regs.get(3).getReg() : 0;
    int regG = (regA > 4) ? regs.get(4).getReg() : 0;

    // The output format is: A|G|op BBBB F|E|D|C HHHHH
    write(out,
          opcodeUnit(insn, makeByte(regG, regA)),
          regB,
          codeUnit(regC, regD, regE, regF),
          regH);
}
 
Example #8
Source File: Form12x.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();

    /*
     * The (sz - 2) and (sz - 1) below makes this code work for
     * both the two- and three-register ops. (See "case 3" in
     * isCompatible(), above.)
     */

    write(out, opcodeUnit(insn,
                          makeByte(regs.get(sz - 2).getReg(),
                                   regs.get(sz - 1).getReg())));
}
 
Example #9
Source File: Form45cc.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);

    for (int i = 0; i < sz; i++) {
        RegisterSpec reg = regs.get(i);
        /*
         * The check below adds (category - 1) to the register, to
         * account for the fact that the second half of a
         * category-2 register has to be represented explicitly in
         * the result.
         */
        bits.set(i, unsignedFitsInNibble(reg.getReg() +
                                         reg.getCategory() - 1));
    }

    return bits;
}
 
Example #10
Source File: Form45cc.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);

    for (int i = 0; i < sz; i++) {
        RegisterSpec reg = regs.get(i);
        /*
         * The check below adds (category - 1) to the register, to
         * account for the fact that the second half of a
         * category-2 register has to be represented explicitly in
         * the result.
         */
        bits.set(i, unsignedFitsInNibble(reg.getReg() +
                                         reg.getCategory() - 1));
    }

    return bits;
}
 
Example #11
Source File: Form21c.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();
    BitSet bits = new BitSet(sz);
    boolean compat = unsignedFitsInByte(regs.get(0).getReg());

    if (sz == 1) {
        bits.set(0, compat);
    } else {
        if (regs.get(0).getReg() == regs.get(1).getReg()) {
            bits.set(0, compat);
            bits.set(1, compat);
        }
    }

    return bits;
}
 
Example #12
Source File: Form22c.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(2);

    bits.set(0, unsignedFitsInNibble(regs.get(0).getReg()));
    bits.set(1, unsignedFitsInNibble(regs.get(1).getReg()));
    return bits;
}
 
Example #13
Source File: Form35c.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnCommentString(DalvInsn insn, boolean noteIndices) {
    if (noteIndices) {
        return insn.cstComment();
    } else {
        return "";
    }
}
 
Example #14
Source File: Form12x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int sz = regs.size();

    /*
     * The (sz - 2) and (sz - 1) below makes this code work for
     * both the two- and three-register ops. (See "case 3" in
     * isCompatible(), below.)
     */

    return regs.get(sz - 2).regString() + ", " +
        regs.get(sz - 1).regString();
}
 
Example #15
Source File: Form11x.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #16
Source File: Form3rc.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int cpi = ((CstInsn) insn).getIndex();
    int firstReg = (regs.size() == 0) ? 0 : regs.get(0).getReg();
    int count = regs.getWordCount();

    write(out, opcodeUnit(insn, count), (short) cpi, (short) firstReg);
}
 
Example #17
Source File: Form21c.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    int cpi = ((CstInsn) insn).getIndex();

    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) cpi);
}
 
Example #18
Source File: Form3rc.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnCommentString(DalvInsn insn, boolean noteIndices) {
    if (noteIndices) {
        return insn.cstComment();
    } else {
        return "";
    }
}
 
Example #19
Source File: Form22x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    write(out,
          opcodeUnit(insn, regs.get(0).getReg()),
          (short) regs.get(1).getReg());
}
 
Example #20
Source File: Form11x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #21
Source File: Form51l.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();

    return regs.get(0).regString() + ", " + literalBitsString(value);
}
 
Example #22
Source File: Form32x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(2);

    bits.set(0, unsignedFitsInShort(regs.get(0).getReg()));
    bits.set(1, unsignedFitsInShort(regs.get(1).getReg()));
    return bits;
}
 
Example #23
Source File: Form3rc.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }

    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();
    Constant cst = ci.getConstant();

    if (! unsignedFitsInShort(cpi)) {
        return false;
    }

    if (!((cst instanceof CstMethodRef) ||
          (cst instanceof CstType))) {
        return false;
    }

    RegisterSpecList regs = ci.getRegisters();

    return (regs.size() == 0) ||
        (isRegListSequential(regs) &&
         unsignedFitsInShort(regs.get(0).getReg()) &&
         unsignedFitsInByte(regs.getWordCount()));
}
 
Example #24
Source File: Form12x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof SimpleInsn)) {
        return false;
    }

    RegisterSpecList regs = insn.getRegisters();
    RegisterSpec rs1;
    RegisterSpec rs2;

    switch (regs.size()) {
        case 2: {
            rs1 = regs.get(0);
            rs2 = regs.get(1);
            break;
        }
        case 3: {
            /*
             * This format is allowed for ops that are effectively
             * 3-arg but where the first two args are identical.
             */
            rs1 = regs.get(1);
            rs2 = regs.get(2);
            if (rs1.getReg() != regs.get(0).getReg()) {
                return false;
            }
            break;
        }
        default: {
            return false;
        }
    }

    return unsignedFitsInNibble(rs1.getReg()) &&
        unsignedFitsInNibble(rs2.getReg());
}
 
Example #25
Source File: Form22x.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();

    return (insn instanceof SimpleInsn) &&
        (regs.size() == 2) &&
        unsignedFitsInByte(regs.get(0).getReg()) &&
        unsignedFitsInShort(regs.get(1).getReg());
}
 
Example #26
Source File: Form21s.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public BitSet compatibleRegs(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    BitSet bits = new BitSet(1);

    bits.set(0, unsignedFitsInByte(regs.get(0).getReg()));
    return bits;
}
 
Example #27
Source File: Form11n.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public String insnArgString(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    CstLiteralBits value = (CstLiteralBits) ((CstInsn) insn).getConstant();

    return regs.get(0).regString() + ", " + literalBitsString(value);
}
 
Example #28
Source File: Form32x.java    From J2ME-Loader with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();
    return (insn instanceof SimpleInsn) &&
        (regs.size() == 2) &&
        unsignedFitsInShort(regs.get(0).getReg()) &&
        unsignedFitsInShort(regs.get(1).getReg());
}
 
Example #29
Source File: Form20t.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void writeTo(AnnotatedOutput out, DalvInsn insn) {
    int offset = ((TargetInsn) insn).getTargetOffset();

    write(out, opcodeUnit(insn, 0), (short) offset);
}
 
Example #30
Source File: Form22x.java    From Box with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public boolean isCompatible(DalvInsn insn) {
    RegisterSpecList regs = insn.getRegisters();

    return (insn instanceof SimpleInsn) &&
        (regs.size() == 2) &&
        unsignedFitsInByte(regs.get(0).getReg()) &&
        unsignedFitsInShort(regs.get(1).getReg());
}