我尝试编写一个使用Drozer(一个用Python编写的工具来测试Android应用程序中的漏洞的工具)的Java程序。我需要直接从Java执行命令,到目前为止一切都很顺利,但是当drozer的交互式会话启动时我遇到了问题。似乎当需要处理EOF时会出现问题,因为ctrl + D也无法停止会话。这是我点击ctrl + D
后得到的*** Unknown syntax: EOF
这是我用来连接从Java到Drozer的代码,运行后,我的程序开始无限循环打印相同的错误:***语法未知:EOF。 任何其他命令都像魅力一样。任何想法我做错了什么?
干杯
public class test1 {
public static void main(String a[]) throws InterruptedException, IOException {
List<String> commands = new ArrayList<String>();
List<String> commands1 = new ArrayList<String>();
commands.add("/usr/local/bin/drozer");
commands.add("console");
commands.add("connect");
ProcessBuilder pb = new ProcessBuilder(commands);
pb.redirectErrorStream(true);
try {
Process prs = pb.start();
Thread inThread = new Thread(new In(prs.getInputStream()));
inThread.start();
Thread.sleep(1000);
OutputStream writeTo = prs.getOutputStream();
writeTo.write("oops\n".getBytes());
writeTo.flush();
writeTo.close();
}catch (IOException e) {
e.printStackTrace();
}
}
}
class In implements Runnable {
private InputStream is;
public In(InputStream is) {
this.is = is;
}
@Override
public void run() {
try {
byte[] b = new byte[1024];
int size = 0;
while ((size = is.read(b)) != -1) {
System.out.println(new String(b));
}
is.close();
} catch (IOException ex) {
Logger.getLogger(In.class.getName()).log(Level.SEVERE, null, ex);
}
}
}