时间:2023-03-09 12:09:22 | 栏目:JAVA代码 | 点击:次
file?C>settings?C>plugis ,搜索安装jclasslib-bytecode-viewer,重启idea。
把要修改的class文件用idea打开。
view?C>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,加上
<dependency> <groupId>com.fasterxml.jackson.module</groupId> <artifactId>jackson-module-kotlin</artifactId> <version>2.9.4.1</version> </dependency>