java class反编译后的代码还原

前言

 java class 利用jad 反编译之后,偶尔回碰到一些不正常的代码,

例如:

label0 :_L1 MISSING_BLOCK_LABEL_30、JVM INSTR ret 7 、JVM INSTR tableswitch 1 3: default 269、 JVM INSTR monitorexit、JVM INSTR monitorenter, JVM INSTR monitorexit、

这些一般是由特殊的for循环、try catch finally语句块、synchronized语句反编译后产生的。

下面,就简单介绍一下,一些反编译后的特殊代码的还原规则。本文在Jdk 1.4.2_08+jad 1.58f下测试。jad 1.5.8f可以到这里http://download.csdn.net/source/470540 下载。

 第一部分、for、while循环

1、普通的循环,原始

[java]  view plain copy
  1. public void f1() {  
  2.         boolean flag = false;  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             for (int i = 0; i < 10; i++) {  
  7.                 flag = Boolean.getBoolean("sys");  
  8.                 if (flag) {  
  9.                     System.exit(0);  
  10.                 }  
  11.             }  
  12.         }  
  13.     }  
  14.    
  15.    
反编译后的代码
[java]  view plain copy
  1. public void f1()  
  2.      {  
  3.          boolean flag = false;  
  4.          if(Boolean.getBoolean("sys"))  
  5.          {  
  6.              System.out.println("sys");  
  7.          } else  
  8.          {  
  9.              for(int i = 0; i < 10; i++)  
  10.              {  
  11.                  flag = Boolean.getBoolean("sys");  
  12.                  if(flag)  
  13.                      System.exit(0);  
  14.              }  
  15.    
  16.          }  
  17.      }  
  18.    
  19.       

2、反编译后代码变的很古怪,这是java原代码

[java]  view plain copy
  1. public void f2() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             check: while (true) {  
  7.                 for (int i = 0; i < list.length; i++) {  
  8.                     if (list[i] == 2) {  
  9.                         continue check;  
  10.                     } else {  
  11.                         break;  
  12.                     }  
  13.                 }  
  14.             }  
  15.         }  
  16.     }  
  17.    
  18.        
Java反编译后的代码,部分逻辑丢失。
[java]  view plain copy
  1. public void f2()  
  2.      {  
  3.          int list[] = {  
  4.              1234  
  5.          };  
  6.          if(Boolean.getBoolean("sys"))  
  7.              System.out.println("sys");  
  8.          else  
  9.              do  
  10.              {  
  11.                  int i = 0;  
  12.                  if(i >= list.length || list[i] != 2);  
  13.              } while(true);  
  14.      }  
  15.    
  16.       

3、就是比f2()多了一行System.out.println("list[i]");,反编译后也挺怪的。源码如下:

[java]  view plain copy
  1. public void f3() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             check: while (true) {  
  7.                 for (int i = 0; i < list.length; i++) {  
  8.                     System.out.println("list[i]");  
  9.                     if (list[i] == 2) {  
  10.                         continue check;  
  11.                     } else {  
  12.                         break;  
  13.                     }  
  14.                 }  
  15.             }  
  16.         }  
  17.     }  
  18.        
反编译后的代码:
[java]  view plain copy
  1. public void f3()  
  2.      {  
  3.          int list[] = {  
  4.              1234  
  5.          };  
  6.          if(Boolean.getBoolean("sys"))  
  7.              System.out.println("sys");  
  8.          else  
  9.              do  
  10.              {  
  11.                  int i;  
  12.                  do  
  13.                      i = 0;  
  14.                  while(i >= list.length);  
  15.                  System.out.println("list[i]");  
  16.                  if(list[i] != 2);  
  17.              } while(true);  
  18.      }  
  19.    
  20.       

4、f2()中的break语言,移动了位置。源码如下:

[java]  view plain copy
  1. public void f4() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             check: while (true) {  
  7.                 for (int i = 0; i < list.length; i++) {  
  8.                     if (list[i] == 2) {  
  9.                         continue check;  
  10.                     }  
  11.                 }  
  12.                 break;  
  13.             }  
  14.         }  
  15.     }  
  16.    
  17.        
反编译后代码:
[java]  view plain copy
  1. public void f4()  
  2.      {  
  3.          int list[] = {  
  4.              1234  
  5.          };  
  6.          int i;  
  7.          if(Boolean.getBoolean("sys"))  
  8.              System.out.println("sys");  
  9.          else  
  10.  label0:  
  11.              do  
  12.              {  
  13.                  for(i = 0; i < list.length; i++)  
  14.                      if(list[i] == 2)  
  15.                          continue label0;  
  16.    
  17.                  break;  
  18.              } while(true);  
  19.      }  
  20.    
  21.       

