- 浏览: 11416777 次
文章分类
最新评论
-
wahahachuang8:
我觉得这种东西自己开发太麻烦了,就别自己捣鼓了,找个第三方,方 ...
WebSocket和node.js -
xhpscdx:
写的这么详细,全面,对架构师的工作职责,个人能力都进行了梳理。 ...
架构师之路---王泽宾谈架构师的职责 -
xgbzsc:
是http://www.haoservice.com 吗?
android WIFI定位 -
lehehe:
http://www.haoservice.com/docs/ ...
android WIFI定位 -
lehehe:
http://www.haoservice.com/docs/ ...
android WIFI定位
Android代码混淆前后分析
为了方便站在巨人臂膀上研读源码,特地将自己写的源码进行混淆之后与源码进行比较。
使用混淆的方法在project.properties文件上加入
proguard.config=proguard.cfg这一条代码。关于如何反编译源码,请看之前的一篇博客如何反编绎APK文件。
一、代码结构
1、源码
2、未带混淆机制代码
3、混淆后的代码
从图中可以看出未带混淆机制的代码基本上与源码的结构相同,同时加入了R文件和android.annotation包。而混淆之后的代码删除了TestCommon文件,因为没有任何其他的文件使用到了这个文件当中的方法,因此使用混淆机制后其被删除。
二、MyTabHost代码分析
1、MyTabHost源码
package com.yang.confusion; import android.content.Context; import android.util.AttributeSet; import android.widget.TabHost; public class MyTabHost extends TabHost { public MyTabHost(Context context) { super(context); } public MyTabHost(Context context, AttributeSet attrs) { super(context, attrs); } public TabSpec setIndicator(CharSequence label) { return null; } private String str = null; private static final int FLAG = 1; //测试if public void testIf() { if (str == null) { System.out.println("空"); } } /** * 测试IfElse */ public void testIfElse() { if (str == null) { System.out.println("空"); } else { System.out.println("不空"); } } public void testIfWhile() { if (str == null) { while (str == null) { System.out.println("空"); } } } public void testIfDoWhile() { if (str == null) { do { System.out.println("空"); } while (str == null); } } public void testFor() { for (int i = 0; i < 10; i++) { System.out.println("asdf"); } } public void testForIf() { for (int i = 0; i < 10; i++) { if (i == 1) { System.out.println("asdf"); } } } public void testWhile() { while (str == null) { System.out.println("空"); } } @SuppressWarnings("unused") private void testSwitch(int key) { switch (key) { case FLAG: break; default: break; } } }TestActivity
2、未带混淆机制MyTabHost代码
package com.yang.confusion; import android.content.Context; import android.util.AttributeSet; import android.widget.TabHost; import android.widget.TabHost.TabSpec; import java.io.PrintStream; public class MyTabHost extends TabHost { private static final int FLAG = 1; private String str = null; public MyTabHost(Context paramContext) { super(paramContext); } public MyTabHost(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); } private void testSwitch(int paramInt) { switch (paramInt) { case 1: } } public TabHost.TabSpec setIndicator(CharSequence paramCharSequence) { return null; } public void testFor() { for (int i = 0; ; i++) { if (i >= 10) return; System.out.println("asdf"); } } public void testForIf() { for (int i = 0; ; i++) { if (i >= 10) return; if (i != 1) continue; System.out.println("asdf"); } } public void testIf() { if (this.str == null) System.out.println("空"); } public void testIfDoWhile() { if (this.str == null) do System.out.println("空"); while (this.str == null); } public void testIfElse() { if (this.str == null) System.out.println("空"); while (true) { return; System.out.println("不空"); } } public void testIfWhile() { if (this.str == null); while (true) { if (this.str != null) return; System.out.println("空"); } } public void testWhile() { while (true) { if (this.str != null) return; System.out.println("空"); } } }
3、混淆后的MyTabHost代码
package com.yang.confusion; import android.content.Context; import android.util.AttributeSet; import android.widget.TabHost; public class MyTabHost extends TabHost { private String a = null; public MyTabHost(Context paramContext, AttributeSet paramAttributeSet) { super(paramContext, paramAttributeSet); } }从中可以看出,只要源码没有进行混淆设置,还是可以读懂的。没有混淆机制的代码,对源码进行相应的改动,具体改动的目的不知道,但是还是可以看懂的。而对于混淆后的代码,对源代码进行了进一步的缩减,对源码当中没有使用到的方法全部删除。
三、TestActivity代码分析
1、TestActivity源码
package com.yang.confusion; import android.app.Activity; import android.os.Bundle; public class TestActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); testIf(); testIfElse(); testIfWhile(); testIfDoWhile(); testFor(); testForIf(); testWhile(); testSwitch(2); } private String str = null; private static final int FLAG = 1; //测试if public void testIf() { if (str == null) { System.out.println("空"); } } /** * 测试IfElse */ public void testIfElse() { if (str == null) { System.out.println("空"); } else { System.out.println("不空"); } } public void testIfWhile() { if (str == null) { while (str == null) { System.out.println("空"); } } } public void testIfDoWhile() { if (str == null) { do { System.out.println("空"); } while (str == null); } } public void testFor() { for (int i = 0; i < 10; i++) { System.out.println("asdf"); } } public void testForIf() { for (int i = 0; i < 10; i++) { if (i == 1) { System.out.println("asdf"); } } } public void testWhile() { while (str == null) { System.out.println("空"); } } private void testSwitch(int key) { switch (key) { case FLAG: break; default: break; } } }
2、未带混淆机制的TestActivity代码
package com.yang.confusion; import android.app.Activity; import android.os.Bundle; import java.io.PrintStream; public class TestActivity extends Activity { private static final int FLAG = 1; private String str = null; private void testSwitch(int paramInt) { switch (paramInt) { case 1: } } protected void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); testIf(); testIfElse(); testIfWhile(); testIfDoWhile(); testFor(); testForIf(); testWhile(); testSwitch(2); } public void testFor() { for (int i = 0; ; i++) { if (i >= 10) return; System.out.println("asdf"); } } public void testForIf() { for (int i = 0; ; i++) { if (i >= 10) return; if (i != 1) continue; System.out.println("asdf"); } } public void testIf() { if (this.str == null) System.out.println("空"); } public void testIfDoWhile() { if (this.str == null) do System.out.println("空"); while (this.str == null); } public void testIfElse() { if (this.str == null) System.out.println("空"); while (true) { return; System.out.println("不空"); } } public void testIfWhile() { if (this.str == null); while (true) { if (this.str != null) return; System.out.println("空"); } } public void testWhile() { while (true) { if (this.str != null) return; System.out.println("空"); } } }
3、混淆后的TestActivity代码
package com.yang.confusion; import android.app.Activity; import android.os.Bundle; import java.io.PrintStream; public class TestActivity extends Activity { private String a = null; protected void onCreate(Bundle paramBundle) { int i = 0; super.onCreate(paramBundle); if (this.a == null) System.out.println("空"); label44: int j; if (this.a == null) { System.out.println("空"); if (this.a == null) if (this.a == null) break label106; if (this.a == null) do System.out.println("空"); while (this.a == null); j = 0; label75: if (j < 10) break label117; label81: if (i < 10) break label131; } while (true) { if (this.a != null) { return; System.out.println("不空"); break; label106: System.out.println("空"); break label44; label117: System.out.println("asdf"); j++; break label75; label131: if (i == 1) System.out.println("asdf"); i++; break label81; } System.out.println("空"); } } }
四、MainTabHostActivity代码分析
1、MainTabHostActivity源码
package com.yang.tabhost; import android.app.TabActivity; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.View; import android.view.Window; import android.widget.ImageView; import android.widget.RelativeLayout; import android.widget.TabHost; import android.widget.TabWidget; import android.widget.TextView; /** * * @Title: MainTabHostActivity.java * @Package com.yang.tabhost * @Description: MainTabHostActivity * @author Yang * @date 2012-8-13 下午4:35:30 * @version V1.0 */ public class MainTabHostActivity extends TabActivity { private TabHost tabHost; private TabWidget tabWidget; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // No Title bar requestWindowFeature(Window.FEATURE_NO_TITLE); requestWindowFeature(Window.FEATURE_PROGRESS); setContentView(R.layout.main_layout); makeTab(); } private void makeTab() { if (this.tabHost == null) { tabHost = getTabHost(); tabWidget = getTabWidget(); tabHost.setup(); tabHost.bringToFront(); setupChild1(); setupChild2(); } for (int i = 0; i < tabWidget.getChildCount(); i++) { TextView tv = (TextView) tabWidget.getChildAt(i).findViewById( android.R.id.title); android.widget.RelativeLayout.LayoutParams tvp = new android.widget.RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); tvp.addRule(RelativeLayout.ALIGN_PARENT_TOP); tvp.addRule(RelativeLayout.CENTER_HORIZONTAL); tv.setLayoutParams(tvp); ImageView iv = (ImageView) tabWidget.getChildAt(i).findViewById( android.R.id.icon); android.widget.RelativeLayout.LayoutParams ivp = new android.widget.RelativeLayout.LayoutParams( RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); ivp.addRule(RelativeLayout.CENTER_HORIZONTAL); ivp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); iv.setLayoutParams(ivp); // 得到每个tab View vvv = tabWidget.getChildAt(i); // 设置背景色为透明 vvv.setBackgroundColor(Color.TRANSPARENT); // 设置字体颜色和大小 tv.setTextColor(this.getResources() .getColorStateList(R.color.white)); tv.setTextSize(15); } } private void setupChild2() { Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.setClass(this, AnotherChildActivity.class); String name = (String) this.getResources().getText(R.string.allimage); tabHost.addTab(tabHost .newTabSpec(name) .setIndicator(name, getResources().getDrawable(R.drawable.tab_selected)) .setContent(intent)); } private void setupChild1() { Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN); intent.setClass(this, ChildTabHostActivity.class); String name = (String) this.getResources().getText(R.string.onepiece); tabHost.addTab(tabHost .newTabSpec(name) .setIndicator(name, getResources().getDrawable(R.drawable.tab_selected)) .setContent(intent)); } }
2、未带混淆机制的MainTabHostActivity代码
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 tabHost; private TabWidget tabWidget; private void makeTab() { if (this.tabHost == null) { this.tabHost = getTabHost(); this.tabWidget = getTabWidget(); this.tabHost.setup(); this.tabHost.bringToFront(); setupChild1(); setupChild2(); } for (int i = 0; ; i++) { if (i >= this.tabWidget.getChildCount()) return; TextView localTextView = (TextView)this.tabWidget.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.tabWidget.getChildAt(i).findViewById(16908294); RelativeLayout.LayoutParams localLayoutParams2 = new RelativeLayout.LayoutParams(-2, -2); localLayoutParams2.addRule(14); localLayoutParams2.addRule(12); localImageView.setLayoutParams(localLayoutParams2); this.tabWidget.getChildAt(i).setBackgroundColor(0); localTextView.setTextColor(getResources().getColorStateList(2130968578)); localTextView.setTextSize(15.0F); } } private void setupChild1() { Intent localIntent = new Intent(); localIntent.setAction("android.intent.action.MAIN"); localIntent.setClass(this, ChildTabHostActivity.class); String str = (String)getResources().getText(2131034113); this.tabHost.addTab(this.tabHost.newTabSpec(str).setIndicator(str, getResources().getDrawable(2130837512)).setContent(localIntent)); } private void setupChild2() { Intent localIntent = new Intent(); localIntent.setAction("android.intent.action.MAIN"); localIntent.setClass(this, AnotherChildActivity.class); String str = (String)getResources().getText(2131034114); this.tabHost.addTab(this.tabHost.newTabSpec(str).setIndicator(str, getResources().getDrawable(2130837512)).setContent(localIntent)); } protected void onCreate(Bundle paramBundle) { super.onCreate(paramBundle); requestWindowFeature(1); requestWindowFeature(2); setContentView(2130903041); makeTab(); } }3、混淆后的MainTabHostActivity代码
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); } } }
从中可以看出,混淆后的代码难以阅读,但是可以从中找到规律,至于什么规律,博主能力有限,看大家去找了……
相关推荐
Android代码的混淆配置,不熟悉的可以看看挺详细
Android 代码混淆,实例
android 代码混淆自己目前项目所用,真实有效
Android代码混淆的使用情况分析.pdf
Android代码混淆的使用情况分析.docx
介绍了Android代码混淆的三种方法及可能出现的问题.通过jocky或proguard实现jar包混淆;通过proguard实现Android项目整体导出混淆。并总结了一些容易出现的问题
高版本Android项目下的proguard-project.txt,里边包含了常规混淆,以及防止第三方混淆的代码。
Android 反编译和代码混淆里面工具和文档都很全,欢迎大家下载!
Android代码混淆及签名.doc
android ndk+代码混淆demo
新写的proguard代码混淆的文档 大家可以看看
Android混淆打包不混淆第三方jar包Android 混淆打包不混淆第三方jar包
其中包括第三方jar混淆报错及解决办法,以及普通的代码混淆办法,相信能给你帮助
Android代码混淆及签名.docx
得到别人写的AndroidStudio插件,先放着http://www.cnblogs.com/common1140/p/5569934.html 安装完成之后,在顶部Edit的第一个选项就是了
本篇文章主要介绍了Android代码混淆的写法总结,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
Android studio多module混淆成一个Jar
它的功能是混淆构建的dotNet程序集,如assembly csharp和assembly unityscript for Windows/Mac/Linux独立游戏以及Android和IPhone等嵌入式系统。其他平台也有可能,但尚未测试。 Obfuscator Pro考虑了特定的统一...