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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations