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 java.time.Duration;
import java.lang.invoke.VarHandle;
import java.lang.invoke.MethodHandles;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.apache.bcel.Const;
import org.apache.bcel.generic.*;
import java.lang.reflect.Type;
import java.awt.geom.*;
import static x30_pkg.x30_util.DynamicObject;
import java.text.*;
import java.text.NumberFormat;
import java.util.TimeZone;
class main {
// BCEL
static class ClassMaker {
final public String getClassName(){ return className(); }
public String className() { return className; }
String className;
ClassGen cg;
JavaClass baked;
InMemoryClassLoader classLoader;
Class loadedClass;
final public ClassMaker setPrintDisassembly(boolean printDisassembly){ return printDisassembly(printDisassembly); }
public ClassMaker printDisassembly(boolean printDisassembly) { this.printDisassembly = printDisassembly; return this; } final public boolean getPrintDisassembly(){ return printDisassembly(); }
public boolean printDisassembly() { return printDisassembly; }
boolean printDisassembly = false;
final public ClassMaker setSuperClassName(String superClassName){ return superClassName(superClassName); }
public ClassMaker superClassName(String superClassName) { this.superClassName = superClassName; return this; } final public String getSuperClassName(){ return superClassName(); }
public String superClassName() { return superClassName; }
String superClassName = "java.lang.Object";
final public ClassMaker setFileName(String fileName){ return fileName(fileName); }
public ClassMaker fileName(String fileName) { this.fileName = fileName; return this; } final public String getFileName(){ return fileName(); }
public String fileName() { return fileName; }
String fileName;
ClassMaker(String className) {
this(className, null);
}
ClassMaker(String className, String[] interfaces) {
this.className = className;
setClassGen(new ClassGen(className, superClassName, fileName,
Const.ACC_PUBLIC, interfaces));
}
ClassMaker(Class interfaceToImplement) {
className = randomClassName();
setClassGen(new ClassGen(className, "java.lang.Object", null,
Const.ACC_PUBLIC, new String[] { main.className(interfaceToImplement) }));
addDefaultConstructor();
}
void addDefaultConstructor() {
cg.addEmptyConstructor(Const.ACC_PUBLIC);
}
void setClassGen(ClassGen cg) {
this.cg = cg;
// up the byte code version so we can do ldc of class objects (e.g.)
cg.setMajor(50); // JDK 6
//cg.setMajor(55); // JDK 11. can't use yet because StackMapTable became mandatory in JDK 8 and BCEL doesn't generate that
cg.setMinor(0);
}
JavaClass bake() {
if (baked == null) {
baked = cg.getJavaClass();
if (printDisassembly)
printClassWithMethods();
}
return baked;
}
// tabs can look bad in JTextArea, so we're using tabToSingleSpace
void printClassWithMethods() {
// print class overview
print_tabToSingleSpace(bake());
// print the methods
for (var method : baked.getMethods()) {
print_tabToSingleSpace("\n" + method);
print_tabToSingleSpace(method.getCode());
}
}
byte[] getBytes_cache;
final byte[] getBytes() { if (getBytes_cache == null) getBytes_cache = getBytes_load(); return getBytes_cache;}
final byte[] getBytes_load(){ return toBytes(); }
byte[] toBytes() {
return bake().getBytes();
}
Class load() {
if (loadedClass == null) {
var bytes = toBytes();
classLoader = new InMemoryClassLoader(myClassLoader());
loadedClass = (Class) classLoader.defineAClass(className, bytes);
}
return loadedClass;
}
A newInstance() {
return main.newInstance(load());
}
void addField(FieldGen fg) {
cg.addField(fg.getField());
}
ConstantPoolGen getConstantPool() {
return cg.getConstantPool();
}
}
static String className(Object o) {
return getClassName(o);
}
static String fileName(File f) {
return f == null ? null : f.getName();
}
static AtomicLong randomClassName_counter = new AtomicLong();
static String randomClassName() {
return "UserCode" + inc(randomClassName_counter);
}
static A print_tabToSingleSpace(A o) {
print(tabToSingleSpace(str(o)));
return o;
}
static Object load(String varName) {
readLocally(varName);
return get(mc(), varName);
}
static Object load(String progID, String varName) {
readLocally(progID, varName);
return get(mc(), varName);
}
static ClassLoader myClassLoader() {
return _getClass(mc()).getClassLoader();
}
static A newInstance(Class c, Object... args) {
return nuObject(c, args);
}
static Object newInstance(String className, Object... args) {
return nuObject(className, args);
}
static String getClassName(Object o) {
return o == null ? "null" : o instanceof Class ? ((Class) o).getName() : o.getClass().getName();
}
static int inc(AtomicInteger i) {
return incAtomicInt(i);
}
static int inc(AtomicInteger i, int delta) {
return incAtomicInt(i, delta);
}
static long inc(AtomicLong l) {
return incAtomicLong(l);
}
static long inc(AtomicLong l, long b) {
return l.addAndGet(b);
}
static int inc(IntVar v) {
synchronized(v) {
int val = v.get() + 1;
v.set(val);
return val;
}
}
static int inc(int i) { return i+1; }
static long inc(long l) { return l+1; }
static volatile StringBuffer local_log = new StringBuffer(); // not redirected
static boolean printAlsoToSystemOut = true;
static volatile Appendable print_log = local_log; // might be redirected, e.g. to main bot
// in bytes - will cut to half that
static volatile int print_log_max = 1024*1024;
static volatile int local_log_max = 100*1024;
static boolean print_silent = false; // total mute if set
static Object print_byThread_lock = new Object();
static volatile ThreadLocal