├── app
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── styles.xml
│ │ │ └── dimens.xml
│ │ ├── drawable-hdpi
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-mdpi
│ │ │ └── ic_stat_kd.png
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_kd.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_kd.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_kd.png
│ │ ├── drawable-hdpi-v9
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-mdpi-v9
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-xhdpi
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-xxhdpi
│ │ │ └── ic_stat_kd.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_kd.png
│ │ ├── drawable-hdpi-v11
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-mdpi-v11
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-xhdpi-v11
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-xhdpi-v9
│ │ │ └── ic_stat_kd.png
│ │ ├── drawable-xxhdpi-v9
│ │ │ └── ic_stat_kd.png
│ │ ├── mipmap-xxxhdpi
│ │ │ └── ic_launcher_kd.png
│ │ ├── drawable-xxhdpi-v11
│ │ │ └── ic_stat_kd.png
│ │ ├── values-w820dp
│ │ │ └── dimens.xml
│ │ └── layout
│ │ │ └── activity_main.xml
│ │ ├── ic_launcher_kd-web.png
│ │ ├── AndroidManifest.xml
│ │ └── java
│ │ └── com
│ │ └── pmbento
│ │ └── karmadetector
│ │ ├── MainActivity.java
│ │ └── WifiScannerService.java
├── build.gradle
└── proguard-rules.pro
├── settings.gradle
├── screenshot1.png
├── dist
└── karmadetector-v0.1.apk
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
├── gradlew
└── LICENSE
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/screenshot1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/screenshot1.png
--------------------------------------------------------------------------------
/dist/karmadetector-v0.1.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/dist/karmadetector-v0.1.apk
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | KarmaDetector
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/ic_launcher_kd-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/ic_launcher_kd-web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-hdpi/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-mdpi/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi-v9/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-hdpi-v9/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi-v9/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-mdpi-v9/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-xhdpi/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-xxhdpi/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-hdpi-v11/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-hdpi-v11/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-mdpi-v11/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-mdpi-v11/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi-v11/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-xhdpi-v11/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xhdpi-v9/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-xhdpi-v9/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi-v9/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-xxhdpi-v9/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable-xxhdpi-v11/ic_stat_kd.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/pmbento/karmadetector/HEAD/app/src/main/res/drawable-xxhdpi-v11/ic_stat_kd.png
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Aug 23 23:03:05 WEST 2015
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.4-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values-w820dp/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 | 64dp
6 |
7 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | #*.apk
3 | *.ap_
4 |
5 | # Files for the Dalvik VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # Generated files
12 | bin/
13 | gen/
14 |
15 | # Gradle files
16 | .gradle/
17 | build/
18 | /*/build/
19 |
20 | # Local configuration file (sdk path, etc)
21 | local.properties
22 |
23 | # Proguard folder generated by Eclipse
24 | proguard/
25 |
26 | # Log Files
27 | *.log
28 |
29 | *.iml
30 | lint.xml
31 | ant.properties
32 | signing.properties
33 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 23
5 | buildToolsVersion "23.0.0"
6 | defaultConfig {
7 | applicationId 'com.pmbento.karmadetector'
8 | minSdkVersion 17
9 | targetSdkVersion 23
10 | versionName '0.1'
11 | }
12 | buildTypes {
13 | release {
14 | minifyEnabled true
15 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16 | }
17 | }
18 | productFlavors {
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(include: ['*.jar'], dir: 'libs')
24 | compile 'com.android.support:appcompat-v7:23.0.0'
25 | }
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # KarmaDetector
2 |
3 | KarmaDetector is an Android application that tries to detect [wireless Karma attacks](http://theta44.org/karma/).
4 |
5 | The current version is still in alpha stage, but should work.
6 |
7 |
8 |
9 | ## Instructions and Implementation Details
10 |
11 | Please visit the [Wiki](https://github.com/pmbento/karmadetector/wiki) section for more details.
12 |
13 | ## Contributing Funds
14 |
15 | Please feel free to contribute with your donations.
16 |
17 | [](https://www.coinbase.com/pmbento)
18 |
19 | ## License
20 |
21 | Copyright 2015 Patrício Batista
22 |
23 | Licensed under the GPLv3: http://www.gnu.org/licenses/gpl-3.0.html
24 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m
13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14 |
15 | # When configured, Gradle will run in incubating parallel mode.
16 | # This option should only be used with decoupled projects. More details, visit
17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18 | # org.gradle.parallel=true
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /Users/pmbento/Library/Android/sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | -assumenosideeffects class android.util.Log {
20 | public static boolean isLoggable(java.lang.String, int);
21 | public static int v(...);
22 | public static int i(...);
23 | public static int w(...);
24 | public static int d(...);
25 | public static int e(...);
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
15 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
17 |
18 |
25 |
26 |
32 |
33 |
34 |
35 |
41 |
42 |
50 |
51 |
61 |
62 |
63 |
64 |
71 |
72 |
78 |
79 |
85 |
86 |
87 |
94 |
95 |
106 |
107 |
108 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # For Cygwin, ensure paths are in UNIX format before anything is touched.
46 | if $cygwin ; then
47 | [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
48 | fi
49 |
50 | # Attempt to set APP_HOME
51 | # Resolve links: $0 may be a link
52 | PRG="$0"
53 | # Need this for relative symlinks.
54 | while [ -h "$PRG" ] ; do
55 | ls=`ls -ld "$PRG"`
56 | link=`expr "$ls" : '.*-> \(.*\)$'`
57 | if expr "$link" : '/.*' > /dev/null; then
58 | PRG="$link"
59 | else
60 | PRG=`dirname "$PRG"`"/$link"
61 | fi
62 | done
63 | SAVED="`pwd`"
64 | cd "`dirname \"$PRG\"`/" >&-
65 | APP_HOME="`pwd -P`"
66 | cd "$SAVED" >&-
67 |
68 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
69 |
70 | # Determine the Java command to use to start the JVM.
71 | if [ -n "$JAVA_HOME" ] ; then
72 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
73 | # IBM's JDK on AIX uses strange locations for the executables
74 | JAVACMD="$JAVA_HOME/jre/sh/java"
75 | else
76 | JAVACMD="$JAVA_HOME/bin/java"
77 | fi
78 | if [ ! -x "$JAVACMD" ] ; then
79 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
80 |
81 | Please set the JAVA_HOME variable in your environment to match the
82 | location of your Java installation."
83 | fi
84 | else
85 | JAVACMD="java"
86 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
87 |
88 | Please set the JAVA_HOME variable in your environment to match the
89 | location of your Java installation."
90 | fi
91 |
92 | # Increase the maximum file descriptors if we can.
93 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
94 | MAX_FD_LIMIT=`ulimit -H -n`
95 | if [ $? -eq 0 ] ; then
96 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
97 | MAX_FD="$MAX_FD_LIMIT"
98 | fi
99 | ulimit -n $MAX_FD
100 | if [ $? -ne 0 ] ; then
101 | warn "Could not set maximum file descriptor limit: $MAX_FD"
102 | fi
103 | else
104 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
105 | fi
106 | fi
107 |
108 | # For Darwin, add options to specify how the application appears in the dock
109 | if $darwin; then
110 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
111 | fi
112 |
113 | # For Cygwin, switch paths to Windows format before running java
114 | if $cygwin ; then
115 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
116 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
158 | function splitJvmOpts() {
159 | JVM_OPTS=("$@")
160 | }
161 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
162 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
163 |
164 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
165 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pmbento/karmadetector/MainActivity.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 Patrício Batista
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | package com.pmbento.karmadetector;
19 |
20 | import android.content.BroadcastReceiver;
21 | import android.content.Context;
22 | import android.content.Intent;
23 | import android.content.IntentFilter;
24 | import android.content.SharedPreferences;
25 | import android.content.pm.ActivityInfo;
26 | import android.os.Bundle;
27 | import android.support.v7.app.AppCompatActivity;
28 | import android.text.Editable;
29 | import android.text.TextWatcher;
30 | import android.text.method.ScrollingMovementMethod;
31 | import android.view.View;
32 | import android.widget.CompoundButton;
33 | import android.widget.EditText;
34 | import android.widget.Switch;
35 | import android.widget.TextView;
36 |
37 | import java.text.DateFormat;
38 | import java.util.Date;
39 |
40 | public class MainActivity extends AppCompatActivity {
41 | private final ResponseReceiver receiver = new ResponseReceiver();
42 | private SharedPreferences sharedPreferences;
43 | private SharedPreferences.Editor editor;
44 | private final CompoundButton.OnCheckedChangeListener autoStartSwitchWatcher = new CompoundButton.OnCheckedChangeListener() {
45 | @Override
46 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
47 | editor = sharedPreferences.edit();
48 | editor.putBoolean("autoStart", isChecked);
49 | editor.apply();
50 | }
51 | };
52 | private Intent wifiScannerIntent;
53 | private TextView textViewLog;
54 | private EditText scanFrequencyText;
55 | private int scanFrequency;
56 | private final TextWatcher frequencyScanTextWatcher = new TextWatcher() {
57 | @Override
58 | public void beforeTextChanged(CharSequence s, int start, int count, int after) {
59 |
60 | }
61 |
62 | @Override
63 | public void onTextChanged(CharSequence s, int start, int before, int count) {
64 |
65 | }
66 |
67 | public void afterTextChanged(Editable s) {
68 | try {
69 | scanFrequency = Integer.parseInt(s.toString());
70 | if (scanFrequency < 5)
71 | scanFrequency = 5;
72 | } catch (Exception e) {
73 | scanFrequency = 5;
74 | }
75 |
76 | editor = sharedPreferences.edit();
77 | editor.putInt("scanFrequency", scanFrequency);
78 | editor.apply();
79 | }
80 | };
81 | private Switch autoStartSwitch;
82 |
83 | @Override
84 | protected void onCreate(Bundle savedInstanceState) {
85 | setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
86 | super.onCreate(savedInstanceState);
87 | setContentView(R.layout.activity_main);
88 | textViewLog = (TextView) findViewById(R.id.textViewLog);
89 | wifiScannerIntent = new Intent(this, WifiScannerService.class);
90 | textViewLog.setMovementMethod(new ScrollingMovementMethod());
91 | sharedPreferences = getSharedPreferences("karmaDetectorPrefs", Context.MODE_PRIVATE);
92 | scanFrequencyText = (EditText) findViewById(R.id.scanFrequency);
93 | scanFrequencyText.addTextChangedListener(frequencyScanTextWatcher);
94 | autoStartSwitch = (Switch) findViewById(R.id.switchAutoStart);
95 | autoStartSwitch.setOnCheckedChangeListener(autoStartSwitchWatcher);
96 | loadPrefs();
97 | addToLog("App started.");
98 | }
99 |
100 | @Override
101 | protected void onDestroy() {
102 | stopService(wifiScannerIntent);
103 | unregisterReceiver(receiver);
104 | super.onDestroy();
105 | }
106 |
107 | @Override
108 | protected void onResume() {
109 | super.onResume();
110 | loadPrefs();
111 | registerReceiver(receiver, new IntentFilter(ResponseReceiver.ACTION_RESP));
112 | }
113 |
114 | public void startScanner(View v) {
115 | startService(wifiScannerIntent);
116 | addToLog("Requested scan service start.");
117 | }
118 |
119 | public void stopScanner(View v) {
120 | stopService(wifiScannerIntent);
121 | addToLog("Requested scan service stop.");
122 | }
123 |
124 | private void addToLog(String content) {
125 | final int LOG_MAX_BUFFER = 2000;
126 | // lame log rotation implementation
127 | if (textViewLog.length() > LOG_MAX_BUFFER)
128 | textViewLog.setText(textViewLog.getText().toString().substring(100, textViewLog.length()));
129 | String currentDateTimeString = DateFormat.getDateTimeInstance().format(new Date());
130 | textViewLog.append(currentDateTimeString + ": " + content + "\n");
131 | }
132 |
133 | private void loadPrefs() {
134 | autoStartSwitch.setChecked(sharedPreferences.getBoolean("autoStart", false));
135 | scanFrequency = sharedPreferences.getInt("scanFrequency", 0);
136 | if (scanFrequency == 0) {
137 | editor = sharedPreferences.edit();
138 | int DEFAULT_SCAN_FREQ = 300;
139 | editor.putInt("scanFrequency", DEFAULT_SCAN_FREQ);
140 | editor.apply();
141 | scanFrequencyText.setText("" + DEFAULT_SCAN_FREQ);
142 | } else {
143 | scanFrequencyText.setText("" + scanFrequency);
144 | }
145 | }
146 |
147 | public class ResponseReceiver extends BroadcastReceiver {
148 | public static final String ACTION_RESP = "com.pmbento.karmadetector.wifiscannerservice.response";
149 |
150 | @Override
151 | public void onReceive(Context context, Intent intent) {
152 | if (intent.getAction().equals(ACTION_RESP)) {
153 | addToLog(intent.getStringExtra("message"));
154 | }
155 | }
156 | }
157 | }
158 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU LESSER GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 |
9 | This version of the GNU Lesser General Public License incorporates
10 | the terms and conditions of version 3 of the GNU General Public
11 | License, supplemented by the additional permissions listed below.
12 |
13 | 0. Additional Definitions.
14 |
15 | As used herein, "this License" refers to version 3 of the GNU Lesser
16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU
17 | General Public License.
18 |
19 | "The Library" refers to a covered work governed by this License,
20 | other than an Application or a Combined Work as defined below.
21 |
22 | An "Application" is any work that makes use of an interface provided
23 | by the Library, but which is not otherwise based on the Library.
24 | Defining a subclass of a class defined by the Library is deemed a mode
25 | of using an interface provided by the Library.
26 |
27 | A "Combined Work" is a work produced by combining or linking an
28 | Application with the Library. The particular version of the Library
29 | with which the Combined Work was made is also called the "Linked
30 | Version".
31 |
32 | The "Minimal Corresponding Source" for a Combined Work means the
33 | Corresponding Source for the Combined Work, excluding any source code
34 | for portions of the Combined Work that, considered in isolation, are
35 | based on the Application, and not on the Linked Version.
36 |
37 | The "Corresponding Application Code" for a Combined Work means the
38 | object code and/or source code for the Application, including any data
39 | and utility programs needed for reproducing the Combined Work from the
40 | Application, but excluding the System Libraries of the Combined Work.
41 |
42 | 1. Exception to Section 3 of the GNU GPL.
43 |
44 | You may convey a covered work under sections 3 and 4 of this License
45 | without being bound by section 3 of the GNU GPL.
46 |
47 | 2. Conveying Modified Versions.
48 |
49 | If you modify a copy of the Library, and, in your modifications, a
50 | facility refers to a function or data to be supplied by an Application
51 | that uses the facility (other than as an argument passed when the
52 | facility is invoked), then you may convey a copy of the modified
53 | version:
54 |
55 | a) under this License, provided that you make a good faith effort to
56 | ensure that, in the event an Application does not supply the
57 | function or data, the facility still operates, and performs
58 | whatever part of its purpose remains meaningful, or
59 |
60 | b) under the GNU GPL, with none of the additional permissions of
61 | this License applicable to that copy.
62 |
63 | 3. Object Code Incorporating Material from Library Header Files.
64 |
65 | The object code form of an Application may incorporate material from
66 | a header file that is part of the Library. You may convey such object
67 | code under terms of your choice, provided that, if the incorporated
68 | material is not limited to numerical parameters, data structure
69 | layouts and accessors, or small macros, inline functions and templates
70 | (ten or fewer lines in length), you do both of the following:
71 |
72 | a) Give prominent notice with each copy of the object code that the
73 | Library is used in it and that the Library and its use are
74 | covered by this License.
75 |
76 | b) Accompany the object code with a copy of the GNU GPL and this license
77 | document.
78 |
79 | 4. Combined Works.
80 |
81 | You may convey a Combined Work under terms of your choice that,
82 | taken together, effectively do not restrict modification of the
83 | portions of the Library contained in the Combined Work and reverse
84 | engineering for debugging such modifications, if you also do each of
85 | the following:
86 |
87 | a) Give prominent notice with each copy of the Combined Work that
88 | the Library is used in it and that the Library and its use are
89 | covered by this License.
90 |
91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license
92 | document.
93 |
94 | c) For a Combined Work that displays copyright notices during
95 | execution, include the copyright notice for the Library among
96 | these notices, as well as a reference directing the user to the
97 | copies of the GNU GPL and this license document.
98 |
99 | d) Do one of the following:
100 |
101 | 0) Convey the Minimal Corresponding Source under the terms of this
102 | License, and the Corresponding Application Code in a form
103 | suitable for, and under terms that permit, the user to
104 | recombine or relink the Application with a modified version of
105 | the Linked Version to produce a modified Combined Work, in the
106 | manner specified by section 6 of the GNU GPL for conveying
107 | Corresponding Source.
108 |
109 | 1) Use a suitable shared library mechanism for linking with the
110 | Library. A suitable mechanism is one that (a) uses at run time
111 | a copy of the Library already present on the user's computer
112 | system, and (b) will operate properly with a modified version
113 | of the Library that is interface-compatible with the Linked
114 | Version.
115 |
116 | e) Provide Installation Information, but only if you would otherwise
117 | be required to provide such information under section 6 of the
118 | GNU GPL, and only to the extent that such information is
119 | necessary to install and execute a modified version of the
120 | Combined Work produced by recombining or relinking the
121 | Application with a modified version of the Linked Version. (If
122 | you use option 4d0, the Installation Information must accompany
123 | the Minimal Corresponding Source and Corresponding Application
124 | Code. If you use option 4d1, you must provide the Installation
125 | Information in the manner specified by section 6 of the GNU GPL
126 | for conveying Corresponding Source.)
127 |
128 | 5. Combined Libraries.
129 |
130 | You may place library facilities that are a work based on the
131 | Library side by side in a single library together with other library
132 | facilities that are not Applications and are not covered by this
133 | License, and convey such a combined library under terms of your
134 | choice, if you do both of the following:
135 |
136 | a) Accompany the combined library with a copy of the same work based
137 | on the Library, uncombined with any other library facilities,
138 | conveyed under the terms of this License.
139 |
140 | b) Give prominent notice with the combined library that part of it
141 | is a work based on the Library, and explaining where to find the
142 | accompanying uncombined form of the same work.
143 |
144 | 6. Revised Versions of the GNU Lesser General Public License.
145 |
146 | The Free Software Foundation may publish revised and/or new versions
147 | of the GNU Lesser General Public License from time to time. Such new
148 | versions will be similar in spirit to the present version, but may
149 | differ in detail to address new problems or concerns.
150 |
151 | Each version is given a distinguishing version number. If the
152 | Library as you received it specifies that a certain numbered version
153 | of the GNU Lesser General Public License "or any later version"
154 | applies to it, you have the option of following the terms and
155 | conditions either of that published version or of any later version
156 | published by the Free Software Foundation. If the Library as you
157 | received it does not specify a version number of the GNU Lesser
158 | General Public License, you may choose any version of the GNU Lesser
159 | General Public License ever published by the Free Software Foundation.
160 |
161 | If the Library as you received it specifies that a proxy can decide
162 | whether future versions of the GNU Lesser General Public License shall
163 | apply, that proxy's public statement of acceptance of any version is
164 | permanent authorization for you to choose that version for the
165 | Library.
166 |
167 |
--------------------------------------------------------------------------------
/app/src/main/java/com/pmbento/karmadetector/WifiScannerService.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2015 Patrício Batista
3 | *
4 | * This program is free software: you can redistribute it and/or modify
5 | * it under the terms of the GNU General Public License as published by
6 | * the Free Software Foundation, either version 3 of the License, or
7 | * (at your option) any later version.
8 | *
9 | * This program is distributed in the hope that it will be useful,
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | * GNU General Public License for more details.
13 | *
14 | * You should have received a copy of the GNU General Public License
15 | * along with this program. If not, see .
16 | */
17 |
18 | package com.pmbento.karmadetector;
19 |
20 | import android.app.IntentService;
21 | import android.app.Notification;
22 | import android.app.NotificationManager;
23 | import android.app.PendingIntent;
24 | import android.content.BroadcastReceiver;
25 | import android.content.Context;
26 | import android.content.Intent;
27 | import android.content.IntentFilter;
28 | import android.content.SharedPreferences;
29 | import android.graphics.Color;
30 | import android.media.RingtoneManager;
31 | import android.net.Uri;
32 | import android.net.wifi.ScanResult;
33 | import android.net.wifi.WifiConfiguration;
34 | import android.net.wifi.WifiManager;
35 |
36 | import java.util.List;
37 | import java.util.Random;
38 |
39 | //import android.util.Log;
40 |
41 |
42 | public class WifiScannerService extends IntentService {
43 | private int frequency; // scan frequency (in seconds)
44 | private BroadcastReceiver receiver;
45 | private WifiManager wifiManager;
46 | private WifiManager.WifiLock wifiLock;
47 | private String decoySsid;
48 | private boolean shouldRun = true;
49 | private Uri defaultNotificationUri;
50 | private NotificationManager notificationManager;
51 |
52 | public WifiScannerService() {
53 | super(WifiScannerService.class.getName());
54 | }
55 |
56 | private static String getRandomString(int length) {
57 | final String AB = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
58 | Random rnd = new Random();
59 |
60 | StringBuilder sb = new StringBuilder(length);
61 | for (int i = 0; i < length; i++)
62 | sb.append(AB.charAt(rnd.nextInt(AB.length())));
63 | return sb.toString();
64 | }
65 |
66 | @Override
67 | public int onStartCommand(Intent intent, int flags, int startId) {
68 | super.onStartCommand(intent, flags, startId);
69 | return START_STICKY;
70 | }
71 |
72 | @Override
73 | public void onCreate() {
74 | SharedPreferences sharedPreferences = getSharedPreferences("karmaDetectorPrefs", Context.MODE_PRIVATE);
75 | wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
76 | wifiLock = wifiManager.createWifiLock(WifiManager.WIFI_MODE_FULL, "WifiScannerService");
77 | defaultNotificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
78 | notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
79 | shouldRun = true;
80 | int DEFAULT_SCAN_FREQ = 300;
81 | frequency = sharedPreferences.getInt("scanFrequency", DEFAULT_SCAN_FREQ);
82 |
83 | if (!wifiManager.isWifiEnabled()) {
84 | boolean ret = wifiManager.setWifiEnabled(true);
85 | if (!ret)
86 | addToLog("Problem activating Wifi. Active scans will not work.");
87 | }
88 | removeDecoyNetworks();
89 | createDecoyNetwork();
90 |
91 | startBroadcastReceiver();
92 | super.onCreate();
93 | }
94 |
95 | @Override
96 | public void onDestroy() {
97 | //Log.d("WifiScannerService", "Going to destroy the handler");
98 | shouldRun = false;
99 | if (receiver != null) {
100 | unregisterReceiver(receiver);
101 | }
102 | releaseWifiLock();
103 | removeDecoyNetworks();
104 | super.onDestroy();
105 | }
106 |
107 | @Override
108 | protected void onHandleIntent(Intent workIntent) {
109 | //Log.d("WifiScannerService", "Handling");
110 | startNetworkScanner();
111 | //Log.d("WifiScannerService", "Done Handling");
112 | }
113 |
114 | private void startBroadcastReceiver() {
115 | IntentFilter i = new IntentFilter();
116 | i.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
117 |
118 | receiver = new BroadcastReceiver() {
119 | @Override
120 | public void onReceive(Context context, Intent i) {
121 | if (!i.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)) {
122 | //Log.d("WifiScannerService", "Action received but not handled: " + i.getAction());
123 | return;
124 | }
125 | List l = wifiManager.getScanResults();
126 | for (ScanResult r : l) {
127 | //Log.d("WifiScannerService", r.SSID);
128 | if (r.SSID.equals(decoySsid)) {
129 |
130 | sendNotification("BSSID: " + r.BSSID + "\n" + "Signal level: " + r.level);
131 | String message;
132 | message = "Possible Karma attack detected!" + "\n"
133 | + "BSSID: " + r.BSSID + "\n"
134 | + "Decoy SSID: " + r.SSID + "\n"
135 | + "Capabilities: " + r.capabilities + "\n"
136 | + "Frequency: " + r.frequency + "\n"
137 | + "Signal level (in dBm): " + r.level;
138 | //Log.d("WifiScannerService", message);
139 | addToLog(message);
140 | }
141 | }
142 | releaseWifiLock();
143 | }
144 | };
145 | registerReceiver(receiver, i);
146 | }
147 |
148 | private boolean createDecoyNetwork() {
149 | decoySsid = "KD-" + getRandomString(13);
150 |
151 | wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
152 | WifiConfiguration wifiConfiguration = new WifiConfiguration();
153 | wifiConfiguration.SSID = decoySsid;
154 | wifiConfiguration.preSharedKey = "\"".concat(getRandomString(63)).concat("\"");
155 | wifiConfiguration.hiddenSSID = true;
156 | wifiConfiguration.status = WifiConfiguration.Status.ENABLED;
157 | wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP);
158 | wifiConfiguration.allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP);
159 | wifiConfiguration.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
160 | wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP);
161 | wifiConfiguration.allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP);
162 | wifiConfiguration.allowedProtocols.set(WifiConfiguration.Protocol.RSN);
163 |
164 | //Log.d("WifiPreference", "going to add network " + decoySsid);
165 | int networkId = wifiManager.addNetwork(wifiConfiguration);
166 | if (networkId == -1) {
167 | addToLog("Error adding decoy network!");
168 | return false;
169 | }
170 | //Log.d("WifiPreference", "add Network returned " + networkId);
171 | boolean es = wifiManager.saveConfiguration();
172 | //Log.d("WifiPreference", "saveConfiguration returned " + es);
173 | if (!es) {
174 | addToLog("Error saving the network configuration for the decoy network!");
175 | return false;
176 | }
177 | boolean b = wifiManager.enableNetwork(networkId, false);
178 | //Log.d("WifiPreference", "enableNetwork returned " + b);
179 | if (!b) {
180 | addToLog("Error enabling the decoy network!");
181 | return false;
182 | }
183 | return true;
184 | }
185 |
186 | private boolean removeDecoyNetworks() {
187 | //Log.d("WifiScannerService", "Clearing old decoy networks");
188 | List l = wifiManager.getConfiguredNetworks();
189 | if (l != null) {
190 | for (WifiConfiguration r : l) {
191 | if (r.SSID.startsWith("\"KD-") && r.SSID.length() == 18) {
192 | //Log.d("WifiScannerService", "Going to remove network: " + r.SSID);
193 | boolean ea = wifiManager.removeNetwork(r.networkId);
194 | //Log.d("WifiPreference", "remove Network returned " + ea);
195 | if (!ea) {
196 | addToLog("Error removing decoy network!");
197 | return false;
198 | }
199 | }
200 | }
201 | boolean es = wifiManager.saveConfiguration();
202 | //Log.d("WifiPreference", "saveConfiguration returned " + es);
203 | if (!es) {
204 | addToLog("Error saving the network configuration while removing decoy networks!");
205 | return false;
206 | }
207 | }
208 | return true;
209 | }
210 |
211 | private void startNetworkScanner() {
212 | while (shouldRun) {
213 | //Log.d("WifiScannerService", "Starting scan. Next scan in " + frequency + " seconds.");
214 | addToLog("Starting scan. Next scan in " + frequency + " seconds.");
215 | acquireWifiLock();
216 | wifiManager.startScan();
217 | try {
218 | Thread.sleep(frequency * 1000);
219 | } catch (InterruptedException e) {
220 | e.printStackTrace();
221 | }
222 | }
223 | }
224 |
225 | private void sendNotification(String contentText) {
226 | Intent notificationIntent = new Intent(getApplicationContext(), MainActivity.class);
227 | notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
228 | PendingIntent intent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
229 |
230 | Notification n = new Notification.Builder(this)
231 | .setSmallIcon(R.drawable.ic_stat_kd)
232 | .setContentTitle("Possible Karma attack detected!")
233 | .setContentText(contentText)
234 | .setSound(defaultNotificationUri)
235 | .setLights(Color.RED, 500, 500)
236 | .setOnlyAlertOnce(true)
237 | .setContentIntent(intent)
238 | .setAutoCancel(true).build();
239 |
240 | notificationManager.notify(0, n);
241 | }
242 |
243 | private void addToLog(String message) {
244 | Intent broadcastIntent = new Intent();
245 | broadcastIntent.setAction(MainActivity.ResponseReceiver.ACTION_RESP);
246 | broadcastIntent.putExtra("message", message);
247 | sendBroadcast(broadcastIntent);
248 | }
249 |
250 | private void acquireWifiLock() {
251 | if (!wifiLock.isHeld()) {
252 | wifiLock.setReferenceCounted(false);
253 | wifiLock.acquire();
254 | //Log.d("WifiScannerService", "wifi lock acquired: " + wifiLock.isHeld());
255 | }
256 | }
257 |
258 | private void releaseWifiLock() {
259 | if (wifiLock != null) {
260 | if (wifiLock.isHeld()) {
261 | wifiLock.release();
262 | }
263 | }
264 | }
265 |
266 | public static class BroadcastResponseReceiver extends BroadcastReceiver {
267 | @Override
268 | public void onReceive(Context context, Intent intent) {
269 | if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
270 | SharedPreferences sharedPreferences = context.getSharedPreferences("karmaDetectorPrefs", Context.MODE_PRIVATE);
271 | if (sharedPreferences.getBoolean("autoStart", false)) {
272 | Intent wifiScannerIntent = new Intent(context, WifiScannerService.class);
273 | context.startService(wifiScannerIntent);
274 | Intent broadcastIntent = new Intent();
275 | broadcastIntent.setAction(MainActivity.ResponseReceiver.ACTION_RESP);
276 | broadcastIntent.putExtra("message", "Current state: running");
277 | context.sendBroadcast(broadcastIntent);
278 | }
279 | }
280 | }
281 | }
282 | }
283 |
--------------------------------------------------------------------------------