Java Code Examples for codechicken.lib.asm.ASMHelper#createClassNode()

The following examples show how to use codechicken.lib.asm.ASMHelper#createClassNode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MCStripTransformer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static byte[] transform(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);

    boolean changed = false;
    Iterator<MethodNode> it = cnode.methods.iterator();
    while (it.hasNext()) {
        MethodNode mnode = it.next();
        ReferenceDetector r = new ReferenceDetector();
        mnode.accept(new RemappingMethodAdapter(mnode.access, mnode.desc, new MethodVisitor(Opcodes.ASM4) {
        }, r));
        if (r.found) {
            it.remove();
            changed = true;
        }
    }
    if (changed) {
        bytes = ASMHelper.createBytes(cnode, 0);
    }
    return bytes;
}
 
Example 2
Source File: ClassDiscoverer.java    From CodeChickenCore with MIT License 6 votes vote down vote up
private void checkAddClass(String resource) {
    try {
        String classname = resource.replace(".class", "").replace("\\", ".").replace("/", ".");
        byte[] bytes = Launch.classLoader.getClassBytes(classname);
        if (bytes == null)
            return;

        ClassNode cnode = ASMHelper.createClassNode(bytes);
        for (String superclass : superclasses)
            if (!cnode.interfaces.contains(superclass) && !cnode.superName.equals(superclass))
                return;

        addClass(classname);
    } catch (IOException e) {
        CodeChickenCorePlugin.logger.error("Unable to load class: " + resource, e);
    }
}
 
Example 3
Source File: MCStripTransformer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static byte[] transform(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);

    boolean changed = false;
    Iterator<MethodNode> it = cnode.methods.iterator();
    while(it.hasNext()) {
        MethodNode mnode = it.next();
        ReferenceDetector r = new ReferenceDetector();
        mnode.accept(new RemappingMethodAdapter(mnode.access, mnode.desc, new MethodVisitor(Opcodes.ASM4) {}, r));
        if(r.found) {
            it.remove();
            changed = true;
        }
    }
    if(changed)
        bytes = ASMHelper.createBytes(cnode, 0);
    return bytes;
}
 
Example 4
Source File: InterfaceDependancyTransformer.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public byte[] transform(String name, String tname, byte[] bytes) {
    if (bytes == null) return null;
    ClassNode cnode = ASMHelper.createClassNode(bytes);

    boolean hasDependancyInterfaces = false;
    if (cnode.visibleAnnotations != null)
        for (AnnotationNode ann : cnode.visibleAnnotations)
            if (ann.desc.equals(Type.getDescriptor(InterfaceDependancies.class))) {
                hasDependancyInterfaces = true;
                break;
            }

    if (!hasDependancyInterfaces)
        return bytes;

    hasDependancyInterfaces = false;
    for (Iterator<String> iterator = cnode.interfaces.iterator(); iterator.hasNext(); ) {
        try {
            Launch.classLoader.findClass(new ObfMapping(iterator.next()).toRuntime().javaClass());
        } catch (ClassNotFoundException cnfe) {
            iterator.remove();
            hasDependancyInterfaces = true;
        }
    }

    if (!hasDependancyInterfaces)
        return bytes;

    return ASMHelper.createBytes(cnode, 0);
}
 
Example 5
Source File: DefaultImplementationTransformer.java    From CodeChickenCore with MIT License 5 votes vote down vote up
private static ClassNode getClassNode(String name) {
  	try {
	return ASMHelper.createClassNode(cl.getClassBytes(name.replace('/', '.')));
} catch (IOException e) {
	throw new RuntimeException(e);
}
  }
 
Example 6
Source File: DefaultImplementationTransformer.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
	if(transformedName.startsWith("net.minecraft") || impls.isEmpty())
		return bytes;
	
	ClassNode cnode = ASMHelper.createClassNode(bytes);
	boolean changed = false;
	for(String iname : cnode.interfaces) {
		InterfaceImpl impl = impls.get(iname);
		if(impl != null)
			changed |= impl.patch(cnode);
	}
	
	return changed ? ASMHelper.createBytes(cnode, 0) : bytes;
}
 
Example 7
Source File: MCPDeobfuscationTransformer.java    From CodeChickenCore with MIT License 5 votes vote down vote up
@Override
public byte[] transform(String name, String transformedName, byte[] bytes) {
    if (name.equals("net.minecraftforge.fml.common.Loader")) {
        bytes = injectCallback(bytes);
        activated = true;
    }

    if (!activated || bytes == null)
        return bytes;

    ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES);
    ClassWriter cw = new CC_ClassWriter(0, true);
    run.remap(cnode, cw);
    return cw.toByteArray();
}
 
Example 8
Source File: MCPDeobfuscationTransformer.java    From CodeChickenCore with MIT License 4 votes vote down vote up
private byte[] injectCallback(byte[] bytes) {
    ClassNode cnode = ASMHelper.createClassNode(bytes);
    MethodNode mnode = ASMHelper.findMethod(new ObfMapping(cnode.name, "<clinit>", "()V"), cnode);
    mnode.instructions.insert(new MethodInsnNode(INVOKESTATIC, "codechicken/core/asm/MCPDeobfuscationTransformer", "loadCallback", "()V"));
    return ASMHelper.createBytes(cnode, 0);
}