网络防火墙系统的实现(三)

帮助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();

}


            


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值