soot.Body.getLocals()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(175)

本文整理了Java中soot.Body.getLocals()方法的一些代码示例,展示了Body.getLocals()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.getLocals()方法的具体详情如下:
包路径:soot.Body
类名称:Body
方法名:getLocals

Body.getLocals介绍

[英]Returns a backed chain of the locals declared in this Body.
[中]

代码示例

代码示例来源:origin: Sable/soot

private Local getLocalUnsafe(Body b, String name) {
 for (Local local : b.getLocals()) {
  if (local.getName().equals(name)) {
   return local;
  }
 }
 return null;
}

代码示例来源:origin: Sable/soot

private void retrieveAllArrayLocals(Body body, Set<Local> container) {
 for (Local local : body.getLocals()) {
  Type type = local.getType();
  if (type instanceof IntType || type instanceof ArrayType) {
   container.add(local);
  }
 }
}

代码示例来源:origin: Sable/soot

/**
 * Gets all variables that are not used in this body
 *
 * @return The list of variables declared, but not used in this body
 */
public Set<Local> getUnusedVariables() {
 Set<Local> res = new HashSet<Local>(body.getLocals());
 res.retainAll(getUsedVariables());
 return res;
}

代码示例来源:origin: Sable/soot

private void initLocalNames() {
 localNames = new HashSet<String>();
 for (Local l : body.getLocals()) {
  localNames.add(l.getName());
 }
}

代码示例来源:origin: Sable/soot

private void retrieveMultiArrayLocals(Body body, Set<Local> container) {
 for (Local local : body.getLocals()) {
  Type type = local.getType();
  if (type instanceof ArrayType) {
   if (((ArrayType) type).numDimensions > 1) {
    this.multiarraylocals.add(local);
   }
  }
 }
}

代码示例来源:origin: Sable/soot

public LocalMustNotAliasAnalysis(DirectedGraph<Unit> directedGraph, Body b) {
 super(directedGraph);
 locals = new HashSet<Local>();
 locals.addAll(b.getLocals());
 for (Local l : b.getLocals()) {
  if (l.getType() instanceof RefLikeType) {
   locals.add(l);
  }
 }
 doAnalysis();
}

代码示例来源:origin: Sable/soot

protected void internalTransform(Body body, String phaseName, Map<String, String> options) {
  soot.jbco.Main.methods2JLocals.put(body.getMethod(), new ArrayList<Local>(body.getLocals()));
 }
}

代码示例来源:origin: Sable/soot

public SimpleLocalDefs(UnitGraph graph, FlowAnalysisMode mode) {
 this(graph, graph.getBody().getLocals(), mode);
}

代码示例来源:origin: Sable/soot

private boolean hasArrayLocals(Body body) {
 Iterator localIt = body.getLocals().iterator();
 while (localIt.hasNext()) {
  Local local = (Local) localIt.next();
  if (local.getType() instanceof ArrayType) {
   return true;
  }
 }
 return false;
}

代码示例来源:origin: Sable/soot

public String toString() {
 StringBuffer tmp = new StringBuffer();
 Body b = cfg.getBody();
 Iterator localsIt = b.getLocals().iterator();
 while (localsIt.hasNext()) {
  Local local = (Local) localsIt.next();
  tmp.append(local + "\t" + getGlobalValueNumber(local) + "\n");
 }
 /*
  * Iterator partitionsIt = partitions.iterator(); while(partitionsIt.hasNext()){ Partition partition = (Partition)
  * partitionsIt.next(); int partitionNumber = partition.getPartitionNumber();
  *
  * Iterator partitionIt = partition.iterator(); while(partitionIt.hasNext()){ Local local =
  * vg.getLocal((Node)partitionIt.next()); if(local == null) continue; tmp.append(local + "\t" + partitionNumber + "\n");
  * } }
  */
 return tmp.toString();
}

代码示例来源:origin: Sable/soot

@Override
public void validate(Body body, List<ValidationException> exception) {
 for (Local l : body.getLocals()) {
  if (l.getType() instanceof VoidType) {
   exception.add(new ValidationException(l, "Local " + l + " in " + body.getMethod() + " defined with void type"));
  }
 }
}

代码示例来源:origin: Sable/soot

