IDEA利用jclasslib 修改class文件的實現
file?>settings?>plugis ,搜索安裝jclasslib-bytecode-viewer,重啟idea。
把要修改的class文件用idea打開。
使用jclasslibview?>show bytecode with jclasslib.常量池,使用過濾器過濾文本。找到對應的指向數字。
使用下列代碼更改內容。
package com.yys.screendisplay.controller;import java.io.*;import com.sun.org.apache.bcel.internal.classfile.ConstantString;import org.gjt.jclasslib.io.ClassFileWriter;import org.gjt.jclasslib.structures.ClassFile;import org.gjt.jclasslib.structures.Constant;import org.gjt.jclasslib.structures.constants.ConstantDoubleInfo;import org.gjt.jclasslib.structures.constants.ConstantUtf8Info;import org.gjt.jclasslib.structures.constants.ConstantStringInfo;public class Test { public static void main(String[] args) throws Exception { String filePath = 'C:UsersHMSDesktopAppService.class'; FileInputStream fis = new FileInputStream(filePath); DataInput di = new DataInputStream(fis); ClassFile cf = new ClassFile(); cf.read(di); Constant[] infos = cf.getConstantPool(); int count = infos.length; for (int i = 0; i < count; i++) { if (infos[i] != null) { if(i==1813){ System.out.print(i); System.out.print(' = '); System.out.print(infos[i].getVerbose()); System.out.print(' = '); System.out.println(infos[i]); System.out.println(infos[i].getClass().getSimpleName()); ConstantUtf8Info uInfo = (ConstantUtf8Info)infos[i];//根據對應的類型轉換 uInfo.setString(''); infos[i]=uInfo; } } } cf.setConstantPool(infos); fis.close(); File f = new File(filePath); ClassFileWriter.writeToFile(f, cf); }}其他
對應的jar包可以在idea安裝的插件里面找。
報java.lang.ClassNotFoundException: kotlin.jvm.internal.Reflection,加上
<dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-kotlin</artifactId> <version>2.9.4.1</version></dependency>
到此這篇關于IDEA利用jclasslib 修改class文件的實現的文章就介紹到這了,更多相關IDEA jclasslib 修改class內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!
相關文章:
1. IDEA EasyCode 一鍵幫你生成所需代碼2. Ajax引擎 ajax請求步驟詳細代碼3. Java構建JDBC應用程序的實例操作4. Spring應用拋出NoUniqueBeanDefinitionException異常的解決方案5. ThinkPHP5 通過ajax插入圖片并實時顯示(完整代碼)6. javascript設計模式 ? 建造者模式原理與應用實例分析7. 一篇文章帶你了解JavaScript-對象8. Python使用oslo.vmware管理ESXI虛擬機的示例參考9. IntelliJ IDEA設置條件斷點的方法步驟10. Express 框架中使用 EJS 模板引擎并結合 silly-datetime 庫進行日期格式化的實現方法
