- 浏览: 104001 次
- 性别:
- 来自: 上海
最新评论
-
wangdongjie03:
Java.util.date 与 java.sql.date区别和转换 -
hwujo:
挺好的,谢谢!
http -
nniu520:
像这种不记录任何有效信息的日志,我看在微博里写更合适。
回归整理 -
nniu520:
恩,学习是一个循序渐进且永无止境的过程,与生命类似。
走的太久,都忘记了方向 -
zhangyou1010:
很实用,谢谢了。
oracle监听的设置
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可以到这里http://download.csdn.net/source/470540 下载。
第一部分、for、while循环
1、普通的循环,原始
view plaincopy to clipboardprint?
反编译后的代码 view plaincopy to clipboardprint?
2、反编译后代码变的很古怪,这是java原代码 view plaincopy to clipboardprint?
Java反编译后的代码,部分逻辑丢失。 view plaincopy to clipboardprint?
3、就是比f2()多了一行System.out.println("list[i]");,反编译后也挺怪的。源码如下: view plaincopy to clipboardprint?
反编译后的代码: view plaincopy to clipboardprint?
4、f2()中的break语言,移动了位置。源码如下: view plaincopy to clipboardprint?
反编译后代码: view plaincopy to clipboardprint?
5、就是比f4()多了一行System.out.println("list[i]");,反编译后相当怪的。源码如下: view plaincopy to clipboardprint?
反编译后比较晕的代码: view plaincopy to clipboardprint?
6、就是比f5()多了一行System.exit(0);代码,但是差异确很大。源码如下: view plaincopy to clipboardprint?
编译后代码,比f5()差异太大了。 view plaincopy to clipboardprint?
7、差异就是f6()中的System.exit(0);移动了位置,但是差异确很大。源码如下: view plaincopy to clipboardprint?
编译后代码,比f6()差异太大了。 view plaincopy to clipboardprint?
8、逻辑和f7比没有变,只是多了一些System.out.println()代码。 view plaincopy to clipboardprint?
反编译后的代码:和f7()比较一下,基本就可以确定反编译后的代码对应关系了。 view plaincopy to clipboardprint?
9、逻辑和f8比没有变,只是多了一行System.out.println()代码,导致了反编译后的/* Loop/switch isn't completed */。 view plaincopy to clipboardprint?
反编译后的代码: view plaincopy to clipboardprint?
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可以到这里http://download.csdn.net/source/470540 下载。
第二部分、异常
下面的代码前提是类中有如下属性, Calendar cal = Calendar.getInstance();。
1、Exceptioin的还原 反编译后的代码如下:
view plaincopy to clipboardprint?
public boolean f1()
{
return cal.getTime().after(new Date());
Exception e;
e;
e.printStackTrace();
return false;
}
public boolean f1()
{
return cal.getTime().after(new Date());
Exception e;
e;
e.printStackTrace();
return false;
}
还原后的Java代码 view plaincopy to clipboardprint?
public boolean f1()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
public boolean f1()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
2、finally代码的还原 反编译后的Java代码如下: view plaincopy to clipboardprint?
public boolean f2()
{
boolean flag = cal.getTime().after(new Date());
System.out.println("finally");
return flag;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
return false;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
public boolean f2()
{
boolean flag = cal.getTime().after(new Date());
System.out.println("finally");
return flag;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
return false;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
还原后的代码如下: view plaincopy to clipboardprint?
public boolean f2()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
finally
{
System.out.println("finally");
}
}
public boolean f2()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
finally
{
System.out.println("finally");
}
}
3、MISSING_BLOCK_LABEL_的还原反编译后的代码 view plaincopy to clipboardprint?
public Object f22()
{
Date date = cal.getTime();
System.out.println("finally");
return date;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
break MISSING_BLOCK_LABEL_45;
Exception exception;
exception;
System.out.println("finally");
throw exception;
return null;
}
public Object f22()
{
Date date = cal.getTime();
System.out.println("finally");
return date;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
break MISSING_BLOCK_LABEL_45;
Exception exception;
exception;
System.out.println("finally");
throw exception;
return null;
}
还原后的Java代码 view plaincopy to clipboardprint?
public Object f22()
{
try
{
return cal.getTime();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("finally");
}
return null;
}
public Object f22()
{
try
{
return cal.getTime();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("finally");
}
return null;
}
4、异常中:label的还原反编译后的代码 view plaincopy to clipboardprint?
public String f4()
throws Exception
{
l0:
{
try
{
Integer i = new Integer(1);
if(i.intValue() > 0)
{
System.out.println(i);
break label0;
}
System.err.println(i);
}
catch(Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
return null;
}
return "Hello";
}
public String f4()
throws Exception
{
label0:
{
try
{
Integer i = new Integer(1);
if(i.intValue() > 0)
{
System.out.println(i);
break label0;
}
System.err.println(i);
}
catch(Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
return null;
}
return "Hello";
}
注意,这个代码有点诡异,实际代码如下: view plaincopy to clipboardprint?
public String f4() throws Exception
{
try
{
Integer i = new Integer(1);
if (i.intValue() > 0)
{
System.out.println(i);
}
else
{
System.err.println(i);
return null;
}
return "Hello";
}
catch (Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
}
public String f4() throws Exception
{
try
{
Integer i = new Integer(1);
if (i.intValue() > 0)
{
System.out.println(i);
}
else
{
System.err.println(i);
return null;
}
return "Hello";
}
catch (Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
}
5、典型数据库操作代码还原反编译后代码 view plaincopy to clipboardprint?
public HashMap f5()
{
Connection conn = null;
HashMap hashmap;
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
String columnVallue;
for(ResultSet rs = pstmt.executeQuery(); rs.next(); map.put(columnVallue, ""))
columnVallue = rs.getString("column");
hashmap = map;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
return hashmap;
ClassNotFoundException cnfe;
cnfe;
cnfe.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
SQLException sqle;
sqle;
sqle.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
Exception exception;
exception;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
throw exception;
return null;
}
public HashMap f5()
{
Connection conn = null;
HashMap hashmap;
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
String columnVallue;
for(ResultSet rs = pstmt.executeQuery(); rs.next(); map.put(columnVallue, ""))
columnVallue = rs.getString("column");
hashmap = map;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
return hashmap;
ClassNotFoundException cnfe;
cnfe;
cnfe.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
SQLException sqle;
sqle;
sqle.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
Exception exception;
exception;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
throw exception;
return null;
}
实际代码如下: view plaincopy to clipboardprint?
public HashMap f5()
{
Connection conn = null;
try
{
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
String columnVallue = rs.getString("column");
map.put(columnVallue, "");
}
return map;
}
catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException sqlce)
{
sqlce.printStackTrace();
}
}
}
return null;
}
public HashMap f5()
{
Connection conn = null;
try
{
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
String columnVallue = rs.getString("column");
map.put(columnVallue, "");
}
return map;
}
catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException sqlce)
{
sqlce.printStackTrace();
}
}
}
return null;
}
6、两层异常嵌套代码还原反编译后的代码 view plaincopy to clipboardprint?
public int f6()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
System.out.println("finally");
return -2;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
public int f6()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
System.out.println("finally");
return -2;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
实际代码 view plaincopy to clipboardprint?
public int f6()
{
try
{
try
{
return cal.getTime().compareTo(new Date());
}
catch (Exception e1)
{
e1.printStackTrace();
return -1;
}
}
catch (Exception e2)
{
e2.printStackTrace();
return -2;
}
finally
{
System.out.println("finally");
}
}
public int f6()
{
try
{
try
{
return cal.getTime().compareTo(new Date());
}
catch (Exception e1)
{
e1.printStackTrace();
return -1;
}
}
catch (Exception e2)
{
e2.printStackTrace();
return -2;
}
finally
{
System.out.println("finally");
}
}
7、非常诡异的代码反编译后的代码 view plaincopy to clipboardprint?
public int f7()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
_L2:
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
if(true) goto _L2; else goto _L1
_L1:
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
public int f7()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
_L2:
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
if(true) goto _L2; else goto _L1
_L1:
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
原始代码 view plaincopy to clipboardprint?
public int f7()
{
try
{
try
{
return cal.getTime().compareTo(new Date());
}
catch (Exception e1)
{
e1.printStackTrace();
return -1;
}
}
catch (Exception e2)
{
e2.printStackTrace();
return -1;
}
finally
{
System.out.println("finally");
}
}
第一部分、for、while循环
1、普通的循环,原始
view plaincopy to clipboardprint?
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); } } } }
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); } } } }
反编译后的代码 view plaincopy to clipboardprint?
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); } } }
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、反编译后代码变的很古怪,这是java原代码 view plaincopy to clipboardprint?
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; } } } } }
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; } } } } }
Java反编译后的代码,部分逻辑丢失。 view plaincopy to clipboardprint?
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); }
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、就是比f2()多了一行System.out.println("list[i]");,反编译后也挺怪的。源码如下: view plaincopy to clipboardprint?
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; } } } } }
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; } } } } }
反编译后的代码: view plaincopy to clipboardprint?
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); }
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、f2()中的break语言,移动了位置。源码如下: view plaincopy to clipboardprint?
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; } } }
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; } } }
反编译后代码: view plaincopy to clipboardprint?
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); }
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、就是比f4()多了一行System.out.println("list[i]");,反编译后相当怪的。源码如下: view plaincopy to clipboardprint?
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; } } }
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; } } }
反编译后比较晕的代码: view plaincopy to clipboardprint?
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: }
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、就是比f5()多了一行System.exit(0);代码,但是差异确很大。源码如下: view plaincopy to clipboardprint?
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; } } }
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; } } }
编译后代码,比f5()差异太大了。 view plaincopy to clipboardprint?
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); }
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、差异就是f6()中的System.exit(0);移动了位置,但是差异确很大。源码如下: view plaincopy to clipboardprint?
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); } }
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); } }
编译后代码,比f6()差异太大了。 view plaincopy to clipboardprint?
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); }
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、逻辑和f7比没有变,只是多了一些System.out.println()代码。 view plaincopy to clipboardprint?
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); } }
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); } }
反编译后的代码:和f7()比较一下,基本就可以确定反编译后的代码对应关系了。 view plaincopy to clipboardprint?
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); }
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、逻辑和f8比没有变,只是多了一行System.out.println()代码,导致了反编译后的/* Loop/switch isn't completed */。 view plaincopy to clipboardprint?
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); } } }
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); } } }
反编译后的代码: view plaincopy to clipboardprint?
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: } }
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可以到这里http://download.csdn.net/source/470540 下载。
第二部分、异常
下面的代码前提是类中有如下属性, Calendar cal = Calendar.getInstance();。
1、Exceptioin的还原 反编译后的代码如下:
view plaincopy to clipboardprint?
public boolean f1()
{
return cal.getTime().after(new Date());
Exception e;
e;
e.printStackTrace();
return false;
}
public boolean f1()
{
return cal.getTime().after(new Date());
Exception e;
e;
e.printStackTrace();
return false;
}
还原后的Java代码 view plaincopy to clipboardprint?
public boolean f1()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
public boolean f1()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
}
2、finally代码的还原 反编译后的Java代码如下: view plaincopy to clipboardprint?
public boolean f2()
{
boolean flag = cal.getTime().after(new Date());
System.out.println("finally");
return flag;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
return false;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
public boolean f2()
{
boolean flag = cal.getTime().after(new Date());
System.out.println("finally");
return flag;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
return false;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
还原后的代码如下: view plaincopy to clipboardprint?
public boolean f2()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
finally
{
System.out.println("finally");
}
}
public boolean f2()
{
try
{
return cal.getTime().after(new Date());
}
catch (Exception e)
{
e.printStackTrace();
return false;
}
finally
{
System.out.println("finally");
}
}
3、MISSING_BLOCK_LABEL_的还原反编译后的代码 view plaincopy to clipboardprint?
public Object f22()
{
Date date = cal.getTime();
System.out.println("finally");
return date;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
break MISSING_BLOCK_LABEL_45;
Exception exception;
exception;
System.out.println("finally");
throw exception;
return null;
}
public Object f22()
{
Date date = cal.getTime();
System.out.println("finally");
return date;
Exception e;
e;
e.printStackTrace();
System.out.println("finally");
break MISSING_BLOCK_LABEL_45;
Exception exception;
exception;
System.out.println("finally");
throw exception;
return null;
}
还原后的Java代码 view plaincopy to clipboardprint?
public Object f22()
{
try
{
return cal.getTime();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("finally");
}
return null;
}
public Object f22()
{
try
{
return cal.getTime();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
System.out.println("finally");
}
return null;
}
4、异常中:label的还原反编译后的代码 view plaincopy to clipboardprint?
public String f4()
throws Exception
{
l0:
{
try
{
Integer i = new Integer(1);
if(i.intValue() > 0)
{
System.out.println(i);
break label0;
}
System.err.println(i);
}
catch(Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
return null;
}
return "Hello";
}
public String f4()
throws Exception
{
label0:
{
try
{
Integer i = new Integer(1);
if(i.intValue() > 0)
{
System.out.println(i);
break label0;
}
System.err.println(i);
}
catch(Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
return null;
}
return "Hello";
}
注意,这个代码有点诡异,实际代码如下: view plaincopy to clipboardprint?
public String f4() throws Exception
{
try
{
Integer i = new Integer(1);
if (i.intValue() > 0)
{
System.out.println(i);
}
else
{
System.err.println(i);
return null;
}
return "Hello";
}
catch (Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
}
public String f4() throws Exception
{
try
{
Integer i = new Integer(1);
if (i.intValue() > 0)
{
System.out.println(i);
}
else
{
System.err.println(i);
return null;
}
return "Hello";
}
catch (Exception dae)
{
System.err.println(dae);
throw new RuntimeException(dae);
}
}
5、典型数据库操作代码还原反编译后代码 view plaincopy to clipboardprint?
public HashMap f5()
{
Connection conn = null;
HashMap hashmap;
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
String columnVallue;
for(ResultSet rs = pstmt.executeQuery(); rs.next(); map.put(columnVallue, ""))
columnVallue = rs.getString("column");
hashmap = map;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
return hashmap;
ClassNotFoundException cnfe;
cnfe;
cnfe.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
SQLException sqle;
sqle;
sqle.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
Exception exception;
exception;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
throw exception;
return null;
}
public HashMap f5()
{
Connection conn = null;
HashMap hashmap;
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
String columnVallue;
for(ResultSet rs = pstmt.executeQuery(); rs.next(); map.put(columnVallue, ""))
columnVallue = rs.getString("column");
hashmap = map;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
return hashmap;
ClassNotFoundException cnfe;
cnfe;
cnfe.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
SQLException sqle;
sqle;
sqle.printStackTrace();
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
break MISSING_BLOCK_LABEL_188;
Exception exception;
exception;
if(conn != null)
try
{
conn.close();
}
catch(SQLException sqlce)
{
sqlce.printStackTrace();
}
throw exception;
return null;
}
实际代码如下: view plaincopy to clipboardprint?
public HashMap f5()
{
Connection conn = null;
try
{
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
String columnVallue = rs.getString("column");
map.put(columnVallue, "");
}
return map;
}
catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException sqlce)
{
sqlce.printStackTrace();
}
}
}
return null;
}
public HashMap f5()
{
Connection conn = null;
try
{
HashMap map = new HashMap();
Class.forName("");
conn = DriverManager.getConnection("jdbc:odbc:");
PreparedStatement pstmt = conn.prepareStatement("select * from table");
pstmt.setString(1, "param");
ResultSet rs = pstmt.executeQuery();
while (rs.next())
{
String columnVallue = rs.getString("column");
map.put(columnVallue, "");
}
return map;
}
catch (ClassNotFoundException cnfe)
{
cnfe.printStackTrace();
}
catch (SQLException sqle)
{
sqle.printStackTrace();
}
finally
{
if (conn != null)
{
try
{
conn.close();
}
catch (SQLException sqlce)
{
sqlce.printStackTrace();
}
}
}
return null;
}
6、两层异常嵌套代码还原反编译后的代码 view plaincopy to clipboardprint?
public int f6()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
System.out.println("finally");
return -2;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
public int f6()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
System.out.println("finally");
return -2;
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
实际代码 view plaincopy to clipboardprint?
public int f6()
{
try
{
try
{
return cal.getTime().compareTo(new Date());
}
catch (Exception e1)
{
e1.printStackTrace();
return -1;
}
}
catch (Exception e2)
{
e2.printStackTrace();
return -2;
}
finally
{
System.out.println("finally");
}
}
public int f6()
{
try
{
try
{
return cal.getTime().compareTo(new Date());
}
catch (Exception e1)
{
e1.printStackTrace();
return -1;
}
}
catch (Exception e2)
{
e2.printStackTrace();
return -2;
}
finally
{
System.out.println("finally");
}
}
7、非常诡异的代码反编译后的代码 view plaincopy to clipboardprint?
public int f7()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
_L2:
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
if(true) goto _L2; else goto _L1
_L1:
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
public int f7()
{
int i = cal.getTime().compareTo(new Date());
System.out.println("finally");
return i;
Exception e1;
e1;
e1.printStackTrace();
_L2:
System.out.println("finally");
return -1;
Exception e2;
e2;
e2.printStackTrace();
if(true) goto _L2; else goto _L1
_L1:
Exception exception;
exception;
System.out.println("finally");
throw exception;
}
原始代码 view plaincopy to clipboardprint?
public int f7()
{
try
{
try
{
return cal.getTime().compareTo(new Date());
}
catch (Exception e1)
{
e1.printStackTrace();
return -1;
}
}
catch (Exception e2)
{
e2.printStackTrace();
return -1;
}
finally
{
System.out.println("finally");
}
}
发表评论
-
日期相关-报表
2009-05-23 01:12 1277package com.cd.date; impor ... -
aaa
2009-03-05 21:09 1026import java.util.ArrayList; imp ... -
跟踪每日一题
2009-02-27 21:04 1005import java.util.ArrayList; ... -
编程随想
2009-02-14 22:39 4833只有两样东西可能是无 ... -
java编程规范
2009-02-04 21:04 1040命名规范 定义这个规范的目的是让项目中所有的文档都看起来像一个 ... -
final && static
2009-02-04 20:47 1469一、final 根据程序上下文环境,Java ... -
正则表达式初步
2009-02-04 20:33 10861 为什么用正则表达式? String已经 ... -
Java.util.date 与 java.sql.date区别和转换
2009-02-04 20:31 377071、将java.util.Date 转换为 java.sql. ... -
日期相关总结
2009-02-04 20:11 900Java日期小结 Java 语言的Calendar(日历), ... -
java基础笔记(二)
2009-02-04 20:01 8044、类与对象 4.1、对象的创建和使用 4.1.1、构 ... -
java基础笔记(一)
2009-02-04 19:59 15201、 java编译器 Java提供了 ...
相关推荐
Java类反编译后的代码还原是指将编译后的Java类文件(.class)转换回Java源代码的过程。在这个过程中,可能会出现一些不正常的代码,例如label0 :_L1 MISSING_BLOCK_LABEL_30、JVM INSTR ret 7、JVM INSTR ...
Java Class反编译工具是程序员在处理已编译的字节码文件时不可或缺的辅助工具。这类工具的主要功能是将`.class`文件转换回可读性强的`.java`源代码,帮助开发者理解或修改已有的Java程序,尤其在没有源代码的情况下...
使用XJad或其他现代的Class反编译工具,开发者通常会得到一个与原始源代码相似但不完全一样的结果,因为反编译过程无法完美地还原所有的细节,比如注释、变量名、原始排版等。尽管如此,反编译结果依然足够理解代码...
标题提及的“jdk1.8 class反编译”是指利用特定的工具对JDK 1.8环境下生成的.class文件进行反编译的过程。这个过程中,我们通常会使用到反编译器,例如Procyon。 Procyon是一款开源的Java和.NET编译器及反编译器,...
在某些情况下,我们可能需要查看或理解这些二进制文件的原始Java代码,这时就需要用到"Class文件反编译工具"。 "Class文件反编译工具"是一种专门用来将`.class`和`.jar`文件转换回可读的Java源代码格式的软件。这种...
然而,由于`.class`文件是二进制格式,对于开发者来说,直接阅读它们并不直观,因此出现了“类文件反编译工具”,如标题提到的,用于将`.class`文件转换回可读的Java源代码。 “class文件反编译工具”是一种实用的...
Java编程语言以其跨平台、面向对象的特性深受开发者喜爱,但在某些情况下,我们可能需要将已编译的`.class`文件还原为可读的`.java`源代码,这就是所谓的反编译。在这种需求下,出现了专门用于反编译Java字节码的...
Java类class反编译工具是开发者在理解和学习Java字节码或者进行逆向工程时必不可少的辅助工具。这些工具能够将已经编译过的.class文件转换回可读性强的.java源代码,帮助我们查看和理解已有的Java类结构,尤其是在...
标题中的"Class反编译工具"主要指的是能够解析和转换Java Class文件的工具。Class文件是Java编译后的产物,包含了类定义、方法定义以及元数据等信息。当源代码丢失或者需要查看非开源库的内部实现时,反编译工具就...
这里我们关注的是“class反编译”,这是一个关键的开发工具功能,特别是对于Java开发者而言。标题提到的“class反编译软件”指的是能够将已编译的Java字节码(.class文件)转换回源代码(.java文件)的工具。 描述...
JavaClass反编译是开发者在探索和理解Java代码运行机制时常用的一种技术。jd-gui是一款功能强大的开源工具,专门用于将编译后的.class文件转换回可读的Java源代码,帮助开发者查看和理解二进制字节码背后的逻辑。在...
Java字节码是一种中间语言,由JVM(Java虚拟机)执行,而反编译就是尝试将这种二进制形式还原成人类可读的代码。 2. **Java反编译的用途**: - **代码理解**:当没有源代码时,反编译可以帮助理解第三方库的内部...
Java反编译是将已编译的字节码(.class文件)转换回源代码(.java文件)的过程,这对于理解和学习已有的Java程序、逆向工程或调试都是很有用的。标题提到的"java反编译工具"是用于这个目的的软件,它能够帮助开发者...
本篇文章将详细介绍三种常用的`.class`文件反编译工具:JAD、JD-GUI和FrontEndPlus。 1. **JAD** JAD(Java Decompiler)是一款开源的Java反编译器,它可以将`.class`文件转换回接近原始的Java源代码。JAD支持多种...
标题提到的“class反编译java源码.zip”是一个压缩包,其中包含了一个能够帮助我们把Java字节码(.class)转换回源码(.java)的工具。 首先,我们需要理解什么是.class文件。在Java中,源代码文件(.java)经过编译后...
3. 反编译细节:它可以解析出大部分的Java语法,如循环、条件语句、异常处理等,尽管可能无法完美还原原始源代码的注释和精确格式。 4. 内存友好:jd-gui运行时占用的内存资源相对较少,适合开发者日常使用。 5. ...
类反编译工具的主要功能是将`.class`文件解析并展示为接近原始Java源代码的形式,虽然这种还原并不总是能完全恢复原始代码,但对于理解代码执行流程和调试是非常有帮助的。常见的类反编译工具有JD-GUI、JAD、...
FrontEnd Plus作为压缩包内的文件名,可能是指一个特定的前端开发工具或者框架,与class反编译工具的主题看似无关,但实际上,前端开发中也可能遇到类似的需求,比如JavaScript的.min.js文件的源码还原。前端开发者...