Always use global mount namespace

This commit is contained in:
topjohnwu 2017-08-12 17:07:28 +08:00
parent 337b4c4268
commit 3cc458abd9

View File

@ -29,38 +29,42 @@ 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;
DataOutputStream in = null; DataOutputStream in = null;
DataInputStream out = null; DataInputStream out = null;
try {
// 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) {
// Feature not implemented, normal root shell
try { try {
process = Runtime.getRuntime().exec("su"); process = Runtime.getRuntime().exec("su");
in = new DataOutputStream(process.getOutputStream()); in = new DataOutputStream(process.getOutputStream());
out = new DataInputStream(process.getInputStream()); out = new DataInputStream(process.getInputStream());
} catch (IOException e) { testRootShell(in, out);
} catch (IOException e1) {
rootStatus = 0; rootStatus = 0;
} }
}
while (true) { if (!rootAccess()) {
if (rootAccess()) {
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();
}
} catch (IOException e) {
rootStatus = -1;
continue;
}
break;
} else {
// 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 {
isValid = false; isValid = false;
return; return;
} }
break;
}
} }
isValid = true; isValid = true;