Skip to content

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

Open
@sarpedondev

Description

@sarpedondev

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions