Translate

Showing posts with label apks. Show all posts
Showing posts with label apks. Show all posts

Friday

Creating Control Flow Diagram from Java Class files Using Soot.

Creating Control Flow Diagram from Java Class files Using Soot.

In order to create control flow diagram you need to convert Java class file into dot files by using control flow viewer soot tool. You can get HelloWorld.java file from previous posts(here). Convert it in to class file and type following commands on command prompt inside soot directory where HelloWorld is located:

>Java soot.tools.CFGViewer HelloWorld

And if you do not set classpath then type following inside soot directory where HelloWorld  and soot jars are located:

>Java -cp soot-2.5.0.jar soot.tools.CFGViewer HelloWorld

you will see following if it succeed:


It will create graphical representation of control flow graph of dot file format for each method from the class files. 

Java.lang.String[] Method:

digraph "void main(java.lang.String[])" {
    label="void main(java.lang.String[])";
    node [shape=box];
    "0" [style=filled,fillcolor=gray,label="r0 := @parameter0",];
    "1" [label="$r1 = new HelloWorld",];
    "0"->"1";
    "2" [label="specialinvoke $r1.<init>()",];
    "1"->"2";
    "3" [label="HelloWorld.helloObj = $r1",];
    "2"->"3";
    "4" [label="$r2 = java.lang.System.out",];
    "3"->"4";
    "5" [label="$r3 = HelloWorld.helloObj",];
    "4"->"5";
    "6" [label="$r4 = $r3.printMessage()",];
    "5"->"6";
    "7" [label="$r2.println($r4)",];
    "6"->"7";
    "8" [style=filled,fillcolor=lightgray,label="return",];
    "7"->"8";
}
 

Print Message() Method:

digraph "java.lang.String printMessage()" {
    label="java.lang.String printMessage()";
    node [shape=box];
    "0" [style=filled,fillcolor=gray,label="r0 := @this",];
    "1" [label="$r1 = r0.output",];
    "0"->"1";
    "2" [style=filled,fillcolor=lightgray,label="return $r1",];
    "1"->"2";
}



Jimple files Codes - Static Analysis of Android Applications Using Soot

Jimple files Codes

From previous example (Click Here  to view)HelloWorld.Jimple contains located at sootOutput directory following: 

public class HelloWorld extends java.lang.Object
{
    java.lang.String output;
    static HelloWorld helloObj;

    public void <init>()
    {
        HelloWorld r0;

  
      r0 := @this: HelloWorld;
        
specialinvoke r0.<java.lang.Object: void <init>()>();
        
r0.<HelloWorld: java.lang.String output> = "";
        
r0.<HelloWorld: java.lang.String output> = "Hello world";
        
return;
    
}

    public java.lang.String printMessage()
    {
        HelloWorld r0;
        
java.lang.String $r1;

        
r0 := @this: HelloWorld;
        
$r1 = r0.<HelloWorld: java.lang.String output>;
        
return $r1;
    
}

    public static void main(java.lang.String[])
    {
    java.lang.String[] r0;
        
HelloWorld $r1, $r3;
        
java.io.PrintStream $r2;
        
java.lang.String $r4;

        r0 := @parameter0: java.lang.String[];
        
$r1 = new HelloWorld;
        
specialinvoke $r1.<HelloWorld: void <init>()>();
        
<HelloWorld: HelloWorld helloObj> = $r1;
        
$r2 = <java.lang.System: java.io.PrintStream out>;
        
$r3 = <HelloWorld: HelloWorld helloObj>;
        
$r4 = virtualinvoke $r3.<HelloWorld: java.lang.String printMessage()>();
       
virtualinvoke $r2.<java.io.PrintStream: void println(java.lang.String)>($r4);
        
return;
    
}
}