android146 360 病毒查杀
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的android146 360 病毒查杀的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 单片机预备知识(电平、进制转换、字节、数
- 下一篇: GDB调试使用详解