From 3fe1a9ec8d8e6279968c3d10473e9339414e7c78 Mon Sep 17 00:00:00 2001 From: p30496857 Date: Thu, 23 Nov 2023 13:51:30 +0800 Subject: [PATCH] ADD file via upload --- MyAnalysisCamera2.java | 138 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 MyAnalysisCamera2.java diff --git a/MyAnalysisCamera2.java b/MyAnalysisCamera2.java new file mode 100644 index 0000000..3f32ce8 --- /dev/null +++ b/MyAnalysisCamera2.java @@ -0,0 +1,138 @@ +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 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 classes = Scene.v().getClasses(); +// Set 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 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 methodsWithCamera2Resource = new HashSet<>(); +// +// // 创建控制流图 +// DirectedGraph 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); +// } +// } +// } +//}