Android weixin service

17674 ワード

概要
長い間考えていたが、なぜAndroid微信のサービスは死ななかったのだろうか.権限が与えられていないし、手動で起動していないのに、なぜ自動的に受信メッセージを開くのですか?おかしい?
どんな方法を採用しても、ソースコードを見て、自分の結論を分析します.
コード解析
AndroidManifest.xmlでのサービスとブロードキャスト
<!--        -->
<receiver
    android:name="com.tencent.mm.booter.NotifyReceiver"
    android:exported="false" />
<receiver android:name="com.tencent.mm.booter.notification.NotificationDeleteReceive" />
<!--      -->
<receiver
    android:name="com.tencent.mm.sandbox.monitor.CrashUploadAlarmReceiver"
    android:exported="false" />

<receiver android:name="com.tencent.mm.booter.MountReceiver" >
    <intent-filter>
        <action android:name="android.intent.action.MEDIA_MOUNTED" />
        <action android:name="android.intent.action.MEDIA_EJECT" />
        <action android:name="android.intent.action.MEDIA_UNMOUNTED" />
        <action android:name="android.intent.action.MEDIA_SHARED" />
        <action android:name="android.intent.action.MEDIA_SCANNER_STARTED" />
        <action android:name="android.intent.action.MEDIA_SCANNER_FINISHED" />
        <action android:name="android.intent.action.MEDIA_REMOVED" />
        <action android:name="android.intent.action.MEDIA_BAD_REMOVAL" />

        <data android:scheme="file" />
    </intent-filter>

</receiver><service android:name="com.tencent.mm.booter.NotifyReceiver$NotifyService" />
<service android:name="com.tencent.mm.modelfriend.AddrBookObserver$AddrBookService" />
<receiver android:name="com.tencent.mm.booter.BluetoothReceiver" > //    
    <intent-filter>
        <action android:name="android.media.SCO_AUDIO_STATE_CHANGED" />
        <action android:name="android.media.ACTION_SCO_AUDIO_STATE_UPDATED" />
    </intent-filter>

</receiver><receiver android:name="com.tencent.mm.booter.InstallReceiver" > //     

    <intent-filter>
        <action android:name="com.android.vending.INSTALL_REFERRER" />//     ?
    </intent-filter>

</receiver>
<receiver
    android:name="com.tencent.mm.booter.MMReceivers$ToolsProcessReceiver" 
    android:exported="false"
    android:process=":tools" />
<receiver
    android:name="com.tencent.mm.plugin.backup.bakpcmodel.BakchatPcmgrNorify" //     
    android:permission="" >

    <intent-filter>
        <action android:name="MMBakchatServiceStart" />
        <action android:name="MMBakchatServiceStop" />
    </intent-filter>

</receiver><service
    android:name="com.tencent.mm.plugin.backup.bakpcmodel.BakchatPcUsbService"
    android:exported="false" >

    <intent-filter>
        <action android:name="com.tencent.mm.plugin.backup.bakpcmodel.BakchatPcUsbService" />
    </intent-filter>

</service><service
    android:name="com.tencent.mm.booter.CoreService"  //    
    android:process=":push" />
<service
    android:name="com.tencent.mm.booter.cache.CacheService" //    
    android:process=":push" />
<receiver
    android:name="com.tencent.mm.booter.MMReceivers$BootReceiver" //    
    android:process=":push" >

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

</receiver><receiver
    android:name="com.tencent.mm.booter.MMReceivers$ConnectionReceiver" //      
    android:process=":push" >

    <intent-filter>
        <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
    </intent-filter>

</receiver><receiver
    android:name="com.tencent.mm.booter.MMReceivers$AlarmReceiver" //   
    android:process=":push" />
<receiver
    android:name="com.tencent.mm.jni.platformcomm.Alarm" //     
    android:exported="false"
    android:process=":push" />
<receiver android:name="com.tencent.mm.plugin.base.stub.WXEntryActivity$EntryReceiver" >

    <intent-filter>
        <action android:name="com.tencent.mm.plugin.openapi.Intent.ACTION_HANDLE_APP_REGISTER" />
        <action android:name="com.tencent.mm.plugin.openapi.Intent.ACTION_HANDLE_APP_UNREGISTER" />
    </intent-filter>

