本文整理汇总了Java中soot.jimple.ThrowStmt类的典型用法代码示例。如果您正苦于以下问题:Java ThrowStmt类的具体用法?Java ThrowStmt怎么用?Java ThrowStmt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ThrowStmt类属于soot.jimple包,在下文中一共展示了ThrowStmt类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: internalTransform
import soot.jimple.ThrowStmt; //导入依赖的package包/类
@Override
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
LocalCreation lc = new LocalCreation(b.getLocals(), "ex");
for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext(); ) {
Unit u = unitIt.next();
// Check for a null exception
if (u instanceof ThrowStmt) {
ThrowStmt throwStmt = (ThrowStmt) u;
if (throwStmt.getOp() == NullConstant.v()
|| throwStmt.getOp().equals(IntConstant.v(0))
|| throwStmt.getOp().equals(LongConstant.v(0))) {
createThrowStmt(b, throwStmt, lc);
}
}
}
}
示例2: propagateNormalFlow
import soot.jimple.ThrowStmt; //导入依赖的package包/类
@Override
public KillGenInfo propagateNormalFlow(Trackable trackable, Unit curr, Unit succ) {
if (curr instanceof ReturnStmt) {
Value retValue = getBase(((ReturnStmt) curr).getOp());
if (retValue instanceof Constant) {
return kill();
} else {
ReturnValueTaint retValTaint = (ReturnValueTaint) trackable;
if (AnalysisUtil.isAssignable(retValTaint.type, retValue.getType()))
return propagate(new Taint(curr, trackable, retValue, retValTaint.type));
else
return kill();
}
} else if (curr instanceof ThrowStmt)
return kill();
throw new IllegalStateException();
}
示例3: methodIsAndroidStub
import soot.jimple.ThrowStmt; //导入依赖的package包/类
/**
* Checks whether the given method is a library stub method
* @param method The method to check
* @return True if the given method is an Android library stub, false
* otherwise
*/
private boolean methodIsAndroidStub(SootMethod method) {
if (!(Options.v().src_prec() == Options.src_prec_apk
&& method.getDeclaringClass().isLibraryClass()
&& SystemClassHandler.isClassInSystemPackage(
method.getDeclaringClass().getName())))
return false;
// Check whether there is only a single throw statement
for (Unit u : method.getActiveBody().getUnits()) {
if (u instanceof DefinitionStmt) {
DefinitionStmt defStmt = (DefinitionStmt) u;
if (!(defStmt.getRightOp() instanceof ThisRef)
&& !(defStmt.getRightOp() instanceof ParameterRef)
&& !(defStmt.getRightOp() instanceof NewExpr))
return false;
}
else if (u instanceof InvokeStmt) {
InvokeStmt stmt = (InvokeStmt) u;
// Check for exception constructor invocations
SootMethod callee = stmt.getInvokeExpr().getMethod();
if (!callee.getSubSignature().equals("void <init>(java.lang.String)"))
// Check for super class constructor invocation
if (!(method.getDeclaringClass().hasSuperclass()
&& callee.getDeclaringClass() == method.getDeclaringClass().getSuperclass()
&& callee.getName().equals("<init>")))
return false;
}
else if (!(u instanceof ThrowStmt))
return false;
}
return true;
}
示例4: caseThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
public void caseThrowStmt(ThrowStmt stmt) {
if (uses) {
if (stmt.getOp() instanceof Local) {
TypeVariable op = resolver.typeVariable((Local) stmt.getOp());
op.addParent(resolver.typeVariable(RefType.v("java.lang.Throwable")));
}
}
}
示例5: caseThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
@Override
public void caseThrowStmt(ThrowStmt stmt) {
Value exception = stmt.getOp();
constantV.setOrigStmt(stmt);
Register exceptionReg = regAlloc.asImmediate(exception, constantV);
addInsn(new Insn11x(Opcode.THROW, exceptionReg), stmt);
}
示例6: buildHeadsAndTails
import soot.jimple.ThrowStmt; //导入依赖的package包/类
/**
* Utility method, to be called only after the unitToPreds and unitToSuccs
* maps have been built. It defines the graph's set of heads to include the
* first {@link Unit} in the graph's body, together with all the
* <code>Unit</code>s in <code>additionalHeads</code>. It defines the
* graph's set of tails to include all <code>Unit</code>s which represent
* some sort of return bytecode or an <code>athrow</code> bytecode which may
* escape the method.
*/
private void buildHeadsAndTails(Set<Unit> additionalHeads) {
List<Unit> headList = new ArrayList<Unit>(additionalHeads.size() + 1);
headList.addAll(additionalHeads);
if (unitChain.isEmpty())
throw new IllegalStateException("No body for method "
+ body.getMethod().getSignature());
Unit entryPoint = unitChain.getFirst();
if (!headList.contains(entryPoint)) {
headList.add(entryPoint);
}
List<Unit> tailList = new ArrayList<Unit>();
for (Unit u : unitChain) {
if (u instanceof soot.jimple.ReturnStmt
|| u instanceof soot.jimple.ReturnVoidStmt
|| u instanceof soot.baf.ReturnInst
|| u instanceof soot.baf.ReturnVoidInst) {
tailList.add(u);
} else if (u instanceof soot.jimple.ThrowStmt
|| u instanceof soot.baf.ThrowInst) {
Collection<ExceptionDest> dests = getExceptionDests(u);
int escapeMethodCount = 0;
for (ExceptionDest dest : dests) {
if (dest.getTrap() == null) {
escapeMethodCount++;
}
}
if (escapeMethodCount > 0) {
tailList.add(u);
}
}
}
tails = Collections.unmodifiableList(tailList);
heads = Collections.unmodifiableList(headList);
}
示例7: testJThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
@Test
public void testJThrowStmt() {
// First test with an argument that is included in
// PERENNIAL_THROW_EXCEPTIONS.
ThrowStmt s = Jimple.v().newThrowStmt(Jimple.v().newLocal("local0",
RefType.v("java.lang.NullPointerException")));
Set expectedRep = new ExceptionHashSet(utility.PERENNIAL_THROW_EXCEPTIONS);
expectedRep.remove(utility.NULL_POINTER_EXCEPTION);
expectedRep.add(AnySubType.v(utility.NULL_POINTER_EXCEPTION));
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
assertEquals(utility.PERENNIAL_THROW_EXCEPTIONS_PLUS_SUPERTYPES,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
// Throw a local of type IncompatibleClassChangeError.
Local local = Jimple.v().newLocal("local1",
utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
s.setOp(local);
expectedRep = new ExceptionHashSet(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE);
expectedRep.remove(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR);
expectedRep.add(AnySubType.v(utility.INCOMPATIBLE_CLASS_CHANGE_ERROR));
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
assertEquals(utility.THROW_PLUS_INCOMPATIBLE_CLASS_CHANGE_PLUS_SUBTYPES_PLUS_SUPERTYPES,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
// Throw a local of unknown type.
local = Jimple.v().newLocal("local1", soot.UnknownType.v());
s.setOp(local);
assertTrue(ExceptionTestUtility.sameMembers(utility.ALL_THROWABLES_REP,
Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
assertEquals(utility.ALL_TEST_THROWABLES,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
示例8: findExceptionType
import soot.jimple.ThrowStmt; //导入依赖的package包/类
private SootClass findExceptionType(ThrowStmt s) {
if (s.getOp() instanceof NewExpr) {
NewExpr ne = (NewExpr) s.getOp();
return ne.getBaseType().getSootClass();
} else if (s.getOp() instanceof Local) {
Local l = (Local) s.getOp();
if (l.getType() instanceof RefType) {
return ((RefType) l.getType()).getSootClass();
}
}
// System.err.println("Unexpected value in throw stmt " + s.getOp());
return Scene.v().loadClass("java.lang.Throwable", SootClass.SIGNATURES);
}
示例9: caseThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
@Override
public void caseThrowStmt(ThrowStmt arg0) {
injectLabelStatements(arg0);
// find the type of the exception that is thrown.
SootClass c = findExceptionType(arg0);
arg0.getOp().apply(this.valueswitch);
Expression right = this.valueswitch.getExpression();
// assign the value from arg0.getOp() to the $exception variable of
// the current procedure.
// Note that this only works because soot moves the "new" statement
// to a new local variable.
AssignmentTranslation.translateAssignment(this,
this.procInfo.getExceptionVariable(), right);
// Add a goto statement to the exceptional successors.
List<Trap> traps = new LinkedList<Trap>();
List<Trap> finally_traps = new LinkedList<Trap>(); // TODO: do we have
TranslationHelpers.getReachableTraps(arg0,
this.procInfo.getSootMethod(), traps, finally_traps);
// TODO, maybe we need to consider the case that
// we don't know the exact type of arg0.getOp at this point?
for (Trap trap : traps) {
if (GlobalsCache.v().isSubTypeOrEqual(c, trap.getException())) {
this.boogieStatements.add(this.pf.mkGotoStatement(GlobalsCache
.v().getUnitLabel((Stmt) trap.getHandlerUnit())));
return;
}
}
this.boogieStatements.add(this.pf.mkReturnStatement());
}
示例10: isBranch
import soot.jimple.ThrowStmt; //导入依赖的package包/类
public static boolean isBranch(Unit u){
if(u instanceof IfStmt ||
u instanceof GotoStmt ||
u instanceof SwitchStmt ||
u instanceof ThrowStmt ||
u instanceof ReturnStmt ||
u instanceof ReturnVoidStmt)
return true;
return false;
}
示例11: findExceptionType
import soot.jimple.ThrowStmt; //导入依赖的package包/类
private SootClass findExceptionType(ThrowStmt s) {
if (s.getOp() instanceof NewExpr) {
NewExpr ne = (NewExpr) s.getOp();
return ne.getBaseType().getSootClass();
} else if (s.getOp() instanceof Local) {
Local l = (Local) s.getOp();
if (l.getType() instanceof RefType) {
return ((RefType) l.getType()).getSootClass();
}
}
System.err.println("Unexpected value in throw stmt " + s.getOp());
return Scene.v().loadClass("java.lang.Throwable", SootClass.SIGNATURES);
}
示例12: caseThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
@Override
public void caseThrowStmt(ThrowStmt stmt) {
throw new RuntimeException("todo");
}
示例13: fixExceptions
import soot.jimple.ThrowStmt; //导入依赖的package包/类
private void fixExceptions(SootMethod caller, Unit callSite, Set<SootClass> doneSet) {
ThrowAnalysis ta = Options.v().src_prec() == Options.src_prec_apk
? DalvikThrowAnalysis.v() : UnitThrowAnalysis.v();
ThrowableSet throwSet = ta.mightThrow(callSite);
for (final Trap t : caller.getActiveBody().getTraps())
if (doneSet.add(t.getException())
&& throwSet.catchableAs(t.getException().getType())) {
SootMethod thrower = exceptionThrowers.get(t.getException());
if (thrower == null) {
if (exceptionClass == null) {
exceptionClass = new SootClass("FLOWDROID_EXCEPTIONS", Modifier.PUBLIC);
Scene.v().addClass(exceptionClass);
}
// Create the new method
thrower = new SootMethod("throw" + exceptionThrowers.size(),
Collections.<Type>emptyList(), VoidType.v());
thrower.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
final Body body = Jimple.v().newBody(thrower);
thrower.setActiveBody(body);
final SootMethod meth = thrower;
IEntryPointCreator epc = new BaseEntryPointCreator() {
@Override
public Collection<String> getRequiredClasses() {
return Collections.emptySet();
}
@Override
protected SootMethod createDummyMainInternal(SootMethod emptySootMethod) {
LocalGenerator generator = new LocalGenerator(body);
// Create the counter used for the opaque predicate
int conditionCounter = 0;
Value intCounter = generator.generateLocal(IntType.v());
AssignStmt assignStmt = new JAssignStmt(intCounter, IntConstant.v(conditionCounter));
body.getUnits().add(assignStmt);
Stmt afterEx = Jimple.v().newNopStmt();
IfStmt ifStmt = Jimple.v().newIfStmt(Jimple.v().newEqExpr(intCounter,
IntConstant.v(conditionCounter)), afterEx);
body.getUnits().add(ifStmt);
conditionCounter++;
Local lcEx = generator.generateLocal(t.getException().getType());
AssignStmt assignNewEx = Jimple.v().newAssignStmt(lcEx,
Jimple.v().newNewExpr(t.getException().getType()));
body.getUnits().add(assignNewEx);
InvokeStmt consNewEx = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(lcEx,
Scene.v().makeConstructorRef(exceptionClass, Collections.<Type>emptyList())));
body.getUnits().add(consNewEx);
ThrowStmt throwNewEx = Jimple.v().newThrowStmt(lcEx);
body.getUnits().add(throwNewEx);
body.getUnits().add(afterEx);
return meth;
}
};
epc.createDummyMain(thrower);
exceptionThrowers.put(t.getException(), thrower);
exceptionClass.addMethod(thrower);
}
// Call the exception thrower after the old call site
Stmt throwCall = Jimple.v().newInvokeStmt(Jimple.v().newStaticInvokeExpr(thrower.makeRef()));
caller.getActiveBody().getUnits().insertBefore(throwCall, callSite);
}
}
示例14: caseThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
public void caseThrowStmt(ThrowStmt stmt) {
String varName = printValueAssignment(stmt.getOp(),"op");
printStmt(stmt, varName);
}
示例15: caseThrowStmt
import soot.jimple.ThrowStmt; //导入依赖的package包/类
public void caseThrowStmt(ThrowStmt stmt)
{
stmt.setOp(this.uv.visit(
stmt.getOp(), RefType.v("java.lang.Throwable"), stmt));
}