139 lines
4.7 KiB
Java
139 lines
4.7 KiB
Java
package com.nii.soot.CFGCamera2Analyser;
|
||
|
||
import java.util.HashSet;
|
||
import java.util.Iterator;
|
||
import java.util.Map;
|
||
import java.util.Set;
|
||
|
||
import soot.*;
|
||
import soot.jimple.*;
|
||
import soot.jimple.internal.*;
|
||
import soot.toolkits.graph.*;
|
||
import soot.options.Options;
|
||
import soot.tagkit.LineNumberTag;
|
||
import soot.tagkit.Tag;
|
||
import soot.toolkits.graph.CompleteBlockGraph;
|
||
import soot.toolkits.scalar.ArraySparseSet;
|
||
import soot.util.Chain;
|
||
import soot.util.HashChain;
|
||
|
||
public class MyAnalysisCamera2 extends BodyTransformer {
|
||
|
||
protected void internalTransform(final Body body,String phase, @SuppressWarnings("rawtypes")Map options){
|
||
for (SootClass c:Scene.v().getApplicationClasses()) {
|
||
// System.out.println("[sootClass]"+c);
|
||
for(SootMethod method:c.getMethods())
|
||
{
|
||
System.out.println("[sootMethod]"+method);
|
||
|
||
if (method.hasActiveBody()) {
|
||
Body methodBody = method.getActiveBody();
|
||
Iterator<Unit> unitIt = methodBody.getUnits().snapshotIterator();
|
||
|
||
while (unitIt.hasNext()) {
|
||
Stmt stmt = (Stmt) unitIt.next();
|
||
|
||
// 在语句中查找与camera2相关的内容
|
||
if (stmt.toString().contains("camera2")) {
|
||
System.out.println("Found camera2-related code in method: " + method);
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
//
|
||
// // 获取所有类
|
||
// Chain<SootClass> classes = Scene.v().getClasses();
|
||
// Set<SootMethod> methodsWithCamera2Resource = new HashSet<>();
|
||
//
|
||
// // 遍历所有类
|
||
// for (SootClass sootClass : classes) {
|
||
// // 遍历类中的方法
|
||
// for (SootMethod sootMethod : sootClass.getMethods()) {
|
||
// // 分析每个方法是否包含 Camera2 相关资源
|
||
// if (sootMethod.hasActiveBody()) {
|
||
// if (containsCamera2Resource(sootMethod)) {
|
||
// methodsWithCamera2Resource.add(sootMethod);
|
||
// }
|
||
// }
|
||
// }
|
||
// }
|
||
//
|
||
// if (!methodsWithCamera2Resource.isEmpty()) {
|
||
// System.out.println("Methods that contain Camera2 resource calls:");
|
||
// for (SootMethod method : methodsWithCamera2Resource) {
|
||
// System.out.println("Class: " + method.getDeclaringClass() + ", Method: " + method);
|
||
// }
|
||
// }
|
||
// else
|
||
// {
|
||
// System.out.println("No methods found that contain Camera2 resource calls.");
|
||
// }
|
||
// }
|
||
//
|
||
//
|
||
//
|
||
// public static boolean containsCamera2Resource(SootMethod method) {
|
||
// DirectedGraph<Unit> cfg = new ExceptionalUnitGraph(method.getActiveBody());
|
||
//
|
||
// for (Unit unit : cfg) {
|
||
// Stmt stmt = (Stmt) unit;
|
||
// if (stmt.toString().contains("camera2")) {
|
||
// return true;
|
||
// }
|
||
// }
|
||
//
|
||
// return false;
|
||
// }
|
||
//}
|
||
|
||
//import soot.*;
|
||
//import soot.jimple.Stmt;
|
||
//import soot.jimple.internal.*;
|
||
//import soot.toolkits.graph.*;
|
||
//import soot.toolkits.scalar.ArraySparseSet;
|
||
//import soot.util.Chain;
|
||
//import soot.util.HashChain;
|
||
//
|
||
//import java.util.HashSet;
|
||
//import java.util.Map;
|
||
//import java.util.Set;
|
||
//
|
||
//public class MyAnalysisCamera2 extends BodyTransformer{
|
||
//
|
||
// protected void internalTransform(final Body body, String phase, @SuppressWarnings("rawtypes") Map options) {
|
||
// // 创建一个容器,用于存储包含"camera2"资源的方法
|
||
// Set<SootMethod> methodsWithCamera2Resource = new HashSet<>();
|
||
//
|
||
// // 创建控制流图
|
||
// DirectedGraph<Unit> cfg = new ExceptionalUnitGraph(body);
|
||
//
|
||
// // 遍历控制流图的每个节点
|
||
// for (Unit unit : cfg) {
|
||
// Stmt stmt = (Stmt) unit;
|
||
//
|
||
// // 在语句中查找与"camera2"相关的内容
|
||
// if (stmt.toString().contains("Camera2")) {
|
||
// // 如果找到,将包含该资源的方法添加到容器中
|
||
// methodsWithCamera2Resource.add(body.getMethod());
|
||
// break; // 中断循环
|
||
// }
|
||
//
|
||
// }
|
||
//
|
||
// if(methodsWithCamera2Resource.isEmpty())
|
||
// {
|
||
// System.out.println("There is no method to involve camera2 resources.");
|
||
// }
|
||
// else
|
||
// {
|
||
// // 在这里,你可以根据需要处理或记录methodsWithCamera2Resource中的方法
|
||
// for (SootMethod method : methodsWithCamera2Resource) {
|
||
// System.out.println("Method with camera2 resource: " + method);
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|