IDEA利用jclasslib 修改class文件的實(shí)現(xiàn)
file?>settings?>plugis ,搜索安裝jclasslib-bytecode-viewer,重啟idea。
把要修改的class文件用idea打開。
使用jclasslibview?>show bytecode with jclasslib.常量池,使用過濾器過濾文本。找到對應(yīng)的指向數(shù)字。
使用下列代碼更改內(nèi)容。
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];//根據(jù)對應(yīng)的類型轉(zhuǎn)換 uInfo.setString(''); infos[i]=uInfo; } } } cf.setConstantPool(infos); fis.close(); File f = new File(filePath); ClassFileWriter.writeToFile(f, cf); }}其他
對應(yīng)的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>
到此這篇關(guān)于IDEA利用jclasslib 修改class文件的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)IDEA jclasslib 修改class內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 利用promise及參數(shù)解構(gòu)封裝ajax請求的方法2. JSP數(shù)據(jù)交互實(shí)現(xiàn)過程解析3. windows服務(wù)器使用IIS時thinkphp搜索中文無效問題4. .NET中l(wèi)ambda表達(dá)式合并問題及解決方法5. Nginx+php配置文件及原理解析6. 淺談python出錯時traceback的解讀7. ASP 信息提示函數(shù)并作返回或者轉(zhuǎn)向8. Ajax實(shí)現(xiàn)表格中信息不刷新頁面進(jìn)行更新數(shù)據(jù)9. Python importlib動態(tài)導(dǎo)入模塊實(shí)現(xiàn)代碼10. python matplotlib:plt.scatter() 大小和顏色參數(shù)詳解
