Translate

Showing posts with label analysis. Show all posts
Showing posts with label analysis. Show all posts

Wednesday

Static Analysis of Android Apps Using Soot

Static Analysis of Android Apps Using Soot

Related Work
There are some previous works were done on this fields but all are yet to be conclusive to fully analysis android application. Some of the research that follows parital analysis works are:
Flow Droid: It is a context-sensitive, flow-based, field-based, object-sensitive, and lifecycle aware static taint analysis tool for java as well as android programming. Unlike many other static-analysis approaches for android it aims for an analysis with very high recall and accuracy of android programs  To achieve the main goal it accomplished two main challenges as increase in precision and builds an analysis that is context-, flow-, field- and object-sensitive; to increase recall It create a complete model of program lifecycle. 

However, the analysis [10] uses the application instrumentation tools such as Soot and Heros. The Flow Droid uses a very precise call graph which helps us to ensure flow-sensitive and context-sensitivity. Its IFDS-based flow functions guarantee field and object sensitivity. As a result of the highly precise and efficient alias, the procedure for searching is crucial for contextsensitivity in conjunction with field-sensitivity.
Inter-procedural Analysis: While analyzing the resemblance of the efficiency and effectiveness for the inter-procedural class analysis based on the Cartesian product algorithm and   profileguided class which are predicted for the optimizing self-program[8].
But it is the fact that it has very little difference in term of the outcome or performance among the three configurations optimization i.e. using only profile-guided class prediction, using only inter-procedural class analysis, and using both techniques [8]. 
Iterative algorithms: As of now, the main iterative algorithm that has really been executed is Plevyak's iterative algorithms [9]. Various papers proposing new call graph generating calculations have exactly surveyed the adequacy of their calculation by executing them in an improving compiler and utilizing the subsequent control flow graph to perform at least one or more inter-procedural analyses

Soot
Soot [1] was created at McGill University as a java compiler, further developed and become an android static analysis and transformation tool. Soot can be used for multiple tasks i.e. code analyze, transformation of java programs or android apps, instrumentation of an android apps, check that certain properties hold or guarantee correctness of programs.
Multiple tools based on Soot have been developed to perform transformations such as translation of Java to C, instrumentation of android apps or java programs, obfuscator for Java, software watermarking, Soot accepts Java source code, Java bytecode and Jimple source code as input files[1].
Any input format is converted into Soot’s internal representation: Jimple, Baf Grimph and Shimple. Java SIMPLE, is a stack-less, three address representation which features only 15 instructions. Any method code can be viewed as a graph of Jimple statements associated with a list of Jimple local variables.

Dalivk bytecode
Android uses Dalvik Virtual Machine [2, 3] as a main component which is a kind of Java Virtual Machine specially designed and optimized for Android applications. The Dalvik VM makes uses features like memory management and multi-threading, which is intrinsic in the Java language from Linux core system.
The Dalvik VM enables every Android application to run in its own process, with its own instance of the Dalvik virtual machine. Android application developers write Android applications using standard Java programming language with the set of core libraries, which enabled by the Android runtime.

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.


Monday

Graphviz - Graph Visualization Software

Installation 

For installation, download latest version of "Graphviz"  from here. You can either download executable file directly and install or zip file and extract zip and put on command line directory.

To use any executable extension like dot from Graphviz you need to set the PATH after installation. For windows

Control panel -> System-> Advance System Setting -> Environment Variables -> PATH

Normally, file will install in Graphviz directory inside program files so path will looks like :


PATH   ->   C:\Program Files\Graphviz2.38\bin\


To test the installation type following from command line :

> dot -help

If you haven't the set path yet go to graphviz bin directory from command line and type following :

> dot -help

Friday

How to Convert any Android apk file into dalvik bytecode using soot

How to Convert any Android apk file into dalvik bytecode using soot

Lets look at command to convert any android apk file into Dalvik. 
For conversion, you need to:

> Download any .apk file
> Download android sdk from android developer site or download android jars
> Download Soot's nightly build version from Soot- Github


Before applied command, you need to know right path for android sdk -platforms directory, .apk file located directory and nightly build version of soot at right directory

Set CLASSPATH of Soot.jar or go to the directory that contains Soot.jar file then type following Command:

> java -Xmx2g -jar soot-trunk.jar soot.Main -w -allow-phantom-refs       -android-jars "D:\sdk\platform" -src-prec apk -output-format dex         -process-dir "C:\apkpath\example.apk"

If you have already set CLASSPATH for jar then type following

>java -Xmx2g soot.Main -w -allow-phantom-refs -android-jars "D:\sdk\platform" -src-prec apk -output-format dex -process-dir "C:\apkpath\example.apk"


Details: -Xmx2g it represents memory of 2GB which is normally sufficient for any apk process.

-jar can be replaced by -cp which means CLASSPATH or it represent command prompt's current directory.

-W stands for writing

-allow-phantom-refs creates phantom classes for missing or unprocessed classes

-android-jars leads to path for android sdk or jars to process apks

-src-prec represents the file format you are trying to process

-output-format dex is responsible for converting all the classes from apk into dex format
 
-process-dir shows the path for processing directory or apk located directory



Thursday

Testing Your Soot Installation

Testing Your Soot Installation

To test your soot installation as command line tools do following:
Open command Prompt and type following if you already set Soot's jar class-path :

Java soot.Main -version

If you haven't set classpath yet go to Soot jar located directory from command and type following

Java -cp soot-2.5.0.jar soot.Main -version

it will show following:



For help type --help instead of -version and it will show all the soot related commands for your help.






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

PROGRAM ANALYSIS OF SMART PHONE APPS

PROGRAM ANALYSIS OF SMART PHONE APPS

(A research based on program analysis of smart phone applications)


You can find complete tutorials

BY; CHALISE BIRENDRA
Abstract

Here, I am going to present the static analysis of an android app (Google Chrome) with the help of control flow graphs(CFGs) generated by using java bytecode analysis tool soot. For, control flow graphs, Soot converts the android application into its intermediate format(.jimple) and dot file of all methods which is further converted into control flow graphs through graph generated software i.e. Graphviz, before analyzing statically.

Additionally, the graphical representation of an app is created in the form of control flow graphs which is created for all possible java methods of the android app, and implemented to do static analysis of the app. I also generate and calculate the numbers of all java methods as CFG and classes as intermediate representation i.e.jimple.


Finally, I will introduce a new analysis that integrates and enhances existing Android app static analyses and successfully tests the static analysis of given android app by calculating the time span for extracting the methods from an app, number of all reachable classes and methods for the purpose of the CFG static analysis. 

Introduction
Here I am using Soot[1] to convert Android apk to Intermediate Representation mostly as Jimple (can be use baf, Shimple, Grimph etc) and produce Jimple files of each class that belongs to apk graphical representation of each method as dot file which further will generate Control flow graph for static analysis of android apk based on the process of java bytecode [6] (see in figure 1).







Figure 1: Java Bytecode


Moreover, I am using another technique to get similar results for static analysis with soot as Dalvik bytecode to Jimple. As Jimple is Soot’s main internal representation of code, the Dalvik bytecode can be manipulated with any Jimple based tool, for instance for performing point-to or flow analysis.

 Finally, I am able to convert any .java, .class, .apk and .jar files to its all intermediate representation jimple, baf, simple, grimph etc; Create Control Flow Graph, assemble/dissemble, .dex , .apk or delvik bytecode[1,2] which further helps to perform static analysis of all Java or Android files and apps for various security purpose as well[3].