diff options
Diffstat (limited to 'src/cuchaz/enigma/mapping/ClassMapping.java')
| -rw-r--r-- | src/cuchaz/enigma/mapping/ClassMapping.java | 520 |
1 files changed, 221 insertions, 299 deletions
diff --git a/src/cuchaz/enigma/mapping/ClassMapping.java b/src/cuchaz/enigma/mapping/ClassMapping.java index e084d4d..dbb8717 100644 --- a/src/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -16,8 +16,8 @@ import java.util.Map; | |||
| 16 | 16 | ||
| 17 | import com.google.common.collect.Maps; | 17 | import com.google.common.collect.Maps; |
| 18 | 18 | ||
| 19 | public class ClassMapping implements Serializable, Comparable<ClassMapping> | 19 | public class ClassMapping implements Serializable, Comparable<ClassMapping> { |
| 20 | { | 20 | |
| 21 | private static final long serialVersionUID = -5148491146902340107L; | 21 | private static final long serialVersionUID = -5148491146902340107L; |
| 22 | 22 | ||
| 23 | private String m_obfName; | 23 | private String m_obfName; |
| @@ -29,15 +29,13 @@ 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 | public ClassMapping( String obfName ) | 32 | public ClassMapping(String obfName) { |
| 33 | { | 33 | this(obfName, null); |
| 34 | this( obfName, null ); | ||
| 35 | } | 34 | } |
| 36 | 35 | ||
| 37 | public ClassMapping( String obfName, String deobfName ) | 36 | public ClassMapping(String obfName, String deobfName) { |
| 38 | { | ||
| 39 | m_obfName = obfName; | 37 | m_obfName = obfName; |
| 40 | m_deobfName = NameValidator.validateClassName( deobfName, false ); | 38 | m_deobfName = NameValidator.validateClassName(deobfName, false); |
| 41 | m_innerClassesByObf = Maps.newHashMap(); | 39 | m_innerClassesByObf = Maps.newHashMap(); |
| 42 | m_innerClassesByDeobf = Maps.newHashMap(); | 40 | m_innerClassesByDeobf = Maps.newHashMap(); |
| 43 | m_fieldsByObf = Maps.newHashMap(); | 41 | m_fieldsByObf = Maps.newHashMap(); |
| @@ -45,439 +43,363 @@ public class ClassMapping implements Serializable, Comparable<ClassMapping> | |||
| 45 | m_methodsByObf = Maps.newHashMap(); | 43 | m_methodsByObf = Maps.newHashMap(); |
| 46 | m_methodsByDeobf = Maps.newHashMap(); | 44 | m_methodsByDeobf = Maps.newHashMap(); |
| 47 | } | 45 | } |
| 48 | 46 | ||
| 49 | public String getObfName( ) | 47 | public String getObfName() { |
| 50 | { | ||
| 51 | return m_obfName; | 48 | return m_obfName; |
| 52 | } | 49 | } |
| 53 | 50 | ||
| 54 | public String getDeobfName( ) | 51 | public String getDeobfName() { |
| 55 | { | ||
| 56 | return m_deobfName; | 52 | return m_deobfName; |
| 57 | } | 53 | } |
| 58 | public void setDeobfName( String val ) | 54 | |
| 59 | { | 55 | public void setDeobfName(String val) { |
| 60 | m_deobfName = NameValidator.validateClassName( val, false ); | 56 | m_deobfName = NameValidator.validateClassName(val, false); |
| 61 | } | 57 | } |
| 62 | 58 | ||
| 63 | //// INNER CLASSES //////// | 59 | //// INNER CLASSES //////// |
| 64 | 60 | ||
| 65 | public Iterable<ClassMapping> innerClasses( ) | 61 | public Iterable<ClassMapping> innerClasses() { |
| 66 | { | 62 | assert (m_innerClassesByObf.size() >= m_innerClassesByDeobf.size()); |
| 67 | assert( m_innerClassesByObf.size() >= m_innerClassesByDeobf.size() ); | ||
| 68 | return m_innerClassesByObf.values(); | 63 | return m_innerClassesByObf.values(); |
| 69 | } | 64 | } |
| 70 | 65 | ||
| 71 | public void addInnerClassMapping( ClassMapping classMapping ) | 66 | public void addInnerClassMapping(ClassMapping classMapping) { |
| 72 | { | 67 | assert (isSimpleClassName(classMapping.getObfName())); |
| 73 | assert( isSimpleClassName( classMapping.getObfName() ) ); | 68 | boolean obfWasAdded = m_innerClassesByObf.put(classMapping.getObfName(), classMapping) == null; |
| 74 | boolean obfWasAdded = m_innerClassesByObf.put( classMapping.getObfName(), classMapping ) == null; | 69 | assert (obfWasAdded); |
| 75 | assert( obfWasAdded ); | 70 | if (classMapping.getDeobfName() != null) { |
| 76 | if( classMapping.getDeobfName() != null ) | 71 | assert (isSimpleClassName(classMapping.getDeobfName())); |
| 77 | { | 72 | boolean deobfWasAdded = m_innerClassesByDeobf.put(classMapping.getDeobfName(), classMapping) == null; |
| 78 | assert( isSimpleClassName( classMapping.getDeobfName() ) ); | 73 | assert (deobfWasAdded); |
| 79 | boolean deobfWasAdded = m_innerClassesByDeobf.put( classMapping.getDeobfName(), classMapping ) == null; | ||
| 80 | assert( deobfWasAdded ); | ||
| 81 | } | 74 | } |
| 82 | } | 75 | } |
| 83 | 76 | ||
| 84 | public void removeInnerClassMapping( ClassMapping classMapping ) | 77 | public void removeInnerClassMapping(ClassMapping classMapping) { |
| 85 | { | 78 | boolean obfWasRemoved = m_innerClassesByObf.remove(classMapping.getObfName()) != null; |
| 86 | boolean obfWasRemoved = m_innerClassesByObf.remove( classMapping.getObfName() ) != null; | 79 | assert (obfWasRemoved); |
| 87 | assert( obfWasRemoved ); | 80 | if (classMapping.getDeobfName() != null) { |
| 88 | if( classMapping.getDeobfName() != null ) | 81 | boolean deobfWasRemoved = m_innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 89 | { | 82 | assert (deobfWasRemoved); |
| 90 | boolean deobfWasRemoved = m_innerClassesByDeobf.remove( classMapping.getDeobfName() ) != null; | ||
| 91 | assert( deobfWasRemoved ); | ||
| 92 | } | 83 | } |
| 93 | } | 84 | } |
| 94 | 85 | ||
| 95 | public ClassMapping getOrCreateInnerClass( String obfName ) | 86 | public ClassMapping getOrCreateInnerClass(String obfName) { |
| 96 | { | 87 | assert (isSimpleClassName(obfName)); |
| 97 | assert( isSimpleClassName( obfName ) ); | 88 | ClassMapping classMapping = m_innerClassesByObf.get(obfName); |
| 98 | ClassMapping classMapping = m_innerClassesByObf.get( obfName ); | 89 | if (classMapping == null) { |
| 99 | if( classMapping == null ) | 90 | classMapping = new ClassMapping(obfName); |
| 100 | { | 91 | boolean wasAdded = m_innerClassesByObf.put(obfName, classMapping) == null; |
| 101 | classMapping = new ClassMapping( obfName ); | 92 | assert (wasAdded); |
| 102 | boolean wasAdded = m_innerClassesByObf.put( obfName, classMapping ) == null; | ||
| 103 | assert( wasAdded ); | ||
| 104 | } | 93 | } |
| 105 | return classMapping; | 94 | return classMapping; |
| 106 | } | 95 | } |
| 107 | 96 | ||
| 108 | public ClassMapping getInnerClassByObf( String obfName ) | 97 | public ClassMapping getInnerClassByObf(String obfName) { |
| 109 | { | 98 | assert (isSimpleClassName(obfName)); |
| 110 | assert( isSimpleClassName( obfName ) ); | 99 | return m_innerClassesByObf.get(obfName); |
| 111 | return m_innerClassesByObf.get( obfName ); | ||
| 112 | } | 100 | } |
| 113 | 101 | ||
| 114 | public ClassMapping getInnerClassByDeobf( String deobfName ) | 102 | public ClassMapping getInnerClassByDeobf(String deobfName) { |
| 115 | { | 103 | assert (isSimpleClassName(deobfName)); |
| 116 | assert( isSimpleClassName( deobfName ) ); | 104 | return m_innerClassesByDeobf.get(deobfName); |
| 117 | return m_innerClassesByDeobf.get( deobfName ); | ||
| 118 | } | 105 | } |
| 119 | 106 | ||
| 120 | public ClassMapping getInnerClassByDeobfThenObf( String name ) | 107 | public ClassMapping getInnerClassByDeobfThenObf(String name) { |
| 121 | { | 108 | ClassMapping classMapping = getInnerClassByDeobf(name); |
| 122 | ClassMapping classMapping = getInnerClassByDeobf( name ); | 109 | if (classMapping == null) { |
| 123 | if( classMapping == null ) | 110 | classMapping = getInnerClassByObf(name); |
| 124 | { | ||
| 125 | classMapping = getInnerClassByObf( name ); | ||
| 126 | } | 111 | } |
| 127 | return classMapping; | 112 | return classMapping; |
| 128 | } | 113 | } |
| 129 | 114 | ||
| 130 | public String getObfInnerClassName( String deobfName ) | 115 | public String getObfInnerClassName(String deobfName) { |
| 131 | { | 116 | assert (isSimpleClassName(deobfName)); |
| 132 | assert( isSimpleClassName( deobfName ) ); | 117 | ClassMapping classMapping = m_innerClassesByDeobf.get(deobfName); |
| 133 | ClassMapping classMapping = m_innerClassesByDeobf.get( deobfName ); | 118 | if (classMapping != null) { |
| 134 | if( classMapping != null ) | ||
| 135 | { | ||
| 136 | return classMapping.getObfName(); | 119 | return classMapping.getObfName(); |
| 137 | } | 120 | } |
| 138 | return null; | 121 | return null; |
| 139 | } | 122 | } |
| 140 | 123 | ||
| 141 | public String getDeobfInnerClassName( String obfName ) | 124 | public String getDeobfInnerClassName(String obfName) { |
| 142 | { | 125 | assert (isSimpleClassName(obfName)); |
| 143 | assert( isSimpleClassName( obfName ) ); | 126 | ClassMapping classMapping = m_innerClassesByObf.get(obfName); |
| 144 | ClassMapping classMapping = m_innerClassesByObf.get( obfName ); | 127 | if (classMapping != null) { |
| 145 | if( classMapping != null ) | ||
| 146 | { | ||
| 147 | return classMapping.getDeobfName(); | 128 | return classMapping.getDeobfName(); |
| 148 | } | 129 | } |
| 149 | return null; | 130 | return null; |
| 150 | } | 131 | } |
| 151 | 132 | ||
| 152 | public void setInnerClassName( String obfName, String deobfName ) | 133 | public void setInnerClassName(String obfName, String deobfName) { |
| 153 | { | 134 | assert (isSimpleClassName(obfName)); |
| 154 | assert( isSimpleClassName( obfName ) ); | 135 | ClassMapping classMapping = getOrCreateInnerClass(obfName); |
| 155 | ClassMapping classMapping = getOrCreateInnerClass( obfName ); | 136 | if (classMapping.getDeobfName() != null) { |
| 156 | if( classMapping.getDeobfName() != null ) | 137 | boolean wasRemoved = m_innerClassesByDeobf.remove(classMapping.getDeobfName()) != null; |
| 157 | { | 138 | assert (wasRemoved); |
| 158 | boolean wasRemoved = m_innerClassesByDeobf.remove( classMapping.getDeobfName() ) != null; | ||
| 159 | assert( wasRemoved ); | ||
| 160 | } | 139 | } |
| 161 | classMapping.setDeobfName( deobfName ); | 140 | classMapping.setDeobfName(deobfName); |
| 162 | if( deobfName != null ) | 141 | if (deobfName != null) { |
| 163 | { | 142 | assert (isSimpleClassName(deobfName)); |
| 164 | assert( isSimpleClassName( deobfName ) ); | 143 | boolean wasAdded = m_innerClassesByDeobf.put(deobfName, classMapping) == null; |
| 165 | boolean wasAdded = m_innerClassesByDeobf.put( deobfName, classMapping ) == null; | 144 | assert (wasAdded); |
| 166 | assert( wasAdded ); | ||
| 167 | } | 145 | } |
| 168 | } | 146 | } |
| 169 | 147 | ||
| 170 | //// FIELDS //////// | 148 | //// FIELDS //////// |
| 171 | 149 | ||
| 172 | public Iterable<FieldMapping> fields( ) | 150 | public Iterable<FieldMapping> fields() { |
| 173 | { | 151 | assert (m_fieldsByObf.size() == m_fieldsByDeobf.size()); |
| 174 | assert( m_fieldsByObf.size() == m_fieldsByDeobf.size() ); | ||
| 175 | return m_fieldsByObf.values(); | 152 | return m_fieldsByObf.values(); |
| 176 | } | 153 | } |
| 177 | 154 | ||
| 178 | public boolean containsObfField( String obfName ) | 155 | public boolean containsObfField(String obfName) { |
| 179 | { | 156 | return m_fieldsByObf.containsKey(obfName); |
| 180 | return m_fieldsByObf.containsKey( obfName ); | ||
| 181 | } | 157 | } |
| 182 | 158 | ||
| 183 | public boolean containsDeobfField( String deobfName ) | 159 | public boolean containsDeobfField(String deobfName) { |
| 184 | { | 160 | return m_fieldsByDeobf.containsKey(deobfName); |
| 185 | return m_fieldsByDeobf.containsKey( deobfName ); | ||
| 186 | } | 161 | } |
| 187 | 162 | ||
| 188 | public void addFieldMapping( FieldMapping fieldMapping ) | 163 | public void addFieldMapping(FieldMapping fieldMapping) { |
| 189 | { | 164 | if (m_fieldsByObf.containsKey(fieldMapping.getObfName())) { |
| 190 | if( m_fieldsByObf.containsKey( fieldMapping.getObfName() ) ) | 165 | throw new Error("Already have mapping for " + m_obfName + "." + fieldMapping.getObfName()); |
| 191 | { | ||
| 192 | throw new Error( "Already have mapping for " + m_obfName + "." + fieldMapping.getObfName() ); | ||
| 193 | } | 166 | } |
| 194 | if( m_fieldsByDeobf.containsKey( fieldMapping.getDeobfName() ) ) | 167 | if (m_fieldsByDeobf.containsKey(fieldMapping.getDeobfName())) { |
| 195 | { | 168 | throw new Error("Already have mapping for " + m_deobfName + "." + fieldMapping.getDeobfName()); |
| 196 | throw new Error( "Already have mapping for " + m_deobfName + "." + fieldMapping.getDeobfName() ); | ||
| 197 | } | 169 | } |
| 198 | boolean obfWasAdded = m_fieldsByObf.put( fieldMapping.getObfName(), fieldMapping ) == null; | 170 | boolean obfWasAdded = m_fieldsByObf.put(fieldMapping.getObfName(), fieldMapping) == null; |
| 199 | assert( obfWasAdded ); | 171 | assert (obfWasAdded); |
| 200 | boolean deobfWasAdded = m_fieldsByDeobf.put( fieldMapping.getDeobfName(), fieldMapping ) == null; | 172 | boolean deobfWasAdded = m_fieldsByDeobf.put(fieldMapping.getDeobfName(), fieldMapping) == null; |
| 201 | assert( deobfWasAdded ); | 173 | assert (deobfWasAdded); |
| 202 | assert( m_fieldsByObf.size() == m_fieldsByDeobf.size() ); | 174 | assert (m_fieldsByObf.size() == m_fieldsByDeobf.size()); |
| 203 | } | 175 | } |
| 204 | 176 | ||
| 205 | public void removeFieldMapping( FieldMapping fieldMapping ) | 177 | public void removeFieldMapping(FieldMapping fieldMapping) { |
| 206 | { | 178 | boolean obfWasRemoved = m_fieldsByObf.remove(fieldMapping.getObfName()) != null; |
| 207 | boolean obfWasRemoved = m_fieldsByObf.remove( fieldMapping.getObfName() ) != null; | 179 | assert (obfWasRemoved); |
| 208 | assert( obfWasRemoved ); | 180 | if (fieldMapping.getDeobfName() != null) { |
| 209 | if( fieldMapping.getDeobfName() != null ) | 181 | boolean deobfWasRemoved = m_fieldsByDeobf.remove(fieldMapping.getDeobfName()) != null; |
| 210 | { | 182 | assert (deobfWasRemoved); |
| 211 | boolean deobfWasRemoved = m_fieldsByDeobf.remove( fieldMapping.getDeobfName() ) != null; | ||
| 212 | assert( deobfWasRemoved ); | ||
| 213 | } | 183 | } |
| 214 | } | 184 | } |
| 215 | 185 | ||
| 216 | public FieldMapping getFieldByObf( String obfName ) | 186 | public FieldMapping getFieldByObf(String obfName) { |
| 217 | { | 187 | return m_fieldsByObf.get(obfName); |
| 218 | return m_fieldsByObf.get( obfName ); | ||
| 219 | } | 188 | } |
| 220 | 189 | ||
| 221 | public FieldMapping getFieldByDeobf( String deobfName ) | 190 | public FieldMapping getFieldByDeobf(String deobfName) { |
| 222 | { | 191 | return m_fieldsByDeobf.get(deobfName); |
| 223 | return m_fieldsByDeobf.get( deobfName ); | ||
| 224 | } | 192 | } |
| 225 | 193 | ||
| 226 | public String getObfFieldName( String deobfName ) | 194 | public String getObfFieldName(String deobfName) { |
| 227 | { | 195 | FieldMapping fieldMapping = m_fieldsByDeobf.get(deobfName); |
| 228 | FieldMapping fieldMapping = m_fieldsByDeobf.get( deobfName ); | 196 | if (fieldMapping != null) { |
| 229 | if( fieldMapping != null ) | ||
| 230 | { | ||
| 231 | return fieldMapping.getObfName(); | 197 | return fieldMapping.getObfName(); |
| 232 | } | 198 | } |
| 233 | return null; | 199 | return null; |
| 234 | } | 200 | } |
| 235 | 201 | ||
| 236 | public String getDeobfFieldName( String obfName ) | 202 | public String getDeobfFieldName(String obfName) { |
| 237 | { | 203 | FieldMapping fieldMapping = m_fieldsByObf.get(obfName); |
| 238 | FieldMapping fieldMapping = m_fieldsByObf.get( obfName ); | 204 | if (fieldMapping != null) { |
| 239 | if( fieldMapping != null ) | ||
| 240 | { | ||
| 241 | return fieldMapping.getDeobfName(); | 205 | return fieldMapping.getDeobfName(); |
| 242 | } | 206 | } |
| 243 | return null; | 207 | return null; |
| 244 | } | 208 | } |
| 245 | 209 | ||
| 246 | public void setFieldName( String obfName, String deobfName ) | 210 | public void setFieldName(String obfName, String deobfName) { |
| 247 | { | 211 | FieldMapping fieldMapping = m_fieldsByObf.get(obfName); |
| 248 | FieldMapping fieldMapping = m_fieldsByObf.get( obfName ); | 212 | if (fieldMapping == null) { |
| 249 | if( fieldMapping == null ) | 213 | fieldMapping = new FieldMapping(obfName, deobfName); |
| 250 | { | 214 | boolean obfWasAdded = m_fieldsByObf.put(obfName, fieldMapping) == null; |
| 251 | fieldMapping = new FieldMapping( obfName, deobfName ); | 215 | assert (obfWasAdded); |
| 252 | boolean obfWasAdded = m_fieldsByObf.put( obfName, fieldMapping ) == null; | 216 | } else { |
| 253 | assert( obfWasAdded ); | 217 | boolean wasRemoved = m_fieldsByDeobf.remove(fieldMapping.getDeobfName()) != null; |
| 218 | assert (wasRemoved); | ||
| 254 | } | 219 | } |
| 255 | else | 220 | fieldMapping.setDeobfName(deobfName); |
| 256 | { | 221 | if (deobfName != null) { |
| 257 | boolean wasRemoved = m_fieldsByDeobf.remove( fieldMapping.getDeobfName() ) != null; | 222 | boolean wasAdded = m_fieldsByDeobf.put(deobfName, fieldMapping) == null; |
| 258 | assert( wasRemoved ); | 223 | assert (wasAdded); |
| 259 | } | ||
| 260 | fieldMapping.setDeobfName( deobfName ); | ||
| 261 | if( deobfName != null ) | ||
| 262 | { | ||
| 263 | boolean wasAdded = m_fieldsByDeobf.put( deobfName, fieldMapping ) == null; | ||
| 264 | assert( wasAdded ); | ||
| 265 | } | 224 | } |
| 266 | } | 225 | } |
| 267 | 226 | ||
| 268 | //// METHODS //////// | 227 | //// METHODS //////// |
| 269 | 228 | ||
| 270 | public Iterable<MethodMapping> methods( ) | 229 | public Iterable<MethodMapping> methods() { |
| 271 | { | 230 | assert (m_methodsByObf.size() >= m_methodsByDeobf.size()); |
| 272 | assert( m_methodsByObf.size() >= m_methodsByDeobf.size() ); | ||
| 273 | return m_methodsByObf.values(); | 231 | return m_methodsByObf.values(); |
| 274 | } | 232 | } |
| 275 | 233 | ||
| 276 | public boolean containsObfMethod( String obfName, String obfSignature ) | 234 | public boolean containsObfMethod(String obfName, String obfSignature) { |
| 277 | { | 235 | return m_methodsByObf.containsKey(getMethodKey(obfName, obfSignature)); |
| 278 | return m_methodsByObf.containsKey( getMethodKey( obfName, obfSignature ) ); | ||
| 279 | } | 236 | } |
| 280 | 237 | ||
| 281 | public boolean containsDeobfMethod( String deobfName, String deobfSignature ) | 238 | public boolean containsDeobfMethod(String deobfName, String deobfSignature) { |
| 282 | { | 239 | return m_methodsByDeobf.containsKey(getMethodKey(deobfName, deobfSignature)); |
| 283 | return m_methodsByDeobf.containsKey( getMethodKey( deobfName, deobfSignature ) ); | ||
| 284 | } | 240 | } |
| 285 | 241 | ||
| 286 | public void addMethodMapping( MethodMapping methodMapping ) | 242 | public void addMethodMapping(MethodMapping methodMapping) { |
| 287 | { | 243 | String obfKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 288 | String obfKey = getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ); | 244 | if (m_methodsByObf.containsKey(obfKey)) { |
| 289 | if( m_methodsByObf.containsKey( obfKey ) ) | 245 | throw new Error("Already have mapping for " + m_obfName + "." + obfKey); |
| 290 | { | ||
| 291 | throw new Error( "Already have mapping for " + m_obfName + "." + obfKey ); | ||
| 292 | } | 246 | } |
| 293 | boolean wasAdded = m_methodsByObf.put( obfKey, methodMapping ) == null; | 247 | boolean wasAdded = m_methodsByObf.put(obfKey, methodMapping) == null; |
| 294 | assert( wasAdded ); | 248 | assert (wasAdded); |
| 295 | if( methodMapping.getDeobfName() != null ) | 249 | if (methodMapping.getDeobfName() != null) { |
| 296 | { | 250 | String deobfKey = getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature()); |
| 297 | String deobfKey = getMethodKey( methodMapping.getDeobfName(), methodMapping.getObfSignature() ); | 251 | if (m_methodsByDeobf.containsKey(deobfKey)) { |
| 298 | if( m_methodsByDeobf.containsKey( deobfKey ) ) | 252 | throw new Error("Already have mapping for " + m_deobfName + "." + deobfKey); |
| 299 | { | ||
| 300 | throw new Error( "Already have mapping for " + m_deobfName + "." + deobfKey ); | ||
| 301 | } | 253 | } |
| 302 | boolean deobfWasAdded = m_methodsByDeobf.put( deobfKey, methodMapping ) == null; | 254 | boolean deobfWasAdded = m_methodsByDeobf.put(deobfKey, methodMapping) == null; |
| 303 | assert( deobfWasAdded ); | 255 | assert (deobfWasAdded); |
| 304 | } | 256 | } |
| 305 | assert( m_methodsByObf.size() >= m_methodsByDeobf.size() ); | 257 | assert (m_methodsByObf.size() >= m_methodsByDeobf.size()); |
| 306 | } | 258 | } |
| 307 | 259 | ||
| 308 | public void removeMethodMapping( MethodMapping methodMapping ) | 260 | public void removeMethodMapping(MethodMapping methodMapping) { |
| 309 | { | 261 | boolean obfWasRemoved = m_methodsByObf.remove(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature())) != null; |
| 310 | boolean obfWasRemoved = m_methodsByObf.remove( getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ) ) != null; | 262 | assert (obfWasRemoved); |
| 311 | assert( obfWasRemoved ); | 263 | if (methodMapping.getDeobfName() != null) { |
| 312 | if( methodMapping.getDeobfName() != null ) | 264 | boolean deobfWasRemoved = m_methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; |
| 313 | { | 265 | assert (deobfWasRemoved); |
| 314 | boolean deobfWasRemoved = m_methodsByDeobf.remove( getMethodKey( methodMapping.getDeobfName(), methodMapping.getObfSignature() ) ) != null; | ||
| 315 | assert( deobfWasRemoved ); | ||
| 316 | } | 266 | } |
| 317 | } | 267 | } |
| 318 | 268 | ||
| 319 | public MethodMapping getMethodByObf( String obfName, String signature ) | 269 | public MethodMapping getMethodByObf(String obfName, String signature) { |
| 320 | { | 270 | return m_methodsByObf.get(getMethodKey(obfName, signature)); |
| 321 | return m_methodsByObf.get( getMethodKey( obfName, signature ) ); | ||
| 322 | } | 271 | } |
| 323 | 272 | ||
| 324 | public MethodMapping getMethodByDeobf( String deobfName, String signature ) | 273 | public MethodMapping getMethodByDeobf(String deobfName, String signature) { |
| 325 | { | 274 | return m_methodsByDeobf.get(getMethodKey(deobfName, signature)); |
| 326 | return m_methodsByDeobf.get( getMethodKey( deobfName, signature ) ); | ||
| 327 | } | 275 | } |
| 328 | 276 | ||
| 329 | private String getMethodKey( String name, String signature ) | 277 | private String getMethodKey(String name, String signature) { |
| 330 | { | 278 | if (name == null) { |
| 331 | if( name == null ) | 279 | throw new IllegalArgumentException("name cannot be null!"); |
| 332 | { | ||
| 333 | throw new IllegalArgumentException( "name cannot be null!" ); | ||
| 334 | } | 280 | } |
| 335 | if( signature == null ) | 281 | if (signature == null) { |
| 336 | { | 282 | throw new IllegalArgumentException("signature cannot be null!"); |
| 337 | throw new IllegalArgumentException( "signature cannot be null!" ); | ||
| 338 | } | 283 | } |
| 339 | return name + signature; | 284 | return name + signature; |
| 340 | } | 285 | } |
| 341 | 286 | ||
| 342 | public void setMethodName( String obfName, String obfSignature, String deobfName ) | 287 | public void setMethodName(String obfName, String obfSignature, String deobfName) { |
| 343 | { | 288 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfName, obfSignature)); |
| 344 | MethodMapping methodMapping = m_methodsByObf.get( getMethodKey( obfName, obfSignature ) ); | 289 | if (methodMapping == null) { |
| 345 | if( methodMapping == null ) | 290 | methodMapping = createMethodMapping(obfName, obfSignature); |
| 346 | { | 291 | } else if (methodMapping.getDeobfName() != null) { |
| 347 | methodMapping = createMethodMapping( obfName, obfSignature ); | 292 | boolean wasRemoved = m_methodsByDeobf.remove(getMethodKey(methodMapping.getDeobfName(), methodMapping.getObfSignature())) != null; |
| 348 | } | 293 | assert (wasRemoved); |
| 349 | else if( methodMapping.getDeobfName() != null ) | ||
| 350 | { | ||
| 351 | boolean wasRemoved = m_methodsByDeobf.remove( getMethodKey( methodMapping.getDeobfName(), methodMapping.getObfSignature() ) ) != null; | ||
| 352 | assert( wasRemoved ); | ||
| 353 | } | 294 | } |
| 354 | methodMapping.setDeobfName( deobfName ); | 295 | methodMapping.setDeobfName(deobfName); |
| 355 | if( deobfName != null ) | 296 | if (deobfName != null) { |
| 356 | { | 297 | boolean wasAdded = m_methodsByDeobf.put(getMethodKey(deobfName, obfSignature), methodMapping) == null; |
| 357 | boolean wasAdded = m_methodsByDeobf.put( getMethodKey( deobfName, obfSignature ), methodMapping ) == null; | 298 | assert (wasAdded); |
| 358 | assert( wasAdded ); | ||
| 359 | } | 299 | } |
| 360 | } | 300 | } |
| 361 | 301 | ||
| 362 | //// ARGUMENTS //////// | 302 | //// ARGUMENTS //////// |
| 363 | 303 | ||
| 364 | public void setArgumentName( String obfMethodName, String obfMethodSignature, int argumentIndex, String argumentName ) | 304 | public void setArgumentName(String obfMethodName, String obfMethodSignature, int argumentIndex, String argumentName) { |
| 365 | { | 305 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)); |
| 366 | MethodMapping methodMapping = m_methodsByObf.get( getMethodKey( obfMethodName, obfMethodSignature ) ); | 306 | if (methodMapping == null) { |
| 367 | if( methodMapping == null ) | 307 | methodMapping = createMethodMapping(obfMethodName, obfMethodSignature); |
| 368 | { | ||
| 369 | methodMapping = createMethodMapping( obfMethodName, obfMethodSignature ); | ||
| 370 | } | 308 | } |
| 371 | methodMapping.setArgumentName( argumentIndex, argumentName ); | 309 | methodMapping.setArgumentName(argumentIndex, argumentName); |
| 372 | } | 310 | } |
| 373 | 311 | ||
| 374 | public void removeArgumentName( String obfMethodName, String obfMethodSignature, int argumentIndex ) | 312 | public void removeArgumentName(String obfMethodName, String obfMethodSignature, int argumentIndex) { |
| 375 | { | 313 | m_methodsByObf.get(getMethodKey(obfMethodName, obfMethodSignature)).removeArgumentName(argumentIndex); |
| 376 | m_methodsByObf.get( getMethodKey( obfMethodName, obfMethodSignature ) ).removeArgumentName( argumentIndex ); | ||
| 377 | } | 314 | } |
| 378 | 315 | ||
| 379 | private MethodMapping createMethodMapping( String obfName, String obfSignature ) | 316 | private MethodMapping createMethodMapping(String obfName, String obfSignature) { |
| 380 | { | 317 | MethodMapping methodMapping = new MethodMapping(obfName, obfSignature); |
| 381 | MethodMapping methodMapping = new MethodMapping( obfName, obfSignature ); | 318 | boolean wasAdded = m_methodsByObf.put(getMethodKey(obfName, obfSignature), methodMapping) == null; |
| 382 | boolean wasAdded = m_methodsByObf.put( getMethodKey( obfName, obfSignature ), methodMapping ) == null; | 319 | assert (wasAdded); |
| 383 | assert( wasAdded ); | ||
| 384 | return methodMapping; | 320 | return methodMapping; |
| 385 | } | 321 | } |
| 386 | 322 | ||
| 387 | @Override | 323 | @Override |
| 388 | public String toString( ) | 324 | public String toString() { |
| 389 | { | ||
| 390 | StringBuilder buf = new StringBuilder(); | 325 | StringBuilder buf = new StringBuilder(); |
| 391 | buf.append( m_obfName ); | 326 | buf.append(m_obfName); |
| 392 | buf.append( " <-> " ); | 327 | buf.append(" <-> "); |
| 393 | buf.append( m_deobfName ); | 328 | buf.append(m_deobfName); |
| 394 | buf.append( "\n" ); | 329 | buf.append("\n"); |
| 395 | buf.append( "Fields:\n" ); | 330 | buf.append("Fields:\n"); |
| 396 | for( FieldMapping fieldMapping : fields() ) | 331 | for (FieldMapping fieldMapping : fields()) { |
| 397 | { | 332 | buf.append("\t"); |
| 398 | buf.append( "\t" ); | 333 | buf.append(fieldMapping.getObfName()); |
| 399 | buf.append( fieldMapping.getObfName() ); | 334 | buf.append(" <-> "); |
| 400 | buf.append( " <-> " ); | 335 | buf.append(fieldMapping.getDeobfName()); |
| 401 | buf.append( fieldMapping.getDeobfName() ); | 336 | buf.append("\n"); |
| 402 | buf.append( "\n" ); | 337 | } |
| 403 | } | 338 | buf.append("Methods:\n"); |
| 404 | buf.append( "Methods:\n" ); | 339 | for (MethodMapping methodMapping : m_methodsByObf.values()) { |
| 405 | for( MethodMapping methodMapping : m_methodsByObf.values() ) | 340 | buf.append(methodMapping.toString()); |
| 406 | { | 341 | buf.append("\n"); |
| 407 | buf.append( methodMapping.toString() ); | 342 | } |
| 408 | buf.append( "\n" ); | 343 | buf.append("Inner Classes:\n"); |
| 409 | } | 344 | for (ClassMapping classMapping : m_innerClassesByObf.values()) { |
| 410 | buf.append( "Inner Classes:\n" ); | 345 | buf.append("\t"); |
| 411 | for( ClassMapping classMapping : m_innerClassesByObf.values() ) | 346 | buf.append(classMapping.getObfName()); |
| 412 | { | 347 | buf.append(" <-> "); |
| 413 | buf.append( "\t" ); | 348 | buf.append(classMapping.getDeobfName()); |
| 414 | buf.append( classMapping.getObfName() ); | 349 | buf.append("\n"); |
| 415 | buf.append( " <-> " ); | ||
| 416 | buf.append( classMapping.getDeobfName() ); | ||
| 417 | buf.append( "\n" ); | ||
| 418 | } | 350 | } |
| 419 | return buf.toString(); | 351 | return buf.toString(); |
| 420 | } | 352 | } |
| 421 | 353 | ||
| 422 | @Override | 354 | @Override |
| 423 | public int compareTo( ClassMapping other ) | 355 | public int compareTo(ClassMapping other) { |
| 424 | { | ||
| 425 | // sort by a, b, c, ... aa, ab, etc | 356 | // sort by a, b, c, ... aa, ab, etc |
| 426 | if( m_obfName.length() != other.m_obfName.length() ) | 357 | if (m_obfName.length() != other.m_obfName.length()) { |
| 427 | { | ||
| 428 | return m_obfName.length() - other.m_obfName.length(); | 358 | return m_obfName.length() - other.m_obfName.length(); |
| 429 | } | 359 | } |
| 430 | return m_obfName.compareTo( other.m_obfName ); | 360 | return m_obfName.compareTo(other.m_obfName); |
| 431 | } | 361 | } |
| 432 | 362 | ||
| 433 | public boolean renameObfClass( String oldObfClassName, String newObfClassName ) | 363 | public boolean renameObfClass(String oldObfClassName, String newObfClassName) { |
| 434 | { | 364 | |
| 435 | // rename inner classes | 365 | // rename inner classes |
| 436 | for( ClassMapping innerClassMapping : new ArrayList<ClassMapping>( m_innerClassesByObf.values() ) ) | 366 | for (ClassMapping innerClassMapping : new ArrayList<ClassMapping>(m_innerClassesByObf.values())) { |
| 437 | { | 367 | if (innerClassMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 438 | if( innerClassMapping.renameObfClass( oldObfClassName, newObfClassName ) ) | 368 | boolean wasRemoved = m_innerClassesByObf.remove(oldObfClassName) != null; |
| 439 | { | 369 | assert (wasRemoved); |
| 440 | boolean wasRemoved = m_innerClassesByObf.remove( oldObfClassName ) != null; | 370 | boolean wasAdded = m_innerClassesByObf.put(newObfClassName, innerClassMapping) == null; |
| 441 | assert( wasRemoved ); | 371 | assert (wasAdded); |
| 442 | boolean wasAdded = m_innerClassesByObf.put( newObfClassName, innerClassMapping ) == null; | ||
| 443 | assert( wasAdded ); | ||
| 444 | } | 372 | } |
| 445 | } | 373 | } |
| 446 | 374 | ||
| 447 | // rename method signatures | 375 | // rename method signatures |
| 448 | for( MethodMapping methodMapping : new ArrayList<MethodMapping>( m_methodsByObf.values() ) ) | 376 | for (MethodMapping methodMapping : new ArrayList<MethodMapping>(m_methodsByObf.values())) { |
| 449 | { | 377 | String oldMethodKey = getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()); |
| 450 | String oldMethodKey = getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ); | 378 | if (methodMapping.renameObfClass(oldObfClassName, newObfClassName)) { |
| 451 | if( methodMapping.renameObfClass( oldObfClassName, newObfClassName ) ) | 379 | boolean wasRemoved = m_methodsByObf.remove(oldMethodKey) != null; |
| 452 | { | 380 | assert (wasRemoved); |
| 453 | boolean wasRemoved = m_methodsByObf.remove( oldMethodKey ) != null; | 381 | boolean wasAdded = m_methodsByObf.put(getMethodKey(methodMapping.getObfName(), methodMapping.getObfSignature()), methodMapping) == null; |
| 454 | assert( wasRemoved ); | 382 | assert (wasAdded); |
| 455 | boolean wasAdded = m_methodsByObf.put( getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ), methodMapping ) == null; | ||
| 456 | assert( wasAdded ); | ||
| 457 | } | 383 | } |
| 458 | } | 384 | } |
| 459 | 385 | ||
| 460 | if( m_obfName.equals( oldObfClassName ) ) | 386 | if (m_obfName.equals(oldObfClassName)) { |
| 461 | { | ||
| 462 | // rename this class | 387 | // rename this class |
| 463 | m_obfName = newObfClassName; | 388 | m_obfName = newObfClassName; |
| 464 | return true; | 389 | return true; |
| 465 | } | 390 | } |
| 466 | return false; | 391 | return false; |
| 467 | } | 392 | } |
| 468 | 393 | ||
| 469 | public boolean containsArgument( BehaviorEntry obfBehaviorEntry, String name ) | 394 | public boolean containsArgument(BehaviorEntry obfBehaviorEntry, String name) { |
| 470 | { | 395 | MethodMapping methodMapping = m_methodsByObf.get(getMethodKey(obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature())); |
| 471 | MethodMapping methodMapping = m_methodsByObf.get( getMethodKey( obfBehaviorEntry.getName(), obfBehaviorEntry.getSignature() ) ); | 396 | if (methodMapping != null) { |
| 472 | if( methodMapping != null ) | 397 | return methodMapping.containsArgument(name); |
| 473 | { | ||
| 474 | return methodMapping.containsArgument( name ); | ||
| 475 | } | 398 | } |
| 476 | return false; | 399 | return false; |
| 477 | } | 400 | } |
| 478 | 401 | ||
| 479 | public static boolean isSimpleClassName( String name ) | 402 | public static boolean isSimpleClassName(String name) { |
| 480 | { | 403 | return name.indexOf('/') < 0 && name.indexOf('$') < 0; |
| 481 | return name.indexOf( '/' ) < 0 && name.indexOf( '$' ) < 0; | ||
| 482 | } | 404 | } |
| 483 | } | 405 | } |