[Soot-list] Spark & Android Source Code no main class

Jason Ott jott002 at ucr.edu
Fri Mar 27 13:28:13 EDT 2015


So if I wanted to generate a call graph for WifiManager.java (
http://androidxref.com/5.1.0_r1/xref/frameworks/base/wifi/java/android/net/wifi/WifiManager.java)
a class within the Android framework.  Would I have to create and compile a
main.java that instantiates a WifiManager object on the fly, pass that to
Soot and then generate the call graph with the dynamically created main
file as my starting point?

So the code would change a bit to:

dynamically create the java file:

public static void main(String[] args) {
     WifiManager m = new WifiManager();
}

as main.java

Run the following command:

java -cp ../bin/jasminclasses-2.4.0
.jar:../bin/polyglot.jar:../bin/sootclasses-2.4.0.jar:../soot/DumpClass/bin:.
callGrapher.GenerateCallGraph WifiManager.java

*public* *static* *void* main(String[] args) {

             Scene.*v*().loadNecessaryClasses();

             SootClass sc = Scene.*v*()

                           .forceResolve(args[0], SootClass.*BODIES*);

             sc.setApplicationClass();

             SootMethod method = sc.getMethodByName("main");

             List<SootMethod> entryPoints = *new* ArrayList<SootMethod>();

             entryPoints.add(method);

             Scene.*v*().setEntryPoints(entryPoints);

             Options.*v*().set_main_class(method.getSignature());



             PackManager.*v*().runPacks();



             CallGraph callgraph = Scene.*v*().getCallGraph();

             System.*out*.println("[TestSpark] Call graph size " + callgraph
.size());



             *for* (Edge edge : callgraph)

                    System.*out*.println(edge + "");



       }

Assuming this is the case, I'd have to do this for any class or file I'd
want to generate a callgraph for within the Android framework, is that
correct?

On Fri, Mar 27, 2015 at 3:14 AM, Steven Arzt <Steven.Arzt at cased.de> wrote:

> Hi Jason,
>
>
>
> You should never need to call „loadClassAndSupport“ on your own. This is
> done internally by Soot.
>
>
>
> For creating a callgraph, you need an entry point. For normal Java
> applications, this is the main() method. You can either explicitly specify
> it or have Soot automatically select the only main() method in your Soot
> classpath.
>
>
>
> The easiest way to get a callgraph is to call the Soot main method and
> pass the correct command-line parameters:
>
>
>
>                 -p cg.spark on                   This enables SPARK
>
>                 -process-dir                       Path to the classes you
> want to analyze
>
>                 -cp                                        Path to other
> classes that might be referenced from your analysis target
>
>                 -main-class                        The main class to use
>
>
>
> After the call to soot.Main.main(), you should be able to access the
> callgraph.
>
>
>
> A more involved example that calls the required parts of Soot manually
> goes here:
>
>
>
>        *public* *static* *void* main(String[] args) {
>
>              Options.*v*().parse(args);
>
>              Scene.*v*().loadNecessaryClasses();
>
>              SootClass sc = Scene.*v*()
>
>                            .forceResolve("soot.Examples", SootClass.
> *BODIES*);
>
>              sc.setApplicationClass();
>
>              SootMethod method = sc.getMethodByName("main");
>
>              List<SootMethod> entryPoints = *new* ArrayList<SootMethod>();
>
>              entryPoints.add(method);
>
>              Scene.*v*().setEntryPoints(entryPoints);
>
>              Options.*v*().set_main_class(method.getSignature());
>
>
>
>              PackManager.*v*().runPacks();
>
>
>
>              CallGraph callgraph = Scene.*v*().getCallGraph();
>
>              System.*out*.println("[TestSpark] Call graph size " +
> callgraph.size());
>
>
>
>              *for* (Edge edge : callgraph)
>
>                     System.*out*.println(edge + "");
>
>
>
>        }
>
>
>
> This is essentially what the normal Soot main method would do.
>
>
>
> Best regards,
>
>   Steven
>
>
>
> *Von:* soot-list-bounces at CS.McGill.CA [mailto:
> soot-list-bounces at CS.McGill.CA] *Im Auftrag von *Jason Ott
> *Gesendet:* Mittwoch, 25. März 2015 06:31
> *An:* soot-list at CS.McGill.CA
> *Betreff:* [Soot-list] Spark & Android Source Code no main class
>
>
>
> I would like to build a callgraph for each class of the android framework
> and I am struggling.  I haven't found much in the way of documentation or
> examples for using SPARK in general.
>
>
>
> I have a basic program that does the following:
>
>
>
> public class DumpClass {
>
> public static void main(String[] args) {
>
>
>
> Scene.v().loadBasicClasses();
>
>             SootClass mclass;
>
>         mclass = Scene.v().loadClassAndSupport(args[0]);
>
>         mclass.setApplicationClass();
>
>
>
>             Options.v().set_whole_program(true);
>
>             Options.v().setPhaseOption("cg.spark", "on");
>
>             Scene.v().loadNecessaryClasses();
>
>
>
>
> Options.v().set_main_class(mclass.getMethods().get(0).toString());
>
>             PackManager.v().runPacks();
>
>
>
>         new SparkTest(mclass);
>
>     }
>
> }
>
>
>
> Now, when I run this, I get: Exception in thread "main"
> java.lang.RuntimeException: There is no main class set!
>
>
>
> I'm not quite sure what to do with that or what to do next if this thing
> ever works.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20150327/1c3df707/attachment-0001.html 


More information about the Soot-list mailing list