趙雅智_android簡訊竊聽及android簡訊源碼解析

來源:互聯網
上載者:User

標籤:android   簡訊竊取   簡訊備份   簡訊恢複   簡訊監聽   

系統代碼:https://github.com/android

簡訊存在位置

找到android系統資料庫:data-data-com.android.providers.telephony-databases-mmssms.db



簡訊資料庫分析


將mmssms.db表匯出,通過SQLiteexpert查看,如

sms表:簡訊表


表結構分析:

address:簡訊寄件者電話號碼

person:連絡人編號,如果電話薄裡有連絡人則顯示編號,沒有連絡人則顯示null

read:讀取狀態,0為未讀,1為已讀

body:簡訊內容


thread表:線程表


dataL:日期

message_count:簡訊發送的條數

snippet:最後一條簡訊內容

read:簡訊讀取狀態

android簡訊原始碼分析在android系統的簡訊代碼中,AndroidMenifest.xml定義了提供外接查詢的介面

定義了簡訊有關的uri的urimatch操作,例如已讀,未讀,草稿箱,收件匣,寄件匣


步驟
  • 在AndroidMenifest.xml添加存取權限
  • 得到內容解析器
  • 註冊觀察者
    • uri
    • 觀察者
      • handler
        • 當訊息來的時候進行監聽
        • 從資料庫尋找資料,顯示出來
      • 構造器
      • 當資料庫改變時
主要代碼AndroidMenifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.android_readsms"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />    <!-- 簡訊讀取許可權 -->    <uses-permission android:name="android.permission.READ_SMS"/>    <uses-permission android:name="android.permission.WRITE_SMS"/>    <instrumentation android:targetPackage="com.example.android_readsms" android:name="android.test.InstrumentationTestRunner"></instrumentation>    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >        <activity            android:name="com.example.android_readsms.MainActivity"            android:label="@string/app_name" >            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>        <uses-library android:name="android.test.runner"/>    </application></manifest>


MainActivity.java
package com.example.android_readconcats;import java.util.List;import android.os.Bundle;import android.support.v4.app.Fragment;import android.support.v4.app.FragmentActivity;import android.support.v4.app.FragmentManager;import android.support.v4.app.FragmentTransaction;import android.widget.RadioButton;import android.widget.RadioGroup;import android.widget.RadioGroup.OnCheckedChangeListener;import com.example.android_readphone.fragment.CollectionFragment;import com.example.android_readphone.fragment.ConcactsFragment;import com.example.android_readphone.fragment.GroupFragment;public class MainActivity extends FragmentActivity implementsOnCheckedChangeListener {private RadioGroup rg;private FragmentManager fragmentManager;// 存放的標誌符號private String tags[] = { "collection", "contacts", "group" };@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);// 擷取FragmentManager對象fragmentManager = getSupportFragmentManager();rg = (RadioGroup) findViewById(R.id.radioGroup1);rg.setOnCheckedChangeListener(this);initMain();}/** * 初始化第一個介面 */private void initMain() {// 擷取FragmentTransaction對象FragmentTransaction transaction = fragmentManager.beginTransaction();// 添加收藏transaction.add(R.id.show_content, new CollectionFragment(),"collection");// 提交transaction.commit();}/** * 替換面板 */private void replaceMain(String tag) {// 擷取FragmentTransaction對象FragmentTransaction transaction = fragmentManager.beginTransaction();if ("contacts".equals(tag)) {// 替換連絡人transaction.replace(R.id.show_content, new ConcactsFragment(),"contacts");} else if ("group".equals(tag)) {// 替換添加分組transaction.replace(R.id.show_content, new GroupFragment(), "group");} else if ("collection".equals(tag)) {// 替換添加分組transaction.replace(R.id.show_content, new CollectionFragment(),"collection");}// 提交transaction.commit();}/** * 替換面板 */private void replaceMains(String tag) {Fragment fragmentTag = fragmentManager.findFragmentByTag(tag);if (fragmentTag == null) {if ("contacts".equals(tag)) {fragmentManager.beginTransaction().add(R.id.show_content, new ConcactsFragment(),"contacts").commit();} else if ("group".equals(tag)) {fragmentManager.beginTransaction().add(R.id.show_content, new GroupFragment(), "group").commit();} else if ("collection".equals(tag)) {fragmentManager.beginTransaction().add(R.id.show_content, new CollectionFragment(),"collection").commit();}} else {// 判斷是否真的添加了if (fragmentTag.isAdded()) {fragmentManager.beginTransaction().show(fragmentTag).commit();// 顯示}}// 拿到已經添加的所有片段List<Fragment> fList = fragmentManager.getFragments();// 遍曆所有的片段for (Fragment fragment : fList) {// 判斷tag是否是要顯示的片段if (!tag.equals(fragment.getTag())) {fragmentManager.beginTransaction().hide(fragment).commit();// 隱藏}}}@Overridepublic void onCheckedChanged(RadioGroup group, int checkId) {switch (checkId) {case R.id.rb_collection:replaceMain("collection");break;case R.id.rb_contacts:replaceMain("contacts");break;case R.id.tb_group:replaceMain("group");break;default:break;}}}

運行效果使用DDMS的Emulator Control給模擬器傳送簡訊:

用戶端顯示如下:

涉及知識點:contentprovider內容解析器contentprovider內容觀察者handler
系統內建簡訊源碼:http://download.csdn.net/detail/zhaoyazhi2129/7491105
簡訊備份
  1. 讀取系統裡的簡訊
  2. 將讀取出來的簡訊寫成一個xml檔案(簡訊備份)
  3. 寫好的xml檔案上傳到伺服器
  4. 從伺服器上下載下來,將xml檔案解析出來
  5. 插入到自己建立的資料庫中(簡訊恢複)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.