jad反编译心得

工程文件反编译后,首先查看资源文件与配置文件格式是否对的,将src下的R文件放入gen下,修正src下源文件的编码错误.
R.styleable:R下文件的编码错误通常是由资源文件引起的,修改资源文件



通常反编译后类型为Object的,修改其编译类型,如int的则修改为int类型.
null值错误,可以看其类型改为0或""
去掉:import dalvik.annotation.Signature;
去掉: @Signature({“Ljava/util/ArrayList”, “<”, “Lcom/example/android/snake/SnakeView$Coordinate;”, “>;”})
这是反编译时dalvik虚拟机自动生成的.
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语句反编译后产生的。下面,就简单介绍一下,一些反编译后的特殊代码的还原规则。
异常

下面的代码前提是类中有如下属性,

显示代码打印1 Calendar cal = Calendar.getInstance();

1、Exceptioin的还原

反编译后的代码如下:
显示代码打印

public boolean f1() { return cal.getTime().after(new Date()); 
Exception e; 
e; 
e.printStackTrace(); 
return false; 
}

还原后的Java代码
显示代码打印

public boolean f1() { try { return cal.getTime().after(new Date()); 
} catch (Exception e) { e.printStackTrace(); 
return false; 
} }

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

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() { try { return cal.getTime().after(new Date()); 
} catch (Exception e) { e.printStackTrace(); 
return false; 
} finally { System.out.println("finally"); 
} }

3、MISSING_BLOCK_LABEL_的还原反编译后的代码
显示代码打印

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代码
显示代码打印

public Object f22() { try { return cal.getTime(); 
} catch (Exception e) { e.printStackTrace(); 
} finally { System.out.println("finally"); 
} return null; 
}

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

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"; 
}

注意,这个代码有点诡异,实际代码如下:
显示代码打印

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、典型数据库操作代码还原反编译后代码
显示代码打印

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;   
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、两层异常嵌套代码还原反编译后的代码
显示代码打印

01 public int f6() { int i = cal.getTime().compareTo(new Date()); 
02 System.out.println("finally"); 
03 return i; 
04 Exception e1; 
05 e1; 
06 e1.printStackTrace(); 
07 System.out.println("finally"); 
08 return -1; 
09 Exception e2; 
10 e2; 
11 e2.printStackTrace(); 
12 System.out.println("finally"); 
13 return -2; 
14 Exception exception; 
15 exception; 
16 System.out.println("finally"); 
17 throw exception; 
18 }

实际代码
显示代码打印

1 public int f6() { try { try { return cal.getTime().compareTo(new Date()); 
2 } catch (Exception e1) { e1.printStackTrace(); 
3 return -1; 
4 } } catch (Exception e2) { e2.printStackTrace(); 
5 return -2; 
6 } finally { System.out.println("finally"); 
7 } }

7、非常诡异的代码反编译后的代码
显示代码打印

01 public int f7() { int i = cal.getTime().compareTo(new Date()); 
02 System.out.println("finally"); 
03 return i; 
04 Exception e1; 
05 e1; 
06 e1.printStackTrace(); 
07 _L2: System.out.println("finally"); 
08 return -1; 
09 Exception e2; 
10 e2; 
11 e2.printStackTrace(); 
12 if(true) goto _L2; 
13 else goto _L1 _L1: Exception exception; 
14 exception; 
15 System.out.println("finally"); 
16 throw exception; 
17 }

原始代码
显示代码打印

1 public int f7() { try { try { return cal.getTime().compareTo(new Date()); 
2 } catch (Exception e1) { e1.printStackTrace(); 
3 return -1; 
4 } } catch (Exception e2) { e2.printStackTrace(); 
5 return -1; 
6 } finally { System.out.println("finally"); 
7 } }

8.很诡异的JVM INSTR monitorenter ;

显示代码打印

public static ExchangeInfoSequence create()
{
    /*<invalid signature>*/java.lang.Object local = ExchangeInfoSequence.class;
    JVM INSTR monitorenter ;
    return new ExchangeInfoSequence(seq++);
    local;
    JVM INSTR monitorexit ;
    throw ;
}

猜你喜欢

转载自blog.csdn.net/r627179863/article/details/89087331
今日推荐