Translate

Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Tuesday

Converting Dot files into Control Flow Graphs using GraphViz

Generate Control Flow Graph Using Graphviz

To convert android apk into dot files and do analysis by using soot click here. 

To generate control flow graph using graphviz, you need dot files which is generated from all methods of android apks. you can find them on sootOutput directory, now you need to go to command line and type following commands if you have already set graph viz path. 

To convert into pdf:

> dot Tpdf -o Example.pdf Example.dot

To convert into png:

> dot Tpng -o Example.png Example.dot

Note: if you haven't set path you need to set path (to know how to set path see installation post) or go to bin folder of graph viz installation folder and find dot file from command line and type above commands.

commands:

>dot : executable dot file (also MS word old file format for graph)

> -Tpdf, -Tpng: converting file format

> -o: Optimization

> Example.pdf, .png: Name of Control flow graph you wanna give after conversion.

>Example.dot : Name of dot file you wanna convert


Note: Graphviz not only use dot file format and executable files you can convert various different files into control flow graph. This post is on the context of program analysis of smart phone apps i.e. android apps using Soot as analysis tool.


Thursday

Converting a java Class file to Soot's Intermediate Representation Jimple.

Converting a java Class file to Soot's Intermediate Representation Jimple.

Lets look at example to convert java files to Jimple. Here, I am using HelloWorld. java and convert it to class by using javac and Now i am converting HelloWorld.Class to Jimple file.

HelloWorld.Java Contains:

public class HelloWorld{
String output="";
static HelloWorld helloObj;
public HelloWorld(){
output ="Hello world";
}
public String printMessage(){
return output;
}
public static void main(String[] args)
{
helloObj = new HelloWorld();
System.out.println(helloObj.printMessage());
}
} 

Before try to convert into jimple file make sure the class file (HelloWorld.Class) is in the same directory as command line or you set the class-path properly.

Now, to convert class file to Jimple type following on your command line:

>Java soot.Main -f J HelloWorld

(J can be replaced by jimple)

>Java soot.Main -f jimple HelloWorld

(if your classpath is not set)
>Java -cp soot-2.5.0.jar soot.Main -f -J HelloWorld

If you got errors Like could not load class file, pool error at Line 31 etc.
 >Java -cp soot-2.5.0.jar soot.Main -f J -allow-phantom-refs HelloWorld

 -allow-phantom-refs : This option will generate phantom class of error codes and command. 
-f : represents the format for output 
-J: represents the jimple format
HelloWorld: Java class file
-cp: Classpath

Normally, in command works as: JAVA [JAVA OPTIONS]  SOOT[SOOT OPTIONS]

For result, go to soot directory where jar files are located, here soot automatically creates sootOutput directory and you can find HelloWorld.jimple file.