package com.cqu.android.bean;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.List;
import android.app.AlertDialog;
import android.content.Context;
import android.util.Log;
import com.cqu.android.Activity.R;
public class FireWall {
/** special application UID used to indicate "any application" */
public static final int SPECIAL_UID_ANY = -10;
/** special application UID used to indicate the Linux Kernel */
public static final int SPECIAL_UID_KERNEL = -11;
/** root script filename */
private static final String SCRIPT_FILE = "droidwall.sh";
private static List<Integer> blackList=new LinkedList<Integer>();
public static void initBlackList(){
}
/**
* Purge and re-add all rules (internal implementation).
* @param ctx application context (mandatory)
* @param uidsWifi list of selected UIDs for WIFI to allow or disallow (depending on the working mode)
* @param uids3g list of selected UIDs for 2G/3G to allow or disallow (depending on the working mode)
* @param showErrors indicates if errors should be alerted
*/
public static String applyIptablesRulesImpl(Context ctx, List<Integer> uids3g,boolean showErrors) {
if (ctx == null) {
return "";
}
assertBinaries(ctx, showErrors);
final String ITFS_3G[] = {"rmnet+","pdp+","ppp+","uwbr+","wimax+","vsnet+"};
//final String ITFS_3G[] = {"rmnet+","pdp+","ppp+","uwbr+"};
final boolean whitelist = false;
final boolean blacklist = !whitelist;
final StringBuilder script = new StringBuilder();
try {
script.append(scriptHeader(ctx));
script.append("" +
"$IPTABLES --version || exit 1\n" +
"# Create the droidwall chains if necessary\n" +
"$IPTABLES -L droidwall >/dev/null 2>/dev/null || $IPTABLES --new droidwall || exit 2\n" +
"$IPTABLES -L droidwall-3g >/dev/null 2>/dev/null || $IPTABLES --new droidwall-3g || exit 3\n" +
"$IPTABLES -L droidwall-wifi >/dev/null 2>/dev/null || $IPTABLES --new droidwall-wifi || exit 4\n" +
"$IPTABLES -L droidwall-reject >/dev/null 2>/dev/null || $IPTABLES --new droidwall-reject || exit 5\n" +
"# Add droidwall chain to OUTPUT chain if necessary\n" +
"$IPTABLES -L OUTPUT | $GREP -q droidwall || $IPTABLES -A OUTPUT -j droidwall || exit 6\n" +
"# Flush existing rules\n" +
"$IPTABLES -F droidwall || exit 7\n" +
"$IPTABLES -F droidwall-3g || exit 8\n" +
"$IPTABLES -F droidwall-wifi || exit 9\n" +
"$IPTABLES -F droidwall-reject || exit 10\n" +
"");
// Check if logging is enabled
script.append("" +
"# Create the reject rule (log disabled)\n" +
"$IPTABLES -A droidwall-reject -j REJECT || exit 11\n" +
"");
script.append("# Main rules (per interface)\n");
for (final String itf : ITFS_3G) {
script.append("$IPTABLES -A droidwall -o ").append(itf).append(" -j droidwall-3g || exit\n");
}
script.append("# Filtering rules\n");
final String targetRule = (whitelist ? "RETURN" : "droidwall-reject");
final boolean any_3g = uids3g.indexOf(SPECIAL_UID_ANY) >= 0;
if (any_3g) {
if (blacklist) {
/* block any application on this interface */
script.append("$IPTABLES -A droidwall-3g -j ").append(targetRule).append(" || exit\n");
}
} else {
/* release/block individual applications on this interface */
for (final Integer uid : uids3g) {
if (uid >= 0) script.append("$IPTABLES -A droidwall-3g -m owner --uid-owner ").append(uid).append(" -j ").append(targetRule).append(" || exit\n");
}
}
if (whitelist) {
if (!any_3g) {
if (uids3g.indexOf(SPECIAL_UID_KERNEL) >= 0) {
script.append("# hack to allow kernel packets on white-list\n");
script.append("$IPTABLES -A droidwall-3g -m owner --uid-owner 0:999999999 -j droidwall-reject || exit\n");
} else {
script.append("$IPTABLES -A droidwall-3g -j droidwall-reject || exit\n");
}
}
} else {
if (uids3g.indexOf(SPECIAL_UID_KERNEL) >= 0) {
script.append("# hack to BLOCK kernel packets on black-list\n");
script.append("$IPTABLES -A droidwall-3g -m owner --uid-owner 0:999999999 -j RETURN || exit\n");
script.append("$IPTABLES -A droidwall-3g -j droidwall-reject || exit\n");
}
}
final StringBuilder res = new StringBuilder();
Log.v("lck",script.toString());
int code=runScript(ctx, script.toString(), res,40000,true);
if(showErrors&&code<0){
alert(ctx, ctx.getResources().getString(R.string.iptables_applyRule_error) + "\n");
}
return res.toString();
} catch (Exception e) {
}
return "error";
}
/**
* Display a simple alert box
* @param ctx context
* @param msg message
*/
public static void alert(Context ctx, CharSequence msg) {
if (ctx != null) {
new AlertDialog.Builder(ctx)
.setNeutralButton(android.R.string.ok, null)
.setMessage(msg)
.show();
}
}
/**
* Check if we have root access
* @param ctx mandatory context
* @param showErrors indicates if errors should be alerted
* @return boolean true if we have root
*/
public static boolean hasRootAccess(Context ctx, boolean showErrors) {
final StringBuilder res = new StringBuilder();
try {
// Run an empty script just to check root access
if (runScript(ctx, "exit 0", res,-1,true) == 0) {
return true;
}
} catch (Exception e) {
}
if (showErrors) {
alert(ctx, ctx.getResources().getString(R.string.iptables_hasNotRoot_error) + res.toString());
}
return false;
}
/**
* 清除所有规则
* @return 执行结果信息
*/
public static boolean purgeIptables(Context ctx, boolean showErrors) {
StringBuilder res = new StringBuilder();
try {
assertBinaries(ctx,
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
android最新流量监测源码分享 (177个子文件)
all-wcprops 414B
resources.ap_ 984KB
melcome.apk 1.04MB
busybox_g1 115KB
FireWall.class 10KB
mainPage.class 9KB
keepInTime.class 9KB
DatabaseAdapter.class 8KB
setting.class 8KB
AbstractDemoChart.class 7KB
MonitoringService.class 6KB
netList.class 5KB
MonitoringService$1.class 5KB
SetTime.class 5KB
mainPage$1.class 5KB
Round.class 5KB
FlowChart.class 4KB
keepInTime$1.class 4KB
statist.class 4KB
MonthChart.class 4KB
R$id.class 4KB
onGestureListener.class 4KB
setting$5.class 4KB
aboutus.class 3KB
applicationList.class 3KB
netList$AppAdapter.class 3KB
FireWall$ScriptRunner.class 3KB
TrafficMonitoring.class 3KB
applicationList$MyTask.class 3KB
Contact.class 3KB
Left.class 3KB
applicationList$AppAdapter.class 3KB
setting$6$1.class 3KB
netList$1.class 3KB
setting$4$1.class 3KB
setting$6.class 2KB
setting$7.class 2KB
WeekChart.class 2KB
setting$4.class 2KB
setting$3.class 2KB
Parameter.class 2KB
setting$3$1.class 2KB
R$string.class 2KB
mainPage$2.class 2KB
Programme.class 2KB
setting$5$2.class 2KB
setting$5$1.class 2KB
BootBroadcastReceiver.class 2KB
Round$1.class 2KB
setting$1.class 1KB
setting$2.class 1KB
onGestureListener$Current.class 1KB
netList$1$1.class 1KB
setting$7$1.class 1KB
DatabaseAdapter$DatabaseHelper.class 1KB
R$drawable.class 1KB
Application.class 1KB
R$layout.class 1KB
applicationList$1.class 1KB
liuliangjiankong.class 1KB
statist$MonthChartListener.class 1KB
statist$WeekChartListener.class 1KB
statist$DayChartListener.class 1KB
liuliangjiankong$1.class 981B
onGestureListener$SnsConstant.class 682B
R.class 675B
R$raw.class 479B
R$anim.class 442B
IChart.class 360B
R$attr.class 358B
.classpath 390B
Thumbs.db 54KB
classes.dex 161KB
entries 744B
iptables_g1 127KB
iptables_n1 131KB
achartengine-0.6.0.jar 60KB
FireWall.java 18KB
setting.java 14KB
R.java 13KB
mainPage.java 13KB
DatabaseAdapter.java 13KB
keepInTime.java 11KB
AbstractDemoChart.java 8KB
netList.java 8KB
MonitoringService.java 6KB
SetTime.java 5KB
onGestureListener.java 4KB
applicationList.java 4KB
Round.java 4KB
statist.java 4KB
FlowChart.java 3KB
MonthChart.java 3KB
aboutus.java 3KB
TrafficMonitoring.java 2KB
Contact.java 2KB
Parameter.java 2KB
WeekChart.java 2KB
Left.java 1KB
IChart.java 1KB
共 177 条
- 1
- 2
gaobailing
- 粉丝: 0
- 资源: 9
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 937712277954201实习5.word
- 2程序语言基础知识pdf1_1716337722703.jpeg
- 简单的Python示例,演示了如何使用TCP/IP协议进行基本的客户端和服务器通信
- 考试.sql
- keil2 + proteus + 8051.exe
- 1961ee27df03bd4595d28e24b00dde4e_744c805f7e4fb4d40fa3f695bfbab035_8(1).c
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- windows注册表编辑工具
- mediapipe-0.9.0.1-cp37-cp37m-win-amd64.whl.zip
- 校园通行码预约管理系统20240522075502
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页