Permalink
Browse files

app: added missing de.tu_darmstadt.seemoo.nexmon.utils package files.

  • Loading branch information...
matthiasseemoo committed Aug 16, 2017
1 parent 9665dc2 commit 336b6e13d10e106b598ef22b989d902cffa2acce
@@ -0,0 +1,88 @@
package de.tu_darmstadt.seemoo.nexmon.utils;
import android.content.Context;
import android.content.res.AssetManager;
import android.os.Environment;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Set;
import eu.chainfire.libsuperuser.Shell;
/**
* Created by matthias on 31.05.17.
*/
public class Assets {
private static Set<String> upToDateFiles = new HashSet<String>();
public static int copyFileFromAsset(Context context, String sourcePath, String destPath) {
byte[] buff = new byte[1024];
int len;
InputStream in;
OutputStream out;
try {
in = context.getAssets().open(sourcePath);
File tmpFile = File.createTempFile("tmp", "file", context.getCacheDir());
out = new FileOutputStream(tmpFile);
// write file
while ((len = in.read(buff)) != -1) {
out.write(buff, 0, len);
}
in.close();
out.flush();
out.close();
Shell.SU.run("cp " + tmpFile.getAbsolutePath() + " " + destPath);
} catch (Exception ex) {
ex.printStackTrace();
return -1;
}
return 0;
}
public static String getAssetsPath(Context context, String filename) {
byte[] buff = new byte[1024];
int len;
InputStream in;
OutputStream out;
String filesPath = context.getFilesDir().getPath();
if (new File(filesPath + "/" + filename).isFile() && upToDateFiles.contains(filename)) {
Log.d("ASSETS", filename + " found");
return filesPath + "/" + filename;
} else {
try {
in = context.getAssets().open("nexmon/" + filename);
File outFile = new File(filesPath, filename);
out = new FileOutputStream(outFile);
// write file
while ((len = in.read(buff)) != -1) {
out.write(buff, 0, len);
}
in.close();
out.flush();
out.close();
Shell.SU.run("chmod 777 " + filesPath + "/" + filename);
upToDateFiles.add(filename);
Log.d("ASSETS", filename + " extracted");
return filesPath + "/" + filename;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}
}
@@ -0,0 +1,95 @@
/***************************************************************************
* *
* ########### ########### ########## ########## *
* ############ ############ ############ ############ *
* ## ## ## ## ## ## ## *
* ## ## ## ## ## ## ## *
* ########### #### ###### ## ## ## ## ###### *
* ########### #### # ## ## ## ## # # *
* ## ## ###### ## ## ## ## # # *
* ## ## # ## ## ## ## # # *
* ############ ##### ###### ## ## ## ##### ###### *
* ########### ########### ## ## ## ########## *
* *
* S E C U R E M O B I L E N E T W O R K I N G *
* *
* License: *
* *
* Copyright (c) 2017 Secure Mobile Networking Lab (SEEMOO) *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, sublicense, and/or sell copies of the Software, and to *
* permit persons to whom the Software is furnished to do so, subject to *
* the following conditions: *
* *
* 1. The above copyright notice and this permission notice shall be *
* include in all copies or substantial portions of the Software. *
* *
* 2. Any use of the Software which results in an academic publication or *
* other publication which includes a bibliography must include *
* citations to the nexmon project a) and the paper cited under b): *
* *
* a) "Matthias Schulz, Daniel Wegemer and Matthias Hollick. Nexmon: *
* The C-based Firmware Patching Framework. https://nexmon.org" *
* *
* b) "Matthias Schulz, Francesco Gringoli, Daniel Steinmetzer, Michael *
* Koch and Matthias Hollick. Massive Reactive Smartphone-Based *
* Jamming using Arbitrary Waveforms and Adaptive Power Control. *
* Proceedings of the 10th ACM Conference on Security and Privacy *
* in Wireless and Mobile Networks (WiSec 2017), July 2017." *
* *
* 3. The Software is not used by, in cooperation with, or on behalf of *
* any armed forces, intelligence agencies, reconnaissance agencies, *
* defense agencies, offense agencies or any supplier, contractor, or *
* research associated. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, *
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE *
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
**************************************************************************/
package de.tu_darmstadt.seemoo.nexmon.utils;
import android.content.Context;
import android.util.Log;
import java.util.List;
import de.tu_darmstadt.seemoo.nexmon.MyApplication;
import eu.chainfire.libsuperuser.Shell;
/**
* Created by matthias on 24.05.17.
*/
public class Dhdutil {
protected static Dhdutil instance;
private String dhdutilPath;
protected Dhdutil() {
this.instance = this;
dhdutilPath = Assets.getAssetsPath(MyApplication.getAppContext(), "dhdutil");
}
public static Dhdutil getInstance() {
return instance == null ? new Dhdutil() : instance;
}
public String dumpConsole() {
List<String> out = Shell.SU.run(dhdutilPath + " consoledump");
StringBuilder sb = new StringBuilder();
for(String str : out) {
sb.append(str);
sb.append("\n");
}
return sb.toString();
}
}
@@ -0,0 +1,35 @@
package de.tu_darmstadt.seemoo.nexmon.utils;
import android.util.Log;
import java.util.List;
import eu.chainfire.libsuperuser.Shell;
/**
* Created by matthias on 30.06.17.
*/
public class FirmwareUtil {
private static FirmwareUtil instance;
private FirmwareUtil() {
instance = this;
}
public static FirmwareUtil getInstance() {
return instance == null ? new FirmwareUtil() : instance;
}
public static boolean isBroadcomChip() {
Shell.SU.run("ifconfig wlan0 up");
return Nexutil.getInstance().getIntIoctl(0) == 0x14e46c77;
}
public static String getCapabilities() {
Shell.SU.run("ifconfig wlan0 up");
String capabilities = Nexutil.getInstance().getIoctl(400);
return capabilities;
}
}
@@ -0,0 +1,132 @@
package de.tu_darmstadt.seemoo.nexmon.utils;
import android.graphics.Color;
import java.util.List;
import eu.chainfire.libsuperuser.Shell;
/**
* Created by matthias on 30.05.17.
*/
public class LEDControl {
private static final String LED_GREEN_PATH = "/sys/class/leds/green";
private static final String LED_BLUE_PATH = "/sys/class/leds/blue";
private static final String LED_RED_PATH = "/sys/class/leds/red";
private static final String LED_BRIGHTNESS_FILE = "brightness";
private static final String LED_ON_OFF_MS_FILE = "on_off_ms";
private static final String LED_RGB_START_FILE = "rgb_start";
private static int getBrightness(String led_path) {
List<String> out = Shell.SU.run("cat " + led_path + "/" + LED_BRIGHTNESS_FILE);
int ret;
try {
ret = Integer.parseInt(out.toString());
} catch (NumberFormatException e) {
ret = -1;
}
return ret;
}
public static int getBrightnessGreen() {
return getBrightness(LED_GREEN_PATH);
}
public static int getBrightnessRed() {
return getBrightness(LED_RED_PATH);
}
public static int getBrightnessBlue() {
return getBrightness(LED_BLUE_PATH);
}
private static void setBrightness(String led_path, int value) {
Shell.SU.run("echo " + value + " > " + led_path + "/" + LED_BRIGHTNESS_FILE);
}
public static void setBrightnessGreen(int value) {
setBrightness(LED_GREEN_PATH, value);
}
public static void setBrightnessRed(int value) {
setBrightness(LED_RED_PATH, value);
}
public static void setBrightnessBlue(int value) {
setBrightness(LED_BLUE_PATH, value);
}
public static void setBrightnessRGB(int r, int g, int b) {
setBrightness(LED_RED_PATH, r);
setBrightness(LED_GREEN_PATH, g);
setBrightness(LED_BLUE_PATH, b);
}
public static void setBrightnessRGB(int rgb) {
setBrightnessRGB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff);
}
private static int[] getOnOffMs(String led_path) {
List<String> out = Shell.SU.run("cat " + led_path + "/" + LED_ON_OFF_MS_FILE);
int ret[] = new int[2];
String arr[] = out.toString().split(" ");
try {
ret[0] = Integer.parseInt(arr[0]);
ret[1] = Integer.parseInt(arr[1]);
} catch (NumberFormatException e) {
ret[0] = -1;
ret[1] = -1;
}
return ret;
}
public static int[] getOnOffMsGreen() {
return getOnOffMs(LED_GREEN_PATH);
}
public static int[] getOnOffMsRed() {
return getOnOffMs(LED_RED_PATH);
}
public static int[] getOnOffMsBlue() {
return getOnOffMs(LED_BLUE_PATH);
}
private static void setOnOffMs(String led_path, int on, int off) {
Shell.SU.run("echo " + on + " " + off + " > " + led_path + "/" + LED_ON_OFF_MS_FILE);
}
public static void setOnOffMsGreen(int on, int off) {
setOnOffMs(LED_GREEN_PATH, on, off);
}
public static void setOnOffMsRed(int on, int off) {
setOnOffMs(LED_RED_PATH, on, off);
}
public static void setOnOffMsBlue(int on, int off) {
setOnOffMs(LED_BLUE_PATH, on, off);
}
public static void setOnOffMsRGB(int on, int off) {
setOnOffMsRed(on, off);
setOnOffMsGreen(on, off);
setOnOffMsBlue(on, off);
}
public static void activateLED() {
Shell.SU.run("echo 0 > " + LED_GREEN_PATH + "/" + LED_RGB_START_FILE);
Shell.SU.run("echo 1 > " + LED_GREEN_PATH + "/" + LED_RGB_START_FILE);
}
public static void deactivateLED() {
Shell.SU.run("echo 0 > " + LED_GREEN_PATH + "/" + LED_RGB_START_FILE);
}
}
Oops, something went wrong.

0 comments on commit 336b6e1

Please sign in to comment.