5、就是比f4()多了一行System.out.println("list[i]");,反编译后相当怪的。源码如下:

[java]  view plain copy
  1. public void f5() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             check: while (true) {  
  7.                 for (int i = 0; i < list.length; i++) {  
  8.                     System.out.println("list[i]");  
  9.                     if (list[i] == 2) {  
  10.                         continue check;  
  11.                     }  
  12.                 }  
  13.                 break;  
  14.             }  
  15.         }  
  16.     }  
  17.        
反编译后比较晕的代码:
[java]  view plain copy
  1. public void f5()  
  2.      {  
  3.          int list[] = {  
  4.              1234  
  5.          };  
  6.          if(!Boolean.getBoolean("sys")) goto _L2; else goto _L1  
  7.  _L1:  
  8.          System.out.println("sys");  
  9.            goto _L3  
  10.  _L2:  
  11.          int i = 0;  
  12.            goto _L4  
  13.  _L6:  
  14.          System.out.println("list[i]");  
  15.          if(list[i] != 2goto _L5; else goto _L2  
  16.  _L5:  
  17.          i++;  
  18.  _L4:  
  19.          if(i < list.length) goto _L6; else goto _L3  
  20.  _L3:  
  21.      }  
  22.       

6、就是比f5()多了一行System.exit(0);代码,但是差异确很大。源码如下:

[java]  view plain copy
  1. public void f6() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             check: while (true) {  
  7.                 for (int i = 0; i < list.length; i++) {  
  8.                     System.out.println("list[i]");  
  9.                     if (list[i] == 2) {  
  10.                         continue check;  
  11.                     }  
  12.                 }  
  13.                 System.exit(0);  
  14.                 break;  
  15.             }  
  16.         }  
  17.     }  
  18.        
编译后代码,比f5()差异太大了。
[java]  view plain copy
  1. public void f6()  
  2.      {  
  3.          int list[];  
  4.          list = (new int[] {  
  5.              1234  
  6.          });  
  7.          if(Boolean.getBoolean("sys"))  
  8.          {  
  9.              System.out.println("sys");  
  10.              break MISSING_BLOCK_LABEL_75;  
  11.          }  
  12.  _L2:  
  13.          int i = 0;  
  14.            goto _L1  
  15.  _L5:  
  16.          System.out.println("list[i]");  
  17.          if(list[i] != 2goto _L3; else goto _L2  
  18.  _L3:  
  19.          i++;  
  20.  _L1:  
  21.          if(i < list.length) goto _L5; else goto _L4  
  22.  _L4:  
  23.          System.exit(0);  
  24.      }  
  25.       

7、差异就是f6()中的System.exit(0);移动了位置,但是差异确很大。源码如下:

[java]  view plain copy
  1. public void f7() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             check: while (true) {  
  7.                 for (int i = 0; i < list.length; i++) {  
  8.                     System.out.println("list[i]");  
  9.                     if (list[i] == 2) {  
  10.                         continue check;  
  11.                     }  
  12.                 }  
  13.                 break;  
  14.             }  
  15.             System.exit(0);  
  16.         }  
  17.     }  
  18.        
编译后代码,比f6()差异太大了。
[java]  view plain copy
  1. public void f7()  
  2.      {  
  3.          int list[];  
  4.          list = (new int[] {  
  5.              1234  
  6.          });  
  7.          if(Boolean.getBoolean("sys"))  
  8.          {  
  9.              System.out.println("sys");  
  10.              break MISSING_BLOCK_LABEL_75;  
  11.          }  
  12.  _L2:  
  13.          int i = 0;  
  14.            goto _L1  
  15.  _L5:  
  16.          System.out.println("list[i]");  
  17.          if(list[i] != 2goto _L3; else goto _L2  
  18.  _L3:  
  19.          i++;  
  20.  _L1:  
  21.          if(i < list.length) goto _L5; else goto _L4  
  22.  _L4:  
  23.          System.exit(0);  
  24.      }  
  25.       

8、逻辑和f7比没有变,只是多了一些System.out.println()代码。

[java]  view plain copy
  1. public void f8() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             System.out.println(":check while");  
  7.             check: while (true) {  
  8.                 System.out.println("for");  
  9.                 for (int i = 0; i < list.length; i++) {  
  10.                     System.out.println("list[i]");  
  11.                     if (list[i] == 2) {  
  12.                         continue check;  
  13.                     }  
  14.                 }  
  15.                 System.out.println("break");  
  16.                 break;  
  17.             }  
  18.             System.out.println("exit(0)");  
  19.             System.exit(0);  
  20.         }  
  21.     }  
  22.       
反编译后的代码:和f7()比较一下,基本就可以确定反编译后的代码对应关系了。
[java]  view plain copy
  1. public void f8()  
  2.      {  
  3.          int list[];  
  4.          list = (new int[] {  
  5.              1234  
  6.          });  
  7.          if(Boolean.getBoolean("sys"))  
  8.          {  
  9.              System.out.println("sys");  
  10.              break MISSING_BLOCK_LABEL_107;  
  11.          }  
  12.          System.out.println(":check while");  
  13.  _L2:  
  14.          int i;  
  15.          System.out.println("for");  
  16.          i = 0;  
  17.            goto _L1  
  18.  _L5:  
  19.          System.out.println("list[i]");  
  20.          if(list[i] != 2goto _L3; else goto _L2  
  21.  _L3:  
  22.          i++;  
  23.  _L1:  
  24.          if(i < list.length) goto _L5; else goto _L4  
  25.  _L4:  
  26.          System.out.println("break");  
  27.          System.out.println("exit(0)");  
  28.          System.exit(0);  
  29.      }  
  30.       

9、逻辑和f8比没有变,只是多了一行System.out.println()代码,导致了反编译后的/* Loop/switch isn't completed */。

[java]  view plain copy
  1. public void f9() {  
  2.         int[] list = new int[] { 1234 };  
  3.         if (Boolean.getBoolean("sys")) {  
  4.             System.out.println("sys");  
  5.         } else {  
  6.             System.out.println(":check while");  
  7.             check: while (true) {  
  8.                 System.out.println("for");  
  9.                 for (int i = 0; i < list.length; i++) {  
  10.                     System.out.println("list[i]");  
  11.                     if (list[i] == 2) {  
  12.                         System.out.println("continue check");  
  13.                         continue check;  
  14.                     }  
  15.                 }  
  16.                 System.out.println("break");  
  17.                 break;  
  18.             }  
  19.             System.out.println("exit(0)");  
  20.             System.exit(0);  
  21.         }  
  22.     }  
  23.  }  
  24.        
反编译后的代码:
[java]  view plain copy
  1. public void f9()  
  2.      {  
  3.          int list[] = {  
  4.              1234  
  5.          };  
  6.          if(!Boolean.getBoolean("sys")) goto _L2; else goto _L1  
  7.  _L1:  
  8.          System.out.println("sys");  
  9.            goto _L3  
  10.  _L2:  
  11.          System.out.println(":check while");  
  12.  _L5:  
  13.          System.out.println("for");  
  14.          for(int i = 0; i < list.length; i++)  
  15.          {  
  16.              System.out.println("list[i]");  
  17.              if(list[i] != 2)  
  18.                  continue;  
  19.              System.out.println("continue check");  
  20.              continue/* Loop/switch isn't completed */  
  21.          }  
  22.    
  23.          System.out.println("break");  
  24.          System.out.println("exit(0)");  
  25.          System.exit(0);  
  26.  _L3:  
  27.          return;  
  28.          if(truegoto _L5; else goto _L4  
  29.  _L4:  
  30.      }  
  31.  }  

   第二部分、异常

   下面的代码前提是类中有如下属性,  Calendar cal = Calendar.getInstance();。

    1、Exceptioin的还原    反编译后的代码如下:

[java]  view plain copy
  1. public boolean f1()  
  2.   
  3. {  
  4.   
  5.     return cal.getTime().after(new Date());  
  6.   
  7.     Exception e;  
  8.   
  9.     e;  
  10.   
  11.     e.printStackTrace();  
  12.   
  13.     return false;  
  14.   
  15. }  
还原后的Java代码
[java]  view plain copy
  1. public boolean f1()  
  2.   
  3. {  
  4.   
  5.     try  
  6.   
  7.     {  
  8.   
  9.         return cal.getTime().after(new Date());  
  10.   
  11.     }  
  12.   
  13.     catch (Exception e)  
  14.   
  15.     {  
  16.   
  17.         e.printStackTrace();  
  18.   
  19.         return false;  
  20.   
  21.     }  
  22.   
  23. }  

2、finally代码的还原 反编译后的Java代码如下:

[java]  view plain copy
  1. public boolean f2()  
  2.   
  3. {  
  4.   
  5.     boolean flag = cal.getTime().after(new Date());  
  6.   
  7.     System.out.println("finally");  
  8.   
  9.     return flag;  
  10.   
  11.     Exception e;  
  12.   
  13.     e;  
  14.   
  15.     e.printStackTrace();  
  16.   
  17.     System.out.println("finally");  
  18.   
  19.     return false;  
  20.   
  21.     Exception exception;  
  22.   
  23.     exception;  
  24.   
  25.     System.out.println("finally");  
  26.   
  27.     throw exception;  
  28.   
  29.   
  30.   
  31. }  
还原后的代码如下:
[java]  view plain copy
  1. public boolean f2()  
  2.   
  3. {  
  4.   
  5.     try  
  6.   
  7.     {  
  8.   
  9.         return cal.getTime().after(new Date());  
  10.   
  11.     }  
  12.   
  13.     catch (Exception e)  
  14.   
  15.     {  
  16.   
  17.         e.printStackTrace();  
  18.   
  19.         return false;  
  20.   
  21.     }  
  22.   
  23.     finally  
  24.   
  25.     {  
  26.   
  27.         System.out.println("finally");  
  28.   
  29.     }  
  30.   
  31. }  

3、MISSING_BLOCK_LABEL_的还原反编译后的代码

[java]  view plain copy
  1. public Object f22()  
  2.   
  3. {  
  4.   
  5.     Date date = cal.getTime();  
  6.   
  7.     System.out.println("finally");  
  8.   
  9.     return date;  
  10.   
  11.     Exception e;  
  12.   
  13.     e;  
  14.   
  15.     e.printStackTrace();  
  16.   
  17.     System.out.println("finally");  
  18.   
  19.     break MISSING_BLOCK_LABEL_45;  
  20.   
  21.     Exception exception;  
  22.   
  23.     exception;  
  24.   
  25.     System.out.println("finally");  
  26.   
  27.     throw exception;  
  28.   
  29.     return null;  
  30.   
  31. }  
还原后的Java代码
[java]  view plain copy
  1. public Object f22()  
  2.   
  3. {  
  4.   
  5.     try  
  6.   
  7.     {  
  8.   
  9.         return cal.getTime();  
  10.   
  11.     }  
  12.   
  13.     catch (Exception e)  
  14.   
  15.     {  
  16.   
  17.         e.printStackTrace();  
  18.   
  19.     }  
  20.   
  21.     finally  
  22.   
  23.     {  
  24.   
  25.         System.out.println("finally");  
  26.   
  27.     }  
  28.   
  29.     return null;  
  30.   
  31. }  

4、异常中:label的还原反编译后的代码

[java]  view plain copy
  1. public String f4()  
  2.   
  3.     throws Exception  
  4.   
  5. {  
  6.   
  7. l0:  
  8.   
  9.     {  
  10.   
  11.         try  
  12.   
  13.         {  
  14.   
  15.             Integer i = new Integer(1);  
  16.   
  17.             if(i.intValue() > 0)  
  18.   
  19.             {  
  20.   
  21.                 System.out.println(i);  
  22.   
  23.                 break label0;  
  24.   
  25.             }  
  26.   
  27.   
  28.   
  29.             System.err.println(i);  
  30.   
  31.         }  
  32.   
  33.         catch(Exception dae)  
  34.   
  35.   
  36.   
  37.   
  38.   
  39.   
  40.   
  41.         {  
  42.   
  43.             System.err.println(dae);  
  44.   
  45.             throw new RuntimeException(dae);  
  46.   
  47.         }  
  48.   
  49.         return null;  
  50.   
  51.     }  
  52.   
  53.     return "Hello";  
  54.   
  55. }  
注意,这个代码有点诡异,实际代码如下:
[java]  view plain copy
  1. public String f4() throws Exception  
  2.   
  3.   
  4.   
  5.   
  6.   
  7. {  
  8.   
  9.     try  
  10.   
  11.     {  
  12.   
  13.         Integer i = new Integer(1);  
  14.   
  15.         if (i.intValue() > 0)  
  16.   
  17.         {  
  18.   
  19.             System.out.println(i);  
  20.   
  21.         }  
  22.   
  23.         else  
  24.   
  25.         {  
  26.   
  27.             System.err.println(i);  
  28.   
  29.             return null;  
  30.   
  31.         }  
  32.   
  33.         return "Hello";  
  34.   
  35.     }  
  36.   
  37.     catch (Exception dae)  
  38.   
  39.     {  
  40.   
  41.         System.err.println(dae);  
  42.   
  43.         throw new RuntimeException(dae);  
  44.   
  45.     }  
  46.   
  47.   
  48.   
  49.   
  50.   
  51.   
  52.   
  53. }  

