android146 360 病毒查杀

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ><TextViewandroid:layout_width="match_parent"android:layout_height="60dip"android:background="#8866ff00"android:gravity="center"android:text="病毒查杀"android:textSize="24sp" /><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:orientation="horizontal" ><!--  帧布局是一层层往上盖,所以就是图片的叠加,后添加的在上面,先添加的在下面 --><FrameLayout        android:layout_width="wrap_content"android:layout_height="wrap_content" ><ImageViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="@drawable/ic_scanner_malware" /><ImageViewandroid:id="@+id/iv_scanning"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginRight="10dp"android:background="@drawable/act_scanning_03" /></FrameLayout><LinearLayoutandroid:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginTop="10dp"android:orientation="vertical" ><TextViewandroid:id="@+id/tv_init_virus"android:layout_width="match_parent"android:layout_height="wrap_content"android:gravity="center_horizontal"android:text="初始化8核杀毒引擎" /><ProgressBarandroid:id="@+id/progressBar1"style="?android:attr/progressBarStyleHorizontal"android:layout_width="match_parent"android:layout_height="wrap_content"android:layout_marginLeft="10dp"android:layout_marginRight="10dp" /></LinearLayout></LinearLayout><ScrollViewandroid:id="@+id/scrollView"android:layout_width="match_parent"android:layout_height="match_parent" ><LinearLayoutandroid:id="@+id/ll_content"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical" ></LinearLayout></ScrollView>
</LinearLayout>
package com.itheima.mobileguard.activities;import java.io.File;
import java.io.FileInputStream;
import java.security.MessageDigest;
import java.util.List;import org.w3c.dom.Text;import com.itheima.mobileguard.R;
import com.itheima.mobileguard.db.dao.AntivirusDao;
import com.itheima.mobileguard.domain.AppInfo;
import com.itheima.mobileguard.engine.AppInfoParser;
import com.itheima.mobileguard.utils.Md5Utils;import android.R.bool;
import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.SystemClock;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.RotateAnimation;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Scroller;
import android.widget.TextView;public class AntivirusActivity extends Activity {// 扫描开始protected static final int BEGING = 1;// 扫描中protected static final int SCANING = 2;// 扫描结束protected static final int FINISH = 3;private Message message;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);initUI();initData();}Handler handler = new Handler() {public void handleMessage(android.os.Message msg) {switch (msg.what) {case BEGING:tv_init_virus.setText("初始化八核引擎");break;case SCANING:// 病毒扫描中:TextView child = new TextView(AntivirusActivity.this);ScanInfo scanInfo = (ScanInfo) msg.obj;// 如果为true表示有病毒if (scanInfo.desc) {child.setTextColor(Color.RED);child.setText(scanInfo.appName + "有病毒");} else {child.setTextColor(Color.BLACK);
//                    // 为false表示没有病毒child.setText(scanInfo.appName + "扫描安全");}ll_content.addView(child,0);//自动滚动scrollView.post(new Runnable() {@Overridepublic void run() {//一直往下面进行滚动
                        scrollView.fullScroll(scrollView.FOCUS_DOWN);}});System.out.println(scanInfo.appName + "扫描安全");break;case FINISH:// 当扫描结束的时候。停止动画
                iv_scanning.clearAnimation();break;}};};private TextView tv_init_virus;private ProgressBar pb;private ImageView iv_scanning;private LinearLayout ll_content;private ScrollView scrollView;private void initData() {new Thread() {public void run() {message = Message.obtain();message.what = BEGING;PackageManager packageManager = getPackageManager();// 获取到所有安装的应用程序List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);// 返回手机上面安装了多少个应用程序int size = installedPackages.size();// 设置进度条的最大值
                pb.setMax(size);int progress = 0;for (PackageInfo packageInfo : installedPackages) {ScanInfo scanInfo = new ScanInfo();// 获取到当前手机上面的app的名字String appName = packageInfo.applicationInfo.loadLabel(packageManager).toString();scanInfo.appName = appName;String packageName = packageInfo.applicationInfo.packageName;scanInfo.packageName = packageName;// 首先需要获取到每个应用程序的目录String sourceDir = packageInfo.applicationInfo.sourceDir;// 获取到文件的md5String md5 = Md5Utils.getFileMd5(sourceDir);/*public static String getFileMd5(String sourceDir) {File file = new File(sourceDir);try {FileInputStream fis = new FileInputStream(file);byte[] buffer =  new byte[1024];int len = -1;//获取到数字摘要MessageDigest messageDigest = MessageDigest.getInstance("md5");while((len = fis.read(buffer))!= -1){messageDigest.update(buffer, 0, len);}byte[] result = messageDigest.digest();StringBuffer sb = new StringBuffer();for(byte b : result){int number = b&0xff; // 加盐 +1 ;String hex = Integer.toHexString(number);if(hex.length()==1){sb.append("0"+hex);}else{sb.append(hex);}}return sb.toString();} catch (Exception e) {e.printStackTrace();}return null;}*/// 判断当前的文件是否是病毒数据库里面(根据应用的md5判断是否在病毒库中)String desc = AntivirusDao.checkFileVirus(md5);System.out.println("-------------------------");System.out.println(appName);System.out.println(md5);//                    03-06 07:37:32.505: I/System.out(23660): 垃圾
//                    03-06 07:37:32.505: I/System.out(23660): 51dc6ba54cbfbcff299eb72e79e03668
//                    ["md5":"51dc6ba54cbfbcff299eb72e79e03668","desc":"蝗虫病毒赶快卸载","desc":"蝗虫病毒赶快卸载","desc":"蝗虫病毒赶快卸载"]
//                    B7DA3864FD19C0B2390C9719E812E649// 如果当前的描述信息等于null说明没有病毒if (desc == null) {scanInfo.desc = false;} else {scanInfo.desc = true;}progress++;SystemClock.sleep(100);pb.setProgress(progress);message = Message.obtain();message.what = SCANING;message.obj = scanInfo;handler.sendMessage(message);}message = Message.obtain();message.what = FINISH;handler.sendMessage(message);};}.start();}static class ScanInfo {boolean desc;String appName;String packageName;}private void initUI() {setContentView(R.layout.activity_antivirusa);iv_scanning = (ImageView) findViewById(R.id.iv_scanning);tv_init_virus = (TextView) findViewById(R.id.tv_init_virus);pb = (ProgressBar) findViewById(R.id.progressBar1);ll_content = (LinearLayout) findViewById(R.id.ll_content);scrollView = (ScrollView) findViewById(R.id.scrollView);//图片转起来/*** 第一个参数表示开始的角度 ,第二个参数表示结束的角度,*  第三个参数表示X轴参照自己从0.5开始,第四个参数表示Y轴参照自己从0.5开始,*  初始化旋转动画*/RotateAnimation rotateAnimation = new RotateAnimation(0, 360,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,0.5f);// 设置动画的时间rotateAnimation.setDuration(5000);// 设置动画无限循环
        rotateAnimation.setRepeatCount(Animation.INFINITE);// 开始动画
        iv_scanning.startAnimation(rotateAnimation);}
}
package com.itheima.mobileguard.db.dao;import org.json.JSONObject;import com.google.gson.Gson;
import com.itheima.mobileguard.domain.Virus;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
//主动防御:如果有软件想改变c盘改变浏览器改变注册表就认为是病毒,权限判断就是提醒用户他会改变这些东西。
public class AntivirusDao {/*** 检查当前的md5值是否在病毒数据库*/public static String checkFileVirus(String md5){String desc = null;SQLiteDatabase db = SQLiteDatabase.openDatabase("/data/data/com.itheima.mobileguard/files/antivirus.db", null,SQLiteDatabase.OPEN_READONLY);//查询当前传过来的md5是否在病毒数据库里面Cursor cursor = db.rawQuery("select desc from datable where md5 = ?", new String[]{md5});//判断当前的游标是否可以移动if(cursor.moveToNext()){desc = cursor.getString(0);}cursor.close();return desc;}/*** 添加病毒数据库* @param md5  特征码* @param desc 描述信息*/public static void addVirus(String md5,String desc){SQLiteDatabase db = SQLiteDatabase.openDatabase("/data/data/com.itheima.mobileguard/files/antivirus.db", null,SQLiteDatabase.OPEN_READWRITE);ContentValues values = new ContentValues();values.put("md5", md5);values.put("type", 6);values.put("name", "Android.Troj.AirAD.a");values.put("desc", desc);db.insert("datable", null, values);db.close();}/*** 联网进行更新病毒数据库*/private void updataVirus() {dao = new AntivirusDao();//联网从服务器获取到最新数据的md5的特征码HttpUtils httpUtils = new HttpUtils();String url = "http://192.168.13.126:8080/virus.json";httpUtils.send(HttpMethod.GET, url, new RequestCallBack<String>() {@Overridepublic void onFailure(HttpException arg0, String arg1) {}@Overridepublic void onSuccess(ResponseInfo<String> arg0) {System.out.println(arg0.result);
//                {"md5":"51dc6ba54cbfbcff299eb72e79e03668","desc":"蝗虫病毒赶快卸载"}try {JSONObject jsonObject = new JSONObject(arg0.result);Gson gson = new Gson();//解析jsonVirus virus = gson.fromJson(arg0.result, Virus.class);
//                    String md5 = jsonObject.getString("md5");
//                    String desc = jsonObject.getString("desc");
                    dao.addVirus(virus.md5, virus.desc);} catch (Exception e) {e.printStackTrace();}}});}
}

 