public SCPFAnalysis(UnitGraph graph) {
 super(graph);
 emptySet = new ArraySparseSet();
 stmtToReplacement = new HashMap<Stmt, GotoStmt>();
 deadStmts = new ArrayList<IfStmt>();
 // initialise localToConstant map -- assume all scalars are
 // constant (Top)
 {
  Collection<Local> locals = graph.getBody().getLocals();
  Iterator<Local> localsIt = locals.iterator();
  localToConstant = new HashMap<Local, Constant>(graph.size() * 2 + 1, 0.7f);
  while (localsIt.hasNext()) {
   Local local = (Local) localsIt.next();
   localToConstant.put(local, TopConstant.v());
  }
 }
 doAnalysis();
}

代码示例来源:origin: Sable/soot

protected soot.Local createLocal(String name, soot.Type sootType) {
  soot.Local sootLocal = soot.jimple.Jimple.v().newLocal(name, sootType);
  body.getLocals().add(sootLocal);
  return sootLocal;
 }
}

代码示例来源:origin: Sable/soot

private void validateLocal(Body body, ValueBox vb, List<ValidationException> exception) {
 Value value;
 if ((value = vb.getValue()) instanceof Local) {
  if (!body.getLocals().contains(value)) {
   exception.add(new ValidationException(value, "Local not in chain : " + value + " in " + body.getMethod()));
  }
 }
}

代码示例来源:origin: Sable/soot

/**
 * Reassigns the local numbers such that a dense bit set can be created over them
 */
public void pack() {
 int n = body.getLocalCount();
 locals = new Local[n];
 oldNumbers = new int[n];
 n = 0;
 for (Local local : body.getLocals()) {
  locals[n] = local;
  oldNumbers[n] = local.getNumber();
  local.setNumber(n++);
 }
}

代码示例来源:origin: Sable/soot

public InitAnalysis(UnitGraph g) {
 super(g);
 allLocals = new ArraySparseSet<Local>();
 for (Local loc : g.getBody().getLocals()) {
  allLocals.add(loc);
 }
 doAnalysis();
}

代码示例来源:origin: Sable/soot

@Override
protected void internalTransform(Body b, String phaseName, Map<String, String> options) {
 LocalCreation lc = new LocalCreation(b.getLocals(), "ex");
 for (Iterator<Unit> unitIt = b.getUnits().snapshotIterator(); unitIt.hasNext();) {
  Unit u = unitIt.next();
  // Check for a null exception
  if (u instanceof ThrowStmt) {
   ThrowStmt throwStmt = (ThrowStmt) u;
   if (throwStmt.getOp() == NullConstant.v() || throwStmt.getOp().equals(IntConstant.v(0))
     || throwStmt.getOp().equals(LongConstant.v(0))) {
    createThrowStmt(b, throwStmt, lc);
   }
  }
 }
}

代码示例来源:origin: Sable/soot

@Override
protected Map<Value, Parity> newInitialFlow() {
 Map<Value, Parity> initMap = new HashMap<Value, Parity>();
 for (Local l : g.getBody().getLocals()) {
  Type t = l.getType();
  // System.out.println("next local: "+next);
  if ((t instanceof IntegerType) || (t instanceof LongType)) {
   initMap.put(l, BOTTOM);
  }
 }
 for (ValueBox vb : g.getBody().getUseAndDefBoxes()) {
  Value val = vb.getValue();
  if (val instanceof ArithmeticConstant) {
   initMap.put(val, getParity(initMap, val));
  }
 }
 if (Options.v().interactive_mode()) {
  updateBeforeFilterMap();
 }
 return initMap;
}

代码示例来源:origin: Sable/soot

@Override
public void validate(Body body, List<ValidationException> exceptions) {
 SootMethod method = body.getMethod();
 if (method != null) {
  if (!method.getReturnType().isAllowedInFinalCode()) {
   exceptions.add(new ValidationException(method, "Return type not allowed in final code: " + method.getReturnType(),
     "return type not allowed in final code:" + method.getReturnType() + "\n method: " + method));
  }
  for (Type t : method.getParameterTypes()) {
   if (!t.isAllowedInFinalCode()) {
    exceptions.add(new ValidationException(method, "Parameter type not allowed in final code: " + t,
      "parameter type not allowed in final code:" + t + "\n method: " + method));
   }
  }
 }
 for (Local l : body.getLocals()) {
  Type t = l.getType();
  if (!t.isAllowedInFinalCode()) {
   exceptions.add(new ValidationException(l, "Local type not allowed in final code: " + t,
     "(" + method + ") local type not allowed in final code: " + t + " local: " + l));
  }
 }
}

代码示例来源:origin: Sable/soot

/**
 * 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);
}

相关文章