[Soot-list] Help regarding Call graph for multiple apk's

Marc-André Laverdière marc-andre.laverdiere-papineau at polymtl.ca
Wed Sep 10 10:08:44 EDT 2014


Hi Lokesh,

I'm not working on Android, so there could be some small differences here.

But, overall, I notice that you call Options.v().set_process_dir but not
set_soot_classpath. IIRC, things go wrong when the process path has
things that are not in the classpath (but its been a while - so I can't
give details).

Also, Scene.v().setEntryPoints is redundant. You should have enough of
setting the main class.

I see that you are not setting your cg phase option. IIRC, it defaults
to CHA, which could explain a bloated call graph. Try adding option
cg.spark enabled:true and cg.cha enabled:false.

Have fun!

Marc-André Laverdière-Papineau
Doctorant - PhD Candidate

On 09/10/2014 07:11 AM, LOKESH JAIN wrote:
> Hello All,
> 
> This is the code, in this i am calling dotgraph file for making graph.
> Let me know if i have to paste that code also. Actually that code i have
> takenm form dotgraph of soot only.
> 
> import java.io.File;
> import java.io.IOException;
> import java.util.Collections;
> import java.util.HashMap;
> import java.util.Iterator;
> 
> import org.apache.commons.io.FilenameUtils;
> import org.xmlpull.v1.XmlPullParserException;
> 
> import soot.MethodOrMethodContext;
> import soot.PackManager;
> import soot.Scene;
> import soot.SootMethod;
> import soot.jimple.infoflow.android.SetupApplication;
> import soot.jimple.toolkits.callgraph.CallGraph;
> import soot.jimple.toolkits.callgraph.Targets;
> import soot.options.Options;
> public class CFG {
>         private static DotGraph dot = new DotGraph("callgraph");
>         private static HashMap <String,Boolean> visited = new
> HashMap<String,Boolean>();
>         
> public CFG() {
>         
> }
> 
> public static void main(String[] args) {
> 
> File dir = new File("/home/lokesh/Desktop/lokesh/sample_applications");
> File[] files = dir.listFiles();        
> 
> for (int i = 0; i < files.length; i++) {
>         File f = files[i];
>         String source_apk = f.getAbsolutePath();        
>         soot.G.reset();
> 
> SetupApplication app = new
> SetupApplication("/home/lokesh/Desktop/android-sdk-linux/platforms/android-19/android.jar",source_apk);
>         
>         
> try {
> 
> app.calculateSourcesSinksEntrypoints("/home/lokesh/Downloads/soot-infoflow-android-develop/SourcesAndSinks.txt");
> 
> 
> } catch (IOException e) {
> 
> e.printStackTrace();
> 
> } catch (XmlPullParserException e) {
> 
> e.printStackTrace();
> 
> }
> 
> 
> Options.v().set_src_prec(Options.src_prec_apk);
> 
> Options.v().set_process_dir(Collections.singletonList(source_apk));
> Options.v().set_force_android_jar("/home/lokesh/Desktop/android-sdk-linux/platforms/android-19/android.jar");
> 
> Options.v().set_whole_program(true);
> 
> Options.v().set_allow_phantom_refs(true);
> 
> Options.v().set_output_format(Options.output_format_none);
> 
> Options.v().setPhaseOption("cg.spark verbose:true", "on");
> 
> Scene.v().loadNecessaryClasses();
> 
> SootMethod entryPoint = app.getEntryPointCreator().createDummyMain();
> 
> Options.v().set_main_class(entryPoint.getSignature());
> 
> Scene.v().setEntryPoints(Collections.singletonList(entryPoint));
> 
> System.out.println("............"+entryPoint.getActiveBody());
> 
> PackManager.v().runPacks();
> 
> System.out.println(Scene.v().getCallGraph().size());
> CallGraph cg = Scene.v().getCallGraph();
> //System.out.println("+++++++++++++++++" + cg);
> //System.out.println(".................."+entryPoint);
> //String label = Scene.v().getCallGraph().listener().toString();
> //dot.createSubGraph(label);
> visit(cg, entryPoint);
> String dest = f.getName();
> String fileNameWithOutExt = FilenameUtils.removeExtension(dest);
> String destination = "/home/lokesh/Desktop/lokesh/" + fileNameWithOutExt;
> dot.plot(destination + dot.DOT_EXTENSION);
> //soot.PhaseOptions.getBoolean(Scene.v().getCallGraph().listener(),"dump_cg");
> //System.out.println(Scene.v().getCallGraph());
> 
> }
> }
> private static void visit(CallGraph cg, SootMethod k)
> {
> String identifier = k.getName();
> 
> visited.put(k.getSignature(),true);
> 
> //System.out.println(dot.drawNode(identifier));
> dot.drawNode(identifier);
> 
> 
> //iterate over unvisited parents
> Iterator<MethodOrMethodContext> ptargets = new Targets(cg.edgesInto(k));
> 
> 
> if(ptargets != null){
> while(ptargets.hasNext())
> {
> SootMethod p = (SootMethod) ptargets.next();
> 
> 
> if(p == null)
> System.out.println("p is null");
> 
> 
> if(!visited.containsKey(p.getSignature()))
> visit(cg,p);
> }
> }
> 
> 
> //iterate over unvisited children
> Iterator<MethodOrMethodContext> ctargets = new Targets(cg.edgesOutOf(k));
> 
> 
> if(ctargets != null){
> while(ctargets.hasNext())
> {
> SootMethod c = (SootMethod) ctargets.next();
> if(c == null) System.out.println("c is null");
> dot.drawEdge(identifier, c.getName());
> 
> 
> if(!visited.containsKey(c.getSignature()))
> visit(cg,c);
> }
> }
> }
> }
> 
> Please reply fast as i am stuck here.
> 
> Thanks & Regards
> Lokesh Jain
> 
> On Wed, Sep 10, 2014 at 4:23 PM, LOKESH JAIN <lokeshjain92 at gmail.com
> <mailto:lokeshjain92 at gmail.com>> wrote:
> 
>     Hi Marc,
> 
>     Second option that you have mentioned, I haven't quite understood
>     that. APK works on dalvik virtual machine. First class file is
>     created and then it's converted to DVM. Then how to create a new JVM
>     for each apk.
> 
>     Please suggest some easy and simple solution.
>     I will post the code snippet here. Please help me resolve my problem
>     as i am not able figure out.
> 
>     Thanks & Regards
>     Lokesh Jain
> 
>     On Wed, Sep 10, 2014 at 3:28 AM, LOKESH JAIN <lokeshjain92 at gmail.com
>     <mailto:lokeshjain92 at gmail.com>> wrote:
> 
>         Hey Marc,
> 
>         I have tried soot.G.reset() before loading new apk but still
>         getting the same graph. Any other suggestion?
> 
>         Thanks & Regards
>         Lokesh Jain
> 
>         On Mon, Sep 8, 2014 at 9:35 PM, LOKESH JAIN
>         <lokeshjain92 at gmail.com <mailto:lokeshjain92 at gmail.com>> wrote:
> 
>             Hi Stevan,
> 
>             No, I just want to create a call graph for each application
>             seperately without manually giving the path for each
>             application.
> 
>             Currently i had given the path for an application and
>             getting the call graph, it's working fine then.
>             Now, I have written the script that automatically pick 1
>             application at a time and run soot on it(as i have more than
>             1000 apps). I don't specify the path manually for each
>             application. It's now giving me some irrelevant call graph.
>             I had attached both the graphs earlier in this thread.
> 
>             Regards
>             Lokesh Jain
> 
>             On Mon, Sep 8, 2014 at 5:36 PM, Steven Arzt
>             <Steven.Arzt at cased.de <mailto:Steven.Arzt at cased.de>> wrote:
> 
>                 Hi Lokesh,
> 
>                 Are you looking for an inter-component callgraph to take
>                 intent-based communication into account? If so, you
>                 should look into the EPICC paper. Still, I am not sure
>                 that this actually scales to thousands of applications.
>                 What are you trying to achieve in total?
> 
>                 Best regards,
>                 Steven
> 
>                 LOKESH JAIN <lokeshjain92 at gmail.com
>                 <mailto:lokeshjain92 at gmail.com>> wrote:
> 
>                 Please reply fast. I am not able to figure out how to
>                 resolve it.
> 
>                 Regards
>                 Lokesh Jain
> 
>                 On Sat, Sep 6, 2014 at 10:25 PM, LOKESH JAIN
>                 <lokeshjain92 at gmail.com <mailto:lokeshjain92 at gmail.com>>
>                 wrote:
> 
>                     Hello all,
> 
>                     I want the call graph for more than one apk's files
>                     that are in a folder using soot. Please help me to
>                     generate the call graph for multiple applications as
>                     i have to generate the call graph for around 3000
>                     applications and it would be practically impossible
>                     to manually generate call graph for each application.
> 
>                     I am getting the call graph for a single apk i.e
>                     every time i press the run button. But when I am
>                     running the code i.e looping over the all the apk's
>                     (reading apk one by one) in a folder. Then i am not
>                     getting the relevant call graph. I am getting
>                     something absurd.
> 
>                     I am attaching both the call graph that i am getting
>                     while executing on a single application individually
>                     and the other I am getting while looping over
>                     multiple application at once.
> 
>                     Any help would be appreciated.
> 
>                     Regards
>                     Lokesh Jain
> 
> 
> 
> 
> 
> 
> 
> 
> _______________________________________________
> Soot-list mailing list
> Soot-list at CS.McGill.CA
> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
> 


More information about the Soot-list mailing list