基哥SU执行【源码】
本帖最后由 djwdj 于 2017-11-21 00:15 编辑主要代码如下:
String su(String su){
String r=;
try
{
java.lang.Process p = Runtime.getRuntime().exec("su");
DataOutputStream d = new DataOutputStream(p.getOutputStream());
d.write(new StringBuffer().append(su).append("\n").toString().getBytes("UTF-8"));
d.writeBytes("exit\n");
d.flush();
StringBuilder i = new StringBuilder();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while ((s = b.readLine()) != null)
{
if(i.length()!=0){
i.append("\n");
}
i.append(s);
}
p.getErrorStream().close();
r=i.toString();
}catch (IOException e){}
return r;
}
①楼的代码是准确地为输出加入换行。
②楼是先加入换行,再去掉多余的。 String su(String su){
String r=;
try
{
java.lang.Process p = Runtime.getRuntime().exec("su");
DataOutputStream d = new DataOutputStream(p.getOutputStream());
d.write(new StringBuffer().append(su).append("\n").toString().getBytes("UTF-8"));
d.writeBytes("exit\n");
d.flush();
StringBuilder i = new StringBuilder();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while ((s = b.readLine()) != null)
{
if(i.length()!=0){
i.append("\n");
}
i.append(s);
}
p.getErrorStream().close();
r=i.toString();
}catch (IOException e){}
return r;
} String su(String su){
String r=;
try
{
java.lang.Process p = Runtime.getRuntime().exec("su");
DataOutputStream d = new DataOutputStream(p.getOutputStream());
d.write(new StringBuffer().append(su).append("\n").toString().getBytes("UTF-8"));
d.writeBytes("exit\n");
d.flush();
StringBuilder i = new StringBuilder();
BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
String s;
while ((s = b.readLine()) != null)
{
i.append(s+"\n");
}
p.getErrorStream().close();
r=i.toString().trim();
}catch (IOException e){}
return r;
}
页:
[1]