diff options
| author | 2014-09-01 22:52:07 -0400 | |
|---|---|---|
| committer | 2014-09-01 22:52:07 -0400 | |
| commit | 360bbd1c2fca8cbd575907b7d930a8072fccb0c2 (patch) | |
| tree | 93d0f3c4a0901411427df580c5ddb75cf27440f1 /src/cuchaz/enigma/mapping/Renamer.java | |
| parent | added copyright notice (diff) | |
| download | enigma-fork-360bbd1c2fca8cbd575907b7d930a8072fccb0c2.tar.gz enigma-fork-360bbd1c2fca8cbd575907b7d930a8072fccb0c2.tar.xz enigma-fork-360bbd1c2fca8cbd575907b7d930a8072fccb0c2.zip | |
refactored jar,translation index. fixed bug with field renaming when fields are shadowed by subclasses
Diffstat (limited to 'src/cuchaz/enigma/mapping/Renamer.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/Renamer.java | 160 |
1 files changed, 0 insertions, 160 deletions
diff --git a/src/cuchaz/enigma/mapping/Renamer.java b/src/cuchaz/enigma/mapping/Renamer.java deleted file mode 100644 index 15d9af4..0000000 --- a/src/cuchaz/enigma/mapping/Renamer.java +++ /dev/null | |||
| @@ -1,160 +0,0 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2014 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Public License v3.0 | ||
| 5 | * which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/gpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.io.ObjectOutputStream; | ||
| 15 | import java.io.OutputStream; | ||
| 16 | import java.util.Set; | ||
| 17 | import java.util.zip.GZIPOutputStream; | ||
| 18 | |||
| 19 | import cuchaz.enigma.analysis.JarIndex; | ||
| 20 | |||
| 21 | public class Renamer | ||
| 22 | { | ||
| 23 | private JarIndex m_index; | ||
| 24 | private Mappings m_mappings; | ||
| 25 | |||
| 26 | public Renamer( JarIndex index, Mappings mappings ) | ||
| 27 | { | ||
| 28 | m_index = index; | ||
| 29 | m_mappings = mappings; | ||
| 30 | } | ||
| 31 | |||
| 32 | public void setClassName( ClassEntry obf, String deobfName ) | ||
| 33 | { | ||
| 34 | deobfName = NameValidator.validateClassName( deobfName ); | ||
| 35 | ClassEntry targetEntry = new ClassEntry( deobfName ); | ||
| 36 | if( m_mappings.containsDeobfClass( deobfName ) || m_index.containsObfClass( targetEntry ) ) | ||
| 37 | { | ||
| 38 | throw new IllegalNameException( deobfName, "There is already a class with that name" ); | ||
| 39 | } | ||
| 40 | |||
| 41 | ClassMapping classMapping = getOrCreateClassMapping( obf ); | ||
| 42 | |||
| 43 | if( obf.isInnerClass() ) | ||
| 44 | { | ||
| 45 | classMapping.setInnerClassName( obf.getInnerClassName(), deobfName ); | ||
| 46 | } | ||
| 47 | else | ||
| 48 | { | ||
| 49 | m_mappings.m_classesByDeobf.remove( classMapping.getDeobfName() ); | ||
| 50 | classMapping.setDeobfName( deobfName ); | ||
| 51 | m_mappings.m_classesByDeobf.put( deobfName, classMapping ); | ||
| 52 | } | ||
| 53 | |||
| 54 | updateDeobfMethodSignatures(); | ||
| 55 | } | ||
| 56 | |||
| 57 | public void setFieldName( FieldEntry obf, String deobfName ) | ||
| 58 | { | ||
| 59 | deobfName = NameValidator.validateFieldName( deobfName ); | ||
| 60 | FieldEntry targetEntry = new FieldEntry( obf.getClassEntry(), deobfName ); | ||
| 61 | if( m_mappings.containsDeobfField( obf.getClassEntry(), deobfName ) || m_index.containsObfField( targetEntry ) ) | ||
| 62 | { | ||
| 63 | throw new IllegalNameException( deobfName, "There is already a field with that name" ); | ||
| 64 | } | ||
| 65 | |||
| 66 | ClassMapping classMapping = getOrCreateClassMappingOrInnerClassMapping( obf.getClassEntry() ); | ||
| 67 | classMapping.setFieldName( obf.getName(), deobfName ); | ||
| 68 | } | ||
| 69 | |||
| 70 | public void setMethodTreeName( MethodEntry obf, String deobfName ) | ||
| 71 | { | ||
| 72 | Set<MethodEntry> implementations = m_index.getRelatedMethodImplementations( obf ); | ||
| 73 | |||
| 74 | deobfName = NameValidator.validateMethodName( deobfName ); | ||
| 75 | for( MethodEntry entry : implementations ) | ||
| 76 | { | ||
| 77 | MethodEntry targetEntry = new MethodEntry( entry.getClassEntry(), deobfName, entry.getSignature() ); | ||
| 78 | if( m_mappings.containsDeobfMethod( entry.getClassEntry(), deobfName, entry.getSignature() ) || m_index.containsObfMethod( targetEntry ) ) | ||
| 79 | { | ||
| 80 | String className = m_mappings.getTranslator( m_index.getAncestries(), TranslationDirection.Deobfuscating ).translateClass( entry.getClassName() ); | ||
| 81 | throw new IllegalNameException( deobfName, "There is already a method with that name and signature in class " + className ); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | for( MethodEntry entry : implementations ) | ||
| 86 | { | ||
| 87 | setMethodName( entry, deobfName ); | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | public void setMethodName( MethodEntry obf, String deobfName ) | ||
| 92 | { | ||
| 93 | deobfName = NameValidator.validateMethodName( deobfName ); | ||
| 94 | MethodEntry targetEntry = new MethodEntry( obf.getClassEntry(), deobfName, obf.getSignature() ); | ||
| 95 | if( m_mappings.containsDeobfMethod( obf.getClassEntry(), deobfName, obf.getSignature() ) || m_index.containsObfMethod( targetEntry ) ) | ||
| 96 | { | ||
| 97 | String className = m_mappings.getTranslator( m_index.getAncestries(), TranslationDirection.Deobfuscating ).translateClass( obf.getClassName() ); | ||
| 98 | throw new IllegalNameException( deobfName, "There is already a method with that name and signature in class " + className ); | ||
| 99 | } | ||
| 100 | |||
| 101 | ClassMapping classMapping = getOrCreateClassMappingOrInnerClassMapping( obf.getClassEntry() ); | ||
| 102 | String deobfSignature = m_mappings.getTranslator( m_index.getAncestries(), TranslationDirection.Deobfuscating ).translateSignature( obf.getSignature() ); | ||
| 103 | classMapping.setMethodNameAndSignature( obf.getName(), obf.getSignature(), deobfName, deobfSignature ); | ||
| 104 | } | ||
| 105 | |||
| 106 | public void setArgumentName( ArgumentEntry obf, String deobfName ) | ||
| 107 | { | ||
| 108 | deobfName = NameValidator.validateArgumentName( deobfName ); | ||
| 109 | // NOTE: don't need to check arguments for name collisions with names determined by Procyon | ||
| 110 | if( m_mappings.containsArgument( obf.getMethodEntry(), deobfName ) ) | ||
| 111 | { | ||
| 112 | throw new IllegalNameException( deobfName, "There is already an argument with that name" ); | ||
| 113 | } | ||
| 114 | |||
| 115 | ClassMapping classMapping = getOrCreateClassMappingOrInnerClassMapping( obf.getClassEntry() ); | ||
| 116 | classMapping.setArgumentName( obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), deobfName ); | ||
| 117 | } | ||
| 118 | |||
| 119 | public void write( OutputStream out ) | ||
| 120 | throws IOException | ||
| 121 | { | ||
| 122 | // TEMP: just use the object output for now. We can find a more efficient storage format later | ||
| 123 | GZIPOutputStream gzipout = new GZIPOutputStream( out ); | ||
| 124 | ObjectOutputStream oout = new ObjectOutputStream( gzipout ); | ||
| 125 | oout.writeObject( this ); | ||
| 126 | gzipout.finish(); | ||
| 127 | } | ||
| 128 | |||
| 129 | private ClassMapping getOrCreateClassMapping( ClassEntry obfClassEntry ) | ||
| 130 | { | ||
| 131 | String obfClassName = obfClassEntry.getOuterClassName(); | ||
| 132 | ClassMapping classMapping = m_mappings.m_classesByObf.get( obfClassName ); | ||
| 133 | if( classMapping == null ) | ||
| 134 | { | ||
| 135 | classMapping = new ClassMapping( obfClassName, obfClassName ); | ||
| 136 | m_mappings.m_classesByObf.put( classMapping.getObfName(), classMapping ); | ||
| 137 | m_mappings.m_classesByDeobf.put( classMapping.getDeobfName(), classMapping ); | ||
| 138 | } | ||
| 139 | return classMapping; | ||
| 140 | } | ||
| 141 | |||
| 142 | private ClassMapping getOrCreateClassMappingOrInnerClassMapping( ClassEntry obfClassEntry ) | ||
| 143 | { | ||
| 144 | ClassMapping classMapping = getOrCreateClassMapping( obfClassEntry ); | ||
| 145 | if( obfClassEntry.isInnerClass() ) | ||
| 146 | { | ||
| 147 | classMapping = classMapping.getOrCreateInnerClass( obfClassEntry.getInnerClassName() ); | ||
| 148 | } | ||
| 149 | return classMapping; | ||
| 150 | } | ||
| 151 | |||
| 152 | private void updateDeobfMethodSignatures( ) | ||
| 153 | { | ||
| 154 | Translator translator = m_mappings.getTranslator( m_index.getAncestries(), TranslationDirection.Deobfuscating ); | ||
| 155 | for( ClassMapping classMapping : m_mappings.m_classesByObf.values() ) | ||
| 156 | { | ||
| 157 | classMapping.updateDeobfMethodSignatures( translator ); | ||
| 158 | } | ||
| 159 | } | ||
| 160 | } | ||