利用jclasslib修改java編譯后的.class文件


java編譯后的.class文件,當然是可以反編譯的,但主要是反編譯后的java文件不能100%的完全正確,也不能保證能編譯回去,所以直接修改.class文件比較靠譜。

 

1.可以用jd-gui反編譯,找到method

2.用java bytecode (jclasslib) 查找要修改的變量地址

3.使用一下代碼修改:

 

package com.zhahost;

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.ConstantDoubleInfo;

public class ModifyByteCode {
    public void Run() {
        try {
            String filePath = "C:\\ExcelExporter.class";
            FileInputStream fis = new FileInputStream(filePath);

            DataInput di = new DataInputStream(fis);
            ClassFile cf = new ClassFile();
            cf.read(di);
            CPInfo[] infos = cf.getConstantPool();

            int pos = 148;
            if (infos[pos] != null) {
                ConstantDoubleInfo uInfo = (ConstantDoubleInfo) infos[pos];
                uInfo.setDouble(1.0);
                infos[pos] = uInfo;
            }

            cf.setConstantPool(infos);

            fis.close();
            File f = new File(filePath);
            ClassFileWriter.writeToFile(f, cf);

        } catch (Exception e) {

        }
    }
}

 

留着備用,一般人看不懂...


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM