com.tadu.android病毒,[Android开发]Android 病毒

病毒:一个特殊计算机程序.

对于病毒的查杀都是基于特征码的识别.杀毒软件都需要有一个病毒信息的数据库.常用病毒数据库2000万条

杀毒引擎: 一套复杂高效的数据库查询算法.

1. 提取文件特征码 1秒

2. 查询特征码是否在数据库里面 8秒

就是根据文件的特征码去病毒数据库中查询,如果能找到就说明这个文件是一个病毒

病毒的查杀

下面以一个文件的MD5编码后的签名来判断是否是病毒

public class AntiVirusActivity extends Activity {

private ImageView iv_scan;

private PackageManager pm;

private TextView scan_status;

private ProgressBar pb;

private LinearLayout ll_container;

private List virusInfos;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_anti_virus);

iv_scan = (ImageView) findViewById(R.id.iv_scan);

RotateAnimation ra = new RotateAnimation(0, 360,

Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF,

1.0f);

ra.setDuration(800);

ra.setRepeatCount(Animation.INFINITE);

ra.setRepeatMode(Animation.RESTART);

iv_scan.startAnimation(ra);

pb = (ProgressBar) findViewById(R.id.progressBar1);

scan_status = (TextView) findViewById(R.id.scan_status);

ll_container = (LinearLayout) findViewById(R.id.ll_container);

pm = getPackageManager();

virusInfos = new ArrayList();

new AsyncTask() {

@Override

protected Void doInBackground(Void... params) {

// 检查应用程序的签名 是否在病毒数据库里面.

try {

Thread.sleep(500);

List infos = pm

.getInstalledPackages(PackageManager.GET_UNINSTALLED_PACKAGES

| PackageManager.GET_SIGNATURES);

pb.setMax(infos.size());

int total = 0;

for (PackageInfo info : infos) {

Signature[] signatures = info.signatures;

// 得到应用程序的签名信息, 用签名来判断

String sign = signatures[0].toCharsString();

String md5 = MD5Utils.encode(sign);

String result = VirusDao.findVirsu(md5);

if (result != null) {

publishProgress(info, true);

virusInfos.add(info);

} else {

publishProgress(info, false);

}

total++;

pb.setProgress(total);

Thread.sleep(40);

}

} catch (InterruptedException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

return null;

}

@Override

protected void onPreExecute() {

scan_status.setText("正在初始化双核杀毒引擎...");

super.onPreExecute();

}

@Override

protected void onPostExecute(Void result) {

scan_status.setText("扫描完毕!");

iv_scan.clearAnimation();

if (virusInfos.size() > 0) {

AlertDialog.Builder builder = new Builder(

AntiVirusActivity.this);

builder.setTitle("发现病毒");

builder.setMessage("是否立刻清理?");

builder.setPositiveButton("确定", new OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

for (PackageInfo info : virusInfos) {

Intent intent = new Intent();

intent.setAction(Intent.ACTION_DELETE);

intent.setData(Uri.parse("package:"

+ info.packageName));

startActivity(intent);

}

}

});

builder.setNegativeButton("取消", new OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

// TODO Auto-generated method stub

}

});

builder.show();

}

super.onPostExecute(result);

}

@Override

protected void onProgressUpdate(Object... values) {

PackageInfo packinfo = (PackageInfo) values[0];

Boolean result = (Boolean) values[1];

scan_status.setText("正在扫描:"

+ packinfo.applicationInfo.loadLabel(pm));

TextView tv = new TextView(getApplicationContext());

tv.setTextSize(16);

if (result) {// 发现病毒

tv.setTextColor(Color.RED);

tv.setText("发现病毒程序:"

+ packinfo.applicationInfo.loadLabel(pm));

} else {

tv.setTextColor(Color.BLACK);

tv.setText("扫描安全:" + packinfo.applicationInfo.loadLabel(pm));

}

ll_container.addView(tv, 0);

super.onProgressUpdate(values);

}

}.execute();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值