use of org.objectweb.asm.util.CheckClassAdapter in project slab by RichardWarburton.
the class BytecodeGenerator method generate.
@SuppressWarnings("unchecked")
public Class<T> generate() {
ClassWriter out = new ClassWriter(ClassWriter.COMPUTE_MAXS);
CheckClassAdapter writer = new CheckClassAdapter(out);
int offset = 0;
declareClass(writer);
declareConstructor(writer);
for (Method getter : inspector.getters) {
offset = declareField(getter, writer, offset);
}
writer.visitEnd();
return (Class<T>) new GeneratedClassLoader(options).defineClass(implementationName, out);
}
use of org.objectweb.asm.util.CheckClassAdapter in project runelite by runelite.
the class JarUtil method writeClass.
public static byte[] writeClass(ClassGroup group, ClassFile cf) {
ClassWriter writer = new NonloadingClassWriter(group, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
CheckClassAdapter cca = new CheckClassAdapter(writer, false);
cf.accept(cca);
byte[] data = writer.toByteArray();
validateDataFlow(cf.getName(), data);
return data;
}
use of org.objectweb.asm.util.CheckClassAdapter in project HeapDL by plast-lab.
the class Transformer method checkBytecode.
// Check bytecode using ASM's CheckClassAdapter.
private void checkBytecode(ClassLoader loader, String className, byte[] bc, int wFlags) {
ClassReader debugReader = new ClassReader(bc);
ClassWriter debugWriter = new ContextClassWriter(loader, wFlags);
try {
ClassNode debugNode = new ClassNode(Opcodes.ASM5);
debugReader.accept(debugNode, ClassReader.EXPAND_FRAMES);
debugNode.accept(new CheckClassAdapter(debugWriter));
// debugReader.accept(new CheckClassAdapter(debugWriter), 0);
} catch (RuntimeException ex) {
System.err.println("Bytecode check failed for " + className + ":");
ex.printStackTrace();
System.exit(-1);
}
}
use of org.objectweb.asm.util.CheckClassAdapter in project groovy-core by groovy.
the class VerifyClass method readClass.
private boolean readClass(String clazz) throws IOException {
ClassReader cr = new ClassReader(new FileInputStream(clazz));
ClassNode ca = new ClassNode() {
public void visitEnd() {
// accept(cv);
}
};
cr.accept(new CheckClassAdapter(ca), ClassWriter.COMPUTE_MAXS);
boolean failed = false;
List methods = ca.methods;
for (int i = 0; i < methods.size(); ++i) {
MethodNode method = (MethodNode) methods.get(i);
if (method.instructions.size() > 0) {
Analyzer a = new Analyzer(new SimpleVerifier());
try {
a.analyze(ca.name, method);
continue;
} catch (Exception e) {
e.printStackTrace();
}
final Frame[] frames = a.getFrames();
if (!failed) {
failed = true;
log("verifying of class " + clazz + " failed");
}
if (verbose)
log(method.name + method.desc);
TraceMethodVisitor mv = new TraceMethodVisitor(null);
/*= new TraceMethodVisitor(null) {
public void visitMaxs(int maxStack, int maxLocals) {
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < text.size(); ++i) {
String s = frames[i] == null ? "null" : frames[i].toString();
while (s.length() < maxStack + maxLocals + 1) {
s += " ";
}
buffer.append(Integer.toString(i + 100000).substring(1));
buffer.append(" ");
buffer.append(s);
buffer.append(" : ");
buffer.append(text.get(i));
}
if (verbose) log(buffer.toString());
}
};*/
for (int j = 0; j < method.instructions.size(); ++j) {
Object insn = method.instructions.get(j);
if (insn instanceof AbstractInsnNode) {
((AbstractInsnNode) insn).accept(mv);
} else {
mv.visitLabel((Label) insn);
}
}
mv.visitMaxs(method.maxStack, method.maxLocals);
}
}
return !failed;
}
use of org.objectweb.asm.util.CheckClassAdapter in project RecurrentComplex by Ivorforce.
the class VanillaGenerationClassFactory method createClassBinary.
protected byte[] createClassBinary(String className) {
ClassWriter writer = new ClassWriter(0);
ClassVisitor cw = new CheckClassAdapter(writer);
cw.visit(V1_5, ACC_PUBLIC, className, null, Type.getInternalName(GenericVillagePiece.class), null);
{
// empty constructor
String descriptor = Type.getMethodDescriptor(Type.VOID_TYPE);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(GenericVillagePiece.class), "<init>", descriptor, false);
mv.visitInsn(RETURN);
mv.visitMaxs(2, 1);
mv.visitEnd();
}
{
// initial constructor
String descriptor = Type.getMethodDescriptor(Type.VOID_TYPE, Type.getType(StructureVillagePieces.Start.class), Type.INT_TYPE);
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", descriptor, null, null);
mv.visitCode();
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitVarInsn(ILOAD, 2);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(GenericVillagePiece.class), "<init>", descriptor, false);
mv.visitInsn(RETURN);
mv.visitMaxs(4, 3);
mv.visitEnd();
}
cw.visitEnd();
return writer.toByteArray();
}
Aggregations