-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #105 from w-shackleton/root-check
Root check
- Loading branch information
Showing
7 changed files
with
209 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
androidnetspoof/src/main/java/uk/digitalsquid/netspoofer/root/RootChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* This file is part of Network Spoofer for Android. | ||
* Network Spoofer lets you change websites on other people’s computers | ||
* from an Android phone. | ||
* Copyright (C) 2014 Will Shackleton <[email protected]> | ||
* | ||
* Network Spoofer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Network Spoofer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Network Spoofer, in the file COPYING. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package uk.digitalsquid.netspoofer.root; | ||
|
||
import android.content.Context; | ||
import android.util.Log; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.FileNotFoundException; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
|
||
import uk.digitalsquid.netspoofer.config.FileFinder; | ||
import uk.digitalsquid.netspoofer.config.FileInstaller; | ||
import uk.digitalsquid.netspoofer.config.LogConf; | ||
|
||
/** | ||
* Checks that the device has root access. | ||
*/ | ||
public class RootChecker implements LogConf { | ||
private Context mContext; | ||
|
||
public RootChecker(Context context) { | ||
mContext = context; | ||
} | ||
|
||
public enum RootCheckResult { | ||
ERROR, | ||
UNAVAILABLE, | ||
BINARY_NO_EXEC, | ||
AVAILABLE | ||
} | ||
|
||
public RootCheckResult check() { | ||
try { | ||
FileFinder.initialise(mContext); | ||
} catch (FileNotFoundException e) { | ||
// Handle error below | ||
} | ||
if (FileFinder.SU == null || FileFinder.SU == "") { | ||
return RootCheckResult.UNAVAILABLE; | ||
} | ||
|
||
ProcessBuilder pb = new ProcessBuilder(FileFinder.SU, "-c", | ||
FileInstaller.getScriptPath(mContext, "rootcheck")); | ||
|
||
try { | ||
Process p = pb.start(); | ||
BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
BufferedReader stderr = new BufferedReader(new InputStreamReader(p.getInputStream())); | ||
String idLine = stdout.readLine(); | ||
|
||
// Munch garbage | ||
if (idLine != null) { | ||
while (stdout.readLine() != null) ; | ||
} | ||
while (stderr.readLine() != null); | ||
|
||
p.waitFor(); | ||
|
||
return idLine != null && idLine.contains("(root)") ? | ||
RootCheckResult.AVAILABLE : | ||
RootCheckResult.BINARY_NO_EXEC; | ||
} catch (IOException e) { | ||
Log.e(TAG, "Failed to run root check", e); | ||
return RootCheckResult.ERROR; | ||
} catch (InterruptedException e) { | ||
Log.e(TAG, "Failed to run root check", e); | ||
return RootCheckResult.ERROR; | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
androidnetspoof/src/main/java/uk/digitalsquid/netspoofer/servicestatus/RootStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* This file is part of Network Spoofer for Android. | ||
* Network Spoofer lets you change websites on other people’s computers | ||
* from an Android phone. | ||
* Copyright (C) 2014 Will Shackleton <[email protected]> | ||
* | ||
* Network Spoofer is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Network Spoofer is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Network Spoofer, in the file COPYING. | ||
* If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package uk.digitalsquid.netspoofer.servicestatus; | ||
|
||
import uk.digitalsquid.netspoofer.root.RootChecker; | ||
|
||
public class RootStatus extends ServiceStatus { | ||
public final RootChecker.RootCheckResult rootCheckResult; | ||
|
||
public RootStatus(RootChecker.RootCheckResult rootCheckResult) { | ||
this.rootCheckResult = rootCheckResult; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#!/system/bin/sh | ||
# Creates a file as root to verify that root access exists | ||
|
||
id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters