use of soot.dexpler.instructions.MoveExceptionInstruction in project soot by Sable.
the class DexBody method addTraps.
/**
* Add the traps of this body.
*
* Should only be called at the end jimplify.
*/
private void addTraps() {
final Jimple jimple = Jimple.v();
for (TryBlock<? extends ExceptionHandler> tryItem : tries) {
int startAddress = tryItem.getStartCodeAddress();
// .getTryLength();
int length = tryItem.getCodeUnitCount();
// - 1;
int endAddress = startAddress + length;
Unit beginStmt = instructionAtAddress(startAddress).getUnit();
// (startAddress + length) typically points to the first byte of the
// first instruction after the try block
// except if there is no instruction after the try block in which
// case it points to the last byte of the last
// instruction of the try block. Removing 1 from (startAddress +
// length) always points to "somewhere" in
// the last instruction of the try block since the smallest
// instruction is on two bytes (nop = 0x0000).
Unit endStmt = instructionAtAddress(endAddress).getUnit();
// the last instruction in the try block.
if (jBody.getUnits().getLast() == endStmt && instructionAtAddress(endAddress - 1).getUnit() == endStmt) {
Unit nop = jimple.newNopStmt();
jBody.getUnits().insertAfter(nop, endStmt);
endStmt = nop;
}
List<? extends ExceptionHandler> hList = tryItem.getExceptionHandlers();
for (ExceptionHandler handler : hList) {
String exceptionType = handler.getExceptionType();
if (exceptionType == null)
exceptionType = "Ljava/lang/Throwable;";
Type t = DexType.toSoot(exceptionType);
// exceptions can only be of RefType
if (t instanceof RefType) {
SootClass exception = ((RefType) t).getSootClass();
DexlibAbstractInstruction instruction = instructionAtAddress(handler.getHandlerCodeAddress());
if (!(instruction instanceof MoveExceptionInstruction))
logger.debug("" + String.format("First instruction of trap handler unit not MoveException but %s", instruction.getClass().getName()));
else
((MoveExceptionInstruction) instruction).setRealType(this, exception.getType());
Trap trap = jimple.newTrap(exception, beginStmt, endStmt, instruction.getUnit());
jBody.getTraps().add(trap);
}
}
}
}
Aggregations