Skip to content

Commit

Permalink
Merge pull request #58 from w-shackleton/lollipop
Browse files Browse the repository at this point in the history
Added support for Lollipop devices (final stage)
  • Loading branch information
w-shackleton committed Feb 28, 2015
2 parents 8e08922 + 27c2610 commit 6b83600
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected void onCreate(Bundle savedInstanceState) {
wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
wL = wm.createWifiLock(WifiManager.WIFI_MODE_FULL, "android-netspoof");
wL.acquire();

if(wm.getConnectionInfo().getSupplicantState() == SupplicantState.COMPLETED) getAndSetWifiInfo();

IntentFilter wifiFilter = new IntentFilter();
Expand Down Expand Up @@ -306,7 +306,7 @@ private void getAndSetWifiInfo() {
try {
wifiIP = NetHelpers.inetFromInt(ip);
wifiIface = NetHelpers.getIface(wifiIP);
wifiGateway = NetHelpers.getDefaultGateway(wifiIface);
wifiGateway = NetHelpers.getDefaultGateway(wifiIface, wm.getDhcpInfo());
gatewayListAdapter.setWifiGateway(wifiGateway.getGateway().getHostAddress());
if(!autoNextStepStarted && PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("autoChooseRouter", false)) {
autoNextStepStarted = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

package uk.digitalsquid.netspoofer.config;

import android.net.DhcpInfo;
import android.os.Build;
import android.util.Log;

import java.io.BufferedReader;
Expand Down Expand Up @@ -63,7 +65,16 @@ public static final long inetFromByte(byte[] ip) {
((long)(ip[2]&0xFF) << 16) +
((long)(ip[3]&0xFF) << 24);
}


public static final InetAddress inetFromInt(long ip) throws UnknownHostException {
return InetAddress.getByAddress(new byte[] {
(byte) ((ip >> 0 ) & 0xFF),
(byte) ((ip >> 8 ) & 0xFF),
(byte) ((ip >> 16) & 0xFF),
(byte) ((ip >>>24) & 0xFF),
});
}

public static final InetAddress reverseInetFromInt(long ip) throws UnknownHostException {
return InetAddress.getByAddress(new byte[] {
(byte) ((ip >>>24) & 0xFF),
Expand Down Expand Up @@ -161,10 +172,11 @@ public String getIface() {
/**
*
* @param iface
* @param info a DhcpInfo to use on Lollipop devices
* @return
* @throws UnknownHostException
*/
public static final GatewayData getDefaultGateway(NetworkInterface iface) throws UnknownHostException {
public static final GatewayData getDefaultGateway(NetworkInterface iface, DhcpInfo info) throws UnknownHostException {
if(iface == null) throw new IllegalArgumentException("iface is null");

try { FileFinder.initialise(); } catch (FileNotFoundException e1) { }
Expand All @@ -184,6 +196,13 @@ public static final GatewayData getDefaultGateway(NetworkInterface iface) throws
subnet = route.getGenmask();
}
}

// Lollipop, use DhcpInfo
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT && info != null) {
gateway = inetFromInt(info.gateway & 0xFFFFFFFFL).getHostAddress();
subnet = inetFromInt(info.netmask & 0xFFFFFFFFL).getHostAddress();
}

return new GatewayData(InetAddress.getByName(gateway), subnet);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,15 @@ public void startSpoof(SpoofData spoof) throws IOException {
public void stopSpoof(SpoofData spoof) throws IOException {
if(!spoofRunning) return; // Don't do anything.
synchronized(spoofLock) {
cin.write("\n");
cin.flush();
if (cin != null) {
cin.write("\n");
cin.flush();
}

try {
su.waitFor();
if (su != null) {
su.waitFor();
}
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -224,12 +228,12 @@ public boolean checkIfStopped() {
public synchronized ArrayList<String> getNewSpoofOutput() throws IOException {
ArrayList<String> items = new ArrayList<String>();

while(cerr.ready()) {
while(cerr != null && cerr.ready()) {
String line = cerr.readLine();
Log.v(TAG, "cerr: " + line);
items.add(line);
}
while(cout.ready()) {
while(cout != null && cout.ready()) {
String line = cout.readLine();
Log.v(TAG, "cout: " + line);
items.add(line);
Expand Down

0 comments on commit 6b83600

Please sign in to comment.