| 50 | import static soot.SootClass.HIERARCHY; |
| 51 | |
| 52 | public class SootWorldBuilder extends AbstractWorldBuilder { |
| 53 | |
| 54 | private static final Logger logger = LogManager.getLogger(SootWorldBuilder.class); |
| 55 | |
| 56 | /** |
| 57 | * Path to the file which specifies the basic classes that should be |
| 58 | * added to Scene in advance. |
| 59 | */ |
| 60 | private static final String BASIC_CLASSES = "basic-classes.yml"; |
| 61 | |
| 62 | @Override |
| 63 | public void build(Options options, List<AnalysisConfig> analyses) { |
| 64 | initSoot(options, analyses, this); |
| 65 | // set arguments and run soot |
| 66 | List<String> args = new ArrayList<>(); |
| 67 | // set class path |
| 68 | Collections.addAll(args, "-cp", getClassPath(options)); |
| 69 | // set main class |
| 70 | String mainClass = options.getMainClass(); |
| 71 | if (mainClass != null) { |
| 72 | Collections.addAll(args, "-main-class", mainClass, mainClass); |
| 73 | } |
| 74 | // add input classes |
| 75 | args.addAll(getInputClasses(options)); |
| 76 | OptionsHolder.options = options; |
| 77 | runSoot(args.toArray(new String[0])); |
| 78 | } |
| 79 | |
| 80 | private static void initSoot(Options options, List<AnalysisConfig> analyses, |
| 81 | SootWorldBuilder builder) { |
| 82 | // reset Soot |
| 83 | G.reset(); |
| 84 | |
| 85 | // set Soot options |
| 86 | soot.options.Options.v().set_output_dir( |
| 87 | new File(options.getOutputDir(), "sootOutput").toString()); |
| 88 | soot.options.Options.v().set_output_format( |
| 89 | soot.options.Options.output_format_jimple); |
| 90 | soot.options.Options.v().set_keep_line_number(true); |
| 91 | soot.options.Options.v().set_app(true); |
| 92 | // exclude jdk classes from application classes |
| 93 | soot.options.Options.v().set_exclude(List.of("jdk.*", "apple.laf.*")); |
| 94 | soot.options.Options.v().set_whole_program(true); |
| 95 | soot.options.Options.v().set_no_writeout_body_releasing(true); |
| 96 | soot.options.Options.v().setPhaseOption("jb", "preserve-source-annotations:true"); |
| 97 | soot.options.Options.v().setPhaseOption("jb", "model-lambdametafactory:false"); |
| 98 | soot.options.Options.v().setPhaseOption("cg", "enabled:false"); |
| 99 | if (options.isPrependJVM()) { |
| 100 | // TODO: figure out why -prepend-classpath makes Soot faster |
| 101 | soot.options.Options.v().set_prepend_classpath(true); |
| 102 | } |
| 103 | if (options.isAllowPhantom()) { |
| 104 | soot.options.Options.v().set_allow_phantom_refs(true); |
| 105 | } |
| 106 | if (options.isPreBuildIR()) { |
| 107 | // we need to set this option to false when pre-building IRs, |
| 108 | // otherwise Soot throws RuntimeException saying |
| 109 | // "No method source set for method ...". |
nothing calls this directly
no outgoing calls
no test coverage detected