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