网络防火墙系统的实现(三)
2016-03-25 10:50
453 查看
帮助Activity文件
编写文件HelpDialog.java
import android.app.AlertDialog;import android.content.Context;
import android.view.View;
public class HelpDialog extends AlertDialog {
protected HelpDialog (Context context) {
super (context);
final View view = getLayoutInflater().inflate( R.layout.help_dialog, null);
setButton( context.getText (R.string.close), (OnClickListener) null);
setIcon (R.drawable.icon);
setTitle(" DroidWall v" + Api.VERSION);
setView (view);
}
}
公共库函数文件
private static String scriptHeader (Context ctx) {final String dir = ctx.getDir( "bin", 0).getAbsolutePath();
final String myiptables = dir + "/iptables_armv5";
return "" + "IPTABLES=iptables\n" + "BUSYBOX=busybox\n" + "GREP=grep\n"
+ "ECHO=echo\n" + "#Try to find busybox\n" + "if"
+ dir
+ "/busybox_g1 --help > /dev/null 2> /dev/null ; then\n"
+ "BUSYBOX="
+ dir
+ "/busybox_g1\n"
+ " GREP=\ "$BUSYBOX grep \" \n"
+ " ECHO=\ "$BUSYBOX echo \" \n"
+ "elif busybox --help > /dev/null 2> /dev/null ; then\n"
+ " BOSYBOX= bosybox \n"
+ "elif /system/xbin/busybox --help > /dev/null 2> /dev/null; then\n"
+ " BOSYBOX= /system/xbin/busybox \n"
+ "fi \n"
+ "# Try to find grep \n"
+ "if ! $ECHO 1 | $GREP -q 1 > /dev/null 2> /dev/null ; then \n"
+ " if $ECHO 1 | $BUSYBOX grep -q 1 > /dev/null 2> /dev/null ; then \n"
+ " GREP = \" $BUSYBOX grep \" \n"
+ "fi \n"
+ "# Grep is absolutely required \n"
+ " if ! $ECHO 1 | $GREP -q 1 > /dev/null 2 > /dev/null ; then \n"
+ " $ECHO The grep command is required. DroidWall will not work. \n“
+ " fi \n"
+ " fi \n"
+ "# Try to find iptables \n"
+ "if "
+ myiptables
+ " --version > /dev/null 2> /dev/null ; then \n"
+ " IPTABLES="
+ myiptables + "\n" + "fi \n" + "";
编写函数copyRawFile(), 复制一个未加工的资源文件
private static void copyRawFile (Context ctx, int resid, File file, String mode) throws IOException, InterruptedException {final String abspath = file.getAbsolutePath();
//在iptables写入二进制数据
final FIleOutputStream out = new FileOutputStream( file);
final InputStream is = ctx.getResources().openRawResources( resid);
byte buf[ ] = new byte[1024];
int len;
while ((len = is.read(buf)) > 0 ) {
out.write (buf , 0, len);
}
out.close();
is.close();
//允许改变
Runtime.getRuntime( ). exec( "chmod " + mode + " " + abspath).waitFor();
}
相关文章推荐
- 神经网络翻译系统dl4mt源码之Numpy库相关函数的使用(一)
- get与post的区别
- 网络扫描(二)
- HTTP in iOS你看我就够
- android 中HttpClient和URLConnection的区别
- 扒一扒HTTPS网站的内幕
- 原生代码加载网络图片和Volley和Picasso的简单介绍和优缺点对比
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java
- Twsited异步网络框架
- Android中的HTTPS
- 图解SSL/TLS协议(HTTPS的安全层)
- The superclass "javax.servlet.http.HttpServlet" was not found on the Java
- 全站HTTPS能带来怎样的优势?HTTPS原理是什么、如何加密?
- HTTPS连接的前几毫秒发生了什么
- 解决URL中包含以及不包含https、www时引起的JS跨域问题
- HTTPS的层次结构和防范对象
- 启用全站HTTPS后不仅更安全而且更快 看淘宝是如何做到的????
- HTTPS和HTTP的区别
- 图解server端网络架构
- 使用C++ REST SDK开发简单的Web(HTTP)服务