1 19 20 package soot.javaToJimple; 21 22 import java.util.*; 23 24 import soot.SootFieldRef; 25 public class PrivateFieldAccMethodSource implements soot.MethodSource { 26 27 private final soot.Type fieldType; 28 private final String fieldName; 29 private final boolean isStatic; 30 private final soot.SootClass classToInvoke; 31 32 public PrivateFieldAccMethodSource(soot.Type fieldType, String fieldName, boolean isStatic, soot.SootClass classToInvoke ) { 33 this.fieldType = fieldType; 34 this.fieldName = fieldName; 35 this.isStatic = isStatic; 36 this.classToInvoke = classToInvoke; 37 } 38 39 40 public soot.Body getBody(soot.SootMethod sootMethod, String phaseName){ 41 42 soot.Body body = soot.jimple.Jimple.v().newBody(sootMethod); 43 LocalGenerator lg = new LocalGenerator(body); 44 45 soot.Local fieldBase = null; 46 Iterator paramIt = sootMethod.getParameterTypes().iterator(); 48 while (paramIt.hasNext()) { 49 soot.Type sootType = (soot.Type)paramIt.next(); 50 soot.Local paramLocal = lg.generateLocal(sootType); 51 52 soot.jimple.ParameterRef paramRef = soot.jimple.Jimple.v().newParameterRef(sootType, 0); 53 soot.jimple.Stmt stmt = soot.jimple.Jimple.v().newIdentityStmt(paramLocal, paramRef); 54 body.getUnits().add(stmt); 55 fieldBase = paramLocal; 56 } 57 58 soot.Local fieldLocal = lg.generateLocal(fieldType); 60 soot.SootFieldRef field = soot.Scene.v().makeFieldRef( classToInvoke, fieldName, fieldType, isStatic); 62 63 soot.jimple.FieldRef fieldRef = null; 64 if (isStatic) { 65 fieldRef = soot.jimple.Jimple.v().newStaticFieldRef(field); 66 } 67 else { 68 fieldRef = soot.jimple.Jimple.v().newInstanceFieldRef(fieldBase, field); 69 } 70 soot.jimple.AssignStmt assign = soot.jimple.Jimple.v().newAssignStmt(fieldLocal, fieldRef); 71 body.getUnits().add(assign); 72 73 soot.jimple.Stmt retStmt = soot.jimple.Jimple.v().newReturnStmt(fieldLocal); 75 body.getUnits().add(retStmt); 76 77 return body; 78 79 } 80 } 81
| Popular Tags
|