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


Java ClassNode.accept方法代码示例

本文整理汇总了Java中org.objectweb.asm.tree.ClassNode.accept方法的典型用法代码示例。如果您正苦于以下问题:Java ClassNode.accept方法的具体用法?Java ClassNode.accept怎么用?Java ClassNode.accept使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objectweb.asm.tree.ClassNode的用法示例。


在下文中一共展示了ClassNode.accept方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transform

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@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,代码行数:21,代码来源:ClientTransformer.java

示例2: serializeClass

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
public byte[] serializeClass(ClassInstance cls, boolean mapped) {
	ClassNode cn = cls.getMergedAsmNode();
	if (cn == null) throw new IllegalArgumentException("cls without asm node: "+cls);

	ClassWriter writer = new ClassWriter(0);

	synchronized (Util.asmNodeSync) {
		if (mapped) {
			AsmClassRemapper.process(cn, remapper, writer);
		} else {
			cn.accept(writer);
		}
	}

	return writer.toByteArray();
}
 
开发者ID:sfPlayer1,项目名称:Matcher,代码行数:17,代码来源:ClassFeatureExtractor.java

示例3: classNodeToBytes

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
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,代码行数:17,代码来源:ASMBytecodeEmitter.java

示例4: rewriteClass

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
/**
 * Writes a modified *.class file to the output JAR file.
 */
private void rewriteClass(
        JarEntry entry,
        InputStream inputStream,
        JarOutputStream outputStream) throws IOException {
    ClassReader classReader = new ClassReader(inputStream);
    ClassNode classNode = new ClassNode(Opcodes.ASM5);

    classReader.accept(classNode, EMPTY_FLAGS);
    
    modifyClass(classNode);
    
    ClassWriter classWriter = new ClassWriter(0);
    classNode.accept(classWriter);
    
    outputStream.putNextEntry(new ZipEntry(entry.getName()));
    outputStream.write(classWriter.toByteArray());
}
 
开发者ID:codezjx,项目名称:MockableJarGenerator,代码行数:21,代码来源:MockableJarGenerator.java

示例5: write

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@Override
public void write(File file) throws IOException {
    JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
    try {
        for (Iterator<ClassNode> itr = iterator(); itr.hasNext(); ) {
            ClassNode   node   = itr.next();
            ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
            node.accept(new CheckClassAdapter(writer, true));
            byte[] bytes = writer.toByteArray();
            jos.putNextEntry(new JarEntry(node.name.concat(".class")));
            jos.write(bytes);
        }
    } finally {
        jos.close();
    }
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:17,代码来源:JarArchive.java

示例6: transform

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] bytes)
{
    if (bytes == null || name.equals("net.minecraftforge.fml.common.eventhandler.Event") || name.startsWith("net.minecraft.") || name.indexOf('.') == -1)
    {
        return bytes;
    }
    ClassReader cr = new ClassReader(bytes);
    ClassNode classNode = new ClassNode();
    cr.accept(classNode, 0);

    try
    {
        if (buildEvents(classNode))
        {
            ClassWriter cw = new ClassWriter(COMPUTE_FRAMES);
            classNode.accept(cw);
            return cw.toByteArray();
        }
        return bytes;
    }
    catch (ClassNotFoundException ex)
    {
        // Discard silently- it's just noise
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

    return bytes;
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:33,代码来源:EventSubscriptionTransformer.java

示例7: transform

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@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,代码行数:39,代码来源:EventSubscriberTransformer.java

示例8: process

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
private static void process(File jarFile, File outputFile, String message) throws Throwable {
    ZipFile zipFile = new ZipFile(jarFile);
    Enumeration<? extends ZipEntry> entries = zipFile.entries();
    ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outputFile));
    try {
        while (entries.hasMoreElements()) {
            ZipEntry entry = entries.nextElement();
            if (!entry.isDirectory() && entry.getName().endsWith(".class")) {
                try (InputStream in = zipFile.getInputStream(entry)) {
                    ClassReader cr = new ClassReader(in);
                    ClassNode classNode = new ClassNode();
                    cr.accept(classNode, 0);

                    messageInjector(classNode, message);

                    ClassWriter cw = new ClassWriter(0);
                    classNode.accept(cw);
                    ZipEntry newEntry = new ZipEntry(entry.getName());
                    newEntry.setTime(System.currentTimeMillis());
                    out.putNextEntry(newEntry);
                    writeToFile(out, new ByteArrayInputStream(cw.toByteArray()));
                }
            } else {
                entry.setTime(System.currentTimeMillis());
                out.putNextEntry(entry);
                writeToFile(out, zipFile.getInputStream(entry));
            }
        }
    } finally {
        zipFile.close();
        out.close();
        if (!messagegotinjected) {
            // throw new IllegalStateException("Could not find Bukkit onEnable or onLoad method.");
            throw new IllegalStateException("Could not find Bukkit onEnable method.");
        }
    }
}
 
