diff options
| author | 2014-08-17 10:56:17 -0400 | |
|---|---|---|
| committer | 2014-08-17 10:56:17 -0400 | |
| commit | 6c4440ac1133bfaa7871d1049d174528a289ef30 (patch) | |
| tree | fe1142b285c5e43dbd3afe8dd3eb0189f027c6a6 /src/cuchaz/enigma/mapping/Translator.java | |
| parent | trying to get inner/anonymous classes working... I have a working heuristic i... (diff) | |
| download | enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.tar.gz enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.tar.xz enigma-fork-6c4440ac1133bfaa7871d1049d174528a289ef30.zip | |
added support for automatic reconstruction of inner and anonymous classes
also added class to restore bridge method flags taken out by the obfuscator
Diffstat (limited to 'src/cuchaz/enigma/mapping/Translator.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/Translator.java | 104 |
1 files changed, 68 insertions, 36 deletions
diff --git a/src/cuchaz/enigma/mapping/Translator.java b/src/cuchaz/enigma/mapping/Translator.java index 5043321..76f45cd 100644 --- a/src/cuchaz/enigma/mapping/Translator.java +++ b/src/cuchaz/enigma/mapping/Translator.java | |||
| @@ -20,7 +20,7 @@ import cuchaz.enigma.mapping.SignatureUpdater.ClassNameUpdater; | |||
| 20 | public class Translator | 20 | public class Translator |
| 21 | { | 21 | { |
| 22 | private TranslationDirection m_direction; | 22 | private TranslationDirection m_direction; |
| 23 | /* TEMP */ public Map<String,ClassMapping> m_classes; | 23 | public Map<String,ClassMapping> m_classes; |
| 24 | private Ancestries m_ancestries; | 24 | private Ancestries m_ancestries; |
| 25 | 25 | ||
| 26 | protected Translator( TranslationDirection direction, Map<String,ClassMapping> classes, Ancestries ancestries ) | 26 | protected Translator( TranslationDirection direction, Map<String,ClassMapping> classes, Ancestries ancestries ) |
| @@ -30,22 +30,42 @@ public class Translator | |||
| 30 | m_ancestries = ancestries; | 30 | m_ancestries = ancestries; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | public String translate( ClassEntry in ) | 33 | public String translateClass( String className ) |
| 34 | { | 34 | { |
| 35 | return translateClass( in.getName() ); | 35 | return translate( new ClassEntry( className ) ); |
| 36 | } | 36 | } |
| 37 | 37 | ||
| 38 | public String translateClass( String in ) | 38 | public String translate( ClassEntry in ) |
| 39 | { | 39 | { |
| 40 | ClassMapping classIndex = m_classes.get( in ); | 40 | ClassMapping classMapping = m_classes.get( in.getOuterClassName() ); |
| 41 | if( classIndex != null ) | 41 | if( classMapping != null ) |
| 42 | { | 42 | { |
| 43 | return m_direction.choose( | 43 | if( in.isInnerClass() ) |
| 44 | classIndex.getDeobfName(), | 44 | { |
| 45 | classIndex.getObfName() | 45 | // look for the inner class |
| 46 | ); | 46 | String translatedInnerClassName = m_direction.choose( |
| 47 | classMapping.getDeobfInnerClassName( in.getInnerClassName() ), | ||
| 48 | classMapping.getObfInnerClassName( in.getInnerClassName() ) | ||
| 49 | ); | ||
| 50 | if( translatedInnerClassName != null ) | ||
| 51 | { | ||
| 52 | // return outer$inner | ||
| 53 | String translatedOuterClassName = m_direction.choose( | ||
| 54 | classMapping.getDeobfName(), | ||
| 55 | classMapping.getObfName() | ||
| 56 | ); | ||
| 57 | return translatedOuterClassName + "$" + translatedInnerClassName; | ||
| 58 | } | ||
| 59 | } | ||
| 60 | else | ||
| 61 | { | ||
| 62 | // just return outer | ||
| 63 | return m_direction.choose( | ||
| 64 | classMapping.getDeobfName(), | ||
| 65 | classMapping.getObfName() | ||
| 66 | ); | ||
| 67 | } | ||
| 47 | } | 68 | } |
| 48 | |||
| 49 | return null; | 69 | return null; |
| 50 | } | 70 | } |
| 51 | 71 | ||
| @@ -64,21 +84,20 @@ public class Translator | |||
| 64 | for( String className : getSelfAndAncestors( in.getClassName() ) ) | 84 | for( String className : getSelfAndAncestors( in.getClassName() ) ) |
| 65 | { | 85 | { |
| 66 | // look for the class | 86 | // look for the class |
| 67 | ClassMapping classIndex = m_classes.get( className ); | 87 | ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); |
| 68 | if( classIndex != null ) | 88 | if( classMapping != null ) |
| 69 | { | 89 | { |
| 70 | // look for the field | 90 | // look for the field |
| 71 | String deobfName = m_direction.choose( | 91 | String translatedName = m_direction.choose( |
| 72 | classIndex.getDeobfFieldName( in.getName() ), | 92 | classMapping.getDeobfFieldName( in.getName() ), |
| 73 | classIndex.getObfFieldName( in.getName() ) | 93 | classMapping.getObfFieldName( in.getName() ) |
| 74 | ); | 94 | ); |
| 75 | if( deobfName != null ) | 95 | if( translatedName != null ) |
| 76 | { | 96 | { |
| 77 | return deobfName; | 97 | return translatedName; |
| 78 | } | 98 | } |
| 79 | } | 99 | } |
| 80 | } | 100 | } |
| 81 | |||
| 82 | return null; | 101 | return null; |
| 83 | } | 102 | } |
| 84 | 103 | ||
| @@ -99,20 +118,20 @@ public class Translator | |||
| 99 | { | 118 | { |
| 100 | for( String className : getSelfAndAncestors( in.getClassName() ) ) | 119 | for( String className : getSelfAndAncestors( in.getClassName() ) ) |
| 101 | { | 120 | { |
| 102 | // look for the class | 121 | // look for class |
| 103 | ClassMapping classIndex = m_classes.get( className ); | 122 | ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); |
| 104 | if( classIndex != null ) | 123 | if( classMapping != null ) |
| 105 | { | 124 | { |
| 106 | // look for the method | 125 | // look for the method |
| 107 | MethodMapping methodIndex = m_direction.choose( | 126 | MethodMapping methodMapping = m_direction.choose( |
| 108 | classIndex.getMethodByObf( in.getName(), in.getSignature() ), | 127 | classMapping.getMethodByObf( in.getName(), in.getSignature() ), |
| 109 | classIndex.getMethodByDeobf( in.getName(), in.getSignature() ) | 128 | classMapping.getMethodByDeobf( in.getName(), in.getSignature() ) |
| 110 | ); | 129 | ); |
| 111 | if( methodIndex != null ) | 130 | if( methodMapping != null ) |
| 112 | { | 131 | { |
| 113 | return m_direction.choose( | 132 | return m_direction.choose( |
| 114 | methodIndex.getDeobfName(), | 133 | methodMapping.getDeobfName(), |
| 115 | methodIndex.getObfName() | 134 | methodMapping.getObfName() |
| 116 | ); | 135 | ); |
| 117 | } | 136 | } |
| 118 | } | 137 | } |
| @@ -148,19 +167,19 @@ public class Translator | |||
| 148 | for( String className : getSelfAndAncestors( in.getClassName() ) ) | 167 | for( String className : getSelfAndAncestors( in.getClassName() ) ) |
| 149 | { | 168 | { |
| 150 | // look for the class | 169 | // look for the class |
| 151 | ClassMapping classIndex = m_classes.get( className ); | 170 | ClassMapping classMapping = findClassMapping( new ClassEntry( className ) ); |
| 152 | if( classIndex != null ) | 171 | if( classMapping != null ) |
| 153 | { | 172 | { |
| 154 | // look for the method | 173 | // look for the method |
| 155 | MethodMapping methodIndex = m_direction.choose( | 174 | MethodMapping methodMapping = m_direction.choose( |
| 156 | classIndex.getMethodByObf( in.getMethodName(), in.getMethodSignature() ), | 175 | classMapping.getMethodByObf( in.getMethodName(), in.getMethodSignature() ), |
| 157 | classIndex.getMethodByDeobf( in.getMethodName(), in.getMethodSignature() ) | 176 | classMapping.getMethodByDeobf( in.getMethodName(), in.getMethodSignature() ) |
| 158 | ); | 177 | ); |
| 159 | if( methodIndex != null ) | 178 | if( methodMapping != null ) |
| 160 | { | 179 | { |
| 161 | return m_direction.choose( | 180 | return m_direction.choose( |
| 162 | methodIndex.getDeobfArgumentName( in.getIndex() ), | 181 | methodMapping.getDeobfArgumentName( in.getIndex() ), |
| 163 | methodIndex.getObfArgumentName( in.getIndex() ) | 182 | methodMapping.getObfArgumentName( in.getIndex() ) |
| 164 | ); | 183 | ); |
| 165 | } | 184 | } |
| 166 | } | 185 | } |
| @@ -207,4 +226,17 @@ public class Translator | |||
| 207 | ancestry.addAll( m_ancestries.getAncestry( className ) ); | 226 | ancestry.addAll( m_ancestries.getAncestry( className ) ); |
| 208 | return ancestry; | 227 | return ancestry; |
| 209 | } | 228 | } |
| 229 | |||
| 230 | private ClassMapping findClassMapping( ClassEntry classEntry ) | ||
| 231 | { | ||
| 232 | ClassMapping classMapping = m_classes.get( classEntry.getOuterClassName() ); | ||
| 233 | if( classMapping != null && classEntry.isInnerClass() ) | ||
| 234 | { | ||
| 235 | classMapping = m_direction.choose( | ||
| 236 | classMapping.getInnerClassByObf( classEntry.getInnerClassName() ), | ||
| 237 | classMapping.getInnerClassByDeobf( classEntry.getInnerClassName() ) | ||
| 238 | ); | ||
| 239 | } | ||
| 240 | return classMapping; | ||
| 241 | } | ||
| 210 | } | 242 | } |