    001/*
    002 * Forge Mod Loader
    003 * Copyright (c) 2012-2013 cpw.
    004 * All rights reserved. This program and the accompanying materials
    005 * are made available under the terms of the GNU Lesser Public License v2.1
    006 * which accompanies this distribution, and is available at
    007 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
    008 *
    009 * Contributors:
    010 *     cpw - implementation
    011 */
    012
    013package cpw.mods.fml.common.asm.transformers;
    014
    015import org.objectweb.asm.ClassReader;
    016import org.objectweb.asm.ClassWriter;
    017import org.objectweb.asm.Opcodes;
    018import org.objectweb.asm.commons.RemappingClassAdapter;
    019import org.objectweb.asm.tree.ClassNode;
    020
    021import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
    022import cpw.mods.fml.common.asm.transformers.deobf.FMLRemappingAdapter;
    023import cpw.mods.fml.relauncher.IClassNameTransformer;
    024import cpw.mods.fml.relauncher.IClassTransformer;
    025
    026public class DeobfuscationTransformer implements IClassTransformer, IClassNameTransformer {
    027
    028    @Override
    029    public byte[] transform(String name, String transformedName, byte[] bytes)
    030    {
    031        if (bytes == null)
    032        {
    033            return null;
    034        }
    035        ClassReader classReader = new ClassReader(bytes);
    036        ClassWriter classWriter = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    037        RemappingClassAdapter remapAdapter = new FMLRemappingAdapter(classWriter);
    038        classReader.accept(remapAdapter, ClassReader.EXPAND_FRAMES);
    039        return classWriter.toByteArray();
    040    }
    041
    042    @Override
    043    public String remapClassName(String name)
    044    {
    045        return FMLDeobfuscatingRemapper.INSTANCE.map(name.replace('.','/')).replace('/', '.');
    046    }
    047
    048    @Override
    049    public String unmapClassName(String name)
    050    {
    051        return FMLDeobfuscatingRemapper.INSTANCE.unmap(name.replace('.', '/')).replace('/','.');
    052    }
    053
    054}