怎么直接运用eclipse运行一段JAVA代码?
我在网上看到一个修改别人class文件的教程,到了要用到eclipse软件的一步,原文是(在eclipse里面新建一个Test来处理GenEntity.class),然后...
我在网上看到一个修改别人class文件的教程,到了要用到eclipse软件的一步,原文是(在eclipse里面新建一个Test来处理GenEntity.class),然后代码如下
import java.io.*;
import org.gjt.jclasslib.io.ClassFileWriter;
import org.gjt.jclasslib.structures.CPInfo;
import org.gjt.jclasslib.structures.ClassFile;
import org.gjt.jclasslib.structures.constants.ConstantUtf8Info;
public class Test {
public static void main(String[] args) throws Exception {
String filePath = "C:\\GenEntity.class";
FileInputStream fis = new FileInputStream(filePath);
DataInput di = new DataInputStream(fis);
ClassFile cf = new ClassFile();
cf.read(di);
CPInfo[] infos = cf.getConstantPool();
int count = infos.length;
for (int i = 0; i < count; i++) {
if (infos[i] != null) {
System.out.print(i);
System.out.print(" = ");
System.out.print(infos[i].getVerbose());
System.out.print(" = ");
System.out.println(infos[i].getTagVerbose());
if(i == 362){
ConstantUtf8Info uInfo = (ConstantUtf8Info)infos[i];
uInfo.setBytes("芝麻不开门!".getBytes());
infos[i]=uInfo;
}
}
}
cf.setConstantPool(infos);
fis.close();
File f = new File(filePath);
ClassFileWriter.writeToFile(f, cf);
}
} 展开
import java.io.*;
import org.gjt.jclasslib.io.ClassFileWriter;
import org.gjt.jclasslib.structures.CPInfo;
import org.gjt.jclasslib.structures.ClassFile;
import org.gjt.jclasslib.structures.constants.ConstantUtf8Info;
public class Test {
public static void main(String[] args) throws Exception {
String filePath = "C:\\GenEntity.class";
FileInputStream fis = new FileInputStream(filePath);
DataInput di = new DataInputStream(fis);
ClassFile cf = new ClassFile();
cf.read(di);
CPInfo[] infos = cf.getConstantPool();
int count = infos.length;
for (int i = 0; i < count; i++) {
if (infos[i] != null) {
System.out.print(i);
System.out.print(" = ");
System.out.print(infos[i].getVerbose());
System.out.print(" = ");
System.out.println(infos[i].getTagVerbose());
if(i == 362){
ConstantUtf8Info uInfo = (ConstantUtf8Info)infos[i];
uInfo.setBytes("芝麻不开门!".getBytes());
infos[i]=uInfo;
}
}
}
cf.setConstantPool(infos);
fis.close();
File f = new File(filePath);
ClassFileWriter.writeToFile(f, cf);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询