本文整理汇总了Java中soot.javaToJimple.LocalGenerator类的典型用法代码示例。如果您正苦于以下问题:Java LocalGenerator类的具体用法?Java LocalGenerator怎么用?Java LocalGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LocalGenerator类属于soot.javaToJimple包,在下文中一共展示了LocalGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Alexandre-Bartel,项目名称:permission-map,代码行数:20,代码来源:Util.java
示例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;
}
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:32,代码来源:BaseEntryPointCreator.java
示例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;
}
开发者ID:serval-snt-uni-lu,项目名称:DroidRA,代码行数:24,代码来源:DummyMainGenerator.java
示例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;
}
开发者ID:0-14N,项目名称:soot-inflow,代码行数:32,代码来源:BaseEntryPointCreator.java
示例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;
}
开发者ID:secure-software-engineering,项目名称:cheetah,代码行数:33,代码来源:AndroidEntryPointCreatorJIT.java
示例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());
}
}
}
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:37,代码来源:OnFlyCallGraphBuilder.java
示例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);
}
开发者ID:serval-snt-uni-lu,项目名称:DroidRA,代码行数:10,代码来源:DefaultInstrumentation.java
示例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;
}
开发者ID:lilicoding,项目名称:soot-infoflow-android-iccta,代码行数:35,代码来源:ICCInstrumentDestination.java
示例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;
}
开发者ID:lilicoding,项目名称:soot-infoflow-android-iccta,代码行数:35,代码来源:ICCInstrumentDestination.java
示例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;
}
开发者ID:lilicoding,项目名称:soot-infoflow-android-iccta,代码行数:28,代码来源:ICCInstrumentDestination.java
示例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;
}
开发者ID:lilicoding,项目名称:soot-infoflow-android-iccta,代码行数:58,代码来源:ICCRedirectionCreator.java
示例13: generateFreshLocal
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public static Local generateFreshLocal(Body body, Type type){
LocalGenerator lg = new LocalGenerator(body);
return lg.generateLocal(type);
}
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:5,代码来源:UtilInstrumenter.java
示例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);
}
开发者ID:srasthofer,项目名称:FuzzDroid,代码行数:56,代码来源:DynamicValueTransformer.java
示例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;
}
开发者ID:Alexandre-Bartel,项目名称:permission-map,代码行数:53,代码来源:CreateManagers.java
示例16: createJimple
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
public static void createJimple(Body b, Unit uriUnit, SootMethod cpMethod, String uri) {
if (uri == null) {
System.out.println("warning: authority is null!!");
}
String auth = uri.replaceAll("content://", "");
auth = auth.replaceAll("/.*", "");
Provider cp = auth2cp.get(auth);
if (cp == null) {
System.out.println("warning: authority not found '" + auth + "'");
return;
}
System.out.println("content provider: redirecting to " + cp.classname + " ("
+ cp.authorities);
LocalGenerator lg = new LocalGenerator(b);
List<Unit> newUnits = new ArrayList<Unit>();
SootClass servicesInitClass = Scene.v().getSootClass(
GenerateServiceInit.servicesInitClassName);
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);
newUnits.add(u0);
// call content provider onCreate()
SootClass cpClass = Scene.v().getSootClass(cp.classname);
Local cpLocal = lg.generateLocal(cpClass.getType());
Unit u1 = Jimple.v().newAssignStmt(cpLocal, Jimple.v().newNewExpr(cpClass.getType()));
boolean has = false;
for (SootMethod sm : cpClass.getMethods()) {
if (sm.getName().equals("onCreate")) {
has = true;
}
}
if (!has) {
System.out.println("warning: no method onCreate found!");
return;
}
Unit u2 = Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(cpLocal,
Scene.v().getMethod("<" + cpClass + ": boolean onCreate()>").makeRef()));
newUnits.add(u1);
newUnits.add(u2);
// call Context.checkPermission with
// content provider's readPermission and/or writePermission
SootMethod checkPermission = Scene.v().getMethod(
"<android.content.Context: int checkCallingPermission(java.lang.String)>");
if (cp.readPermission != null) {
Unit ru = Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(contextLocal, checkPermission.makeRef(),
StringConstant.v(cp.readPermission)));
newUnits.add(ru);
}
if (cp.writePermission != null) {
Unit wu = Jimple.v().newInvokeStmt(
Jimple.v().newVirtualInvokeExpr(contextLocal, checkPermission.makeRef(),
StringConstant.v(cp.writePermission)));
newUnits.add(wu);
}
for (Unit u : newUnits) {
b.getUnits().insertBefore(u, uriUnit);
}
// call (redirect) call to content provider's cpMethod
// TODO
}
开发者ID:Alexandre-Bartel,项目名称:permission-map,代码行数:77,代码来源:Provider.java
示例17: createDummyMainInternal
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
@Override
protected SootMethod createDummyMainInternal(SootMethod mainMethod) {
Map<String, Set<String>> classMap =
SootMethodRepresentationParser.v().parseClassNames(methodsToCall, false);
// create new class:
Body body = mainMethod.getActiveBody();
LocalGenerator generator = new LocalGenerator(body);
HashMap<String, Local> localVarsForClasses = new HashMap<String, Local>();
// create constructors:
for(String className : classMap.keySet()){
SootClass createdClass = Scene.v().forceResolve(className, SootClass.BODIES);
createdClass.setApplicationClass();
Local localVal = generateClassConstructor(createdClass, body);
if (localVal == null) {
logger.warn("Cannot generate constructor for class: {}", createdClass);
continue;
}
localVarsForClasses.put(className, localVal);
}
// add entrypoint calls
int conditionCounter = 0;
JNopStmt startStmt = new JNopStmt();
JNopStmt endStmt = new JNopStmt();
Value intCounter = generator.generateLocal(IntType.v());
body.getUnits().add(startStmt);
for (Entry<String, Set<String>> entry : classMap.entrySet()){
Local classLocal = localVarsForClasses.get(entry.getKey());
for (String method : entry.getValue()){
SootMethodAndClass methodAndClass =
SootMethodRepresentationParser.v().parseSootMethodString(method);
SootMethod currentMethod = findMethod(Scene.v().getSootClass(methodAndClass.getClassName()),
methodAndClass.getSubSignature());
if (currentMethod == null) {
logger.warn("Entry point not found: {}", method);
continue;
}
JEqExpr cond = new JEqExpr(intCounter, IntConstant.v(conditionCounter));
conditionCounter++;
JNopStmt thenStmt = new JNopStmt();
JIfStmt ifStmt = new JIfStmt(cond, thenStmt);
body.getUnits().add(ifStmt);
buildMethodCall(currentMethod, body, classLocal, generator);
body.getUnits().add(thenStmt);
}
}
body.getUnits().add(endStmt);
JGotoStmt gotoStart = new JGotoStmt(startStmt);
body.getUnits().add(gotoStart);
body.getUnits().add(Jimple.v().newReturnVoidStmt());
NopEliminator.v().transform(body);
eliminateSelfLoops(body);
return mainMethod;
}
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:60,代码来源:DefaultEntryPointCreator.java
示例18: createDummyMainInternal
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
@Override
protected SootMethod createDummyMainInternal(SootMethod mainMethod) {
Map<String, Set<String>> classMap =
SootMethodRepresentationParser.v().parseClassNames(methodsToCall, false);
// create new class:
Body body = mainMethod.getActiveBody();
LocalGenerator generator = new LocalGenerator(body);
// Create the classes
for (String className : classMap.keySet()) {
SootClass createdClass = Scene.v().forceResolve(className, SootClass.BODIES);
createdClass.setApplicationClass();
Local localVal = generateClassConstructor(createdClass, body);
if (localVal == null) {
logger.warn("Cannot generate constructor for class: {}", createdClass);
continue;
}
// Create the method calls
for (String method : classMap.get(className)) {
SootMethodAndClass methodAndClass =
SootMethodRepresentationParser.v().parseSootMethodString(method);
SootMethod methodToInvoke = findMethod(Scene.v().getSootClass(
methodAndClass.getClassName()), methodAndClass.getSubSignature());
if (methodToInvoke == null)
System.err.println("Method " + methodAndClass + " not found, skipping");
else if (methodToInvoke.isConcrete()) {
// Load the method
methodToInvoke.retrieveActiveBody();
buildMethodCall(methodToInvoke, body, localVal, generator);
}
}
}
// Jimple needs an explicit return statement
body.getUnits().add(Jimple.v().newReturnVoidStmt());
return mainMethod;
}
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:42,代码来源:SequentialEntryPointCreator.java
示例19: buildMethodCall
import soot.javaToJimple.LocalGenerator; //导入依赖的package包/类
protected Stmt buildMethodCall(SootMethod methodToCall, Body body,
Local classLocal, LocalGenerator gen,
Set<SootClass> parentClasses){
assert methodToCall != null : "Current method was null";
assert body != null : "Body was null";
assert gen != null : "Local generator was null";
if (classLocal == null && !methodToCall.isStatic()) {
logger.warn("Cannot call method {}, because there is no local for base object: {}",
methodToCall, methodToCall.getDeclaringClass());
failedMethods.add(methodToCall);
return null;
}
final InvokeExpr invokeExpr;
List<Value> args = new LinkedList<Value>();
if(methodToCall.getParameterCount()>0){
for (Type tp : methodToCall.getParameterTypes())
args.add(getValueForType(body, gen, tp, new HashSet<SootClass>(), parentClasses));
if(methodToCall.isStatic())
invokeExpr = Jimple.v().newStaticInvokeExpr(methodToCall.makeRef(), args);
else {
assert classLocal != null : "Class local method was null for non-static method call";
if (methodToCall.isConstructor())
invokeExpr = Jimple.v().newSpecialInvokeExpr(classLocal, methodToCall.makeRef(),args);
else
invokeExpr = Jimple.v().newVirtualInvokeExpr(classLocal, methodToCall.makeRef(),args);
}
}else{
if(methodToCall.isStatic()){
invokeExpr = Jimple.v().newStaticInvokeExpr(methodToCall.makeRef());
}else{
assert classLocal != null : "Class local method was null for non-static method call";
if (methodToCall.isConstructor())
invokeExpr = Jimple.v().newSpecialInvokeExpr(classLocal, methodToCall.makeRef());
else
invokeExpr = Jimple.v().newVirtualInvokeExpr(classLocal, methodToCall.makeRef());
}
}
Stmt stmt;
if (!(methodToCall.getReturnType() instanceof VoidType)) {
Local returnLocal = gen.generateLocal(methodToCall.getReturnType());
stmt = Jimple.v().newAssignStmt(returnLocal, invokeExpr);
} else {
stmt = Jimple.v().newInvokeStmt(invokeExpr);
}
body.getUnits().add(stmt);
// Clean up
for (Object val : args)
if (val instanceof Local && ((Value) val).getType() instanceof RefType)
body.getUnits().add(Jimple.v().newAssignStmt((Value) val, NullConstant.v()));
return stmt;
}
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:59,代码来源:BaseEntryPointCreator.java
示例20: fixExceptions
import soot.javaToJimple.LocalGenerator; //导入依赖的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);
}
}
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:75,代码来源:InterproceduralConstantValuePropagator.java
注:本文中的soot.javaToJimple.LocalGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论