使用Soot,我正在尝试构建调用图。据我所知,问题在于,在处理API时,没有可用作入口点的主要方法。我更彻底地检查了加载的是什么。使用的类是“正确加载的”(我从Scene.v().getClasses()打印了它们的列表,它显示了项目中正确的类(源代码和测试源)。
现在,当使用Scene.v().getCallGraph()请求调用图时,Soot不断引发相同的异常:
java.lang.RuntimeException: No call graph present in Scene. Maybe you want Whole Program mode (-w).因此,我尝试手动添加入口点,在测试套件中查找用于此目的的方法。我发现,如果加载了类,那么它们的方法就不会加载。这是我使用的代码片段,可以在Soot的教程中找到,用于加载类方法:
SootClass c = Scene.v().loadClassAndSupport(name);
c.setApplicationClass();
Iterator<SootMethod> mi = c.getMethods().iterator();
while (mi.hasNext()) {
SootMethod sm = (SootMethod)mi.next();
if (sm.isConcrete()) {
sm.retrieveActiveBody();
}
}但是c.getMethods()不返回任何方法...更多的是,调用sm.retrieveActiveBody();引发了一个异常:
java.lang.RuntimeException: Failed to apply jb to <com.[...classified...].resource.VoidResource: void <init>()>
at soot.asm.AsmMethodSource.getBody(AsmMethodSource.java:1911)
at soot.SootMethod.getBodyFromMethodSource(SootMethod.java:126)
at soot.SootMethod.retrieveActiveBody(SootMethod.java:385)
at ca.umontreal.iro.soot.CallGraphExample.loadClass(CallGraphExample.java:204)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:139)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:157)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:157)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:157)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:157)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:157)
at ca.umontreal.iro.soot.CallGraphExample.loadClasses(CallGraphExample.java:157)
at ca.umontreal.iro.soot.CallGraphExample.main(CallGraphExample.java:95)
Caused by: java.lang.IllegalStateException: RefType java.lang.InstantiationError not loaded. If you tried to get the RefType of a library class, did you call loadNecessaryClasses()? Otherwise please check Soot's classpath.
at soot.Scene.getRefType(Scene.java:916)
at soot.toolkits.exceptions.ThrowableSet$Manager.<init>(ThrowableSet.java:213)
at soot.Singletons.soot_toolkits_exceptions_ThrowableSet_Manager(Singletons.java:1829)
at soot.toolkits.exceptions.ThrowableSet$Manager.v(ThrowableSet.java:277)
at soot.toolkits.exceptions.UnitThrowAnalysis.<init>(UnitThrowAnalysis.java:215)
at soot.toolkits.exceptions.UnitThrowAnalysis.<init>(UnitThrowAnalysis.java:231)
at soot.Singletons.soot_toolkits_exceptions_UnitThrowAnalysis(Singletons.java:1843)
at soot.toolkits.exceptions.UnitThrowAnalysis.v(UnitThrowAnalysis.java:246)
at soot.Scene.getDefaultThrowAnalysis(Scene.java:1324)
at soot.jimple.toolkits.scalar.UnreachableCodeEliminator.internalTransform(UnreachableCodeEliminator.java:78)
at soot.BodyTransformer.transform(BodyTransformer.java:54)
at soot.Transform.apply(Transform.java:105)
at soot.JimpleBodyPack.applyPhaseOptions(JimpleBodyPack.java:62)
at soot.JimpleBodyPack.internalApply(JimpleBodyPack.java:105)
at soot.Pack.apply(Pack.java:125)
at soot.asm.AsmMethodSource.getBody(AsmMethodSource.java:1909)
... 11 more这几乎适用于所有类(测试类除外)。我做错了什么?为什么这些方法会被拒绝?
发布于 2017-11-24 01:57:01
您是否按照错误消息提示的那样使用了命令行参数-w?
发布于 2021-03-24 09:48:52
伙计。你可以试着这样写:
Options.v().set_whole_program(true);
Scene.v().loadNecessaryClasses();
PackManager.v().runPacks();哈哈,也许这对你有帮助。
https://stackoverflow.com/questions/47417394
复制相似问题