IDEA利用jclasslib 修改class文件的實現(xiàn)
idea安裝jclasslib-bytecode-viewer插件
file–>settings–>plugis ,搜索安裝jclasslib-bytecode-viewer,重啟idea。
準(zhǔn)備好class文件
把要修改的class文件用idea打開。
使用jclasslib
view–>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:\\Users\\HMS\\Desktop\\AppService.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文件的實現(xiàn)的文章就介紹到這了,更多相關(guān)IDEA jclasslib 修改class內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java Spring-IOC容器與Bean管理之基于注解的方式案例詳解
這篇文章主要介紹了Java Spring-IOC容器與Bean管理之基于注解的方式案例詳解,本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下2021-08-08Session過期后實現(xiàn)自動跳轉(zhuǎn)登錄頁面
這篇文章主要介紹了Session過期后實現(xiàn)自動跳轉(zhuǎn)登錄頁面,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-12-12Idea2019創(chuàng)建Springboot Web項目的方法步驟
這篇文章主要介紹了Idea2019創(chuàng)建Springboot Web項目的方法步驟,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10如何使用pipeline和jacoco獲取自動化測試代碼覆蓋率
這篇文章主要介紹了如何使用pipeline和jacoco獲取自動化測試代碼覆蓋率,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-11-11解讀線程池-Executors的newSingleThreadExecutor和newFixedThreadPool(1
這篇文章主要介紹了解讀線程池-Executors的newSingleThreadExecutor和newFixedThreadPool(1)區(qū)別,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-08-08MyBatis?實現(xiàn)多對多中間表插入數(shù)據(jù)
這篇文章主要介紹了MyBatis?實現(xiàn)多對多中間表插入數(shù)據(jù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-02-02