本文整理汇总了Java中org.objectweb.asm.ClassWriter.COMPUTE_MAXS属性的典型用法代码示例。如果您正苦于以下问题:Java ClassWriter.COMPUTE_MAXS属性的具体用法?Java ClassWriter.COMPUTE_MAXS怎么用?Java ClassWriter.COMPUTE_MAXS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.objectweb.asm.ClassWriter
的用法示例。
在下文中一共展示了ClassWriter.COMPUTE_MAXS属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convert
@NotNull
@SuppressWarnings("unchecked")
static <T extends IClassTransformer> Class<T> convert(@NotNull Class<? extends OrionTransformer> transformer) {
if(Arrays.asList(transformer.getInterfaces()).contains(IClassTransformer.class))
return (Class<T>) transformer; /* no-op */
// Orion transformer name
String rawTransformerName = transformer.getName().replace('.', '/');
// New wrapper class name
String newWrapperName = getNewName(transformer);
// Start generating new TransformerWrapper
ClassReader cr = new ClassReader(TW_DATA);
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
ClassNode cn = new ClassNode();
cr.accept(cn, 0);
cn.accept(new WrapperGenerator(cw, TW_TYPE.getInternalName(), newWrapperName.replace('.', '/'), rawTransformerName));
return requireNonNull((Class<T>) ClassLoaderTools.defineClass(Launch.classLoader, newWrapperName, cw.toByteArray()));
}
示例2: transform
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass) {
List<ITransformer> transformers = getTransformers(transformedName);
if (!transformers.isEmpty()) {
ClassNode cn = getClassNode(basicClass);
if (cn == null)
return basicClass;
// Run all transformers on the Class
transformers.forEach(transformer -> transformer.transform(cn));
// Return transformed class bytecode
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cn.accept(cw);
return cw.toByteArray();
}
return basicClass;
}
示例3: generateTests
private void generateTests() throws IOException {
ClassReader cr = new ClassReader(new FileInputStream(classNamePath.toFile()));
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cr.accept(
new ClassVisitor(Opcodes.ASM5, cw) {
@Override
public void visitEnd() {
generateMethodTest1(cw);
generateMethodTest2(cw);
generateMethodTest3(cw);
generateMethodTest4(cw);
generateMethodTest5(cw);
generateMethodTest6(cw);
generateMethodTest7(cw);
generateMethodTest8(cw);
generateMethodTest9(cw);
generateMethodTest10(cw);
generateMethodTest11(cw);
generateMethodTest12(cw);
generateMethodTest13(cw);
generateMethodMain(cw);
super.visitEnd();
}
}, 0);
new FileOutputStream(classNamePath.toFile()).write(cw.toByteArray());
}
示例4: generate
public byte[] generate(){
String className = "eu.mikroskeem.test.shuriken.common.classtools.gen.InvalidGeneratedClass";
String classNameInternal = className.replaceAll("\\.", "/");
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS + ClassWriter.COMPUTE_FRAMES);
cw.visit(
V1_8,
ACC_PUBLIC + ACC_SUPER,
classNameInternal,
null,
Type.getInternalName(Object.class),
null);
FieldVisitor fv = cw.visitField(ACC_PRIVATE + ACC_STATIC, "test", Type.getDescriptor(String.class), null, "hey");
fv.visitEnd();
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
mv.visitVarInsn(ALOAD, 0);
mv.visitVarInsn(ALOAD, 1);
mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
cw.visitEnd();
return cw.toByteArray();
}
示例5: transformCode
public byte[] transformCode(String className, byte[] fb) {
this.className = className;
ClassReader cr = new ClassReader(fb);
// ClassReader cr = new ClassReader(className);
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_MAXS);
ClassVisitor cv = new ClassInsert(cw);
cr.accept(cv, ClassReader.EXPAND_FRAMES);
/*byte[] code = cw.toByteArray();
File file = new File("Idtk.class");
try {
FileUtils.writeByteArrayToFile(file,code);
}catch (IOException e){
System.out.println("=======IOException=======");
}*/
return cw.toByteArray();
}
示例6: classNodeToBytes
private byte[] classNodeToBytes(ClassNode classNode) {
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
byte[] bytes = writer.toByteArray();
// verify bytecode
if (verifyAndPrint) {
ClassReader reader = new ClassReader(bytes);
ClassVisitor tracer = new TraceClassVisitor(new PrintWriter(System.out));
ClassVisitor checker = new CheckClassAdapter(tracer, true);
reader.accept(checker, 0);
}
return bytes;
}
示例7: transform
@Override
public byte[] transform(String name, String transformedName, byte[] bytes)
{
if (bytes == null) { return null; }
if (!markers.containsKey(name)) { return bytes; }
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
for (String marker : markers.get(name))
{
classNode.interfaces.add(marker);
}
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
示例8: transform
private static byte[] transform(byte[] serverClass, boolean isObfuscated, transformType type)
{
System.out.println("MALMO: Attempting to transform MinecraftServer");
try
{
ClassNode cnode = new ClassNode();
ClassReader creader = new ClassReader(serverClass);
creader.accept(cnode, 0);
switch (type)
{
case SERVER:
overclockServer(cnode, isObfuscated);
break;
case RENDERER:
overclockRenderer(cnode, isObfuscated);
break;
}
ClassWriter cwriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cnode.accept(cwriter);
return cwriter.toByteArray();
}
catch (Exception e)
{
System.out.println("MALMO FAILED to transform MinecraftServer - overclocking not available!");
}
return serverClass;
}
示例9: generateMethodArgsUpdater
public static byte[] generateMethodArgsUpdater(Class<?> classToProxy, Method method, int methodId) throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
String classToProxyDescriptor = Type.getDescriptor(classToProxy);
String classToProxyInternalName = Type.getInternalName(classToProxy);
String suffix = SUFFIX_START + method.getName() + methodId;
String selfClassInternalName = classToProxyInternalName + suffix;
String selfClassDescriptor = BytecodeGenUtils.makeSuffixClassDescriptor(classToProxyDescriptor, suffix);
String argsClassInternalName = classToProxyInternalName + MethodArgumentsGenerator.SUFFIX_START + method.getName() + methodId;
String constDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
Stream.concat(Stream.of(List.class), Stream.of(method.getParameterTypes())).map(Type::getType)
.toArray(Type[]::new));
cw.visit(52, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, selfClassInternalName, null, "java/lang/Object",
new String[] { "io/primeval/reflex/arguments/ArgumentsUpdater" });
Parameter[] parameters = method.getParameters();
generateFields(method, cw, parameters);
generateConstructor(method, cw, selfClassInternalName, selfClassDescriptor, constDesc, parameters);
generateHashCodeMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateEqualsMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateToStringMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateUpdateMethod(cw, selfClassInternalName, selfClassDescriptor, argsClassInternalName, constDesc, parameters);
generateParametersGetter(cw, selfClassInternalName, selfClassDescriptor);
generateArgumentSetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateArgumentGetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
cw.visitEnd();
return cw.toByteArray();
}
示例10: createContentHandler
public final ContentHandler createContentHandler() {
final ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
return new ASMContentHandler(cw) {
@Override
public void endDocument() throws SAXException {
try {
os.write(cw.toByteArray());
} catch (IOException e) {
throw new SAXException(e);
}
}
};
}
示例11: transform
@Override
public byte[] transform(String name, String transformedName, byte[] basicClass)
{
if (basicClass == null) return null;
ClassNode classNode = new ClassNode();
new ClassReader(basicClass).accept(classNode, 0);
boolean isSubscriber = false;
for (MethodNode methodNode : classNode.methods)
{
List<AnnotationNode> anns = methodNode.visibleAnnotations;
if (anns != null && Iterables.any(anns, SubscribeEventPredicate.INSTANCE))
{
if (Modifier.isPrivate(methodNode.access))
{
String msg = "Cannot apply @SubscribeEvent to private method %s/%s%s";
throw new RuntimeException(String.format(msg, classNode.name, methodNode.name, methodNode.desc));
}
methodNode.access = toPublic(methodNode.access);
isSubscriber = true;
}
}
if (isSubscriber)
{
classNode.access = toPublic(classNode.access);
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
classNode.accept(writer);
return writer.toByteArray();
}
return basicClass;
}
示例12: modify
/**
* Modifies the class and returns the result as a byte array
*
* @return byte array
*
* @throws IOException rethrown from the {@link ClassReader} constructor
*/
public byte[] modify() throws IOException
{
if (this.output == null)
{
final ClassReader classReader = new ClassReader(this.inputStream);
final ClassWriter classWriter = new ClassWriter(classReader, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
this.cv = classWriter;
classReader.accept(this, ClassReader.EXPAND_FRAMES);
this.output = classWriter.toByteArray();
}
return this.output;
}
示例13: transform
@Override
public byte[] transform(String name, String realName, byte[] bytes) {
if (transformingClasses.containsKey(realName)) {
ClassTransformer transformer = transformingClasses.get(realName);
try {
LOGGER.info("Transforming class " + realName);
ClassNode classNode = new ClassNode();
ClassReader classReader = new ClassReader(bytes);
classReader.accept(classNode, 0);
transformer.transform(classNode);
ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
classNode.accept(classWriter);
// let gc clean this up
transformingClasses.remove(realName);
return classWriter.toByteArray();
} catch (Exception e) {
LOGGER.error(e.getClass().getSimpleName() + " thrown from transforming class " + realName + ": " + e.getMessage());
ASMStackLogger.printStackTrace(e);
}
}
return bytes;
}
示例14: generateMethodArgs
public static byte[] generateMethodArgs(Class<?> classToProxy, Method method, int methodId) throws Exception {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
String classToProxyDescriptor = Type.getDescriptor(classToProxy);
String classToProxyInternalName = Type.getInternalName(classToProxy);
String suffix = SUFFIX_START + method.getName() + methodId;
String selfClassInternalName = classToProxyInternalName + suffix;
String selfClassDescriptor = BytecodeGenUtils.makeSuffixClassDescriptor(classToProxyDescriptor, suffix);
String updaterClassInternalName = classToProxyInternalName + MethodArgumentssUpdaterGenerator.SUFFIX_START + method.getName() + methodId;
String constDesc = Type.getMethodDescriptor(Type.VOID_TYPE,
Stream.concat(Stream.of(List.class), Stream.of(method.getParameterTypes())).map(Type::getType)
.toArray(Type[]::new));
cw.visit(52, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, selfClassInternalName, null, "java/lang/Object",
new String[] { "io/primeval/reflex/arguments/Arguments" });
Parameter[] parameters = method.getParameters();
generateFields(method, cw, parameters);
generateConstructor(method, cw, selfClassInternalName, selfClassDescriptor, constDesc, parameters);
generateHashCodeMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateEqualsMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateToStringMethod(cw, selfClassInternalName, selfClassDescriptor, parameters);
generateUpdaterMethod(cw, selfClassInternalName, selfClassDescriptor, updaterClassInternalName, constDesc, parameters);
generateParametersGetter(cw, selfClassInternalName, selfClassDescriptor);
generateArgumentGetters(cw, selfClassInternalName, selfClassDescriptor, parameters);
cw.visitEnd();
return cw.toByteArray();
}
示例15: findClass
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
if (name.equals(POISON_IMPL_NAME)) {
ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
cw.visit(Opcodes.V1_8, Opcodes.ACC_PUBLIC, POISON_IMPL_NAME.replace('.', '/'), null, Type.getInternalName(Pill.class), null);
// constructor
MethodVisitor constructor = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
constructor.visitCode();
constructor.visitVarInsn(Opcodes.ALOAD, 0);
constructor.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Pill.class), "<init>", "()V", false);
constructor.visitInsn(Opcodes.RETURN);
constructor.visitMaxs(0, 0);
constructor.visitEnd();
MethodVisitor setList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setField", "()V", null, null);
setList.visitCode();
setList.visitVarInsn(Opcodes.ALOAD, 0);
setList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
setList.visitInsn(Opcodes.DUP);
setList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
setList.visitFieldInsn(Opcodes.PUTFIELD, Type.getInternalName(Pill.class), "field", Type.getDescriptor(TestInterface.class));
setList.visitInsn(Opcodes.RETURN);
setList.visitMaxs(0, 0);
setList.visitEnd();
MethodVisitor setStaticList = cw.visitMethod(Opcodes.ACC_PUBLIC, "setStaticField", "()V", null, null);
setStaticList.visitCode();
setStaticList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
setStaticList.visitInsn(Opcodes.DUP);
setStaticList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
setStaticList.visitFieldInsn(Opcodes.PUTSTATIC, Type.getInternalName(Pill.class), "staticField", Type.getDescriptor(TestInterface.class));
setStaticList.visitInsn(Opcodes.RETURN);
setStaticList.visitMaxs(0, 0);
setStaticList.visitEnd();
MethodVisitor callMe = cw.visitMethod(Opcodes.ACC_PUBLIC, "callMe", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(CallBack.class)), null, null);
callMe.visitCode();
callMe.visitVarInsn(Opcodes.ALOAD, 1);
callMe.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
callMe.visitInsn(Opcodes.DUP);
callMe.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
callMe.visitMethodInsn(Opcodes.INVOKEINTERFACE, Type.getInternalName(CallBack.class), "callBack", Type.getMethodDescriptor(Type.INT_TYPE, Type.getType(TestInterface.class)), true);
callMe.visitInsn(Opcodes.IRETURN);
callMe.visitMaxs(0, 0);
callMe.visitEnd();
MethodVisitor getList = cw.visitMethod(Opcodes.ACC_PUBLIC, "get", Type.getMethodDescriptor(Type.getType(TestInterface.class)), null, null);
getList.visitCode();
getList.visitTypeInsn(Opcodes.NEW, Type.getInternalName(Object.class));
getList.visitInsn(Opcodes.DUP);
getList.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(Object.class), "<init>", "()V", false);
getList.visitInsn(Opcodes.ARETURN);
getList.visitMaxs(0, 0);
getList.visitEnd();
cw.visitEnd();
byte[] bytes = cw.toByteArray();
return defineClass(name, bytes, 0, bytes.length);
}
return super.findClass(name);
}