本文整理汇总了Java中soot.jimple.StringConstant类的典型用法代码示例。如果您正苦于以下问题:Java StringConstant类的具体用法?Java StringConstant怎么用?Java StringConstant使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringConstant类属于soot.jimple包,在下文中一共展示了StringConstant类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: caseSpecialInvokeExpr
import soot.jimple.StringConstant; //导入依赖的package包/类
@Override
public void caseSpecialInvokeExpr(SpecialInvokeExpr v) {
//is the invokeExpr a source method?
if(isSourceMethod(v)) {
StringConstant newSourceValue = StringConstant.v("loggingPoint");
SMTBinding binding = stmtVisitor.createNewBindingForValue(newSourceValue);
stmtVisitor.addValueBindingToVariableDeclaration(newSourceValue, binding);
//no smt-statement required, just return the binding
this.result = binding;
// Additionally check whether the source method need special treatment
if(isExpressionThatNeedsToBeConvertedToSMT(v)) {
convertSpecialExpressionsToSMT(v, currentStatement);
}
} else {
if(isStringOperationSupportedBySMT(v))
convertStringOperationToSMT(v, v.getBase());
else if(isExpressionThatNeedsToBeConvertedToSMT(v))
convertSpecialExpressionsToSMT(v, currentStatement);
else
convertAPIMethodToSMT(v);
}
}
示例2: caseVirtualInvokeExpr
import soot.jimple.StringConstant; //导入依赖的package包/类
@Override
public void caseVirtualInvokeExpr(VirtualInvokeExpr virtualInvokeExpr) {
//is the invokeExpr a source method?
if(isSourceMethod(virtualInvokeExpr)) {
StringConstant newSourceValue = StringConstant.v("loggingPoint");
SMTBinding binding = stmtVisitor.createNewBindingForValue(newSourceValue);
stmtVisitor.addValueBindingToVariableDeclaration(newSourceValue, binding);
//no smt-statement required, just return the binding
this.result = binding;
// Additionally check whether the source method need special treatment
if(isExpressionThatNeedsToBeConvertedToSMT(virtualInvokeExpr)) {
convertSpecialExpressionsToSMT(virtualInvokeExpr, currentStatement);
}
} else {
if(isStringOperationSupportedBySMT(virtualInvokeExpr))
convertStringOperationToSMT(virtualInvokeExpr, virtualInvokeExpr.getBase());
else if(isExpressionThatNeedsToBeConvertedToSMT(virtualInvokeExpr))
convertSpecialExpressionsToSMT(virtualInvokeExpr, currentStatement);
else
convertAPIMethodToSMT(virtualInvokeExpr);
}
}
示例3: getNameFromGetInstance
import soot.jimple.StringConstant; //导入依赖的package包/类
private String getNameFromGetInstance(SootMethod sm) {
Body b = sm.retrieveActiveBody();
for (Unit u: b.getUnits()){
Stmt s = (Stmt)u;
if (s.containsInvokeExpr()) {
InvokeExpr ie = (InvokeExpr)s.getInvokeExpr();
String name = ie.getMethodRef().name();
if (name.equals("getService")|| name.equals("getSystemService")) {
List<Value> args = ie.getArgs();
int size = args.size();
Value v = args.get(size-1);
if (v instanceof StringConstant) {
StringConstant c = (StringConstant)v;
return c.value;
} else {
throw new RuntimeException("error: expected constant string: "+ b);
}
}
}
}
throw new RuntimeException("error: nothing found, expected constant string: "+ b);
}
示例4: getStmtsWithConstants
import soot.jimple.StringConstant; //导入依赖的package包/类
private Map<Unit, Body> getStmtsWithConstants() {
Map<Unit, Body> retMap = new LinkedHashMap<Unit, Body>();
for (SootClass sc : Scene.v().getClasses()) {
for (SootMethod sm : sc.getMethods()) {
if (!sm.hasActiveBody())
continue;
Body methodBody = sm.retrieveActiveBody();
for (Unit u : methodBody.getUnits()) {
if (u instanceof ReturnStmt) {
if (((ReturnStmt) u).getOp() instanceof Constant) {
retMap.put(u, methodBody);
}
} else if (((Stmt) u).containsInvokeExpr()) {
InvokeExpr ie = ((Stmt) u).getInvokeExpr();
for (Value arg : ie.getArgs()) {
if (arg instanceof StringConstant || arg instanceof NumericConstant) {
retMap.put(u, methodBody);
break;
}
}
}
}
}
}
return retMap;
}
示例5: findLastStringAssignment
import soot.jimple.StringConstant; //导入依赖的package包/类
/**
* Finds the last assignment to the given String local by searching upwards
* from the given statement
*
* @param stmt
* The statement from which to look backwards
* @param local
* The variable for which to look for assignments
* @return The last value assigned to the given variable
*/
private String findLastStringAssignment(Stmt stmt, Local local, BiDiInterproceduralCFG<Unit, SootMethod> cfg) {
if (stmt instanceof AssignStmt) {
AssignStmt assign = (AssignStmt) stmt;
if (assign.getLeftOp() == local) {
// ok, now find the new value from the right side
if (assign.getRightOp() instanceof StringConstant)
return ((StringConstant) assign.getRightOp()).value;
}
}
// Continue the search upwards
for (Unit pred : cfg.getPredsOf(stmt)) {
if (!(pred instanceof Stmt))
continue;
String lastAssignment = findLastStringAssignment((Stmt) pred, local, cfg);
if (lastAssignment != null)
return lastAssignment;
}
return null;
}
示例6: getSimpleDefaultValue
import soot.jimple.StringConstant; //导入依赖的package包/类
protected Value getSimpleDefaultValue(String t) {
if (t.equals("java.lang.String"))
return StringConstant.v("");
if (t.equals("char"))
return DIntConstant.v(0, CharType.v());
if (t.equals("byte"))
return DIntConstant.v(0, ByteType.v());
if (t.equals("short"))
return DIntConstant.v(0, ShortType.v());
if (t.equals("int"))
return IntConstant.v(0);
if (t.equals("float"))
return FloatConstant.v(0);
if (t.equals("long"))
return LongConstant.v(0);
if (t.equals("double"))
return DoubleConstant.v(0);
if (t.equals("boolean"))
return DIntConstant.v(0, BooleanType.v());
//also for arrays etc.
return G.v().soot_jimple_NullConstant();
}
示例7: createThrowStmt
import soot.jimple.StringConstant; //导入依赖的package包/类
/**
* Creates a new statement that throws a NullPointerException
* @param body The body in which to create the statement
* @param oldStmt The old faulty statement that shall be replaced with the
* exception
* @param lc The object for creating new locals
*/
private void createThrowStmt(Body body, Unit oldStmt, LocalCreation lc) {
RefType tp = RefType.v("java.lang.NullPointerException");
Local lcEx = lc.newLocal(tp);
SootMethodRef constructorRef = Scene.v().makeConstructorRef(tp.getSootClass(),
Collections.singletonList((Type) RefType.v("java.lang.String")));
// Create the exception instance
Stmt newExStmt = Jimple.v().newAssignStmt(lcEx, Jimple.v().newNewExpr(tp));
body.getUnits().insertBefore(newExStmt, oldStmt);
Stmt invConsStmt = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(lcEx,
constructorRef, Collections.singletonList(StringConstant.v(
"Invalid array reference replaced by Soot"))));
body.getUnits().insertBefore(invConsStmt, oldStmt);
// Throw the exception
body.getUnits().swapWith(oldStmt, Jimple.v().newThrowStmt(lcEx));
}
示例8: addExceptionAfterUnit
import soot.jimple.StringConstant; //导入依赖的package包/类
/**
* Insert a runtime exception before unit u of body b. Useful to analyze broken code (which make reference to inexisting class for instance)
* exceptionType: e.g., "java.lang.RuntimeException"
*/
public static void addExceptionAfterUnit(Body b, String exceptionType, Unit u, String m) {
LocalCreation lc = new LocalCreation(b.getLocals());
Local l = lc.newLocal(RefType.v(exceptionType));
List<Unit> newUnits = new ArrayList<Unit>();
Unit u1 = Jimple.v().newAssignStmt(l, Jimple.v().newNewExpr(RefType.v(exceptionType)));
Unit u2 = Jimple.v().newInvokeStmt(
Jimple.v().newSpecialInvokeExpr(
l,
Scene.v().makeMethodRef(Scene.v().getSootClass(exceptionType),
"<init>",
Collections.singletonList((Type) RefType.v("java.lang.String")),
VoidType.v(),
false),
StringConstant.v(m)));
Unit u3 = Jimple.v().newThrowStmt(l);
newUnits.add(u1);
newUnits.add(u2);
newUnits.add(u3);
b.getUnits().insertBefore(newUnits, u);
}
示例9: createThrowStmt
import soot.jimple.StringConstant; //导入依赖的package包/类
/**
* Creates a new statement that throws a NullPointerException
* @param body The body in which to create the statement
* @param oldStmt The old faulty statement that shall be replaced with the
* exception
* @param lc The object for creating new locals
*/
private void createThrowStmt(Body body, Unit oldStmt, LocalCreation lc) {
RefType tp = RefType.v("java.lang.NullPointerException");
Local lcEx = lc.newLocal(tp);
SootMethodRef constructorRef = Scene.v().makeConstructorRef(tp.getSootClass(),
Collections.singletonList((Type) RefType.v("java.lang.String")));
// Create the exception instance
Stmt newExStmt = Jimple.v().newAssignStmt(lcEx, Jimple.v().newNewExpr(tp));
body.getUnits().insertBefore(newExStmt, oldStmt);
Stmt invConsStmt = Jimple.v().newInvokeStmt(Jimple.v().newVirtualInvokeExpr(lcEx,
constructorRef, Collections.singletonList(StringConstant.v(
"Null throw statement replaced by Soot"))));
body.getUnits().insertBefore(invConsStmt, oldStmt);
// Throw the exception
body.getUnits().swapWith(oldStmt, Jimple.v().newThrowStmt(lcEx));
}
示例10: toSootValue
import soot.jimple.StringConstant; //导入依赖的package包/类
private Value toSootValue(Object val) throws AssertionError {
Value v;
if (val instanceof Integer)
v = IntConstant.v((Integer) val);
else if (val instanceof Float)
v = FloatConstant.v((Float) val);
else if (val instanceof Long)
v = LongConstant.v((Long) val);
else if (val instanceof Double)
v = DoubleConstant.v((Double) val);
else if (val instanceof String)
v = StringConstant.v(val.toString());
else if (val instanceof org.objectweb.asm.Type)
v = ClassConstant.v(((org.objectweb.asm.Type) val).getInternalName());
else if (val instanceof Handle)
v = MethodHandle.v(toSootMethodRef((Handle) val), ((Handle)val).getTag());
else
throw new AssertionError("Unknown constant type: " + val.getClass());
return v;
}
示例11: testJEnterMonitorStmt
import soot.jimple.StringConstant; //导入依赖的package包/类
@Test
public void testJEnterMonitorStmt() {
Stmt s = Jimple.v().newEnterMonitorStmt(StringConstant.v("test"));
Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
expectedRep.add(utility.NULL_POINTER_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
示例12: testGEnterMonitorStmt
import soot.jimple.StringConstant; //导入依赖的package包/类
@Test
public void testGEnterMonitorStmt() {
Stmt s = Grimp.v().newEnterMonitorStmt(StringConstant.v("test"));
Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
expectedRep.add(utility.NULL_POINTER_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
示例13: testJExitMonitorStmt
import soot.jimple.StringConstant; //导入依赖的package包/类
@Test
public void testJExitMonitorStmt() {
Stmt s = Jimple.v().newExitMonitorStmt(StringConstant.v("test"));
Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
expectedRep.add(utility.NULL_POINTER_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
示例14: testGExitMonitorStmt
import soot.jimple.StringConstant; //导入依赖的package包/类
@Test
public void testGExitMonitorStmt() {
Stmt s = Grimp.v().newExitMonitorStmt(StringConstant.v("test"));
Set expectedRep = new ExceptionHashSet(utility.VM_ERRORS);
expectedRep.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
expectedRep.add(utility.NULL_POINTER_EXCEPTION);
assertTrue(ExceptionTestUtility.sameMembers(expectedRep, Collections.EMPTY_SET,
unitAnalysis.mightThrow(s)));
Set expectedCatch = new ExceptionHashSet(utility.VM_ERRORS_PLUS_SUPERTYPES);
expectedCatch.add(utility.ILLEGAL_MONITOR_STATE_EXCEPTION);
expectedCatch.add(utility.NULL_POINTER_EXCEPTION);
expectedCatch.add(utility.RUNTIME_EXCEPTION);
expectedCatch.add(utility.EXCEPTION);
assertEquals(expectedCatch,
utility.catchableSubset(unitAnalysis.mightThrow(s)));
}
示例15: changeConstantStringInField
import soot.jimple.StringConstant; //导入依赖的package包/类
public static void changeConstantStringInField(SootField sf,
String newConstantString) {
SootClass sc = sf.getDeclaringClass();
SootMethod sm = sc.getMethodByName("<clinit>");
boolean hasBeenUpdated = false;
for (Unit u: sm.retrieveActiveBody().getUnits()) {
if (u instanceof AssignStmt) {
AssignStmt ass = (AssignStmt)u;
Value lop = ass.getLeftOp();
if (lop.toString().equals(sf.toString())) {
System.out.println("previous string: "+ ass);
ass.setRightOp(StringConstant.v(newConstantString));
hasBeenUpdated = true;
System.out.println("updated string : "+ ass);
}
}
}
if (!hasBeenUpdated)
throw new RuntimeException("error: no StringConstant found for field "+ sf);
}