启动新进程

很多恶意程序会释放新的程序,启动新的进程,这通过Runtime来实现:

<span style="font-family: Arial, Helvetica, sans-serif;">Process process= Runtime.getRuntime().exec("getprop ro.kernel.qemu");</span>
DataOutputStream os=new DataoutPutStream(process.getOutputStream()--与native process的标准输入相联系);
BufferedReader in=new BufferedReader(new InputStreamReader(process.getInputStream(),"GBK"));
os.writeBytes("exit\n");//执行退出
os.flush();//
process.waitFor();
boolean qemuKernel=(Integer.valueof(in.readLine())==1)//判断ro.kernel.qemu属性值是否为1

process.destory();


abstract InputStream	getInputStream()// Returns an input stream that is connected to the standard output stream (stdout) of the native process (exec()这个方法所启动的一个新进程)represented by this object.
abstract OutputStream	getOutputStream() //Returns an output stream that is connected to the standard input stream (stdin) of the native process represented by this object.


abstract int	waitFor() Causes the calling thread to wait for the native process associated with this object to finish executing.

启动新进程实例:
Process process = new ProcessBuilder()
.command("/system/bin/ping", "android.com")
.redirectErrorStream(true)
.start();
try {
InputStream in = process.getInputStream();
OutputStream out = process.getOutputStream();

readStream(in);

finally {
process.destroy();
}
}



posted @ 2014-08-30 10:33  徐小鱼  阅读(225)  评论(0编辑  收藏  举报