Android代码搅混前后分析

Android代码混淆前后分析为了方便站在巨人臂膀上研读源码,特地将自己写的源码进行混淆之后与源码进行比较。

Android代码混淆前后分析

为了方便站在巨人臂膀上研读源码,特地将自己写的源码进行混淆之后与源码进行比较。

使用混淆的方法在project.properties文件上加入


2、未带混淆机制代码

Android代码搅混前后分析

3、混淆后的代码

Android代码搅混前后分析

从图中可以看出未带混淆机制的代码基本上与源码的结构相同,同时加入了R文件和android.annotation包。而混淆之后的代码删除了TestCommon文件,因为没有任何其他的文件使用到了这个文件当中的方法,因此使用混淆机制后其被删除。

二、MyTabHost代码分析1、MyTabHost源码

package com.yang.tabhost;import android.app.TabActivity;import android.content.Intent;import android.content.res.Resources;import android.os.Bundle;import android.view.View;import android.widget.ImageView;import android.widget.RelativeLayout.LayoutParams;import android.widget.TabHost;import android.widget.TabHost.TabSpec;import android.widget.TabWidget;import android.widget.TextView;public class MainTabHostActivity extends TabActivity{  private TabHost a;  private TabWidget b;  protected void onCreate(Bundle paramBundle)  {    super.onCreate(paramBundle);    requestWindowFeature(1);    requestWindowFeature(2);    setContentView(2130903041);    if (this.a == null)    {      this.a = getTabHost();      this.b = getTabWidget();      this.a.setup();      this.a.bringToFront();      Intent localIntent1 = new Intent();      localIntent1.setAction("android.intent.action.MAIN");      localIntent1.setClass(this, ChildTabHostActivity.class);      String str1 = (String)getResources().getText(2131034113);      this.a.addTab(this.a.newTabSpec(str1).setIndicator(str1, getResources().getDrawable(2130837512)).setContent(localIntent1));      Intent localIntent2 = new Intent();      localIntent2.setAction("android.intent.action.MAIN");      localIntent2.setClass(this, AnotherChildActivity.class);      String str2 = (String)getResources().getText(2131034114);      this.a.addTab(this.a.newTabSpec(str2).setIndicator(str2, getResources().getDrawable(2130837512)).setContent(localIntent2));    }    for (int i = 0; ; i++)    {      if (i >= this.b.getChildCount())        return;      TextView localTextView = (TextView)this.b.getChildAt(i).findViewById(16908310);      RelativeLayout.LayoutParams localLayoutParams1 = new RelativeLayout.LayoutParams(-2, -2);      localLayoutParams1.addRule(10);      localLayoutParams1.addRule(14);      localTextView.setLayoutParams(localLayoutParams1);      ImageView localImageView = (ImageView)this.b.getChildAt(i).findViewById(16908294);      RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-2, -2);      localLayoutParams2.addRule(14);      localLayoutParams2.addRule(12);      localImageView.setLayoutParams(localLayoutParams2);      this.b.getChildAt(i).setBackgroundColor(0);      localTextView.setTextColor(getResources().getColorStateList(2130968578));      localTextView.setTextSize(15.0F);    }  }}

从中可以看出,混淆后的代码难以阅读,但是可以从中找到规律,至于什么规律,博主能力有限,看大家去找了……源码下载编译后代码下载