现在的位置: 首页 > 综合 > 正文

android 反编译和代码解读

2013年07月23日 ⁄ 综合 ⁄ 共 3388字 ⁄ 字号 评论关闭

http://farwmarth.com/?p=745

 反编译工具小米人改之理:  http://www.xiaomiren.net/apkmodifier/

一  apk反编译

将apk文件解压后有两部分文件需要处理,一种是xml文件,另一种一个dex文件(.dex)

1.对xml文件进行包的解析,一般有两种方式:apktool(推荐)和AXMLPrinter2.jar;
2.从dex到class公认dex2jar.bat,实现反编译;公认的强者;
3.而class到java的方式要更多样化一些,因为只是查看反编译后的代码:jd-gui(推荐),Jodeclipse(Jode的Eclipse插件),JadClipse(Jad的Eclipse插件)。

dex解包
1.首先把apk文件改名为.zip,然后解压缩其中的class.dex文件,它就是java文件编译再通过dx工具打包成的。
2.把class.dex拷贝到dex2jar.bat所在目录。运行dex2jar.bat class.dex,生成classes.dex.dex2jar.jar。
3.运行JD-GUI工具(绿色软件,好用的软件!),打开上面的jar文件,即可看到java源代码。
4 file-saveall将java源码保存为zip文件

资源文件解包
1 安装apktool,将apk反编译
image image 
将smali文件包删除.
2 将上一步保存的源码解压,在此建立一个src目录.将源码放入src下,导入到eclipse中.结构如下.
image image 
反编译完成.错误会很多..可以选择不同的工具来反编译,然后交叉对比.我一般使用jd-ui和jad-eclipse插件来编译.

jad-eclipse配置
image 
image

二 错误代码还原规则

if…else 语句:

反编译代码

 

if (paramBoolean)
        paramTextView.setTextColor(-16727809);
       while (true)
       {
         return;
         paramTextView.setTextColor(-1315861);
       }

 

 还原后

 

      if (paramBoolean)
         {
           paramTextView.setTextColor(-16727809);
         }
         else
         {
            paramTextView.setTextColor(-1315861);
         }  

 

会把if ..esle 反编译成 if …while(true)结构.

 

反编译代码

 

 if (paramInt1 != 1)
        break label185;
      if (this.countChild_1 == null)
      {
        this.countChild_1 = new PokerCountChild(this.mContext);
        this.countChild_1 = new PokerCountChild(this.mContext);
        this.countChild_1.setPosition((int)(0.83D * BaseGameActivity.screenWidth

 

 - this.countChild_1.getWidth()), (int)(0.2D * BaseGameActivity.screenHeight));
        this.countChild_1.setCount(paramInt2);
        addOneChild(this.countChild_1);
        if (paramInt2 == 0)
          this.countChild_1.setAlpha(0);
      }
      this.countChild_1.setCount(paramInt2);
    }
    label185: 
    do
      return;
    while (paramInt1 != 2);
    if (this.countChild_2 == null)
    {
      this.countChild_2 = new PokerCountChild(this.mContext);
      this.countChild_2 = new PokerCountChild(this.mContext);
      this.countChild_2.setPosition((int)(0.17D * BaseGameActivity.screenWidth),

 

 (int)(0.2D * BaseGameActivity.screenHeight));
      this.countChild_2.setCount(paramInt2);
      addOneChild(this.countChild_2);
      if (paramInt2 == 0)
        this.countChild_2.setAlpha(0);
    }
    this.countChild_2.setCount(paramInt2);

 

还原

 

 if(i == 1)
            {
                if(countChild_1 == null)
                {
                    countChild_1 = new PokerCountChild(mContext);
                    countChild_1 = new PokerCountChild(mContext);
                    countChild_1.setPosition((int)(0.83D * 

 

(double)BaseGameActivity.screenWidth - (double)countChild_1.getWidth()), 

 

(int)(0.2D * (double)BaseGameActivity.screenHeight));
                    countChild_1.setCount(j);
                    addOneChild(countChild_1);
                    if(j == 0)
                        countChild_1.setAlpha(0);
                }
                countChild_1.setCount(j);
            } else
            if(i == 2)
            {
                if(countChild_2 == null)
                {
                    countChild_2 = new PokerCountChild(mContext);
                    countChild_2 = new PokerCountChild(mContext);
                    countChild_2.setPosition((int)(0.17D * 

 

(double)BaseGameActivity.screenWidth), (int)(0.2D *

 

 (double)BaseGameActivity.screenHeight));
                    countChild_2.setCount(j);
                    addOneChild(countChild_2);
                    if(j == 0)
                        countChild_2.setAlpha(0);
                }
                countChild_2.setCount(j);
                return;
            }
会将语句倒序,出现break label结构

 

 

反编译代码
image 
jd-gui有时会将whilei语句翻译成if,此处要将if改成while

 

switch语句

反编译代码

 

   switch (this.mBand)
    {
     default:
     case 0:
     case 1:
     case 2:
    }
    while (true)
    {
      return;
      this.mBand.setText("FM1");
      continue;
      this.mBand.setText("FM2");
      continue;
      this.mBand.setText("AM");
    }
还原

 

switch (mBand)
    {
     case 0:
      mBand.setText("FM1");
      break;
     case 1:
       mBand.setText("FM2");
       break;
     case 2:
       mBand.setText("AM");
       break;
     default:
    }

switch规则就是一个continue对应一个case.要注意是是要外层的continue才算数,在if里的continue不算

enum枚举
image 
还原
image

 

jd-gui
http://www.qiaodiqiu.com/how-to-read-java-confusion-after-the-anti-compiled-code.html
http://blog.csdn.net/xyz_fly/article/details/8014455
http://blog.csdn.net/hp_2008/article/details/8626010

jad
http://blog.csdn.net/z3h/article/details/2515287
http://blog.csdn.net/z3h/article/details/2640522

 

抱歉!评论已关闭.