Commit 3cc458ab authored by topjohnwu's avatar topjohnwu

Always use global mount namespace

parent 337b4c42
...@@ -29,6 +29,17 @@ public class Shell { ...@@ -29,6 +29,17 @@ public class Shell {
private boolean isValid; 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() { private Shell() {
rootStatus = 1; rootStatus = 1;
Process process = null; Process process = null;
...@@ -36,31 +47,24 @@ public class Shell { ...@@ -36,31 +47,24 @@ public class Shell {
DataInputStream out = null; DataInputStream out = null;
try { try {
process = Runtime.getRuntime().exec("su"); // Try getting global namespace
process = Runtime.getRuntime().exec("su --mount-master");
in = new DataOutputStream(process.getOutputStream()); in = new DataOutputStream(process.getOutputStream());
out = new DataInputStream(process.getInputStream()); out = new DataInputStream(process.getInputStream());
testRootShell(in, out);
} catch (IOException e) { } catch (IOException e) {
rootStatus = 0; // Feature not implemented, normal root shell
}
while (true) {
if (rootAccess()) {
try { try {
in.write(("id\n").getBytes("UTF-8")); process = Runtime.getRuntime().exec("su");
in.flush(); in = new DataOutputStream(process.getOutputStream());
String s = new BufferedReader(new InputStreamReader(out)).readLine(); out = new DataInputStream(process.getInputStream());
if (TextUtils.isEmpty(s) || !s.contains("uid=0")) { testRootShell(in, out);
in.close(); } catch (IOException e1) {
out.close(); rootStatus = 0;
process.destroy();
throw new IOException();
} }
} catch (IOException e) {
rootStatus = -1;
continue;
} }
break;
} else { if (!rootAccess()) {
// Try to gain non-root sh // Try to gain non-root sh
try { try {
process = Runtime.getRuntime().exec("sh"); process = Runtime.getRuntime().exec("sh");
...@@ -74,8 +78,6 @@ public class Shell { ...@@ -74,8 +78,6 @@ public class Shell {
isValid = false; isValid = false;
return; return;
} }
break;
}
} }
isValid = true; 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