最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
IDEA利用jclasslib修改class文件实现代码
时间:2021-02-26 编辑:袖梨 来源:一聚教程网
本篇文章小编给大家分享一下IDEA利用jclasslib修改class文件实现代码,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。
idea安装jclasslib-bytecode-viewer插件
file–>settings–>plugis ,搜索安装jclasslib-bytecode-viewer,重启idea。
准备好class文件
把要修改的class文件用idea打开。
使用jclasslib
view–>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:\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];//根据对应的类型转换 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,加上
com.fasterxml.jackson.module jackson-module-kotlin 2.9.4.1
相关文章
- SpringBoot自定义bean绑定解析 10-24
- Javaweb工程运行报错HTTP Status 404解决教程 10-20
- JAVA获取jvm和操作系统相关信息方法 10-20
- BeanFactory和FactoryBean的区别讲解 10-20
- 微信小程序的宿主环境实现教程 10-10
- dispatchEvent解决重叠元素响应事件教程 10-10