</receiver><service android:name="com.tencent.mm.remoteservice.RemoteService" /> 
<receiver
    android:name="com.tencent.mm.modelstat.WatchDogPushReceiver" //     
    android:exported="false"
    android:process=":push" />
<service android:name="com.tencent.mm.pluginsdk.model.downloader.FileDownloadManger$FileDownloadService" />
<receiver android:name="com.tencent.mm.pluginsdk.model.downloader.FileDownloadManger$FileDownloadReceiver" >

    <intent-filter>
        <action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
        <action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" />
    </intent-filter>

</receiver><service
    android:name="com.tencent.mm.plugin.accountsync.model.AccountAuthenticatorService"
    android:exported="true" >

    <intent-filter>
        <action android:name="android.accounts.AccountAuthenticator" />
    </intent-filter>

    <meta-data
        android:name="android.accounts.AccountAuthenticator"
        android:resource="@xml/g" />

</service><service
    android:name="com.tencent.mm.plugin.accountsync.model.ContactsSyncService"
    android:exported="true" >

    <intent-filter>
        <action android:name="android.content.SyncAdapter" />
    </intent-filter>

    <meta-data
        android:name="android.content.SyncAdapter"
        android:resource="@xml/bf" />
    <meta-data
        android:name="android.provider.CONTACTS_STRUCTURE"
        android:resource="@xml/aa" />

</service><receiver
    android:name="com.tencent.mm.plugin.gcm.modelgcm.GcmBroadcastReceiver"
    android:permission="com.google.android.c2dm.permission.SEND" >

    <intent-filter>
        <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

        <category android:name="com.tencent.mm" />
    </intent-filter>

</receiver><service android:name="com.tencent.mm.plugin.notification.ui.FailSendMsgNotification$FailSendNormalMsgNotificationService" />
<service android:name="com.tencent.mm.plugin.notification.ui.FailSendMsgNotification$FailSendSnsMsgNotificationService" />
<service
    android:name="com.tencent.mm.sandbox.monitor.ExceptionMonitorService"
    android:process=":sandbox" />
<service //  
    android:name="com.tencent.mm.sandbox.updater.UpdaterService"
    android:process=":sandbox" />
<receiver //
    android:name="com.tencent.mm.plugin.shoot.remote.RemoteNetSceneMgr$RespReceiver"
    android:exported="false"
    android:process=":tools" >
 -->

</receiver><receiver //    
    android:name="com.tencent.mm.plugin.shootstub.communicate.ReqReceiver"
    android:exported="false" >

    <intent-filter>
        <action android:name="com.tencent.mm.action.SHOOT_STUB_REQ" />
    </intent-filter>

</receiver>
//web  
<service android:name="com.tencent.mm.plugin.webview.stub.WebViewStubService" />

CoreServiceコアサービス
public class CoreService extends Service implements f, ag, bs {
	private as eoE; //    sdk   
	private ab eoF = new ab(); //     
	private boolean eoG = true;
	public final int eoH = -1213;
	private final ae eoI = new d(this);
	private com.tencent.mm.modelstat.k eoJ = null; //       
	private AddrBookObserver eoK; //        
	private WatchDogPushReceiver eoL; //    (    )
	private WakerLock eoM = null;
	private com.tencent.mm.platformtools.k eoN = new com.tencent.mm.platformtools.k(); //     
	private ax eoO = new ax(new e(this), false);//       (   Handle)