转载于:https://www.cnblogs.com/yaowen/p/5154914.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/419081.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

24 | 二叉树基础(下):有了如此高效的散列表,为什么还需要二叉树?

这节学习一种特殊的二叉树—二叉查找树。它最大的特点是支持动态数据集合的快速插入、删除、查找操作。但是散列表也是支持这些操作的&#xff0c;并且散列表的这些操作比二叉查找树更高效&#xff0c;时间复杂度是 O(1)。 问题引入 既然有高效的散列表&#xff0c;二叉树的地…

【可持久化线段树】【主席树】[HDU4417]Super Mario

Mario is world-famous plumber. His “burly” figure and amazing jumping ability reminded in our memory. Now the poor princess is in trouble again and Mario needs to save his lover. We regard the road to the boss’s castle as a line (the length is n), on ev…

25 | 红黑树(上):为什么工程中都用红黑树这种二叉树?

问题引入 二叉查找树在频繁的动态更新过程中&#xff0c;可能会出现树的高度远大于 log2n 的情况&#xff0c;从而导致各个操作的效率下降。极端情况下&#xff0c;二叉树会退化为链表&#xff0c;时间复杂度会退化到 O(n)。要解决这个复杂度退化的问题&#xff0c;需要设计一…

PHP扩展开发(3)-config.m4

