當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。