use of soot.jimple.AssignStmt in project soot by Sable.
the class AgetInstruction method jimplify.
@Override
public void jimplify(DexBody body) throws InvalidDalvikBytecodeException {
if (!(instruction instanceof Instruction23x))
throw new IllegalArgumentException("Expected Instruction23x but got: " + instruction.getClass());
Instruction23x aGetInstr = (Instruction23x) instruction;
int dest = aGetInstr.getRegisterA();
Local arrayBase = body.getRegisterLocal(aGetInstr.getRegisterB());
Local index = body.getRegisterLocal(aGetInstr.getRegisterC());
ArrayRef arrayRef = Jimple.v().newArrayRef(arrayBase, index);
Local l = body.getRegisterLocal(dest);
AssignStmt assign = Jimple.v().newAssignStmt(l, arrayRef);
if (aGetInstr.getOpcode() == Opcode.AGET_OBJECT)
assign.addTag(new ObjectOpTag());
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
DalvikTyper.v().addConstraint(assign.getLeftOpBox(), assign.getRightOpBox());
DalvikTyper.v().setType(arrayRef.getIndexBox(), IntType.v(), true);
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class BinopLitInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
if (!(instruction instanceof Instruction22s) && !(instruction instanceof Instruction22b))
throw new IllegalArgumentException("Expected Instruction22s or Instruction22b but got: " + instruction.getClass());
NarrowLiteralInstruction binOpLitInstr = (NarrowLiteralInstruction) this.instruction;
int dest = ((TwoRegisterInstruction) instruction).getRegisterA();
int source = ((TwoRegisterInstruction) instruction).getRegisterB();
Local source1 = body.getRegisterLocal(source);
IntConstant constant = IntConstant.v(binOpLitInstr.getNarrowLiteral());
Value expr = getExpression(source1, constant);
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
assign.addTag(getTag());
setUnit(assign);
addTags(assign);
body.add(assign);
/*if (IDalvikTyper.ENABLE_DVKTYPER) {
Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
int op = (int)instruction.getOpcode().value;
if (op >= 0xd8) {
op -= 0xd8;
} else {
op -= 0xd0;
}
BinopExpr bexpr = (BinopExpr)expr;
//body.dvkTyper.setType((op == 1) ? bexpr.getOp2Box() : bexpr.getOp1Box(), op1BinType[op]);
DalvikTyper.v().setType(((JAssignStmt)assign).leftBox, op1BinType[op], false);
}*/
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class CheckCastInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
if (!(instruction instanceof Instruction21c))
throw new IllegalArgumentException("Expected Instruction21c but got: " + instruction.getClass());
Instruction21c checkCastInstr = (Instruction21c) instruction;
Local castValue = body.getRegisterLocal(checkCastInstr.getRegisterA());
Type checkCastType = DexType.toSoot((TypeReference) checkCastInstr.getReference());
CastExpr castExpr = Jimple.v().newCastExpr(castValue, checkCastType);
// generate "x = (Type) x"
// splitter will take care of the rest
AssignStmt assign = Jimple.v().newAssignStmt(castValue, castExpr);
setUnit(assign);
addTags(assign);
body.add(assign);
if (IDalvikTyper.ENABLE_DVKTYPER) {
DalvikTyper.v().setType(assign.getLeftOpBox(), checkCastType, false);
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class Util method emptyBody.
/**
* Remove all statements except from IdentityStatements for parameters.
* Return default value (null or zero or nothing depending on the return
* type).
*
* @param jBody
*/
public static void emptyBody(Body jBody) {
// identity statements
List<Unit> idStmts = new ArrayList<Unit>();
List<Local> idLocals = new ArrayList<Local>();
for (Unit u : jBody.getUnits()) {
if (u instanceof IdentityStmt) {
IdentityStmt i = (IdentityStmt) u;
if (i.getRightOp() instanceof ParameterRef || i.getRightOp() instanceof ThisRef) {
idStmts.add(u);
idLocals.add((Local) i.getLeftOp());
}
}
}
jBody.getUnits().clear();
jBody.getLocals().clear();
jBody.getTraps().clear();
final LocalGenerator lg = new LocalGenerator(jBody);
for (Unit u : idStmts) jBody.getUnits().add(u);
for (Local l : idLocals) jBody.getLocals().add(l);
Type rType = jBody.getMethod().getReturnType();
jBody.getUnits().add(Jimple.v().newNopStmt());
if (rType instanceof VoidType) {
jBody.getUnits().add(Jimple.v().newReturnVoidStmt());
} else {
Type t = jBody.getMethod().getReturnType();
Local l = lg.generateLocal(t);
AssignStmt ass = null;
if (t instanceof RefType || t instanceof ArrayType) {
ass = Jimple.v().newAssignStmt(l, NullConstant.v());
} else if (t instanceof LongType) {
ass = Jimple.v().newAssignStmt(l, LongConstant.v(0));
} else if (t instanceof FloatType) {
ass = Jimple.v().newAssignStmt(l, FloatConstant.v(0.0f));
} else if (t instanceof IntType) {
ass = Jimple.v().newAssignStmt(l, IntConstant.v(0));
} else if (t instanceof DoubleType) {
ass = Jimple.v().newAssignStmt(l, DoubleConstant.v(0));
} else if (t instanceof BooleanType || t instanceof ByteType || t instanceof CharType || t instanceof ShortType) {
ass = Jimple.v().newAssignStmt(l, IntConstant.v(0));
} else {
throw new RuntimeException("error: return type unknown: " + t + " class: " + t.getClass());
}
jBody.getUnits().add(ass);
jBody.getUnits().add(Jimple.v().newReturnStmt(l));
}
}
use of soot.jimple.AssignStmt in project soot by Sable.
the class Binop2addrInstruction method jimplify.
@Override
public void jimplify(DexBody body) {
if (!(instruction instanceof Instruction12x))
throw new IllegalArgumentException("Expected Instruction12x but got: " + instruction.getClass());
Instruction12x binOp2AddrInstr = (Instruction12x) instruction;
int dest = binOp2AddrInstr.getRegisterA();
Local source1 = body.getRegisterLocal(binOp2AddrInstr.getRegisterA());
Local source2 = body.getRegisterLocal(binOp2AddrInstr.getRegisterB());
Value expr = getExpression(source1, source2);
AssignStmt assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), expr);
assign.addTag(getTag());
setUnit(assign);
addTags(assign);
body.add(assign);
/*
if (IDalvikTyper.ENABLE_DVKTYPER) {
BinopExpr bexpr = (BinopExpr)expr;
short op = instruction.getOpcode().value;
DalvikTyper.v().setType(bexpr.getOp1Box(), op1BinType[op-0xb0], true);
DalvikTyper.v().setType(bexpr.getOp2Box(), op2BinType[op-0xb0], true);
DalvikTyper.v().setType(assign.getLeftOpBox(), resBinType[op-0xb0], false);
}
*/
}
Aggregations