1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package de.tudarmstadt.informatik.hostage.system;
- import java.io.IOException;
- import android.util.Log;
- import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
- public class Device {
- private static String porthackFilepath = "/data/local/bind";
- private static boolean initialized = false;
- private static boolean root = false; // device is rooted
- private static boolean porthack = false; // porthack installed
- private static boolean iptables = false; // iptables redirection confirmed working
- public static void checkCapabilities() {
- // assume worst case
- initialized = false;
- root = false;
- porthack = false;
- iptables = false;
- porthackFilepath = HelperUtils.getPorthackFilepath();
- String porthackExists = "[ -e "+porthackFilepath+" ]"; // checks existence of porthack
- try {
- Process p = new ProcessBuilder("su", "-c", porthackExists).start();
- switch (p.waitFor()) {
- case 0: porthack = true;
- // fall through and don't break
- case 1: root = true; // 0 and 1 are valid return values of the porthack
- break;
- case 127: // command not found or executable
- root = false;
- porthack = false;
- break;
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- final String ipTablesList = "iptables -L -n -t nat"; // list all rules in NAT table
- try {
- Process p = new ProcessBuilder("su", "-c", ipTablesList).start();
- switch (p.waitFor()) {
- case 0: // everything is fine
- iptables = true; // iptables available and working
- break;
- case 3: // no such table
- case 127: // command not found
- default: // unexpected return code
- // while testing code 3 has been returned when table NAT is not available
- iptables = false;
- }
- } catch (IOException e) {
- e.printStackTrace();
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- initialized = true;
- }
- public static boolean isRooted() {
- assert(initialized);
- return root;
- }
- public static boolean isPorthackInstalled() {
- assert(initialized);
- return porthack;
- }
- public static boolean isPortRedirectionAvailable() { // using iptables
- assert(initialized);
- return iptables;
- }
- }
|