1. 宏命令1.1. dnl 注释 1.2. 扩展的工作方式1.2.1) PHP_ARG_WITH不需要第三方库1.2.2) PHP_ARG_ENABLE依赖第三方库1.3. PHP_REQUIRE_CXX 用于指定这个扩展用到C1.4. PHP_ADD_INCLUDE 指定扩展用到的头文件目录1.5. PHP_CHECK_LIBRARY 指定扩展的PHP_ADD_LIBRARY_WITH_PATH定义…

Rabbitmq如何设置优先级队列?如何限流?如何重试?如何处理幂等性?

优先级队列 方式一&#xff1a;可以通过RabbitMQ管理界面配置队列的优先级属性&#xff0c;如下图的x-max-priority 方式二&#xff1a;代码设置 Map<String,Object> args new HashMap<String,Object>(); args.put("x-max-priority", 10); channel.que…

26 | 红黑树(下):掌握这些技巧,你也可以实现一个红黑树

红黑树的实现&#xff0c;对于基础不太好的同学理解起来困难&#xff08;说的就是我——劝退&#xff09;。学习红黑树的代码实现&#xff0c;对平时做项目开发基本没有太大帮助。对于绝大部分开发工程师来说&#xff0c;这辈子可能都用不着亲手写一个红黑树。 对于我而言&…

【Qt】Qt之进程间通信(Windows消息)【转】

简述 通过上一节的了解&#xff0c;我们可以看出进程通信的方式很多&#xff0c;今天分享下如何利用Windows消息机制来进行不同进程间的通信。 简述效果发送消息 自定义类型与接收窗体发送数据接收消息 设置标题重写nativeEvent效果 发送消息 自定义类型与接收窗体 包含所需库&…

启动nginx服务报错Job for nginx.service failed because the control process exited with error code.

nginx使用service nginx restart报错 启动nginx服务时如果遇到这个错误 Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. 可能原因: 1、配…

几个比58同城交换更好玩的交换玩法

交换&#xff0c;不仅仅是一个经久不息的话题&#xff0c;更是人类自古至今生来就有的行为。货币的产生&#xff0c;为交换带来了便捷&#xff0c;解决了交换的不等价和匹配问题。到今天&#xff0c;社会活动日益丰富&#xff0c;交换赋予了更多的意义和创新。交换的行为&#…

27 | 递归树:如何借助树来求解递归算法的时间复杂度?

目的 借助递归树来分析递归算法的时间复杂度 递归树 递归的思想就是将大问题分解为小问题来求解&#xff0c;然后再将小问题分解为小小问题。这样一层一层地分解&#xff0c;直到问题的数据规模被分解得足够小&#xff0c;不用继续递归分解为止。 如果我们把这个一层一层的…

阿里云IE测试地址

http://ali-aegis.aliyun.com/noPermission.htm 转载于:https://www.cnblogs.com/yexiangwang/p/5163780.html

LightOJ 1422 Halloween Costumes

题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id27130 ------------------------------------------------------------------------------------------------- 模拟一下整个过程是一个栈的操作 很难想到会是区间$DP$ 不过多想想或许可以发现 对于一个…