Translate

Showing posts with label Android Apps. Show all posts
Showing posts with label Android Apps. Show all posts

Wednesday

Program Analysis of Google Chrome

Program Analysis of Google Chrome


Tested Android Application
The android Chrome application is taken as demonstration application originally developed by the Goolgle Team on Android platform. It features 4552 classes, 14184 methods and was written in Java code. The first method used is conversion of java codes in to soot’s intermediate representation Jimple files for each 4552 java classes and graphical representation for each 14184 methods which further converted in to control flow graph and call graph based on nodes and edges inside the method. Secondly, the generated Dalvik bytecode contains Dalvik instructions.
From the Dalvik bytecode of the Chrome application I generate Jimple code in one second (duration for the Dalvik to Jimple conversion only). Then I ask Soot to generate Java bytecode from the Jimple representation. I convert the Java bytecode back to Dalvik, repackage an Android application and launch it on the Android emulator. The application runs smoothly and the app is working.

Static Analysis on Chrome
I use Soot to generate a call graph of the Chrome application, portion of the control flow graph represented in Figure 2.


Control Flow analysis Graph (Call Graph) for  org.chromium.chrome.browser.preferences.website.WebsitemergePermissionInfoForTopLevelOrigin(org.chromium.chrome.browser.preferences. website.WebsiteAddress,java.util.List) Method Extracted from the Generated Jimple Representation. .36 seconds (duration from the launch time of Soot until Soot has finished). I perform this to check that the generated call graph and CFG correspond to the original code meaning that the conversion from Dalvik to Jimple is correct for this code.
I have successfully tested Soot as IR Jimple conversion to and another tool Dalvik bytecode to an Android application.

Figure 2: Partial Call graph for (chrome.browser.preferences.website) method
Process Analysis
Firstly, I used soot for conversion of Chrome.apk i.e. downloads from google play store to Soot’s Intermediate Representation Jimple and Soot’s CFG Viewer to produce graphical representation of all the methods from classes as dot files based on existing works of Droiddel[7].

Second Method, since there no existing tool directly converts Dalvik bytecode to Jimple. I either found tools to convert Dalvik bytecode to Java bytecode or tools to disassemble and/or assemble assemble Dalvik bytecode using an intermediate representation [4].
Dalvik to Java Bytecode Converter Ded is a Dalvik bytecode to Java bytecode converter. Once the Java bytecode is generated, Soot is used to optimize the code. Dex2jar also generates Java bytecode from Dalvik bytecode but no not use any external tool to optimize the resulting Java bytecode [5]. Undx is also a Dalvik to Java bytecode converter but seems to be unavailable. I on the other hand do not directly generate Java bytecode but Jimple code.
From there, since the Jimple code is within Soot, I can generate Java bytecode as well. Dalvik Assembler/Disassembler Smali or Androguard can be used to reverse engineer Dalvik bytecode. They use their own representation of the Dalvik bytecode: they cannot leverage existing analysis tools. This tool, use Soot’s internal representation which allows existing tools to analyze/transform the Dalvik bytecode [7].


Conclusion
Here we introduced a new analysis that integrates and enhances existing Android app static analyses. I have presented the phenomena of static analysis of android apps based on the control flow graphs by using soot. I successfully use conversion of an android app (java byte code) into dalvik bytecode (android app). And generate the control flow graphs from java methods and perform the static analysis.

This can further be used for static analysis of any android apps or java programs and computation of nodes and edges for the analysis of the complex algorithm. Finally, it is also can be used on static fields, implicit flow, distinguish different receive intents as well as other data channels.

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



How to Convert any Android apk file into Soot's Intermediate Representation Jimple

How to Convert any Android apk file into Soot's Intermediate Representation Jimple

Lets look at command to convert any android apk file into Jimple. 
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 -f jimple -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 -f jimple -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

-f jimple or -f J is responsible for converting all the classes from apk into jimple files
-process-dir shows the path for processing directory or apk located directory




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;
    
}
}

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.


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