1、反編譯一個類(包括內部函數、方法、類型、參數)java
package com.bjpowernode.java_learning; public class D118_CustomerService { public boolean login(String name,String pwd) { if("admin".contentEquals(name) && "123".contentEquals(pwd)) { return true; } return false; } public void logout() { System.out.println("系統已經安全退出"); } }
package com.bjpowernode.java_learning; import java.lang.reflect.*; public class D118_1_MethodOfDecompilation { public static void main(String[] args) throws Exception { //獲取類 Class c = Class.forName("com.bjpowernode.java_learning.D118_CustomerService"); //獲取全部方法,Method是reflect中的類,是獲取反編譯的類裏面的方法 Method[] ms = c.getDeclaredMethods(); for (Method m:ms) { //返回修飾符 System.out.println(Modifier.toString(m.getModifiers())); //方法的返回值類型 Class returnType = m.getReturnType(); System.out.println(returnType.getSimpleName()); //返回方法名 System.out.println(m.getName()); //方法的形式參數列表 Class[] parameterTypes = m.getParameterTypes(); for(Class x:parameterTypes) { System.out.println(x.getSimpleName()); } System.out.println("===================="); } StringBuffer sb = new StringBuffer(); sb.append(Modifier.toString(c.getModifiers())+" class "); sb.append(c.getSimpleName()+"{\n"); for(Method m:ms) { sb.append("\t"); sb.append(Modifier.toString(m.getModifiers())+" "); sb.append(m.getReturnType().getSimpleName() + " "); sb.append(m.getName()+"("); //形參 Class[] parameterTypes = m.getParameterTypes(); for (int i=0;i<parameterTypes.length;i++) { Class parameterType = parameterTypes[i]; if(i==parameterTypes.length-1) { sb.append(parameterType.getSimpleName()); }else { sb.append(parameterType.getSimpleName()+","); } } sb.append("){}\n"); } sb.append("}"); System.out.println(sb); } }
2、源碼:node
D118_1_MethodOfDecompilation.javagit
D118_CustomerService.javagithub
https://github.com/ruigege66/Java/blob/master/D118_1_MethodOfDecompilation.java安全
https://github.com/ruigege66/Java/blob/master/D118_CustomerService.java微信
2.CSDN:https://blog.csdn.net/weixin_44630050app
3.博客園:https://www.cnblogs.com/ruigege0000/函數
4.歡迎關注微信公衆號:傅里葉變換,我的公衆號,僅用於學習交流,後臺回覆」禮包「,獲取大數據學習資料學習