gpt4 book ai didi

java - 是否可以在不调用 soot.Main.main(...) 的情况下使用 Soot 分析?

转载 作者:行者123 更新时间:2023-11-29 06:40:40 25 4
gpt4 key购买 nike

我想使用 Soot对 Java 程序进行静态分析,例如控制流图。

各种tutorials假设使用 Soot 的“标准方法”是创建一个主要方法,其中将自定义转换添加到 Soot 管道 ,然后调用 soot.Main.main(...) :

public static void main(String[] args) {        
PackManager.v().getPack("jtp").add(
new Transform("jtp.gotoinstrumenter", GotoInstrumenter.v()));
soot.Main.main(args);
}

当然,如果您想在命令行工具之外的其他地方使用 Soot,这会有一些严重的限制。例如,我不清楚在一个程序中多次调用 Soot 的 main 方法是否合法。

那么有谁知道可以通过更复杂一点的 API 直接使用 Soot 分析工具吗?

最佳答案

答案是肯定的。在您的主体中,您可以设置您使用的类:

configure("../yourClasspath/");
SootClass sootClass = Scene.v().loadClassAndSupport("className");
sootClass.setApplicationClass();

// Retrieve the method and its body
SootMethod m = c.getMethodByName("methodName");
Body b = m.retrieveActiveBody();

// Instruments bytecode
new YourTransform().transform(b);

之后,您可以构建 CFG 并运行一些分析。

它遵循配置方法:

public static void configure(String classpath) {

Options.v().set_verbose(false);
Options.v().set_keep_line_number(true);
Options.v().set_src_prec(Options.src_prec_class);
Options.v().set_soot_classpath(classpath);
Options.v().set_prepend_classpath(true);

PhaseOptions.v().setPhaseOption("bb", "off");
PhaseOptions.v().setPhaseOption("tag.ln", "on");
PhaseOptions.v().setPhaseOption("jj.a", "on");
PhaseOptions.v().setPhaseOption("jj.ule", "on");

Options.v().set_whole_program(true);
}

关于java - 是否可以在不调用 soot.Main.main(...) 的情况下使用 Soot 分析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12703500/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com