	private void DV() //     
	{
		x.w("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "[COMPLETE EXIT]");
		br.IS().e(3, 10000, "");
		bn.onDestroy();
		try {
			//    
			MMReceivers.AlarmReceiver.ao(getApplicationContext());
			MMReceivers.AlarmReceiver.am(getApplicationContext());
			Alarm.aB(getApplicationContext());
			x.appenderClose(); //     
			Process.killProcess(Process.myPid());
			return;
		} catch (Exception localException) {
		}
	}

	public final void as(boolean paramBoolean) //   start
	{
		if (!paramBoolean) {
			x.w("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "[NETWORK LOST]");
			br.IO().eBE = false;
			br.IP().gn(0);
			br.IN().a(10502, "", null);
			if (this.eoG) {
				br.IR().Iy();
				this.eoF.Ei();
			}
			this.eoG = false;
		}
		while (true) {
			return;
			x.w("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "[NETWORK CONNECTED]");
			br.IO().eBE = true;
			boolean bool = this.eoF.Ej();
			if ((this.eoG) && (!bool)) {
				Object[] arrayOfObject = new Object[1];
				arrayOfObject[0] = Boolean.valueOf(this.eoG);
				x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd",
						"network not change or can't get network info, lastStatus connect:%b",
						arrayOfObject);
			}
			if (bool)
				br.IR().Iy();
			this.eoG = true;
			br.IP().gn(1);
			br.IN().a(10501, "", null);
			if (this.eoM == null)
				this.eoM = new WakerLock(getApplicationContext());
			if (!this.eoM.isLocking())
				this.eoM.lock(14000L);
			x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd",
					"checking ready, start in 7000ms");
			this.eoO.dv(7000L);
		}
	}

	public final boolean b(int paramInt, byte[] paramArrayOfByte)
{
  int i = 0;
  if (getSharedPreferences("system_config_prefs", m.Gh()).getBoolean("settings_fully_exit", true))
    x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "fully exited, no need to notify worker");
  while (true)
  {
    return i;
    Intent localIntent = new Intent(this, NotifyReceiver.class);
    localIntent.putExtra("notify_option_type", 2);
    localIntent.putExtra("notify_uin", this.eoE.ID().qk());
    localIntent.putExtra("notify_respType", paramInt);
    localIntent.putExtra("notify_respBuf", paramArrayOfByte);
    localIntent.putExtra("notfiy_recv_time", cm.Jo());
    localIntent.putExtra("notify_skey", this.eoE.ID().sq());
    x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "notify broadcast:" + localIntent.getAction() + ", type=" + paramInt);
    try
    {
      sendBroadcast(localIntent);
      label165: i = 1;
    }
    catch (Exception localException)
    {
      Object[] arrayOfObject = new Object[1];
      arrayOfObject[i] = localException.toString();
      x.f("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "onNotify hasDestroyed %s", arrayOfObject);
      break label165:
    }
  }
}

	public IBinder onBind(Intent paramIntent) {
		x.d("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "onBind~~~ threadID:"
				+ Thread.currentThread());
		return this.eoE;
	}

