0

使用 Soot,我正在尝试构建调用图。据我所知,问题在于,在处理 API 时,没有可用作入口点的主要方法。我更彻底地检查了 Soot 正在加载什么。使用的类是“正确加载的”(我从中打印它们的列表Scene.v().getClasses(),它显示了项目中的正确类(源和测试源)。

现在,Soot 在请求调用图时不断出现相同的异常Scene.v().getCallGraph()

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

这适用于几乎所有类(测试类除外)。我究竟做错了什么 ?为什么方法被拒绝?

4

2 回答 2

0

老兄。你可以试试这样写:

Options.v().set_whole_program(true);
Scene.v().loadNecessaryClasses();
PackManager.v().runPacks();

大声笑也许它可以帮助你。

于 2021-03-24T01:48:51.543 回答
0

您是否按照错误消息的提示使用命令行参数 -w ?

于 2017-11-23T17:57:00.647 回答