本文整理汇总了Java中soot.javaToJimple.LocalGenerator类的典型用法代码示例。如果您正苦于以下问题:Java LocalGenerator类的具体用法?Java LocalGenerator怎么用?Java LocalGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalGenerator类属于soot.javaToJimple包,在下文中一共展示了LocalGenerator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeUnit
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public static void removeUnit(Body b, Unit u) {
LocalGenerator lg = new LocalGenerator(b);
if (u instanceof DefinitionStmt) {
DefinitionStmt def = (DefinitionStmt) u;
Type t = def.getRightOp().getType();
if (!(t instanceof PrimType)) {
Local l_obj = lg.generateLocal(RefType.v("java.lang.Object"));
Local l_type = lg.generateLocal(t);
Unit u1 = Jimple.v().newAssignStmt(l_obj,
Jimple.v().newNewExpr(RefType.v("java.lang.Object")));
Unit u2 = Jimple.v().newAssignStmt(l_type, Jimple.v().newCastExpr(l_obj, t));
def.getRightOpBox().setValue(l_type);
b.getUnits().insertBefore(u1, u);
b.getUnits().insertBefore(u2, u);
return;
}
}
b.getUnits().remove(u);
}
示例2: buildArrayOfType
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
/**
* Constructs an array of the given type with a single element of this type
* in the given method
* @param body The body of the method in which to create the array
* @param gen The local generator
* @param tp The type of which to create the array
* @param constructionStack Set of classes currently being built to avoid
* constructor loops
* @param parentClasses If a requested type is compatible with one of the
* types in this list, the already-created object is used instead of
* creating a new one.
* @return The local referencing the newly created array, or null if the
* array generation failed
*/
private Value buildArrayOfType(Body body, LocalGenerator gen, ArrayType tp,
Set<SootClass> constructionStack, Set<SootClass> parentClasses) {
Local local = gen.generateLocal(tp);
// Generate a new single-element array
NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(),
IntConstant.v(1));
AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr);
body.getUnits().add(assignArray);
// Generate a single element in the array
AssignStmt assign = Jimple.v().newAssignStmt
(Jimple.v().newArrayRef(local, IntConstant.v(0)),
getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses));
body.getUnits().add(assign);
return local;
}
示例3: generateFuzzyMethod
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public SootMethod generateFuzzyMethod(SootClass sootClass)
{
String name = "fuzzyMe";
List<Type> parameters = new ArrayList<Type>();
Type returnType = IntType.v();
int modifiers = Modifier.PUBLIC;
SootMethod fuzzyMeMethod = new SootMethod(name, parameters, returnType, modifiers);
sootClass.addMethod(fuzzyMeMethod);
{
Body b = Jimple.v().newBody(fuzzyMeMethod);
fuzzyMeMethod.setActiveBody(b);
LocalGenerator lg = new LocalGenerator(b);
Local thisLocal = lg.generateLocal(sootClass.getType());
Unit thisU = Jimple.v().newIdentityStmt(thisLocal,
Jimple.v().newThisRef(sootClass.getType()));
Unit returnU = Jimple.v().newReturnStmt(IntConstant.v(1));
b.getUnits().add(thisU);
b.getUnits().add(returnU);
}
return fuzzyMeMethod;
}
示例4: buildArrayOfType
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
/**
* Constructs an array of the given type with a single element of this type
* in the given method
* @param body The body of the method in which to create the array
* @param gen The local generator
* @param tp The type of which to create the array
* @param constructionStack Set of classes currently being built to avoid
* constructor loops
* @param parentClasses If a requested type is compatible with one of the
* types in this list, the already-created object is used instead of
* creating a new one.
* @return The local referencing the newly created array, or null if the
* array generation failed
*/
private Value buildArrayOfType(JimpleBody body, LocalGenerator gen, ArrayType tp,
Set<SootClass> constructionStack, Set<SootClass> parentClasses) {
Local local = gen.generateLocal(tp);
// Generate a new single-element array
NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(tp.getElementType(),
IntConstant.v(1));
AssignStmt assignArray = Jimple.v().newAssignStmt(local, newArrayExpr);
body.getUnits().add(assignArray);
// Generate a single element in the array
AssignStmt assign = Jimple.v().newAssignStmt
(Jimple.v().newArrayRef(local, IntConstant.v(19)),
getValueForType(body, gen, tp.getElementType(), constructionStack, parentClasses));
body.getUnits().add(assign);
return local;
}
示例5: createEmptyMainMethod
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
protected SootMethod createEmptyMainMethod(Body body, String className) {
Scene.v().forceResolve(className, SootClass.SIGNATURES);
final SootClass mainClass;
String methodName = Config.dummyMainMethodName;
if (Scene.v().containsClass(className)) {
int methodIndex = 0;
mainClass = Scene.v().getSootClass(className);
while (mainClass.declaresMethodByName(methodName))
methodName = Config.dummyMainMethodName + "_" + methodIndex++;
} else
throw new RuntimeException("SootClass does not exist " + className);
Type stringArrayType = ArrayType.v(RefType.v("java.lang.String"), 1);
SootMethod mainMethod = new SootMethod(methodName, Collections.singletonList(stringArrayType), VoidType.v());
body.setMethod(mainMethod);
mainMethod.setActiveBody(body);
mainClass.addMethod(mainMethod);
// Add a parameter reference to the body
LocalGenerator lg = new LocalGenerator(body);
Local paramLocal = lg.generateLocal(stringArrayType);
body.getUnits()
.addFirst(Jimple.v().newIdentityStmt(paramLocal, Jimple.v().newParameterRef(stringArrayType, 0)));
// First add class to scene, then make it an application class
// as addClass contains a call to "setLibraryClass"
mainClass.setApplicationClass();
mainMethod.setModifiers(Modifier.PUBLIC);
return mainMethod;
}
示例6: insertGuard
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
private void insertGuard(Guard guard) {
if(options.guards().equals("ignore")) return;
SootMethod container = guard.container;
Stmt insertionPoint = guard.stmt;
if(!container.hasActiveBody()) {
G.v().out.println("WARNING: Tried to insert guard into "+container+" but couldn't because method has no body.");
} else {
Body body = container.getActiveBody();
//exc = new Error
RefType runtimeExceptionType = RefType.v("java.lang.Error");
NewExpr newExpr = Jimple.v().newNewExpr(runtimeExceptionType);
LocalGenerator lg = new LocalGenerator(body);
Local exceptionLocal = lg.generateLocal(runtimeExceptionType);
AssignStmt assignStmt = Jimple.v().newAssignStmt(exceptionLocal, newExpr);
body.getUnits().insertBefore(assignStmt, insertionPoint);
//exc.<init>(message)
SootMethodRef cref = runtimeExceptionType.getSootClass().getMethod("<init>", Collections.<Type>singletonList(RefType.v("java.lang.String"))).makeRef();
SpecialInvokeExpr constructorInvokeExpr = Jimple.v().newSpecialInvokeExpr(exceptionLocal, cref, StringConstant.v(guard.message));
InvokeStmt initStmt = Jimple.v().newInvokeStmt(constructorInvokeExpr);
body.getUnits().insertAfter(initStmt, assignStmt);
if(options.guards().equals("print")) {
//exc.printStackTrace();
VirtualInvokeExpr printStackTraceExpr = Jimple.v().newVirtualInvokeExpr(exceptionLocal, Scene.v().getSootClass("java.lang.Throwable").getMethod("printStackTrace", Collections.<Type>emptyList()).makeRef());
InvokeStmt printStackTraceStmt = Jimple.v().newInvokeStmt(printStackTraceExpr);
body.getUnits().insertAfter(printStackTraceStmt, initStmt);
} else if(options.guards().equals("throw")) {
body.getUnits().insertAfter(Jimple.v().newThrowStmt(exceptionLocal), initStmt);
} else {
throw new RuntimeException("Invalid value for phase option (guarding): "+options.guards());
}
}
}
示例7: injectedStmtWrapper
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public void injectedStmtWrapper(Body body, LocalGenerator localGenerator, Stmt stmt, Stmt nextStmt)
{
Local opaqueLocal = localGenerator.generateLocal(IntType.v());
Unit assignU = Jimple.v().newAssignStmt(opaqueLocal, Jimple.v().newStaticInvokeExpr(Alteration.v().getTryMethod().makeRef(), IntConstant.v(0)));
Unit ifU = Jimple.v().newIfStmt(Jimple.v().newEqExpr(IntConstant.v(1), opaqueLocal), nextStmt);
body.getUnits().insertAfter(ifU, stmt);
body.getUnits().insertAfter(assignU, stmt);
}
示例8: replaceSootField
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
private void replaceSootField(SootClass sc, Body b, AssignStmt aStmt, SootField sf)
{
SootClass sfClass = sf.getDeclaringClass();
LocalGenerator lg = new LocalGenerator(b);
Local sfLocal = lg.generateLocal(sc.getType());
Unit sfLocalAssignU = Jimple.v().newAssignStmt(
sfLocal,
Jimple.v().newStaticFieldRef(sc.getField("instance", sc.getType()).makeRef()));
Local sfLocal2 = lg.generateLocal(sfClass.getType());
Unit sfLocalAssignU2 = Jimple.v().newAssignStmt(
sfLocal2,
Jimple.v().newInstanceFieldRef(sfLocal, sc.getField(sfClass.getName(), sfClass.getType()).makeRef()));
Unit assignU = null;
if (aStmt.getLeftOp() instanceof FieldRef)
{
assignU = Jimple.v().newAssignStmt(Jimple.v().newInstanceFieldRef(sfLocal2, sf.makeRef()), aStmt.getRightOp());
}
else
{
assignU = Jimple.v().newAssignStmt(aStmt.getLeftOp(), Jimple.v().newInstanceFieldRef(sfLocal2, sf.makeRef()));
}
b.getUnits().insertBefore(sfLocalAssignU, aStmt);
b.getUnits().insertBefore(sfLocalAssignU2, aStmt);
b.getUnits().insertBefore(assignU, aStmt);
b.getUnits().remove(aStmt);
System.out.println(b);
}
开发者ID:lilicoding,项目名称:soot-infoflow-android-iccta,代码行数:34,代码来源:JimpleReduceStaticFieldsTransformer.java
示例9: generateGetIntentMethod
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
/**
* Override getIntent method to be able to transfer the intent to the destination component
*
* @param compSootClass
* @param intentSootField
* @return
*/
public SootMethod generateGetIntentMethod(SootClass compSootClass, SootField intentSootField)
{
String name = "getIntent";
List<Type> parameters = new ArrayList<Type>();
Type returnType = INTENT_TYPE;
int modifiers = Modifier.PUBLIC;
SootMethod newGetIntent = new SootMethod(name, parameters, returnType, modifiers);
compSootClass.addMethod(newGetIntent);
{
Body b = Jimple.v().newBody(newGetIntent);
newGetIntent.setActiveBody(b);
LocalGenerator lg = new LocalGenerator(b);
Local thisLocal = lg.generateLocal(compSootClass.getType());
Unit thisU = Jimple.v().newIdentityStmt(thisLocal,
Jimple.v().newThisRef(compSootClass.getType()));
Local intentParameterLocal = lg.generateLocal(INTENT_TYPE);
Unit getIntentU = Jimple.v().newAssignStmt(
intentParameterLocal,
Jimple.v().newStaticFieldRef(intentSootField.makeRef()));
Unit returnU = Jimple.v().newReturnStmt(intentParameterLocal);
b.getUnits().add(thisU);
b.getUnits().add(getIntentU);
b.getUnits().add(returnU);
}
return newGetIntent;
}
示例10: generateGetIntentForActivityResultMethod
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
/**
* create getIntentForActivityResult method to be able to transfer the intent back to source component
*
* @param compSootClass
* @param intentSootField
* @return
*/
public SootMethod generateGetIntentForActivityResultMethod(SootClass compSootClass, SootField intentSootField)
{
String name = "getIntentForActivityResult";
List<Type> parameters = new ArrayList<Type>();
Type returnType = INTENT_TYPE;
int modifiers = Modifier.PUBLIC;
SootMethod newGetIntent = new SootMethod(name, parameters, returnType, modifiers);
compSootClass.addMethod(newGetIntent);
{
Body b = Jimple.v().newBody(newGetIntent);
newGetIntent.setActiveBody(b);
LocalGenerator lg = new LocalGenerator(b);
Local thisLocal = lg.generateLocal(compSootClass.getType());
Unit thisU = Jimple.v().newIdentityStmt(thisLocal,
Jimple.v().newThisRef(compSootClass.getType()));
Local intentParameterLocal = lg.generateLocal(INTENT_TYPE);
Unit getIntentU = Jimple.v().newAssignStmt(
intentParameterLocal,
Jimple.v().newStaticFieldRef(intentSootField.makeRef()));
Unit returnU = Jimple.v().newReturnStmt(intentParameterLocal);
b.getUnits().add(thisU);
b.getUnits().add(getIntentU);
b.getUnits().add(returnU);
}
return newGetIntent;
}
示例11: generateGetIBinderMethod
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public SootMethod generateGetIBinderMethod(SootClass compSootClass, SootField ibinderSootField, Type binderType)
{
String name = "getIBinderForIpc";
List<Type> parameters = new ArrayList<Type>();
Type returnType = binderType;
int modifiers = Modifier.PUBLIC;
SootMethod newGetIBinder = new SootMethod(name, parameters, returnType, modifiers);
compSootClass.addMethod(newGetIBinder);
{
Body b = Jimple.v().newBody(newGetIBinder);
newGetIBinder.setActiveBody(b);
LocalGenerator lg = new LocalGenerator(b);
Local thisLocal = lg.generateLocal(compSootClass.getType());
Unit thisU = Jimple.v().newIdentityStmt(thisLocal,
Jimple.v().newThisRef(compSootClass.getType()));
Local ibinderParameterLocal = lg.generateLocal(IBINDER_TYPE);
Unit getIBinderU = Jimple.v().newAssignStmt(
ibinderParameterLocal,
Jimple.v().newStaticFieldRef(ibinderSootField.makeRef()));
Unit returnU = Jimple.v().newReturnStmt(ibinderParameterLocal);
b.getUnits().add(thisU);
b.getUnits().add(getIBinderU);
b.getUnits().add(returnU);
}
return newGetIBinder;
}
示例12: generateRedirectMethodForStartActivity
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public SootMethod generateRedirectMethodForStartActivity(SootClass wrapper) {
System.out.println("create method to call wrapper class: "+ wrapper);
String newSM_name = "redirector" + num++;
List<Type> newSM_parameters = new ArrayList<Type>();
newSM_parameters.add(INTENT_TYPE);
Type newSM_return_type = VoidType.v();
int modifiers = Modifier.STATIC | Modifier.PUBLIC;
SootMethod newSM = new SootMethod(newSM_name, newSM_parameters, newSM_return_type, modifiers);
ipcSC.addMethod(newSM);
JimpleBody b = Jimple.v().newBody(newSM);
newSM.setActiveBody(b);
LocalGenerator lg = new LocalGenerator(b);
// identity
Local intentParameterLocal = lg.generateLocal(INTENT_TYPE);
Unit intentParameterU = Jimple.v().newIdentityStmt(
intentParameterLocal,
Jimple.v().newParameterRef(INTENT_TYPE, 0));
// new
Local al = lg.generateLocal(wrapper.getType());
Unit newU = (Unit) Jimple.v().newAssignStmt(al,
Jimple.v().newNewExpr(wrapper.getType())
);
// init
List<Type> parameters = new ArrayList<Type>();
parameters.add(INTENT_TYPE);
SootMethod method = wrapper.getMethod("<init>", parameters, VoidType.v());
List<Value> args = new ArrayList<Value>();
args.add(intentParameterLocal);
Unit initU = (Unit) Jimple.v().newInvokeStmt(
Jimple.v().newSpecialInvokeExpr(al, method.makeRef(), args));
// call dummyMainMethod
//method = wrapper.getMethodByName(ICCDummyMainCreator.DUMMY_MAIN_METHOD);
method = wrapper.getMethodByName("onCreate");
args = new ArrayList<Value>();
Local pLocal = lg.generateLocal(RefType.v("android.os.Bundle"));
Unit nullParamU = (Unit) Jimple.v().newAssignStmt(pLocal, NullConstant.v());
args.add(pLocal);
InvokeExpr invoke = Jimple.v().newVirtualInvokeExpr(al, method.makeRef(), args);
Unit callU = (Unit) Jimple.v().newInvokeStmt(invoke);
b.getUnits().add(intentParameterU);
b.getUnits().add(newU);
b.getUnits().add(initU);
b.getUnits().add(nullParamU);
b.getUnits().add(callU);
b.getUnits().add(Jimple.v().newReturnVoidStmt());
System.out.println("new lifecypcle method: "+ newSM +" body: "+ newSM.retrieveActiveBody());
return newSM;
}
示例13: generateFreshLocal
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public static Local generateFreshLocal(Body body, Type type){
LocalGenerator lg = new LocalGenerator(body);
return lg.generateLocal(type);
}
示例14: checkAndReport
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
private void checkAndReport(Body b, Stmt curStmt, Value value, int paramIdx) {
LocalGenerator localGenerator = new LocalGenerator(b);
RefType stringType = RefType.v("java.lang.String");
Value lhs = value;
if(lhs instanceof StringConstant)
return;
else if(lhs instanceof IntConstant)
return;
// If this is a CharSequence, we need to convert it into a string
if (lhs.getType() == RefType.v("java.lang.CharSequence") ||
lhs.getType() == RefType.v("java.lang.StringBuilder") && lhs instanceof Local) {
SootMethodRef toStringRef = Scene.v().getMethod("<java.lang.Object: "
+ "java.lang.String toString()>").makeRef();
Local stringLocal = localGenerator.generateLocal(stringType);
Stmt stringAssignStmt = Jimple.v().newAssignStmt(stringLocal,
Jimple.v().newVirtualInvokeExpr((Local) lhs, toStringRef));
stringAssignStmt.addTag(new InstrumentedCodeTag());
b.getUnits().insertBefore(stringAssignStmt, curStmt);
lhs = stringLocal;
}
else if (lhs.getType() != IntType.v() && lhs.getType() != stringType)
return;
//new String() case
if (value instanceof NewExpr)
return;
// Depending on the type of the value, we might need an intermediate local
if (!(lhs instanceof Local)) {
Local newLhs = localGenerator.generateLocal(lhs.getType());
AssignStmt assignLocalStmt = Jimple.v().newAssignStmt(newLhs, lhs);
assignLocalStmt.addTag(new InstrumentedCodeTag());
b.getUnits().insertBefore(assignLocalStmt, curStmt);
lhs = newLhs;
}
// Report the value
Stmt reportValueStmt;
if (lhs.getType() == stringType) {
reportValueStmt = Jimple.v().newInvokeStmt(
Jimple.v().newStaticInvokeExpr(refString, lhs, IntConstant.v(paramIdx)));
}
else if (lhs.getType() == IntType.v()) {
reportValueStmt = Jimple.v().newInvokeStmt(
Jimple.v().newStaticInvokeExpr(refInt, lhs, IntConstant.v(paramIdx)));
}
else
return;
reportValueStmt.addTag(new InstrumentedCodeTag());
b.getUnits().insertBefore(reportValueStmt, curStmt);
}
示例15: createNewInstance
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
/**
* Create getManager_ for managers created through <init> methods
* @param initMethod
* @return
*/
private Body createNewInstance(SootMethod initMethod) {
SootClass servicesInitClass = Scene.v().getSootClass(GenerateServiceInit.servicesInitClassName);
RefType newType = initMethod.getDeclaringClass().getType();
Body b = Jimple.v().newBody();
LocalGenerator lg = new LocalGenerator(b);
Local newLocal = lg.generateLocal(newType);
SootField sf = servicesInitClass.getFieldByName("androidcontentContext");
Value newR = Jimple.v().newStaticFieldRef(sf.makeRef());
Local contextLocal = lg.generateLocal(sf.getType());
Unit u0 = Jimple.v().newAssignStmt(contextLocal, newR);
boolean addU0 = false;
NewExpr n1 = Jimple.v().newNewExpr(newType);
Unit u1 = Jimple.v().newAssignStmt(newLocal, n1);
List<Value> args = new ArrayList<Value>();
for (Type t : initMethod.getParameterTypes()) {
if (t.toString().startsWith("android.content.Context")) {
args.add(contextLocal);
addU0 = true;
} else {
args.add(NullConstant.v());
}
}
InvokeExpr n2 = Jimple.v().newSpecialInvokeExpr(newLocal, initMethod.makeRef(), args);
Unit u2 = Jimple.v().newInvokeStmt(n2);
Unit u3 = Jimple.v().newReturnStmt(newLocal);
if (addU0)
b.getUnits().addFirst(u0);
else
b.getLocals().remove(contextLocal);
System.out.println("u1: "+ u1);
System.out.println("u1: "+ u2);
System.out.println("u1: "+ u3);
if (addU0)
b.getUnits().insertAfter(u1, u0);
else
b.getUnits().addFirst(u1);
b.getUnits().insertAfter(u2, u1);
b.getUnits().insertAfter(u3, u2);
return b;
}