Search in sources :

Example 1 with Insn21c

use of soot.toDex.instructions.Insn21c in project soot by Sable.

the class ExprVisitor method castObject.

private void castObject(Register sourceReg, Type castType) {
    /*
		 * No real "cast" is done: move the object to a tmp reg, check the cast
		 * with check-cast and finally move to the "cast" object location. This
		 * way a) the old reg is not touched by check-cast, and b) the new reg
		 * does change its type only after a successful check-cast.
		 * 
		 * a) is relevant e.g. for "r1 = (String) r0" if r0 contains null, since
		 * the internal type of r0 would change from Null to String after the
		 * check-cast opcode, which alerts the verifier in future uses of r0
		 * although nothing should change during execution.
		 * 
		 * b) is relevant for exceptional control flow: if we move to the new
		 * reg and do the check-cast there, an exception between the end of the
		 * move's execution and the end of the check-cast execution leaves the
		 * new reg with the type of the old reg.
		 */
    TypeReference castTypeItem = DexPrinter.toTypeReference(castType);
    if (sourceReg.getNumber() == destinationReg.getNumber()) {
        // simplyfied case if reg numbers do not differ
        stmtV.addInsn(new Insn21c(Opcode.CHECK_CAST, destinationReg, castTypeItem), origStmt);
    } else {
        // move to tmp reg, check cast, move to destination
        Register tmp = regAlloc.asTmpReg(sourceReg.getType());
        stmtV.addInsn(StmtVisitor.buildMoveInsn(tmp, sourceReg), origStmt);
        stmtV.addInsn(new Insn21c(Opcode.CHECK_CAST, tmp.clone(), castTypeItem), origStmt);
        stmtV.addInsn(StmtVisitor.buildMoveInsn(destinationReg, tmp.clone()), origStmt);
    }
}
Also used : Insn21c(soot.toDex.instructions.Insn21c) TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

Example 2 with Insn21c

use of soot.toDex.instructions.Insn21c in project soot by Sable.

the class ExprVisitor method caseNewExpr.

@Override
public void caseNewExpr(NewExpr ne) {
    TypeReference baseType = DexPrinter.toTypeReference(ne.getBaseType());
    stmtV.addInsn(new Insn21c(Opcode.NEW_INSTANCE, destinationReg, baseType), origStmt);
}
Also used : Insn21c(soot.toDex.instructions.Insn21c) TypeReference(org.jf.dexlib2.iface.reference.TypeReference)

Example 3 with Insn21c

use of soot.toDex.instructions.Insn21c in project soot by Sable.

the class StmtVisitor method buildStaticFieldGetInsn.

private Insn buildStaticFieldGetInsn(Register destinationReg, StaticFieldRef sourceRef) {
    FieldReference sourceField = DexPrinter.toFieldReference(sourceRef.getFieldRef());
    Opcode opc = getPutGetOpcodeWithTypeSuffix(SGET_OPCODE, sourceField.getType());
    return new Insn21c(opc, destinationReg, sourceField);
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) Insn21c(soot.toDex.instructions.Insn21c) Opcode(org.jf.dexlib2.Opcode)

Example 4 with Insn21c

use of soot.toDex.instructions.Insn21c in project soot by Sable.

the class StmtVisitor method buildStaticFieldPutInsn.

private Insn buildStaticFieldPutInsn(StaticFieldRef destRef, Value source) {
    Register sourceReg = regAlloc.asImmediate(source, constantV);
    FieldReference destField = DexPrinter.toFieldReference(destRef.getFieldRef());
    Opcode opc = getPutGetOpcodeWithTypeSuffix(SPUT_OPCODE, destField.getType());
    return new Insn21c(opc, sourceReg, destField);
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) Insn21c(soot.toDex.instructions.Insn21c) Opcode(org.jf.dexlib2.Opcode)

Example 5 with Insn21c

use of soot.toDex.instructions.Insn21c in project soot by Sable.

the class ConstantVisitor method caseStringConstant.

public void caseStringConstant(StringConstant s) {
    StringReference ref = new ImmutableStringReference(s.value);
    stmtV.addInsn(new Insn21c(Opcode.CONST_STRING, destinationReg, ref), origStmt);
}
Also used : Insn21c(soot.toDex.instructions.Insn21c) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference) ImmutableStringReference(org.jf.dexlib2.immutable.reference.ImmutableStringReference) StringReference(org.jf.dexlib2.iface.reference.StringReference)

Aggregations

Insn21c (soot.toDex.instructions.Insn21c)6 TypeReference (org.jf.dexlib2.iface.reference.TypeReference)3 Opcode (org.jf.dexlib2.Opcode)2 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)2 StringReference (org.jf.dexlib2.iface.reference.StringReference)1 ImmutableStringReference (org.jf.dexlib2.immutable.reference.ImmutableStringReference)1 ImmutableTypeReference (org.jf.dexlib2.immutable.reference.ImmutableTypeReference)1