Translate

Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Tuesday

Call Graph Using Soot Of Android app (.apk)


Android applications do not have a single main method but multiple entry points (in xml files, in the code etc), Soot cannot directly generate a call graph of the whole application.

What we need to do it in "FlowDroid" is to generate a "dummy main" method which collects all the entry points of an application "components".


For more details about FlowDroid, look at the project here: https://github.com/secure-software-engineering/soot-infoflow-android/

The dummy main can be created like: 
 > method "private void createMainMethod()"
> SetupApplication.java.

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.


Soot Installation Guide - Command Line Tool

Soot Installation Guide

Download

Before you install soot your machine must have properly installed java. To install soot as command line tool you can download latest version of Jar file (Soot.Jar) or nightly build version(Soot-trunk.jar) from here. Latest version includes all other jar files so you don't need to download any other jars.

SET CLASSPATH

Before you are able to use soot you must set the classpath to various java jars and soot jar. To set jars on classpath for Windows users go to: 

Control Panel -> System -> Advance System Setting 
-> Environment Variables -> CLASSPATH


Find your Java installation folder Normally(C:\Program Files\Java\) and set following jars on classpath :

C:\Program Files\Java\jre7\lib\rt.jar;

C:\Program Files\Java\jdk1.8.0_25\jre\lib\jce.jar;

C:\Program Files\Java\jdk1.8.0_25\lib\tools.jar;

C:\Program Files\Java\jdk1.8.0_25\lib\dt.jar;

C:\soot\soot-2.5.0.jar (This contains your Soot jar file Directory).

soot jar file directory is not necessary, you can use soot jar file directly to your command line.


Static Analysis of Android Applications Using Soot

Soot

Soot has two fundamental uses; it can be used as a stand-alone command line tool or as a Java compiler framework. As a command line tool, Soot can:

1. Disassemble class-files
2. Assemble class-files
3. Optimize class-files
4. Android Apps Analysis
5. Davik bytecode