jclasslib icon indicating copy to clipboard operation
jclasslib copied to clipboard

Adding a ConstantLongInfo to the ConstantPool and any other Constant produces and invalid class file

Open sarpedondev opened this issue 7 months ago • 0 comments

The following code produces an invalid class file when writing it back to the disk. Only adding one long seems to work and adding any amount of utf8 constants works too, however adding a long constant and any other does not. Decompilers and disassemblers are unable to read the file.

import org.gjt.jclasslib.io.ClassFileReader
import org.gjt.jclasslib.io.writeToByteArray
import org.gjt.jclasslib.structures.ConstantPoolUtil
import org.gjt.jclasslib.structures.constants.ConstantLongInfo
import java.io.File

fun main() {
  val cf = ClassFileReader.readFromFile(file = File("Main.class"))
  ConstantPoolUtil.addConstantPoolEntry(cf, ConstantLongInfo(cf).apply { long = 123456789123456789 });
  ConstantPoolUtil.addConstantPoolEntry(cf, ConstantLongInfo(cf).apply { long = 987654321987654321 });
  File("Main-out.class").writeBytes(cf.writeToByteArray())
}

Main class: Image

Main-out.class: Image

Intellij Fernflower: Image

Javap:

$ javap -v Main-out.class
Error: unexpected end of file while reading Main-out.class

sarpedondev avatar May 27 '25 18:05 sarpedondev