use of org.objectweb.asm.ClassWriter in project BetterRain by OreCruncher.
the class Transformer method transformWorld.
private byte[] transformWorld(final byte[] classBytes) {
final String[] names;
if (TransformLoader.runtimeDeobEnabled)
names = new String[] { "updateWeatherBody" };
else
names = new String[] { "updateWeatherBody" };
final String[] targetName = new String[] { "updateWeatherBody" };
final ClassReader cr = new ClassReader(classBytes);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (final MethodNode m : cn.methods) {
if (m.name.equals(names[0])) {
logger.debug("Hooking " + names[0]);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
final String sig = "(Lnet/minecraft/world/World;)V";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/server/WorldHandler", targetName[0], sig, false));
list.add(new InsnNode(RETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
break;
}
}
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
use of org.objectweb.asm.ClassWriter in project BetterRain by OreCruncher.
the class Transformer method transformWorldServer.
private byte[] transformWorldServer(final byte[] classBytes) {
final String[] names;
if (TransformLoader.runtimeDeobEnabled)
names = new String[] { "func_73051_P" };
else
names = new String[] { "resetRainAndThunder" };
final String[] targetName = new String[] { "resetRainAndThunder" };
final ClassReader cr = new ClassReader(classBytes);
final ClassNode cn = new ClassNode(ASM5);
cr.accept(cn, 0);
for (final MethodNode m : cn.methods) {
if (m.name.equals(names[0])) {
logger.debug("Hooking " + names[0]);
InsnList list = new InsnList();
list.add(new VarInsnNode(ALOAD, 0));
final String sig = "(Lnet/minecraft/world/WorldServer;)V";
list.add(new MethodInsnNode(INVOKESTATIC, "org/blockartistry/mod/DynSurround/server/PlayerSleepHandler", targetName[0], sig, false));
list.add(new InsnNode(RETURN));
m.instructions.insertBefore(m.instructions.getFirst(), list);
break;
}
}
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
cn.accept(cw);
return cw.toByteArray();
}
use of org.objectweb.asm.ClassWriter in project fabric8 by fabric8io.
the class TraceStrategy method transform.
@Override
public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException {
byte[] buffer = null;
ClassInfo classInfo = context.getClassInfo(className);
classInfo.setOriginalClass(classBeingRedefined);
if (classInfo.getTransformed() == null) {
// we haven't been transformed before
classInfo.setOriginal(classfileBuffer);
}
if (!cleanUp.get()) {
byte[] classBufferToRedefine = classInfo.getOriginal();
if (configuration.isAudit(className)) {
if (classInfo.isTransformed()) {
// remove metrics from methods no longer defined
context.resetMethods(classInfo);
}
ClassReader cr = new ClassReader(classBufferToRedefine);
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
ApmClassVisitor visitor = new ApmClassVisitor(this, cw, classInfo);
cr.accept(visitor, ClassReader.SKIP_FRAMES);
buffer = cw.toByteArray();
if (!verifyClass(className, buffer)) {
classInfo.setCanTransform(false);
buffer = null;
}
classInfo.setTransformed(buffer);
}
} else {
if (classInfo.getOriginal() != null) {
buffer = classInfo.getOriginal();
context.resetAll(classInfo);
}
}
return buffer;
}
use of org.objectweb.asm.ClassWriter in project wildfly-swarm by wildfly-swarm.
the class ClientServiceFactory method createImpl.
static byte[] createImpl(String implName, ClassInfo classInfo) {
ClassWriter cw = new ClassWriter(0);
MethodVisitor mv;
AnnotationVisitor av0;
cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, implName.replace('.', '/'), null, "java/lang/Object", new String[] { classInfo.name().toString().replace('.', '/') });
int lastDot = implName.lastIndexOf('.');
String simpleName = implName.substring(lastDot + 1);
cw.visitSource(simpleName + ".java", null);
{
av0 = cw.visitAnnotation("Ljavax/enterprise/context/ApplicationScoped;", true);
av0.visitEnd();
}
cw.visitInnerClass("javax/ws/rs/client/Invocation$Builder", "javax/ws/rs/client/Invocation", "Builder", ACC_PUBLIC + ACC_STATIC + ACC_ABSTRACT + ACC_INTERFACE);
{
mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitCode();
Label l0 = new Label();
mv.visitLabel(l0);
mv.visitLineNumber(14, l0);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
Label l1 = new Label();
mv.visitLabel(l1);
mv.visitLineNumber(15, l1);
mv.visitInsn(RETURN);
Label l2 = new Label();
mv.visitLabel(l2);
mv.visitLocalVariable("this", buildTypeDef(implName), null, l0, l2, 0);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
List<AnnotationInstance> annotations = classInfo.annotations().get(DotName.createSimple("org.wildfly.swarm.client.jaxrs.Service"));
String baseUrl = (String) annotations.get(0).value("baseUrl").value();
int lineNum = 18;
classInfo.asClass().methods().stream().forEachOrdered(method -> {
createMethod(cw, implName, classInfo.name().toString(), method, lineNum, baseUrl);
});
cw.visitEnd();
return cw.toByteArray();
}
use of org.objectweb.asm.ClassWriter in project wildfly-swarm by wildfly-swarm.
the class DefaultApplicationFactory method create.
public static byte[] create(String name, String path) throws IOException {
ClassReader reader = new ClassReader(basicClassBytes());
String slashName = name.replace('.', '/');
ClassWriter writer = new ClassWriter(0);
Remapper remapper = new Remapper() {
@Override
public String map(String typeName) {
if (typeName.equals("org/wildfly/swarm/jaxrs/runtime/DefaultApplication")) {
return slashName;
}
return super.map(typeName);
}
};
ClassRemapper adapter = new ClassRemapper(writer, remapper);
reader.accept(adapter, 0);
AnnotationVisitor ann = writer.visitAnnotation("Ljavax/ws/rs/ApplicationPath;", true);
ann.visit("value", path);
ann.visitEnd();
writer.visitEnd();
return writer.toByteArray();
}
Aggregations