瀏覽代碼

work around for iptables bug with older android versions

Fabio Arnold 9 年之前
父節點
當前提交
3d81352366
共有 1 個文件被更改,包括 20 次插入17 次删除
  1. 20 17
      src/de/tudarmstadt/informatik/hostage/system/Device.java

+ 20 - 17
src/de/tudarmstadt/informatik/hostage/system/Device.java

@@ -10,6 +10,7 @@ import java.io.InputStreamReader;
 import java.io.OutputStream;
 
 import android.app.Activity;
+import android.os.Build;
 import android.util.Log;
 
 import de.tudarmstadt.informatik.hostage.commons.HelperUtils;
@@ -52,24 +53,26 @@ public class Device {
 			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;
+		if (Build.VERSION.SDK_INT >= 18) { // iptables isn't fully implemented on older versions
+			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();
 			}
-		} catch (IOException e) {
-			e.printStackTrace();
-		} catch (InterruptedException e) {
-			e.printStackTrace();
 		}
 
 		initialized = true;