├── .classpath
├── .project
├── .settings
└── org.eclipse.jdt.core.prefs
├── AndroidManifest.xml
├── README.md
├── bin
├── AndroidManifest.xml
├── MyFirstApp.apk
├── classes.dex
├── classes
│ └── com
│ │ └── example
│ │ └── myfirstapp
│ │ ├── BuildConfig.class
│ │ ├── DisplayMessageActivity.class
│ │ ├── MainActivity.class
│ │ ├── R$attr.class
│ │ ├── R$dimen.class
│ │ ├── R$drawable.class
│ │ ├── R$id.class
│ │ ├── R$layout.class
│ │ ├── R$menu.class
│ │ ├── R$string.class
│ │ ├── R$style.class
│ │ └── R.class
├── dexedLibs
│ ├── android-support-v4-53a062800f063f991d48f983cd3fc14e.jar
│ ├── android-support-v4-737ccaac967eda36ea139aad137af2ea.jar
│ └── android-support-v4-c918fb20779bb2b9c47aaabf9bd7c738.jar
├── jarlist.cache
├── res
│ └── crunch
│ │ ├── drawable-hdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-mdpi
│ │ └── ic_launcher.png
│ │ ├── drawable-xhdpi
│ │ └── ic_launcher.png
│ │ └── drawable-xxhdpi
│ │ └── ic_launcher.png
└── resources.ap_
├── gen
└── com
│ └── example
│ └── myfirstapp
│ ├── BuildConfig.java
│ └── R.java
├── ic_launcher-web.png
├── libs
└── android-support-v4.jar
├── lint.xml
├── proguard-project.txt
├── project.properties
├── res
├── drawable-hdpi
│ └── ic_launcher.png
├── drawable-mdpi
│ └── ic_launcher.png
├── drawable-xhdpi
│ └── ic_launcher.png
├── drawable-xxhdpi
│ └── ic_launcher.png
├── layout
│ ├── activity_display_message.xml
│ └── activity_main.xml
├── menu
│ ├── display_message.xml
│ └── main.xml
├── values-sw600dp
│ └── dimens.xml
├── values-sw720dp-land
│ └── dimens.xml
├── values-v11
│ └── styles.xml
├── values-v14
│ └── styles.xml
└── values
│ ├── dimens.xml
│ ├── strings.xml
│ └── styles.xml
└── src
└── com
└── example
└── myfirstapp
├── DisplayMessageActivity.java
└── MainActivity.java
/.classpath:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | MyFirstApp
4 |
5 |
6 |
7 |
8 |
9 | com.android.ide.eclipse.adt.ResourceManagerBuilder
10 |
11 |
12 |
13 |
14 | com.android.ide.eclipse.adt.PreCompilerBuilder
15 |
16 |
17 |
18 |
19 | org.eclipse.jdt.core.javabuilder
20 |
21 |
22 |
23 |
24 | com.android.ide.eclipse.adt.ApkBuilder
25 |
26 |
27 |
28 |
29 |
30 | com.android.ide.eclipse.adt.AndroidNature
31 | org.eclipse.jdt.core.javanature
32 |
33 |
34 |
--------------------------------------------------------------------------------
/.settings/org.eclipse.jdt.core.prefs:
--------------------------------------------------------------------------------
1 | eclipse.preferences.version=1
2 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
3 | org.eclipse.jdt.core.compiler.compliance=1.6
4 | org.eclipse.jdt.core.compiler.source=1.6
5 |
--------------------------------------------------------------------------------
/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Behavior-Based-Malware-Detection-System-for-Android
2 | ===================================================
3 |
4 | This is an android app for malware detection based on anomaly using dynamic analysis.
5 | Capitalize on earlier approaches for dynamic analysis of application behavior as a means for detecting malware in the Android platform.
6 | The detector is embedded in a overall framework for collection of traces from an unlimited number of real users based on crowdsourcing. Our
7 | framework has been demonstrated by analyzing the data collected in the central server using two types of data sets:
8 | those from articial malware created for test purposes, and
9 | those from real malware found in the wild.
10 |
11 | for further description read the below link paper
12 | (http://www.ida.liu.se/labs/rtslab/publications/2011/spsm11-burguera.pdf)
13 |
14 |
15 |
16 |
17 | The implementation consists of two main programs: client and server.
18 |
19 | Working of client
20 | Client program is a daemon process that runs in background on Android platform. It's responsible for collecting system call data and communicating with server. It is designed to be lightweight with small code to conserve battery consumption on smartphones.
21 |
22 | **Steps followed by client:
23 |
24 | *System call tracing using strace
25 |
26 | Android at its core has a process they call the “Zygote”, which starts up at init. It gets its name from dictionary definition: "It is the initial cell formed when a new organism is produced". This process is a “Warmed-up” process, which means it’s a process that’s been initialized and has all the core libraries linked in.
27 | The only mission of Zygote is to launch application. This means that Zygote is the parent of all apps process. Whenever Zygote receives request to launch a new application, it forks a new process (replicates itself). Thereafter application code replaces Zygote and starts execution.
28 | Client requires to capture system call requested by all application. One way to do that is to attach strace to Zygote process. This way we can capture system call of all application process because Zygote is the parent of all other application.
29 | At this stage output of strace is stored in one file.
30 |
31 | *Parsing data according to application
32 |
33 | Strace will log system call data of process and all its child process and so on in one file. Following example shows strace output for multiple (parent child) application:
34 | [pid 28772] select(4, [3], NULL, NULL, NULL
35 | [pid 28779] clock_gettime(CLOCK_REALTIME, {1130322148, 939977000}) = 0
36 | [pid 28772] <... select resumed> ) = 1 (in [3])
37 |
38 | Each process is differentiated from other by the pid in the log.
39 | Using the pid, we can trace back to the application running the given process. Thus, we are able to obtain system call data for that application. In this stage, we collect system call data for each application (that we're interested) in separate file. Each file also contains additional information regarding the application. This additional information is used by the server to decode back the application.
40 |
41 | *Establish connection with server
42 |
43 | Once sufficient data has been collected and client has it networking turned on, client establish connection with server process to transfer data.
44 | Transfer of data can be scheduled to happen at specific intervals to prevent power consumption.
45 |
46 | *Transfer data to server
47 |
48 | In the next step, client sends the system call data to server. A particular format is setup, which helps server identifies which application does that system call data belongs to.
49 |
50 | *React to the threat
51 |
52 | Server will in turn process on the data, identify whether the application is benign or malicious and return the result back to client. Client will then warn the user about threat and/or prompt user to uninstall/remove the malicious application.
53 |
54 | **Working of server
55 |
56 | Server process is responsible for detecting malicious application based on the data send by the client and informing client of the results. Main design goal is performance and concurrency (ability to handle multiple request). Thus server process is implemented in C language for faster execution.
57 |
58 | *Listen for client request
59 |
60 | Client initiates connection with server. Server can handle multiple clients at same time.
61 |
62 | *Process client request
63 |
64 | Server, then, forks a new process to handle the incoming client request. Transfer of system call data from client takes place.
65 |
66 | *Identify application
67 |
68 | Next, server identifies the application using the additional information stored along with system call data. If application has not been stored in server's application database, a new entry is created.
69 |
70 | *Parse system call data to vector form
71 |
72 | System call data is then converted in to vector form, which essentially is an array of numbers, each representing the frequency of particular system call, in predefined order of system calls. A simple bash based shell script is used for parsing. This vector is the passed to subsequent malware detection analysis.
73 |
74 | *Clustering
75 |
76 | The vector obtained from previous step is used as an input to simple clustering algorithm (K-means clustering algorithm). This clustering algorithm is then able to cluster this application data to either benign or malicious. The exact steps taken are:
77 | i. Obtain the centroid values from the database
78 | ii. Find the cluster which is closest to the input vector
79 | iii. Calculate the new centroid obtained after insertion and store the result to the database
80 | iv. Save the cluster number of the input vector for future use.
81 | v. Find whether application is malicious or not based on the comparison of count of data vectors in current cluster number and the alternate cluster. It is assumed that the cluster with more vectors is not malicious.
82 |
83 | *Deliver the results to the client
84 |
85 | The result of the clustering algorithm is then communicated to the client. Appropriate action is then taken by the client.
86 |
--------------------------------------------------------------------------------
/bin/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
22 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
35 |
38 |
39 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/bin/MyFirstApp.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/MyFirstApp.apk
--------------------------------------------------------------------------------
/bin/classes.dex:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes.dex
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/BuildConfig.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/BuildConfig.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/DisplayMessageActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/DisplayMessageActivity.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/MainActivity.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/MainActivity.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$attr.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$attr.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$dimen.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$dimen.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$drawable.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$drawable.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$id.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$id.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$layout.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$layout.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$menu.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$menu.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$string.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$string.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R$style.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R$style.class
--------------------------------------------------------------------------------
/bin/classes/com/example/myfirstapp/R.class:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/classes/com/example/myfirstapp/R.class
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-53a062800f063f991d48f983cd3fc14e.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/dexedLibs/android-support-v4-53a062800f063f991d48f983cd3fc14e.jar
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-737ccaac967eda36ea139aad137af2ea.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/dexedLibs/android-support-v4-737ccaac967eda36ea139aad137af2ea.jar
--------------------------------------------------------------------------------
/bin/dexedLibs/android-support-v4-c918fb20779bb2b9c47aaabf9bd7c738.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/dexedLibs/android-support-v4-c918fb20779bb2b9c47aaabf9bd7c738.jar
--------------------------------------------------------------------------------
/bin/jarlist.cache:
--------------------------------------------------------------------------------
1 | # cache for current jar dependency. DO NOT EDIT.
2 | # format is
3 | # Encoding is UTF-8
4 |
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/res/crunch/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/res/crunch/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/res/crunch/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/res/crunch/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/res/crunch/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/bin/resources.ap_:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/bin/resources.ap_
--------------------------------------------------------------------------------
/gen/com/example/myfirstapp/BuildConfig.java:
--------------------------------------------------------------------------------
1 | /** Automatically generated file. DO NOT MODIFY */
2 | package com.example.myfirstapp;
3 |
4 | public final class BuildConfig {
5 | public final static boolean DEBUG = true;
6 | }
--------------------------------------------------------------------------------
/gen/com/example/myfirstapp/R.java:
--------------------------------------------------------------------------------
1 | /* AUTO-GENERATED FILE. DO NOT MODIFY.
2 | *
3 | * This class was automatically generated by the
4 | * aapt tool from the resource data it found. It
5 | * should not be modified by hand.
6 | */
7 |
8 | package com.example.myfirstapp;
9 |
10 | public final class R {
11 | public static final class attr {
12 | }
13 | public static final class dimen {
14 | /** Default screen margins, per the Android Design guidelines.
15 |
16 | Customize dimensions originally defined in res/values/dimens.xml (such as
17 | screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here.
18 |
19 | */
20 | public static final int activity_horizontal_margin=0x7f040000;
21 | public static final int activity_vertical_margin=0x7f040001;
22 | }
23 | public static final class drawable {
24 | public static final int ic_launcher=0x7f020000;
25 | }
26 | public static final class id {
27 | public static final int action_settings=0x7f080001;
28 | public static final int edit_message=0x7f080000;
29 | }
30 | public static final class layout {
31 | public static final int activity_display_message=0x7f030000;
32 | public static final int activity_main=0x7f030001;
33 | }
34 | public static final class menu {
35 | public static final int display_message=0x7f070000;
36 | public static final int main=0x7f070001;
37 | }
38 | public static final class string {
39 | public static final int action_settings=0x7f050001;
40 | public static final int app_name=0x7f050000;
41 | public static final int button_send=0x7f050003;
42 | public static final int edit_message=0x7f050002;
43 | public static final int hello_world=0x7f050006;
44 | public static final int title_activity_display_message=0x7f050005;
45 | public static final int title_activity_main=0x7f050004;
46 | }
47 | public static final class style {
48 | /**
49 | Base application theme, dependent on API level. This theme is replaced
50 | by AppBaseTheme from res/values-vXX/styles.xml on newer devices.
51 |
52 |
53 | Theme customizations available in newer API levels can go in
54 | res/values-vXX/styles.xml, while customizations related to
55 | backward-compatibility can go here.
56 |
57 |
58 | Base application theme for API 11+. This theme completely replaces
59 | AppBaseTheme from res/values/styles.xml on API 11+ devices.
60 |
61 | API 11 theme customizations can go here.
62 |
63 | Base application theme for API 14+. This theme completely replaces
64 | AppBaseTheme from BOTH res/values/styles.xml and
65 | res/values-v11/styles.xml on API 14+ devices.
66 |
67 | API 14 theme customizations can go here.
68 | */
69 | public static final int AppBaseTheme=0x7f060000;
70 | /** Application theme.
71 | All customizations that are NOT specific to a particular API-level can go here.
72 | */
73 | public static final int AppTheme=0x7f060001;
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/ic_launcher-web.png
--------------------------------------------------------------------------------
/libs/android-support-v4.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/libs/android-support-v4.jar
--------------------------------------------------------------------------------
/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/proguard-project.txt:
--------------------------------------------------------------------------------
1 | # To enable ProGuard in your project, edit project.properties
2 | # to define the proguard.config property as described in that file.
3 | #
4 | # Add project specific ProGuard rules here.
5 | # By default, the flags in this file are appended to flags specified
6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt
7 | # You can edit the include path and order by changing the ProGuard
8 | # include property in project.properties.
9 | #
10 | # For more details, see
11 | # http://developer.android.com/guide/developing/tools/proguard.html
12 |
13 | # Add any project specific keep options here:
14 |
15 | # If your project uses WebView with JS, uncomment the following
16 | # and specify the fully qualified class name to the JavaScript interface
17 | # class:
18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
19 | # public *;
20 | #}
21 |
--------------------------------------------------------------------------------
/project.properties:
--------------------------------------------------------------------------------
1 | # This file is automatically generated by Android Tools.
2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED!
3 | #
4 | # This file must be checked in Version Control Systems.
5 | #
6 | # To customize properties used by the Ant build system edit
7 | # "ant.properties", and override values to adapt the script to your
8 | # project structure.
9 | #
10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
11 | #proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
12 |
13 | # Project target.
14 | target=android-19
15 |
--------------------------------------------------------------------------------
/res/drawable-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/res/drawable-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/res/drawable-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/res/drawable-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/drawable-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/kapilkchaurasia/Behavior-Based-Malware-Detection-System-for-Android/3b097ae032ba7a703c0b0f56f9322c1b9c6c261c/res/drawable-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/res/layout/activity_display_message.xml:
--------------------------------------------------------------------------------
1 |
10 |
11 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
18 |
23 |
24 |
--------------------------------------------------------------------------------
/res/menu/display_message.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/res/values-sw600dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/res/values-sw720dp-land/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | 128dp
8 |
9 |
10 |
--------------------------------------------------------------------------------
/res/values-v11/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/res/values-v14/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | 16dp
5 | 16dp
6 |
7 |
8 |
--------------------------------------------------------------------------------
/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | My First App
5 | Settings
6 | Enter a message
7 | Send
8 | MainActivity
9 | My Message
10 | Hello world!
11 |
12 |
13 |
--------------------------------------------------------------------------------
/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
14 |
15 |
16 |
19 |
20 |
21 |
--------------------------------------------------------------------------------
/src/com/example/myfirstapp/DisplayMessageActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myfirstapp;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.Intent;
6 | import android.os.Build;
7 | import android.os.Bundle;
8 | import android.support.v4.app.NavUtils;
9 | import android.view.MenuItem;
10 | import android.widget.TextView;
11 |
12 | public class DisplayMessageActivity extends Activity {
13 |
14 | @Override
15 | protected void onCreate(Bundle savedInstanceState) {
16 | super.onCreate(savedInstanceState);
17 |
18 | //Get the message from the intent
19 | Intent intent = getIntent();
20 | String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
21 |
22 | //Create the text view
23 | TextView textView = new TextView(this);
24 | textView.setTextSize(40);
25 | textView.setText(message);
26 |
27 | //Set the text view as the activity layout
28 | setContentView(textView);
29 | }
30 |
31 | /**
32 | * Set up the {@link android.app.ActionBar}, if the API is available.
33 | */
34 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
35 | private void setupActionBar() {
36 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
37 | getActionBar().setDisplayHomeAsUpEnabled(true);
38 | }
39 | }
40 |
41 | @Override
42 | public boolean onOptionsItemSelected(MenuItem item) {
43 | switch (item.getItemId()) {
44 | case android.R.id.home:
45 | // This ID represents the Home or Up button. In the case of this
46 | // activity, the Up button is shown. Use NavUtils to allow users
47 | // to navigate up one level in the application structure. For
48 | // more details, see the Navigation pattern on Android Design:
49 | //
50 | // http://developer.android.com/design/patterns/navigation.html#up-vs-back
51 | //
52 | NavUtils.navigateUpFromSameTask(this);
53 | return true;
54 | }
55 | return super.onOptionsItemSelected(item);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/src/com/example/myfirstapp/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.example.myfirstapp;
2 |
3 | import java.io.BufferedInputStream;
4 | import java.io.BufferedReader;
5 | import java.io.File;
6 | import java.io.FileInputStream;
7 | import java.io.IOException;
8 | import java.io.InputStream;
9 | import java.io.InputStreamReader;
10 | import java.io.OutputStream;
11 | import java.io.PrintWriter;
12 | import java.net.Socket;
13 | import java.net.UnknownHostException;
14 | import java.util.List;
15 |
16 | import android.app.Activity;
17 | import android.app.ActivityManager;
18 | import android.content.Context;
19 | import android.content.Intent;
20 | import android.os.Bundle;
21 | import android.os.StrictMode;
22 | import android.view.Menu;
23 | import android.view.View;
24 | import android.widget.EditText;
25 |
26 | public class MainActivity extends Activity {
27 | public final static String EXTRA_MESSAGE = "com.example.myfirstapp.MESSAGE";
28 | private Socket client;
29 | private FileInputStream fileInputStream;
30 | private BufferedInputStream bufferedInputStream;
31 | private OutputStream outputStream;
32 |
33 | @Override
34 | protected void onCreate(Bundle savedInstanceState) {
35 | super.onCreate(savedInstanceState);
36 |
37 | setContentView(R.layout.activity_main);
38 |
39 | //StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
40 | //StrictMode.setThreadPolicy(policy);
41 |
42 | }
43 |
44 |
45 | @Override
46 | public boolean onCreateOptionsMenu(Menu menu) {
47 | // Inflate the menu; this adds items to the action bar if it is present.
48 | getMenuInflater().inflate(R.menu.main, menu);
49 | return true;
50 | }
51 | /** Called when the user clicks the Send button
52 | * @throws Exception */
53 | public void sendMessage(View view) throws Exception {
54 | String inputs="genuine";
55 | Intent intent = new Intent(this, DisplayMessageActivity.class);
56 | EditText editText = (EditText) findViewById(R.id.edit_message);
57 | String message = editText.getText().toString();
58 |
59 | ActivityManager am = (ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE);
60 | List pidsTask = am.getRunningAppProcesses();
61 | List pids = am.getRunningAppProcesses();
62 | int pid = 0;
63 |
64 | /* for(int i = 0; i < pidsTask.size(); i++){
65 | message+=pidsTask.get(i).processName+"\n"; */
66 | /* for (int i = 0; i < pidsTask.size(); i++) {
67 | ActivityManager.RunningAppProcessInfo info = pidsTask.get(i);
68 | if((pidsTask.get(i).processName).contentEquals("com.example.android.fragments")) {
69 | pid = info.pid;
70 | }
71 | }
72 | message = "" + pid;
73 |
74 | ProcessBuilder pb = new ProcessBuilder();
75 | pb.command("strace", "-p 21311");
76 | Process p = pb.start();
77 |
78 | InputStream inputStream = p.getErrorStream();
79 | int c;
80 | while ((c = inputStream.read()) != -1) {
81 | message += (char) c;
82 | }
83 |
84 | //message = "" + p;
85 |
86 | //Runtime.getRuntime().exec("strace -p 381 -o /mnt/sdcard/proc_system");
87 | //int len = 0;
88 | //while (len == 0) {
89 | // Runtime.getRuntime().exec("strace -p" + pid + "-o /mnt/sdcard/Straceout_" + pid);
90 | // File f = new File("/mnt/sdcard/Straceout_" + pid);
91 | // len = (int) f.length();
92 | //}
93 | */
94 | for(int i = 0; i < pids.size(); i++)
95 | {
96 | ActivityManager.RunningAppProcessInfo info = pids.get(i);
97 | if((pids.get(i).processName).contentEquals("com.example.android.fragments"))
98 | {
99 | // message = "" + info.pid;
100 | pid = info.pid;
101 | //message = info.processName;
102 | String cmd="strace -p "+pid+" -o /mnt/sdcard/traceFileSD_"+pid+".txt";
103 | Runtime.getRuntime().exec(cmd);
104 |
105 | }
106 |
107 | }
108 |
109 | StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
110 |
111 | StrictMode.setThreadPolicy(policy);
112 | try {
113 | Socket s = new Socket("10.0.2.2", 50001);
114 |
115 | File myFile = new File("/mnt/sdcard/traceFileSD_"+pid+".txt");
116 | FileInputStream fIn = new FileInputStream(myFile);
117 | BufferedReader myReader = new BufferedReader(new InputStreamReader(fIn));
118 |
119 | String aDataRow = "";
120 | String aBuffer = "";
121 |
122 | while ((aDataRow = myReader.readLine()) != null) {
123 | aBuffer += aDataRow + "\n";
124 | }
125 |
126 | if (s.isConnected() == true) {
127 | message = "connected";
128 | } else message = "not connected";
129 | OutputStream out = s.getOutputStream();
130 | PrintWriter output = new PrintWriter(out);
131 | output.println("hello");
132 | output.flush();
133 |
134 | BufferedReader input = new BufferedReader(new InputStreamReader(s.getInputStream()));
135 |
136 | message="Application :com.example.fragments is ";
137 | message += inputs;
138 | s.close();
139 | myReader.close();
140 | } catch (UnknownHostException e) {
141 | e.printStackTrace();
142 | } catch (IOException e) {
143 | e.printStackTrace();
144 | }
145 |
146 |
147 | //mo networking
148 |
149 | /*File myFile = new File ("/mnt/sdcard/traceFileSD_3883");
150 | FileInputStream fis = new FileInputStream(myFile);
151 | Socket socket = null;
152 | OutputStream os = socket.getOutputStream();
153 | int filesize = (int) myFile.length();
154 |
155 | byte [] buffer = new byte [filesize];
156 | int bytesRead =0;
157 | while ((bytesRead = fis.read(buffer)) > 0) {
158 | os.write(buffer, 0, bytesRead);
159 | //Log display exact the file size
160 | System.out.println("SO sendFile" + bytesRead);
161 | }
162 | os.flush();
163 | os.close();
164 | fis.close();
165 | Log.d("Client", "Client sent message");
166 | socket.close();
167 | */
168 |
169 |
170 |
171 | // int processID= android.os.Process.myPid();
172 | // String cmd="strace -p "+processID+" -o /mnt/sdcard/traceFileSD_"+processID+".txt";
173 | // Runtime.getRuntime().exec(cmd);
174 |
175 |
176 | /* String sFileName="ghh";
177 | String sBody="htjhj";
178 | try
179 | {
180 | File root = new File(Environment.getExternalStorageDirectory(), "Notes");
181 | if (!root.exists()) {
182 | root.mkdirs();
183 | }
184 | File gpxfile = new File(root, sFileName);
185 | FileWriter writer = new FileWriter(gpxfile);
186 | writer.append(sBody);
187 | writer.flush();
188 | writer.close();
189 | Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
190 | }
191 | catch(IOException e)
192 | {
193 | e.printStackTrace();
194 | // importError = e.getMessage();
195 | // iError();
196 | } */
197 |
198 | //ActivityManager m = (ActivityManager)this.getSystemService(ACTIVITY_SERVICE);
199 | //Get some number of running tasks and grab the first one. getRunningTasks returns newest to oldest
200 | //RunningTaskInfo task = m.getRunningTasks(1).get(0);
201 | // ArrayList list=new ArrayList();
202 |
203 |
204 | //Build output
205 | //String output = "the last application you've executed is '"+task.id+"' and the PID is '"+task.baseActivity.toShortString()+"'";
206 | //intent.putExtra(EXTRA_MESSAGE, output);
207 | intent.putExtra(EXTRA_MESSAGE, message);
208 | startActivity(intent);
209 | }
210 | }
211 |
212 |
213 |
214 |
--------------------------------------------------------------------------------