ADD file via upload
This commit is contained in:
parent
158f96eb95
commit
540490365b
|
@ -0,0 +1,192 @@
|
|||
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 MyAnalysisCamera 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]"+m);
|
||||
//
|
||||
// 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> methodsWithCameraResource = new HashSet<>();
|
||||
//
|
||||
// // 遍历所有类
|
||||
// for (SootClass sootClass : classes) {
|
||||
// // 遍历类中的方法
|
||||
// for (SootMethod sootMethod : sootClass.getMethods()) {
|
||||
// // 分析每个方法是否包含 Camera2 相关资源
|
||||
// if (sootMethod.hasActiveBody()) {
|
||||
// if (containsCameraResource(sootMethod)) {
|
||||
// methodsWithCameraResource.add(sootMethod);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// if (!methodsWithCameraResource.isEmpty()) {
|
||||
// System.out.println("Methods that contain Camera resource calls:");
|
||||
// for (SootMethod method : methodsWithCameraResource) {
|
||||
// System.out.println("Class: " + method.getDeclaringClass() + ", Method: " + method);
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// System.out.println("No methods found that contain Camera resource calls.");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// public static boolean containsCameraResource(SootMethod method) {
|
||||
// DirectedGraph<Unit> cfg = new ExceptionalUnitGraph(method.getActiveBody());
|
||||
//
|
||||
// for (Unit unit : cfg) {
|
||||
// Stmt stmt = (Stmt) unit;
|
||||
// if (stmt.toString().contains("camera")) {
|
||||
// System.out.println("name: "+stmt);
|
||||
// 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 MyAnalysisCamera 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("cameraX")) {
|
||||
// // 如果找到,将包含该资源的方法添加到容器中
|
||||
// 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
import soot.*;
|
||||
import soot.jimple.Stmt;
|
||||
import soot.jimple.internal.*;
|
||||
import soot.toolkits.graph.CompleteUnitGraph;
|
||||
import soot.toolkits.graph.ExceptionalUnitGraph;
|
||||
import soot.util.Chain;
|
||||
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 MyAnalysisCamera extends BodyTransformer {
|
||||
|
||||
protected void internalTransform(final Body body, String phase, @SuppressWarnings("rawtypes") Map options) {
|
||||
// 创建一个容器,用于存储包含"camera2"资源的方法
|
||||
Set<SootMethod> methodsWithCamera2Resource = new HashSet<>();
|
||||
|
||||
Chain<SootClass> classes = Scene.v().getApplicationClasses();
|
||||
for (SootClass sootClass : classes) {
|
||||
for (SootMethod sootMethod : sootClass.getMethods()) {
|
||||
if (sootMethod.hasActiveBody()) {
|
||||
Body body1 = sootMethod.getActiveBody();
|
||||
CompleteUnitGraph unitGraph = new CompleteUnitGraph(body1);
|
||||
|
||||
for (Unit unit : unitGraph) {
|
||||
Stmt stmt = (Stmt) unit;
|
||||
// 在这里,你可以分析每一行语句(stmt)来检测是否包含 Camera2 相关资源的调用
|
||||
if (stmt.toString().contains("camera")) {
|
||||
// 如果找到,将包含该资源的方法添加到容器中
|
||||
methodsWithCamera2Resource.add(body1.getMethod());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue