diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/ClassMapping.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/ClassMapping.java | 111 |
1 files changed, 69 insertions, 42 deletions
diff --git a/src/cuchaz/enigma/mapping/ClassMapping.java b/src/cuchaz/enigma/mapping/ClassMapping.java index 5faaf2a..bce16cc 100644 --- a/src/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -29,7 +29,11 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 29 | private Map<String,MethodMapping> m_methodsByObf; | 29 | private Map<String,MethodMapping> m_methodsByObf; |
| 30 | private Map<String,MethodMapping> m_methodsByDeobf; | 30 | private Map<String,MethodMapping> m_methodsByDeobf; |
| 31 | 31 | ||
| 32 | // NOTE: this argument order is important for the MethodReader/MethodWriter | 32 | public ClassMapping( String obfName ) |
| 33 | { | ||
| 34 | this( obfName, null ); | ||
| 35 | } | ||
| 36 | |||
| 33 | public ClassMapping( String obfName, String deobfName ) | 37 | public ClassMapping( String obfName, String deobfName ) |
| 34 | { | 38 | { |
| 35 | m_obfName = obfName; | 39 | m_obfName = obfName; |
| @@ -60,14 +64,19 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 60 | 64 | ||
| 61 | public Iterable<ClassMapping> innerClasses( ) | 65 | public Iterable<ClassMapping> innerClasses( ) |
| 62 | { | 66 | { |
| 63 | assert( m_innerClassesByObf.size() == m_innerClassesByDeobf.size() ); | 67 | assert( m_innerClassesByObf.size() >= m_innerClassesByDeobf.size() ); |
| 64 | return m_innerClassesByObf.values(); | 68 | return m_innerClassesByObf.values(); |
| 65 | } | 69 | } |
| 66 | 70 | ||
| 67 | protected void addInnerClassMapping( ClassMapping classMapping ) | 71 | public void addInnerClassMapping( ClassMapping classMapping ) |
| 68 | { | 72 | { |
| 69 | m_innerClassesByObf.put( classMapping.getObfName(), classMapping ); | 73 | boolean obfWasAdded = m_innerClassesByObf.put( classMapping.getObfName(), classMapping ) == null; |
| 70 | m_innerClassesByDeobf.put( classMapping.getDeobfName(), classMapping ); | 74 | assert( obfWasAdded ); |
| 75 | if( classMapping.getDeobfName() != null ) | ||
| 76 | { | ||
| 77 | boolean deobfWasAdded = m_innerClassesByDeobf.put( classMapping.getDeobfName(), classMapping ) == null; | ||
| 78 | assert( deobfWasAdded ); | ||
| 79 | } | ||
| 71 | } | 80 | } |
| 72 | 81 | ||
| 73 | public ClassMapping getOrCreateInnerClass( String obfName ) | 82 | public ClassMapping getOrCreateInnerClass( String obfName ) |
| @@ -75,9 +84,9 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 75 | ClassMapping classMapping = m_innerClassesByObf.get( obfName ); | 84 | ClassMapping classMapping = m_innerClassesByObf.get( obfName ); |
| 76 | if( classMapping == null ) | 85 | if( classMapping == null ) |
| 77 | { | 86 | { |
| 78 | classMapping = new ClassMapping( obfName, obfName ); | 87 | classMapping = new ClassMapping( obfName ); |
| 79 | m_innerClassesByObf.put( obfName, classMapping ); | 88 | boolean wasAdded = m_innerClassesByObf.put( obfName, classMapping ) == null; |
| 80 | m_innerClassesByDeobf.put( obfName, classMapping ); | 89 | assert( wasAdded ); |
| 81 | } | 90 | } |
| 82 | return classMapping; | 91 | return classMapping; |
| 83 | } | 92 | } |
| @@ -115,9 +124,11 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 115 | public void setInnerClassName( String obfName, String deobfName ) | 124 | public void setInnerClassName( String obfName, String deobfName ) |
| 116 | { | 125 | { |
| 117 | ClassMapping classMapping = getOrCreateInnerClass( obfName ); | 126 | ClassMapping classMapping = getOrCreateInnerClass( obfName ); |
| 118 | m_innerClassesByDeobf.remove( classMapping.getDeobfName() ); | 127 | boolean wasRemoved = m_innerClassesByDeobf.remove( classMapping.getDeobfName() ) != null; |
| 128 | assert( wasRemoved ); | ||
| 119 | classMapping.setDeobfName( deobfName ); | 129 | classMapping.setDeobfName( deobfName ); |
| 120 | m_innerClassesByDeobf.put( deobfName, classMapping ); | 130 | boolean wasAdded = m_innerClassesByDeobf.put( deobfName, classMapping ) == null; |
| 131 | assert( wasAdded ); | ||
| 121 | } | 132 | } |
| 122 | 133 | ||
| 123 | //// FIELDS //////// | 134 | //// FIELDS //////// |
| @@ -128,7 +139,7 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 128 | return m_fieldsByObf.values(); | 139 | return m_fieldsByObf.values(); |
| 129 | } | 140 | } |
| 130 | 141 | ||
| 131 | protected void addFieldMapping( FieldMapping fieldMapping ) | 142 | public void addFieldMapping( FieldMapping fieldMapping ) |
| 132 | { | 143 | { |
| 133 | if( m_fieldsByObf.containsKey( fieldMapping.getObfName() ) ) | 144 | if( m_fieldsByObf.containsKey( fieldMapping.getObfName() ) ) |
| 134 | { | 145 | { |
| @@ -138,8 +149,10 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 138 | { | 149 | { |
| 139 | throw new Error( "Already have mapping for " + m_deobfName + "." + fieldMapping.getDeobfName() ); | 150 | throw new Error( "Already have mapping for " + m_deobfName + "." + fieldMapping.getDeobfName() ); |
| 140 | } | 151 | } |
| 141 | m_fieldsByObf.put( fieldMapping.getObfName(), fieldMapping ); | 152 | boolean obfWasAdded = m_fieldsByObf.put( fieldMapping.getObfName(), fieldMapping ) == null; |
| 142 | m_fieldsByDeobf.put( fieldMapping.getDeobfName(), fieldMapping ); | 153 | assert( obfWasAdded ); |
| 154 | boolean deobfWasAdded = m_fieldsByDeobf.put( fieldMapping.getDeobfName(), fieldMapping ) == null; | ||
| 155 | assert( deobfWasAdded ); | ||
| 143 | assert( m_fieldsByObf.size() == m_fieldsByDeobf.size() ); | 156 | assert( m_fieldsByObf.size() == m_fieldsByDeobf.size() ); |
| 144 | } | 157 | } |
| 145 | 158 | ||
| @@ -169,38 +182,47 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 169 | if( fieldMapping == null ) | 182 | if( fieldMapping == null ) |
| 170 | { | 183 | { |
| 171 | fieldMapping = new FieldMapping( obfName, deobfName ); | 184 | fieldMapping = new FieldMapping( obfName, deobfName ); |
| 172 | m_fieldsByObf.put( obfName, fieldMapping ); | 185 | boolean obfWasAdded = m_fieldsByObf.put( obfName, fieldMapping ) == null; |
| 173 | m_fieldsByDeobf.put( deobfName, fieldMapping ); | 186 | assert( obfWasAdded ); |
| 187 | } | ||
| 188 | else | ||
| 189 | { | ||
| 190 | boolean wasRemoved = m_fieldsByDeobf.remove( fieldMapping.getDeobfName() ) != null; | ||
| 191 | assert( wasRemoved ); | ||
| 174 | } | 192 | } |
| 175 | |||
| 176 | m_fieldsByDeobf.remove( fieldMapping.getDeobfName() ); | ||
| 177 | fieldMapping.setDeobfName( deobfName ); | 193 | fieldMapping.setDeobfName( deobfName ); |
| 178 | m_fieldsByDeobf.put( deobfName, fieldMapping ); | 194 | boolean wasAdded = m_fieldsByDeobf.put( deobfName, fieldMapping ) == null; |
| 195 | assert( wasAdded ); | ||
| 179 | } | 196 | } |
| 180 | 197 | ||
| 181 | //// METHODS //////// | 198 | //// METHODS //////// |
| 182 | 199 | ||
| 183 | public Iterable<MethodMapping> methods( ) | 200 | public Iterable<MethodMapping> methods( ) |
| 184 | { | 201 | { |
| 185 | assert( m_methodsByObf.size() == m_methodsByDeobf.size() ); | 202 | assert( m_methodsByObf.size() >= m_methodsByDeobf.size() ); |
| 186 | return m_methodsByObf.values(); | 203 | return m_methodsByObf.values(); |
| 187 | } | 204 | } |
| 188 | 205 | ||
| 189 | protected void addMethodMapping( MethodMapping methodMapping ) | 206 | public void addMethodMapping( MethodMapping methodMapping ) |
| 190 | { | 207 | { |
| 191 | String obfKey = getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ); | 208 | String obfKey = getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ); |
| 192 | String deobfKey = getMethodKey( methodMapping.getDeobfName(), methodMapping.getDeobfSignature() ); | ||
| 193 | if( m_methodsByObf.containsKey( obfKey ) ) | 209 | if( m_methodsByObf.containsKey( obfKey ) ) |
| 194 | { | 210 | { |
| 195 | throw new Error( "Already have mapping for " + m_obfName + "." + obfKey ); | 211 | throw new Error( "Already have mapping for " + m_obfName + "." + obfKey ); |
| 196 | } | 212 | } |
| 197 | if( m_methodsByDeobf.containsKey( deobfKey ) ) | 213 | boolean wasAdded = m_methodsByObf.put( obfKey, methodMapping ) == null; |
| 214 | assert( wasAdded ); | ||
| 215 | if( methodMapping.getDeobfName() != null ) | ||
| 198 | { | 216 | { |
| 199 | throw new Error( "Already have mapping for " + m_deobfName + "." + deobfKey ); | 217 | String deobfKey = getMethodKey( methodMapping.getDeobfName(), methodMapping.getDeobfSignature() ); |
| 218 | if( m_methodsByDeobf.containsKey( deobfKey ) ) | ||
| 219 | { | ||
| 220 | throw new Error( "Already have mapping for " + m_deobfName + "." + deobfKey ); | ||
| 221 | } | ||
| 222 | boolean deobfWasAdded = m_methodsByDeobf.put( deobfKey, methodMapping ) == null; | ||
| 223 | assert( deobfWasAdded ); | ||
| 200 | } | 224 | } |
| 201 | m_methodsByObf.put( obfKey, methodMapping ); | 225 | assert( m_methodsByObf.size() >= m_methodsByDeobf.size() ); |
| 202 | m_methodsByDeobf.put( deobfKey, methodMapping ); | ||
| 203 | assert( m_methodsByObf.size() == m_methodsByDeobf.size() ); | ||
| 204 | } | 226 | } |
| 205 | 227 | ||
| 206 | public MethodMapping getMethodByObf( String obfName, String signature ) | 228 | public MethodMapping getMethodByObf( String obfName, String signature ) |
| @@ -231,13 +253,17 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 231 | MethodMapping methodMapping = m_methodsByObf.get( getMethodKey( obfName, obfSignature ) ); | 253 | MethodMapping methodMapping = m_methodsByObf.get( getMethodKey( obfName, obfSignature ) ); |
| 232 | if( methodMapping == null ) | 254 | if( methodMapping == null ) |
| 233 | { | 255 | { |
| 234 | methodMapping = createMethodIndex( obfName, obfSignature ); | 256 | methodMapping = createMethodMapping( obfName, obfSignature ); |
| 257 | } | ||
| 258 | else | ||
| 259 | { | ||
| 260 | boolean wasRemoved = m_methodsByDeobf.remove( getMethodKey( methodMapping.getDeobfName(), methodMapping.getDeobfSignature() ) ) != null; | ||
| 261 | assert( wasRemoved ); | ||
| 235 | } | 262 | } |
| 236 | |||
| 237 | m_methodsByDeobf.remove( getMethodKey( methodMapping.getDeobfName(), methodMapping.getDeobfSignature() ) ); | ||
| 238 | methodMapping.setDeobfName( deobfName ); | 263 | methodMapping.setDeobfName( deobfName ); |
| 239 | methodMapping.setDeobfSignature( deobfSignature ); | 264 | methodMapping.setDeobfSignature( deobfSignature ); |
| 240 | m_methodsByDeobf.put( getMethodKey( deobfName, deobfSignature ), methodMapping ); | 265 | boolean wasAdded = m_methodsByDeobf.put( getMethodKey( deobfName, deobfSignature ), methodMapping ) == null; |
| 266 | assert( wasAdded ); | ||
| 241 | } | 267 | } |
| 242 | 268 | ||
| 243 | public void updateDeobfMethodSignatures( Translator translator ) | 269 | public void updateDeobfMethodSignatures( Translator translator ) |
| @@ -255,17 +281,16 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 255 | MethodMapping methodIndex = m_methodsByObf.get( getMethodKey( obfMethodName, obfMethodSignature ) ); | 281 | MethodMapping methodIndex = m_methodsByObf.get( getMethodKey( obfMethodName, obfMethodSignature ) ); |
| 256 | if( methodIndex == null ) | 282 | if( methodIndex == null ) |
| 257 | { | 283 | { |
| 258 | methodIndex = createMethodIndex( obfMethodName, obfMethodSignature ); | 284 | methodIndex = createMethodMapping( obfMethodName, obfMethodSignature ); |
| 259 | } | 285 | } |
| 260 | methodIndex.setArgumentName( argumentIndex, argumentName ); | 286 | methodIndex.setArgumentName( argumentIndex, argumentName ); |
| 261 | } | 287 | } |
| 262 | 288 | ||
| 263 | private MethodMapping createMethodIndex( String obfName, String obfSignature ) | 289 | private MethodMapping createMethodMapping( String obfName, String obfSignature ) |
| 264 | { | 290 | { |
| 265 | MethodMapping methodMapping = new MethodMapping( obfName, obfName, obfSignature, obfSignature ); | 291 | MethodMapping methodMapping = new MethodMapping( obfName, obfSignature ); |
| 266 | String key = getMethodKey( obfName, obfSignature ); | 292 | boolean wasAdded = m_methodsByObf.put( getMethodKey( obfName, obfSignature ), methodMapping ) == null; |
| 267 | m_methodsByObf.put( key, methodMapping ); | 293 | assert( wasAdded ); |
| 268 | m_methodsByDeobf.put( key, methodMapping ); | ||
| 269 | return methodMapping; | 294 | return methodMapping; |
| 270 | } | 295 | } |
| 271 | 296 | ||
| @@ -308,9 +333,10 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 308 | { | 333 | { |
| 309 | if( innerClassMapping.renameObfClass( oldObfClassName, newObfClassName ) ) | 334 | if( innerClassMapping.renameObfClass( oldObfClassName, newObfClassName ) ) |
| 310 | { | 335 | { |
| 311 | m_innerClassesByObf.remove( oldObfClassName ); | 336 | boolean wasRemoved = m_innerClassesByObf.remove( oldObfClassName ) != null; |
| 312 | m_innerClassesByObf.put( newObfClassName, innerClassMapping ); | 337 | assert( wasRemoved ); |
| 313 | assert( m_innerClassesByObf.size() == m_innerClassesByDeobf.size() ); | 338 | boolean wasAdded = m_innerClassesByObf.put( newObfClassName, innerClassMapping ) == null; |
| 339 | assert( wasAdded ); | ||
| 314 | } | 340 | } |
| 315 | } | 341 | } |
| 316 | 342 | ||
| @@ -320,9 +346,10 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 320 | String oldMethodKey = getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ); | 346 | String oldMethodKey = getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ); |
| 321 | if( methodMapping.renameObfClass( oldObfClassName, newObfClassName ) ) | 347 | if( methodMapping.renameObfClass( oldObfClassName, newObfClassName ) ) |
| 322 | { | 348 | { |
| 323 | m_methodsByObf.remove( oldMethodKey ); | 349 | boolean wasRemoved = m_methodsByObf.remove( oldMethodKey ) != null; |
| 324 | m_methodsByObf.put( getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ), methodMapping ); | 350 | assert( wasRemoved ); |
| 325 | assert( m_methodsByObf.size() == m_methodsByDeobf.size() ); | 351 | boolean wasAdded = m_methodsByObf.put( getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ), methodMapping ) == null; |
| 352 | assert( wasAdded ); | ||
| 326 | } | 353 | } |
| 327 | } | 354 | } |
| 328 | 355 | ||