import java.util.*; import java.util.zip.*; import java.util.List; import java.util.regex.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; import java.util.concurrent.locks.*; import java.util.function.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.text.*; import javax.swing.table.*; import java.io.*; import java.net.*; import java.lang.reflect.*; import java.lang.ref.*; import java.lang.management.*; import java.security.*; import java.security.spec.*; import java.awt.*; import java.awt.event.*; import java.awt.image.*; import java.awt.geom.*; import javax.imageio.*; import java.math.*; import org.apache.bcel.classfile.ClassParser; import org.apache.bcel.classfile.JavaClass; import org.apache.bcel.Const; import org.apache.bcel.generic.*; import org.apache.bcel.generic.Type; class main { // BCEL public static void main(final String[] args) throws Exception { ClassGen cg = new ClassGen("BadClassFile", "java.lang.Object", null, Const.ACC_PUBLIC, new String[0]); cg.addEmptyConstructor(Const.ACC_PUBLIC); ConstantPoolGen cp = cg.getConstantPool(); InstructionList il = new InstructionList(); MethodGen mg = new MethodGen((short) (Const.ACC_PUBLIC | Const.ACC_STATIC), Type.VOID, new Type[] { new ArrayType(new ObjectType("java.lang.String"), 1) }, null, "main", cg.getClassName(), il, cp); il.append(new LDC(cp.addClass("java.lang.Object"))); il.append(new ASTORE(1)); il.append(new RETURN()); mg.stripAttributes(true); mg.setMaxStack(); mg.setMaxLocals(); cg.addMethod(mg.getMethod()); JavaClass baked = cg.getJavaClass(); var bytes = baked.getBytes(); saveBinaryFile_simple(baked.getClassName() + ".class", bytes); } static void saveBinaryFile_simple(String fileName, byte[] contents) throws IOException { FileOutputStream fileOutputStream = new FileOutputStream(fileName); fileOutputStream.write(contents); fileOutputStream.close(); } }