Code restoration after Java class decompilation (1)

Source: Internet
Author: User
Tags try catch

After using Jad decompilation, Java class occasionally encounters some abnormal code, such as label0: _ L1 missing_block_label_30, JVM instr RET 7, and JVM instr tableswitch 1 3: default 269, JVM instr monitorexit, and JVM instr monitorenter are generally generated after special for loops, try catch finally statement blocks, and synchronized statements are decompiled. Next, we will briefly introduce the restoration rules for some specially compiled code. This article is tested in JDK 1.4.2 _ 08 + Jad 1.58f. Jad 1.5.8f can be downloaded from the http://download.csdn.net/source/470540 here.

Part 1, for, while loop

1. A common loop, original

public void f1() { boolean flag = false; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { for (int i = 0; i < 10; i++) { flag = Boolean.getBoolean("sys"); if (flag) { System.exit(0); } } } }  

Decompiled code

public void f1()     {         boolean flag = false;         if(Boolean.getBoolean("sys"))         {             System.out.println("sys");         } else         {             for(int i = 0; i < 10; i++)             {                 flag = Boolean.getBoolean("sys");                 if(flag)                     System.exit(0);             }          }     }  

2. The Code becomes odd after decompilation. This is the original Java code.

public void f2() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { check: while (true) { for (int i = 0; i < list.length; i++) { if (list[i] == 2) { continue check; } else { break; } } } } }      

Some logic is lost in the Code decompiled by Java.

public void f2()     {         int list[] = {             1, 2, 3, 4         };         if(Boolean.getBoolean("sys"))             System.out.println("sys");         else             do             {                 int i = 0;                 if(i >= list.length || list[i] != 2);             } while(true);     }  

3. A system. Out. println ("list [I]") is added to F2 (), which is quite strange after decompilation. The source code is as follows:

public void f3() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { check: while (true) { for (int i = 0; i < list.length; i++) { System.out.println("list[i]"); if (list[i] == 2) { continue check; } else { break; } } } } }     

Decompiled code:

public void f3()     {         int list[] = {             1, 2, 3, 4         };         if(Boolean.getBoolean("sys"))             System.out.println("sys");         else             do             {                 int i;                 do                     i = 0;                 while(i >= list.length);                 System.out.println("list[i]");                 if(list[i] != 2);             } while(true);     }  

4. The break language in F2 () moves the location. The source code is as follows:

public void f4() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { check: while (true) { for (int i = 0; i < list.length; i++) { if (list[i] == 2) { continue check; } } break; } } }      

Decompiled code:

public void f4()     {         int list[] = {             1, 2, 3, 4         };         int i;         if(Boolean.getBoolean("sys"))             System.out.println("sys");         else label0:             do             {                 for(i = 0; i < list.length; i++)                     if(list[i] == 2)                         continue label0;                  break;             } while(true);     }  

5. A system. Out. println ("list [I]") is added to F4. it is quite strange after decompilation. The source code is as follows:

public void f5() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { check: while (true) { for (int i = 0; i < list.length; i++) { System.out.println("list[i]"); if (list[i] == 2) { continue check; } } break; } } }     

Code that is dizzy after decompilation:

public void f5()     {         int list[] = {             1, 2, 3, 4         };         if(!Boolean.getBoolean("sys")) goto _L2; else goto _L1 _L1:         System.out.println("sys");           goto _L3 _L2:         int i = 0;           goto _L4 _L6:         System.out.println("list[i]");         if(list[i] != 2) goto _L5; else goto _L2 _L5:         i++; _L4:         if(i < list.length) goto _L6; else goto _L3 _L3:     } 

6. There is a line of system. Exit (0); Code more than F5 (), but the difference is indeed great. The source code is as follows:

public void f6() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { check: while (true) { for (int i = 0; i < list.length; i++) { System.out.println("list[i]"); if (list[i] == 2) { continue check; } } System.exit(0); break; } } }     

The compiled code is much different from F5.

public void f6()     {         int list[];         list = (new int[] {             1, 2, 3, 4         });         if(Boolean.getBoolean("sys"))         {             System.out.println("sys");             break MISSING_BLOCK_LABEL_75;         } _L2:         int i = 0;           goto _L1 _L5:         System.out.println("list[i]");         if(list[i] != 2) goto _L3; else goto _L2 _L3:         i++; _L1:         if(i < list.length) goto _L5; else goto _L4 _L4:         System.exit(0);     } 

7. The difference is that system. Exit (0); In F6 () moves the position, but the difference is indeed great. The source code is as follows:

public void f7() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { check: while (true) { for (int i = 0; i < list.length; i++) { System.out.println("list[i]"); if (list[i] == 2) { continue check; } } break; } System.exit(0); } }     

The compiled code is much different from F6.

public void f7()     {         int list[];         list = (new int[] {             1, 2, 3, 4         });         if(Boolean.getBoolean("sys"))         {             System.out.println("sys");             break MISSING_BLOCK_LABEL_75;         } _L2:         int i = 0;           goto _L1 _L5:         System.out.println("list[i]");         if(list[i] != 2) goto _L3; else goto _L2 _L3:         i++; _L1:         if(i < list.length) goto _L5; else goto _L4 _L4:         System.exit(0);     } 

8. Logic and F7 are not changed, but some system. Out. println () code is added.

public void f8() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { System.out.println(":check while"); check: while (true) { System.out.println("for"); for (int i = 0; i < list.length; i++) { System.out.println("list[i]"); if (list[i] == 2) { continue check; } } System.out.println("break"); break; } System.out.println("exit(0)"); System.exit(0); } }    

Decompiled code: compare it with F7 () to determine the correspondence between decompiled code.

public void f8()     {         int list[];         list = (new int[] {             1, 2, 3, 4         });         if(Boolean.getBoolean("sys"))         {             System.out.println("sys");             break MISSING_BLOCK_LABEL_107;         }         System.out.println(":check while"); _L2:         int i;         System.out.println("for");         i = 0;           goto _L1 _L5:         System.out.println("list[i]");         if(list[i] != 2) goto _L3; else goto _L2 _L3:         i++; _L1:         if(i < list.length) goto _L5; else goto _L4 _L4:         System.out.println("break");         System.out.println("exit(0)");         System.exit(0);     } 

9. The logic and F8 ratio remain unchanged, but there is only one additional line of system. Out. println () code, resulting in/* loop/switch isn't completed */after decompilation */.

public void f9() { int[] list = new int[] { 1, 2, 3, 4 }; if (Boolean.getBoolean("sys")) { System.out.println("sys"); } else { System.out.println(":check while"); check: while (true) { System.out.println("for"); for (int i = 0; i < list.length; i++) { System.out.println("list[i]"); if (list[i] == 2) { System.out.println("continue check"); continue check; } } System.out.println("break"); break; } System.out.println("exit(0)"); System.exit(0); } } }     

Decompiled code:

public void f9()     {         int list[] = {             1, 2, 3, 4         };         if(!Boolean.getBoolean("sys")) goto _L2; else goto _L1 _L1:         System.out.println("sys");           goto _L3 _L2:         System.out.println(":check while"); _L5:         System.out.println("for");         for(int i = 0; i < list.length; i++)         {             System.out.println("list[i]");             if(list[i] != 2)                 continue;             System.out.println("continue check");             continue; /* Loop/switch isn't completed */         }          System.out.println("break");         System.out.println("exit(0)");         System.exit(0); _L3:         return;         if(true) goto _L5; else goto _L4 _L4:     } } 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.