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,这些一般是由特殊的for循环、try catch finally语句块、synchronized语句反编译后产生的。下面,就简单介绍一下,一些反编译后的特殊代码的还原规则。本文在Jdk 1.4.2_08+jad 1.58f下测试。jad 1.5.8f可以到这里/source/470540 下载。
第一部分、for、while循环
1、普通的循环,原始
public void f1() { boolean flag = false; if (("sys")) { ("sys"); } else { for (int i = 0; i < 10; i++) { flag = ("sys"); if (flag) { (0); } } } }反编译后的代码
public void f1() { boolean flag = false; if(("sys")) { ("sys"); } else { for(int i = 0; i < 10; i++) { flag = ("sys"); if(flag) (0); } } }2、反编译后代码变的很古怪,这是java原代码
public void f2() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { check: while (true) { for (int i = 0; i < ; i++) { if (list[i] == 2) { continue check; } else { break; } } } } }Java反编译后的代码,部分逻辑丢失。
public void f2() { int list[] = { 1, 2, 3, 4 }; if(("sys")) ("sys"); else do { int i = 0; if(i >= || list[i] != 2); } while(true); }3、就是比f2()多了一行("list[i]");,反编译后也挺怪的。源码如下:
public void f3() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { check: while (true) { for (int i = 0; i < ; i++) { ("list[i]"); if (list[i] == 2) { continue check; } else { break; } } } } }反编译后的代码:
public void f3() { int list[] = { 1, 2, 3, 4 }; if(("sys")) ("sys"); else do { int i; do i = 0; while(i >= ); ("list[i]"); if(list[i] != 2); } while(true); }4、f2()中的break语言,移动了位置。源码如下:
public void f4() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { check: while (true) { for (int i = 0; i < ; i++) { if (list[i] == 2) { continue check; } } break; } } }反编译后代码:
public void f4() { int list[] = { 1, 2, 3, 4 }; int i; if(("sys")) ("sys"); else label0: do { for(i = 0; i < ; i++) if(list[i] == 2) continue label0; break; } while(true); }5、就是比f4()多了一行("list[i]");,反编译后相当怪的。源码如下:
public void f5() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { check: while (true) { for (int i = 0; i < ; i++) { ("list[i]"); if (list[i] == 2) { continue check; } } break; } } }反编译后比较晕的代码:
public void f5() { int list[] = { 1, 2, 3, 4 }; if(!("sys")) goto _L2; else goto _L1 _L1: ("sys"); goto _L3 _L2: int i = 0; goto _L4 _L6: ("list[i]"); if(list[i] != 2) goto _L5; else goto _L2 _L5: i++; _L4: if(i < ) goto _L6; else goto _L3 _L3: }6、就是比f5()多了一行(0);代码,但是差异确很大。源码如下:
public void f6() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { check: while (true) { for (int i = 0; i < ; i++) { ("list[i]"); if (list[i] == 2) { continue check; } } (0); break; } } }编译后代码,比f5()差异太大了。
public void f6() { int list[]; list = (new int[] { 1, 2, 3, 4 }); if(("sys")) { ("sys"); break MISSING_BLOCK_LABEL_75; } _L2: int i = 0; goto _L1 _L5: ("list[i]"); if(list[i] != 2) goto _L3; else goto _L2 _L3: i++; _L1: if(i < ) goto _L5; else goto _L4 _L4: (0); }7、差异就是f6()中的(0);移动了位置,但是差异确很大。源码如下:
public void f7() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { check: while (true) { for (int i = 0; i < ; i++) { ("list[i]"); if (list[i] == 2) { continue check; } } break; } (0); } }编译后代码,比f6()差异太大了。
public void f7() { int list[]; list = (new int[] { 1, 2, 3, 4 }); if(("sys")) { ("sys"); break MISSING_BLOCK_LABEL_75; } _L2: int i = 0; goto _L1 _L5: ("list[i]"); if(list[i] != 2) goto _L3; else goto _L2 _L3: i++; _L1: if(i < ) goto _L5; else goto _L4 _L4: (0); }8、逻辑和f7比没有变,只是多了一些()代码。
public void f8() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { (":check while"); check: while (true) { ("for"); for (int i = 0; i < ; i++) { ("list[i]"); if (list[i] == 2) { continue check; } } ("break"); break; } ("exit(0)"); (0); } }反编译后的代码:和f7()比较一下,基本就可以确定反编译后的代码对应关系了。
public void f8() { int list[]; list = (new int[] { 1, 2, 3, 4 }); if(("sys")) { ("sys"); break MISSING_BLOCK_LABEL_107; } (":check while"); _L2: int i; ("for"); i = 0; goto _L1 _L5: ("list[i]"); if(list[i] != 2) goto _L3; else goto _L2 _L3: i++; _L1: if(i < ) goto _L5; else goto _L4 _L4: ("break"); ("exit(0)"); (0); }9、逻辑和f8比没有变,只是多了一行()代码,导致了反编译后的/* Loop/switch isn't completed */。
public void f9() { int[] list = new int[] { 1, 2, 3, 4 }; if (("sys")) { ("sys"); } else { (":check while"); check: while (true) { ("for"); for (int i = 0; i < ; i++) { ("list[i]"); if (list[i] == 2) { ("continue check"); continue check; } } ("break"); break; } ("exit(0)"); (0); } } }反编译后的代码:
public void f9() { int list[] = { 1, 2, 3, 4 }; if(!("sys")) goto _L2; else goto _L1 _L1: ("sys"); goto _L3 _L2: (":check while"); _L5: ("for"); for(int i = 0; i < ; i++) { ("list[i]"); if(list[i] != 2) continue; ("continue check"); continue; /* Loop/switch isn't completed */ } ("break"); ("exit(0)"); (0); _L3: return; if(true) goto _L5; else goto _L4 _L4: } }