5、典型数据库操作代码还原 反编译后代码

[java]  view plain copy
  1. public HashMap f5()  
  2.   
  3. {  
  4.   
  5.   
  6.   
  7.     Connection conn = null;  
  8.   
  9.     HashMap hashmap;  
  10.   
  11.   
  12.   
  13.     HashMap map = new HashMap();  
  14.   
  15.     Class.forName("");  
  16.   
  17.     conn = DriverManager.getConnection("jdbc:odbc:");  
  18.   
  19.     PreparedStatement pstmt = conn.prepareStatement("select * from table");  
  20.   
  21.     pstmt.setString(1"param");  
  22.   
  23.     String columnVallue;  
  24.   
  25.     for(ResultSet rs = pstmt.executeQuery(); rs.next(); map.put(columnVallue, ""))  
  26.   
  27.         columnVallue = rs.getString("column");  
  28.   
  29.   
  30.   
  31.     hashmap = map;  
  32.   
  33.     if(conn != null)  
  34.   
  35.         try  
  36.   
  37.         {  
  38.   
  39.             conn.close();  
  40.   
  41.         }  
  42.   
  43.         catch(SQLException sqlce)  
  44.   
  45.         {  
  46.   
  47.             sqlce.printStackTrace();  
  48.   
  49.         }  
  50.   
  51.     return hashmap;  
  52.   
  53.     ClassNotFoundException cnfe;  
  54.   
  55.     cnfe;  
  56.   
  57.     cnfe.printStackTrace();  
  58.   
  59.     if(conn != null)  
  60.   
  61.         try  
  62.   
  63.         {  
  64.   
  65.             conn.close();  
  66.   
  67.         }  
  68.   
  69.         catch(SQLException sqlce)  
  70.   
  71.         {  
  72.   
  73.             sqlce.printStackTrace();  
  74.   
  75.         }  
  76.   
  77.     break MISSING_BLOCK_LABEL_188;  
  78.   
  79.     SQLException sqle;  
  80.   
  81.     sqle;  
  82.   
  83.     sqle.printStackTrace();  
  84.   
  85.     if(conn != null)  
  86.   
  87.         try  
  88.   
  89.         {  
  90.   
  91.             conn.close();  
  92.   
  93.         }  
  94.   
  95.         catch(SQLException sqlce)  
  96.   
  97.         {  
  98.   
  99.             sqlce.printStackTrace();  
  100.   
  101.         }  
  102.   
  103.     break MISSING_BLOCK_LABEL_188;  
  104.   
  105.     Exception exception;  
  106.   
  107.     exception;  
  108.   
  109.     if(conn != null)  
  110.   
  111.         try  
  112.   
  113.         {  
  114.   
  115.             conn.close();  
  116.   
  117.         }  
  118.   
  119.         catch(SQLException sqlce)  
  120.   
  121.         {  
  122.   
  123.             sqlce.printStackTrace();  
  124.   
  125.         }  
  126.   
  127.     throw exception;  
  128.   
  129.     return null;  
  130.   
  131. }  
实际代码如下:
[java]  view plain copy
  1. public HashMap f5()  
  2.   
  3. {  
  4.   
  5.   
  6.   
  7.     Connection conn = null;  
  8.   
  9.     try  
  10.   
  11.     {  
  12.   
  13.         HashMap map = new HashMap();  
  14.   
  15.         Class.forName("");  
  16.   
  17.         conn = DriverManager.getConnection("jdbc:odbc:");  
  18.   
  19.         PreparedStatement pstmt = conn.prepareStatement("select * from table");  
  20.   
  21.         pstmt.setString(1"param");  
  22.   
  23.         ResultSet rs = pstmt.executeQuery();  
  24.   
  25.         while (rs.next())  
  26.   
  27.         {  
  28.   
  29.             String columnVallue = rs.getString("column");  
  30.   
  31.             map.put(columnVallue, "");  
  32.   
  33.         }  
  34.   
  35.         return map;  
  36.   
  37.     }  
  38.   
  39.     catch (ClassNotFoundException cnfe)  
  40.   
  41.     {  
  42.   
  43.         cnfe.printStackTrace();  
  44.   
  45.     }  
  46.   
  47.     catch (SQLException sqle)  
  48.   
  49.     {  
  50.   
  51.         sqle.printStackTrace();  
  52.   
  53.     }  
  54.   
  55.     finally  
  56.   
  57.     {  
  58.   
  59.         if (conn != null)  
  60.   
  61.         {  
  62.   
  63.             try  
  64.   
  65.             {  
  66.   
  67.                 conn.close();  
  68.   
  69.             }  
  70.   
  71.             catch (SQLException sqlce)  
  72.   
  73.             {  
  74.   
  75.                 sqlce.printStackTrace();  
  76.   
  77.             }  
  78.   
  79.         }  
  80.   
  81.     }  
  82.   
  83.     return null;  
  84.   
  85. }  