	@JgMethodChecked(author=20, fComment="checked", lastDate="20140429", reviewer=20, vComment={com.jg.EType.RECEIVERCHECK})
public void onCreate()
{
  Object localObject = null;
  x.d("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "onCreate~~~threadID:" + Thread.currentThread());
  super.onCreate();
  if (Build.VERSION.SDK_INT < 18) //           
    startForeground(-1213, new Notification());
  ClassLoader localClassLoader = CoreService.class.getClassLoader(); //    
  o.a(com.tencent.mm.sdk.a.jBq, localClassLoader);
  //     jbq  
//  public static String jBq = "wechatbaseprj";
//  public static String jBr = "wechatnetwork";
//  public static String jBs = "wechatxlog";
//  public static String jBt = "wechatkvcomm";
//  public static String jBu = "wechatcdn";
//  public static String jBv = "wechataccessory";
//  public static String jBx = "wechatwebp";
//  public static String jBy = "wechatutils";
  
  ak localak = new ak(Looper.getMainLooper()); //    
  PlatformComm.a(ai.getContext(), localak);//      
  g localg = new g(this); //    
  localg.DX();
  ac.a(this.eoI);
  if (PlatformComm.exG == null) 
    PlatformComm.exG = this;
  br.a(localak); //    
  br.setContext(getApplicationContext());
  br.a(new bt());
  br.a(new bu());
  br.a(this);//    
  if (this.eoJ == null)
    this.eoJ = new com.tencent.mm.modelstat.k(); //     
  br.a(this.eoJ);
  br.a(new bk());
  this.eoE = br.IR();
  if (this.eoE == null)
  {
    x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "autoAuth is null and new one");
    this.eoE = new as(br.Ae());
    br.e(this.eoE);
    label228: bn.onCreate();
    if (br.IS() != null)
      break label551;
    x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "NetTaskAdapter is null and new one");
    br.a(new bp());
  }
  while (true)
  {
    if (br.IT() == null)
    {
      x.i("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "NetTaskAdapter is null and new one");
      br.a(new bo());
      br.IT().eBo = this;
    }
    String str1 = localg.getString(".com.tencent.mm.debug.server.host.http");
    String str2 = localg.getString(".com.tencent.mm.debug.server.ports.http");
    String str3 = localg.getString(".com.tencent.mm.debug.server.host.socket");
    String str4 = localg.getString(".com.tencent.mm.debug.server.ports.socket");
    this.eoE.c(str1, str2, str3, str4);
    String str5 = localg.getString(".com.tencent.mm.debug.server.host.newdns");
    String str6;
    String str7;
    label389: ConnectivityManager localConnectivityManager;
    if ((str5 != null) && (str5.contains(":")))
    {
      String[] arrayOfString = str5.split(":");
      str6 = arrayOfString[0];
      str7 = arrayOfString[1];
      this.eoE.setNewDnsDebugHost(str6, str7);
      MMReceivers.AlarmReceiver.ao(getApplicationContext()); //    
      MMReceivers.AlarmReceiver.an(getApplicationContext());
      localConnectivityManager = (ConnectivityManager)getSystemService("connectivity");
    }
    try
    {
    	//  
      NetworkInfo localNetworkInfo = localConnectivityManager.getActiveNetworkInfo();
      localObject = localNetworkInfo;
      label436: if ((localObject != null) && (localObject.getState() == NetworkInfo.State.CONNECTED))
        break label581;
      br.IO().eBE = false;
      br.IP().gn(0);
      label464: this.eoK = new AddrBookObserver(this);
      getContentResolver().registerContentObserver(com.tencent.mm.pluginsdk.a.aJf(), true, this.eoK);
      this.eoL = new WatchDogPushReceiver();
      registerReceiver(this.eoL, new IntentFilter("com.tencent.mm.WatchDogPushReceiver"));
      o.a(com.tencent.mm.sdk.a.jBy, CoreService.class.getClassLoader());
      return;
      x.w("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "autoAuth is not null and reset");
      this.eoE.reset();
      break label228:
      label551: x.w("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "NetTaskAdapter is not null and reset");
      label581: br.IS().reset();
    }
    catch (Exception localException)
    {
      x.e("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "getActiveNetworkInfo failed.");
      break label436:
      br.IO().eBE = true;
      br.IP().gn(1);
      break label464:
      str6 = str5;
      str7 = null;
      break label389:
    }
  }
}

	public void onDestroy() //   
	{
		x.d("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "onDestroy~~~ threadID:"
				+ Thread.currentThread());
		this.eoJ.a(10002, null, null); //       
		getContentResolver().unregisterContentObserver(this.eoK); //        
		unregisterReceiver(this.eoL); //     
		super.onDestroy();
		DV(); //     
	}

	public void onRebind(Intent paramIntent) {
		x.d("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "onRebind~~~ threadID:"
				+ Thread.currentThread());
		super.onRebind(paramIntent);
	}

	public boolean onUnbind(Intent paramIntent) {
		x.d("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "onUnbind~~~ threadID:"
				+ Thread.currentThread());
		br.IO().a(null); //     
		br.IU().a(null);
		return super.onUnbind(paramIntent);
	}

	public final void restartProcess() //       
	{
		x.w("!32@/B4Tb64lLpIzvC/moQitzBn6RBAuk+sd", "restartProcess");
		DV();
	}
}

結論
なぜそのサービスは死なないのですか?筆者の推測は以下の通りである.
1、反射修正システムの自分のappに関する属性を修正し、自分を放送に受け入れることができる.(ソースコードからはまだ発見されていません)
2、汎用SDKライブラリに呼び出しがあり、QQ、微信、通信録などは1つのライブラリを共用し、このライブラリはこのサービスがあると判断して起動する.(ソースコードからはまだ発見されていません)
3、タイマーサイクルは起動をトリガし、例えば、終了プロセスは時間間隔があり、この間隔を利用してここで互いに起動しますか?(推測、ソースコードは詳細にフォローされていません)
4、Appをシステムレベルとしてシステムディレクトリにインストールする.(ソースコードから見つかりません)
結論が正しいかどうかにかかわらず、自分でテストすれば結果がわかります.