/******************************************************************************* * Copyright (c) 2014 Jeff Martin. * All rights reserved. This program and the accompanying materials * are made available under the terms of the GNU Public License v3.0 * which accompanies this distribution, and is available at * http://www.gnu.org/licenses/gpl.html * * Contributors: * Jeff Martin - initial API and implementation ******************************************************************************/ package cuchaz.enigma.mapping; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.zip.GZIPOutputStream; import cuchaz.enigma.analysis.JarIndex; import cuchaz.enigma.analysis.MethodInheritanceTreeNode; public class Renamer { private JarIndex m_index; private Mappings m_mappings; public Renamer( JarIndex index, Mappings mappings ) { m_index = index; m_mappings = mappings; } public void setClassName( ClassEntry obf, String deobfName ) { deobfName = NameValidator.validateClassName( deobfName ); ClassMapping classMapping = getOrCreateClassMapping( obf ); if( obf.isInnerClass() ) { classMapping.setInnerClassName( obf.getInnerClassName(), deobfName ); } else { m_mappings.m_classesByDeobf.remove( classMapping.getDeobfName() ); classMapping.setDeobfName( deobfName ); m_mappings.m_classesByDeobf.put( deobfName, classMapping ); } updateDeobfMethodSignatures(); } public void setFieldName( FieldEntry obf, String deobfName ) { deobfName = NameValidator.validateFieldName( deobfName ); ClassMapping classMapping = getOrCreateClassMappingOrInnerClassMapping( obf.getClassEntry() ); classMapping.setFieldName( obf.getName(), deobfName ); } public void setMethodTreeName( MethodEntry obf, String deobfName ) { // get the method tree setMethodTreeName( m_index.getMethodInheritance( m_mappings.getTranslator( m_index.getAncestries(), TranslationDirection.Deobfuscating ), obf ), deobfName ); } private void setMethodTreeName( MethodInheritanceTreeNode node, String deobfName ) { if( node.isImplemented() ) { // apply the name here setMethodName( node.getMethodEntry(), deobfName ); } // recurse for( int i=0; i