java反编译 第二部分、异常
2013-01-21 16:41
519 查看
java反编译 第二部分、异常
第二部分、异常下面的代码前提是类中有如下属性, 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;
}
还原后的Java代码
view plaincopy to clipboardprint?
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;
}
还原后的代码如下:
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");
}
}
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;
}
还原后的Java代码
view plaincopy to clipboardprint?
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";
}
注意,这个代码有点诡异,实际代码如下:
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);
}
}
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;
}
实际代码如下:
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;
}
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;
}
实际代码
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");
}
}
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;
}
原始代码
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");
}
}
转载自:http://blog.sina.com.cn/s/blog_637607ec0101236k.html
相关文章推荐
- java基础部分-《第二部分》-异常机…
- 第二部分_第二章 自动内存管理机制(java内存区域与内存溢出异常)
- java中的异常--Exceptions in Java-- 第二部分
- 黑马程序员--面向对象第二部分-内部类、异常--java学习日记6(基础知识)
- 程序开发工具(Java反编译及Linux等)与调试技巧(eclipse,linux)部分数据库插件
- java基础部分-《第二部分》-线程部…
- java运行时异常和编译时异常的区别
- java学习划重点第二部分
- Java编译时异常与运行时异常
- Gradle 教程:第二部分,JAVA PROJECTS【翻译】
- Neo4j Java开发快速指南 - 第二部分
- intellij IDE build出错,无法显示图片,找不到tomcat server,java编译版本过低,异常推出后无法启动项目等常见问题解决
- 读书笔记-HBase in Action-第二部分Advanced concepts-(3)非Javaclient
- Java部分异常及处理
- Java复习笔记-第二部分
- 《java.util.concurrent 包源码阅读》28 Phaser 第二部分
- 应聘Java笔试时可能出现问题及其答案(第二版 第二部分)
- JAVA编译异常
- objective-c学习笔记第四章《objective-c 类(第二部分)与java中的区别》
- JAVA新手学习笔记——JAVA实战经典(李兴华)第二部分A