开发者ID:ItzSomebody,项目名称:BukkitPlugin-Message-Injector,代码行数:38,代码来源:Injector.java

示例9: getEntry

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@Override
public byte[] getEntry(String name) throws ClassNotFoundException {
    ClassNode node = classes.get(name);
    if (node == null) {
        throw new ClassNotFoundException("Class " + name + " is not valid in the archive.");
    }
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    node.accept(writer);
    return writer.toByteArray();
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:11,代码来源:JarArchive.java

示例10: checkBytecode

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:plast-lab,项目名称:HeapDL,代码行数:16,代码来源:Transformer.java

示例11: transform

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@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,代码行数:28,代码来源:ForgeHaxTransformer.java

示例12: modify

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
/**
 * 类修改器
 * 修改方法
 * @param className 类名
 * @param originalClass 原始类字节数组
 * @param interceptorId 注册的拦截器id
 * @return modified类字节数组
 */
@SuppressWarnings("unchecked")
public static byte[] modify(String className, byte[] originalClass,String interceptorId) {
    Interceptor interceptor = Interceptor.getInterceptor(interceptorId);
    if (!interceptor.matchBeforeReadClass(className, originalClass)) {
        return originalClass;
    }
    ClassReader cr = new ClassReader(originalClass);
    ClassNode cn = new ClassNode();
    cr.accept(cn, 0);

    if (!interceptor.matchAfterReadClass(cn)) {
        return originalClass;
    }

    List<MethodNode> methods = cn.methods;
    boolean transformed = false;
    for (MethodNode node : methods) {
        if (MethodModifier.modifyMethod(interceptor,cn,node)) {
            transformed = true;
        }
    }
    if (!transformed) {
        return originalClass;
    }

    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES);

    cn.accept(cw);

    return cw.toByteArray();

}
 
开发者ID:yutian-tianpl,项目名称:byte-cobweb,代码行数:41,代码来源:ClassModifier.java

示例13: createClass

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
public static Class<?> createClass(ClassNode node)
{
    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS);
    node.accept(writer);

    byte[] bytes = writer.toByteArray();
    return createClassFromBytes(node.name.replace('/', '.'), bytes);
}
 
开发者ID:cubex2,项目名称:customstuff4,代码行数:9,代码来源:AsmHelper.java

示例14: transform

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
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,代码行数:30,代码来源:OverclockingClassTransformer.java

示例15: transform

import org.objectweb.asm.tree.ClassNode; //导入方法依赖的package包/类
@Override
public byte[] transform(String name, String transformedName, byte[] bytes)
{
    if (bytes == null) { return null; }

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    if (remove(classNode.visibleAnnotations, SIDE))
    {
        if (DEBUG)
        {
            System.out.println(String.format("Attempted to load class %s for invalid side %s", classNode.name, SIDE));
        }
        throw new RuntimeException(String.format("Attempted to load class %s for invalid side %s", classNode.name, SIDE));
    }

    Iterator<FieldNode> fields = classNode.fields.iterator();
    while(fields.hasNext())
    {
        FieldNode field = fields.next();
        if (remove(field.visibleAnnotations, SIDE))
        {
            if (DEBUG)
            {
                System.out.println(String.format("Removing Field: %s.%s", classNode.name, field.name));
            }
            fields.remove();
        }
    }
    Iterator<MethodNode> methods = classNode.methods.iterator();
    while(methods.hasNext())
    {
        MethodNode method = methods.next();
        if (remove(method.visibleAnnotations, SIDE))
        {
            if (DEBUG)
            {
                System.out.println(String.format("Removing Method: %s.%s%s", classNode.name, method.name, method.desc));
            }
            methods.remove();
        }
    }

    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(writer);
    return writer.toByteArray();
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:50,代码来源:SideTransformer.java


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