当前位置: 首页>>代码示例>>Java>>正文


Java ClassWriter.COMPUTE_MAXS属性代码示例

本文整理汇总了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()));
}
 
开发者ID:OrionMinecraft,项目名称:Orion,代码行数:22,代码来源:ClassTransformerConverter.java

示例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;
}
 
开发者ID:ImpactDevelopment,项目名称:ClientAPI,代码行数:20,代码来源:ClientTransformer.java

示例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());
}
 
开发者ID:inferjay,项目名称:r8,代码行数:26,代码来源:TestGenerator.java

示例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();
}
 
开发者ID:mikroskeem,项目名称:Shuriken,代码行数:24,代码来源:ValidatorTester.java

示例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();
    }
 
开发者ID:Idtk,项目名称:Hotfix,代码行数:17,代码来源:ASMInsert.java

示例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;
}
 
开发者ID:kroepke,项目名称:luna,代码行数:16,代码来源:ASMBytecodeEmitter.java

示例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();
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:19,代码来源:MarkerTransformer.java

示例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;
}
 
开发者ID:Yarichi,项目名称:Proyecto-DASI,代码行数:29,代码来源:OverclockingClassTransformer.java

示例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();
    }
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:38,代码来源:MethodArgumentssUpdaterGenerator.java

示例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);
            }
        }
    };
}
 
开发者ID:ItzSomebody,项目名称:DirectLeaks-AntiReleak-Remover,代码行数:13,代码来源:Processor.java

示例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;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:38,代码来源:EventSubscriberTransformer.java

示例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;
}
 
开发者ID:MrGregorix,项目名称:Gasket,代码行数:20,代码来源:ClassModifier.java

示例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;
}
 
开发者ID:fr1kin,项目名称:ForgeHax,代码行数:27,代码来源:ForgeHaxTransformer.java

示例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();
    }
 
开发者ID:primeval-io,项目名称:primeval-reflex,代码行数:35,代码来源:MethodArgumentsGenerator.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:63,代码来源:UntrustedInterfaces.java


注:本文中的org.objectweb.asm.ClassWriter.COMPUTE_MAXS属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。