Example usage for org.objectweb.asm.tree ClassNode accept

List of usage examples for org.objectweb.asm.tree ClassNode accept

Introduction

In this page you can find the example usage for org.objectweb.asm.tree ClassNode accept.

Prototype

public void accept(final ClassVisitor classVisitor) 

Source Link

Document

Makes the given class visitor visit this class.

Usage

From source file:com.dragome.compiler.invokedynamic.InvokeDynamicBackporter.java

License:Open Source License

public static byte[] transform(byte[] bytecode) {
    ClassNode classNode = new ClassNode(Opcodes.ASM5);
    InvokeDynamicConverter invokeDynamicConverter = new InvokeDynamicConverter(classNode);
    new ClassReader(bytecode).accept(invokeDynamicConverter, 0);
    ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(cw);
    return cw.toByteArray();
}

From source file:com.dragome.methodlogger.serverside.MethodLoggerBytecodeTransformer.java

License:Apache License

public byte[] transform(String className, byte[] bytecode) {
    if (requiresTransformation(className)) {
        ClassNode classNode = new ClassNode(Opcodes.ASM5);
        MethodLoggerAdapter invokeDynamicConverter = new MethodLoggerAdapter(classNode);
        new ClassReader(bytecode).accept(invokeDynamicConverter, ClassReader.EXPAND_FRAMES);
        ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        classNode.accept(cw);
        return cw.toByteArray();
    } else/* www  . j  a v  a 2s  . c o  m*/
        return bytecode;
}

From source file:com.facebook.buck.android.dalvik.firstorder.FirstOrderHelper.java

License:Apache License

private void addDependencies(Iterable<ClassNode> allClasses) {
    for (ClassNode classNode : allClasses) {
        FirstOrderVisitorContext context = new FirstOrderVisitorContext();
        classNode.accept(context.classVisitor);

        FirstOrderTypeInfo info = context.builder.build();
        knownTypes.put(info.type, info);
    }//from   w  w w.  j a  va  2s  .co m

    // TODO(mmarucheck): consider adding events here that allow developers to track
    // how many non android.* and java.* classes went unrecognized over time.
    //
    // Not all types will be known.  This includes types from Android, java
    // runtime libraries, and any types that have been removed from the application
    // since the scenario ran.

    for (Type type : scenarioTypes) {
        addFirstOrderTypes(type);
    }
}

From source file:com.facebook.buck.dalvik.firstorder.FirstOrderHelper.java

License:Apache License

private ImmutableSet<String> addDependencies(Iterable<ClassNode> allClasses) {
    for (ClassNode classNode : allClasses) {
        FirstOrderVisitorContext context = new FirstOrderVisitorContext();
        classNode.accept(context.classVisitor);

        FirstOrderTypeInfo info = context.builder.build();
        knownTypes.put(info.type, info);
    }//ww  w  .  j  a  v  a2s . c  om

    // TODO(mmarucheck): consider adding events here that allow developers to track
    // how many non android.* and java.* classes went unrecognized over time.
    //
    // Not all types will be known.  This includes types from Android, java
    // runtime libraries, and any types that have been removed from the application
    // since the scenario ran.

    for (Type type : scenarioTypes) {
        addFirstOrderTypes(type);
    }

    return resultBuilder.build();
}

From source file:com.facebook.buck.jvm.java.abi.FilesystemStubJarWriter.java

License:Apache License

private static ByteSource getStubClassBytes(ClassNode node) {
    ClassWriter writer = new ClassWriter(0);
    node.accept(new AbiFilteringClassVisitor(writer));
    return ByteSource.wrap(writer.toByteArray());
}

From source file:com.facebook.buck.tools.dxanalysis.RegisterSpecAnalyzer.java

License:Apache License

private void go() {
    for (ClassNode klass : allClasses.values()) {
        klass.accept(new RegSpecClassVisitor());
    }
}

From source file:com.github.jasmo.obfuscate.Obfuscator.java

License:Open Source License

public void write(Path dest) throws IOException {
    Files.deleteIfExists(dest);// w  ww  .  j a  va 2 s.  c  o m
    StandardOpenOption[] override = { StandardOpenOption.CREATE, StandardOpenOption.CREATE_NEW,
            StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING };
    if (dest.toString().endsWith(".jar")) {
        try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(dest, override))) {
            writeJar(out);
        }
    } else {
        for (ClassNode node : getClassMap().values()) {
            ClassWriter writer = new ClassWriter(getWriteFlags());
            node.accept(writer);
            /**/
            Files.write(Paths.get(dest.toString(), node.name + ".class"), writer.toByteArray(), override);
        }
        for (Map.Entry<String, byte[]> entry : getFiles().entrySet()) {
            Files.write(Paths.get(dest.toString(), entry.getKey()), entry.getValue(), override);
        }
    }
}

From source file:com.github.jasmo.obfuscate.Obfuscator.java

License:Open Source License

private void writeJar(JarOutputStream out) throws IOException {
    for (ClassNode node : getClassMap().values()) {
        JarEntry entry = new JarEntry(node.name + ".class");
        out.putNextEntry(entry);/* w  ww  . j  a va 2 s .c  o m*/
        ClassWriter writer = new ClassWriter(getWriteFlags());
        node.accept(writer);
        out.write(writer.toByteArray());
        out.closeEntry();
    }
    for (Map.Entry<String, byte[]> entry : getFiles().entrySet()) {
        out.putNextEntry(new JarEntry(entry.getKey()));
        out.write(entry.getValue());
        out.closeEntry();
    }
}

From source file:com.github.jasmo.obfuscate.RemoveDebugInfo.java

License:Open Source License

@Override
public void transform(Map<String, ClassNode> classMap) {
    Map<String, ClassNode> map = new HashMap<>();
    for (ClassNode cn : classMap.values()) {
        log.debug("Removing debug info from class: {}", cn.name);
        ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
        cn.accept(writer);
        ClassNode clone = new ClassNode();
        new ClassReader(writer.toByteArray()).accept(clone, ClassReader.SKIP_DEBUG);
        map.put(clone.name, clone);/*from   w w  w.  j a  va 2s.co  m*/
    }
    classMap.clear();
    classMap.putAll(map);
}

From source file:com.github.jasmo.util.BytecodeHelper.java

License:Open Source License

public static void applyMappings(Map<String, ClassNode> classMap, Map<String, String> remap) {
    log.debug("Applying mappings [");
    for (Map.Entry<String, String> entry : remap.entrySet()) {
        String k = entry.getKey();
        String v = entry.getValue();
        if (k.equals(v))
            continue;
        // skip members with same name
        // field format =   [ "<owner>.<name>"          : "<newname>" ]
        // method format =  [ "<owner>.<name> <desc>"   : "<newname>" ]
        int n = k.indexOf('.');
        if (n != -1 && v.length() >= n && v.substring(n).equals(k)) {
            continue;
        }//  w w w.j  a  v a  2s .  c o m
        log.debug(" Map {} to {}", entry.getKey(), entry.getValue());
    }
    log.debug("]");
    SimpleRemapper remapper = new SimpleRemapper(remap);
    for (ClassNode node : new ArrayList<>(classMap.values())) {
        ClassNode copy = new ClassNode();
        ClassRemapper adapter = new ClassRemapper(copy, remapper);
        node.accept(adapter);
        classMap.put(node.name, copy);
    }
}