6、两层异常嵌套代码还原 反编译后的代码

[java]  view plain copy
  1. public int f6()  
  2.   
  3. {  
  4.   
  5.     int i = cal.getTime().compareTo(new Date());  
  6.   
  7.     System.out.println("finally");  
  8.   
  9.     return i;  
  10.   
  11.     Exception e1;  
  12.   
  13.     e1;  
  14.   
  15.     e1.printStackTrace();  
  16.   
  17.     System.out.println("finally");  
  18.   
  19.     return -1;  
  20.   
  21.     Exception e2;  
  22.   
  23.     e2;  
  24.   
  25.     e2.printStackTrace();  
  26.   
  27.     System.out.println("finally");  
  28.   
  29.     return -2;  
  30.   
  31.     Exception exception;  
  32.   
  33.     exception;  
  34.   
  35.     System.out.println("finally");  
  36.   
  37.     throw exception;  
  38.   
  39. }  
实际代码
[java]  view plain copy
  1. public int f6()  
  2.   
  3. {  
  4.   
  5.     try  
  6.   
  7.     {  
  8.   
  9.         try  
  10.   
  11.         {  
  12.   
  13.             return cal.getTime().compareTo(new Date());  
  14.   
  15.         }  
  16.   
  17.         catch (Exception e1)  
  18.   
  19.         {  
  20.   
  21.             e1.printStackTrace();  
  22.   
  23.             return -1;  
  24.   
  25.         }  
  26.   
  27.     }  
  28.   
  29.     catch (Exception e2)  
  30.   
  31.     {  
  32.   
  33.         e2.printStackTrace();  
  34.   
  35.         return -2;  
  36.   
  37.     }  
  38.   
  39.     finally  
  40.   
  41.     {  
  42.   
  43.         System.out.println("finally");  
  44.   
  45.     }  
  46.   
  47. }  

7、非常诡异的代码 反编译后的代码

[java]  view plain copy
  1.     public int f7()  
  2.   
  3.     {  
  4.   
  5.         int i = cal.getTime().compareTo(new Date());  
  6.   
  7.         System.out.println("finally");  
  8.   
  9.         return i;  
  10.   
  11.         Exception e1;  
  12.   
  13.         e1;  
  14.   
  15.         e1.printStackTrace();  
  16.   
  17. _L2:  
  18.   
  19.         System.out.println("finally");  
  20.   
  21.         return -1;  
  22.   
  23.         Exception e2;  
  24.   
  25.         e2;  
  26.   
  27.         e2.printStackTrace();  
  28.   
  29.         if(truegoto _L2; else goto _L1  
  30.   
  31. _L1:  
  32.   
  33.         Exception exception;  
  34.   
  35.         exception;  
  36.   
  37.         System.out.println("finally");  
  38.   
  39.         throw exception;  
  40.   
  41.     }  
原始代码
[java]  view plain copy
  1. public int f7()  
  2.   
  3. {  
  4.   
  5.     try  
  6.   
  7.     {  
  8.   
  9.         try  
  10.   
  11.         {  
  12.   
  13.             return cal.getTime().compareTo(new Date());  
  14.   
  15.         }  
  16.   
  17.         catch (Exception e1)  
  18.   
  19.         {  
  20.   
  21.             e1.printStackTrace();  
  22.   
  23.             return -1;  
  24.   
  25.         }  
  26.   
  27.     }  
  28.   
  29.     catch (Exception e2)  
  30.   
  31.     {  
  32.   
  33.         e2.printStackTrace();  
  34.   
  35.         return -1;  
  36.   
  37.     }  
  38.   
  39.     finally  
  40.   
  41.     {  
  42.   
  43.         System.out.println("finally");  
  44.   
  45.     }  
  46.   
  47. }  
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值