Commit 3cc458ab authored by topjohnwu's avatar topjohnwu

Always use global mount namespace

parent 337b4c42
......@@ -29,6 +29,17 @@ public class Shell {
private boolean isValid;
private void testRootShell(DataOutputStream in, DataInputStream out) throws IOException {
in.write(("id\n").getBytes("UTF-8"));
in.flush();
String s = new BufferedReader(new InputStreamReader(out)).readLine();
if (TextUtils.isEmpty(s) || !s.contains("uid=0")) {
in.close();
out.close();
throw new IOException();
}
}
private Shell() {
rootStatus = 1;
Process process = null;
......@@ -36,31 +47,24 @@ public class Shell {
DataInputStream out = null;
try {
process = Runtime.getRuntime().exec("su");
// Try getting global namespace
process = Runtime.getRuntime().exec("su --mount-master");
in = new DataOutputStream(process.getOutputStream());
out = new DataInputStream(process.getInputStream());
testRootShell(in, out);
} catch (IOException e) {
rootStatus = 0;
}
while (true) {
if (rootAccess()) {
// Feature not implemented, normal root shell
try {
in.write(("id\n").getBytes("UTF-8"));
in.flush();
String s = new BufferedReader(new InputStreamReader(out)).readLine();
if (TextUtils.isEmpty(s) || !s.contains("uid=0")) {
in.close();
out.close();
process.destroy();
throw new IOException();
process = Runtime.getRuntime().exec("su");
in = new DataOutputStream(process.getOutputStream());
out = new DataInputStream(process.getInputStream());
testRootShell(in, out);
} catch (IOException e1) {
rootStatus = 0;
}
} catch (IOException e) {
rootStatus = -1;
continue;
}
break;
} else {
if (!rootAccess()) {
// Try to gain non-root sh
try {
process = Runtime.getRuntime().exec("sh");
......@@ -74,8 +78,6 @@ public class Shell {
isValid = false;
return;
}
break;
}
}
isValid = true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment