diff options
| author | 2014-07-30 23:43:09 -0400 | |
|---|---|---|
| committer | 2014-07-30 23:43:09 -0400 | |
| commit | 4349d22cc8abf5ec74075dde1b45c5f2f8679bbf (patch) | |
| tree | 6200f39f3539e2def5010078200592141498be33 /src/cuchaz/enigma/mapping/ClassMapping.java | |
| parent | forgot to apply copyright notices (diff) | |
| download | enigma-fork-4349d22cc8abf5ec74075dde1b45c5f2f8679bbf.tar.gz enigma-fork-4349d22cc8abf5ec74075dde1b45c5f2f8679bbf.tar.xz enigma-fork-4349d22cc8abf5ec74075dde1b45c5f2f8679bbf.zip | |
switched to line-by-line mergable, human-readable file format for mappings
Diffstat (limited to '')
| -rw-r--r-- | src/cuchaz/enigma/mapping/ClassMapping.java (renamed from src/cuchaz/enigma/mapping/ClassIndex.java) | 110 |
1 files changed, 84 insertions, 26 deletions
diff --git a/src/cuchaz/enigma/mapping/ClassIndex.java b/src/cuchaz/enigma/mapping/ClassMapping.java index 699807b..3ba3569 100644 --- a/src/cuchaz/enigma/mapping/ClassIndex.java +++ b/src/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -14,24 +14,25 @@ import java.io.Serializable; | |||
| 14 | import java.util.Map; | 14 | import java.util.Map; |
| 15 | 15 | ||
| 16 | import com.beust.jcommander.internal.Maps; | 16 | import com.beust.jcommander.internal.Maps; |
| 17 | import com.google.common.collect.BiMap; | ||
| 18 | import com.google.common.collect.HashBiMap; | ||
| 19 | 17 | ||
| 20 | public class ClassIndex implements Serializable | 18 | public class ClassMapping implements Serializable |
| 21 | { | 19 | { |
| 22 | private static final long serialVersionUID = -5148491146902340107L; | 20 | private static final long serialVersionUID = -5148491146902340107L; |
| 23 | 21 | ||
| 24 | private String m_obfName; | 22 | private String m_obfName; |
| 25 | private String m_deobfName; | 23 | private String m_deobfName; |
| 26 | private BiMap<String,String> m_fieldsObfToDeobf; | 24 | private Map<String,FieldMapping> m_fieldsByObf; |
| 27 | private Map<String,MethodIndex> m_methodsByObf; | 25 | private Map<String,FieldMapping> m_fieldsByDeobf; |
| 28 | private Map<String,MethodIndex> m_methodsByDeobf; | 26 | private Map<String,MethodMapping> m_methodsByObf; |
| 27 | private Map<String,MethodMapping> m_methodsByDeobf; | ||
| 29 | 28 | ||
| 30 | public ClassIndex( String obfName, String deobfName ) | 29 | // NOTE: this argument order is important for the MethodReader/MethodWriter |
| 30 | public ClassMapping( String obfName, String deobfName ) | ||
| 31 | { | 31 | { |
| 32 | m_obfName = obfName; | 32 | m_obfName = obfName; |
| 33 | m_deobfName = deobfName; | 33 | m_deobfName = deobfName; |
| 34 | m_fieldsObfToDeobf = HashBiMap.create(); | 34 | m_fieldsByObf = Maps.newHashMap(); |
| 35 | m_fieldsByDeobf = Maps.newHashMap(); | ||
| 35 | m_methodsByObf = Maps.newHashMap(); | 36 | m_methodsByObf = Maps.newHashMap(); |
| 36 | m_methodsByDeobf = Maps.newHashMap(); | 37 | m_methodsByDeobf = Maps.newHashMap(); |
| 37 | } | 38 | } |
| @@ -49,34 +50,91 @@ public class ClassIndex implements Serializable | |||
| 49 | { | 50 | { |
| 50 | m_deobfName = val; | 51 | m_deobfName = val; |
| 51 | } | 52 | } |
| 53 | |||
| 54 | public Iterable<FieldMapping> fields( ) | ||
| 55 | { | ||
| 56 | assert( m_fieldsByObf.size() == m_fieldsByDeobf.size() ); | ||
| 57 | return m_fieldsByObf.values(); | ||
| 58 | } | ||
| 59 | |||
| 60 | protected void addFieldMapping( FieldMapping fieldMapping ) | ||
| 61 | { | ||
| 62 | m_fieldsByObf.put( fieldMapping.getObfName(), fieldMapping ); | ||
| 63 | m_fieldsByDeobf.put( fieldMapping.getDeobfName(), fieldMapping ); | ||
| 64 | } | ||
| 65 | |||
| 66 | public Iterable<MethodMapping> methods( ) | ||
| 67 | { | ||
| 68 | assert( m_methodsByObf.size() == m_methodsByDeobf.size() ); | ||
| 69 | return m_methodsByObf.values(); | ||
| 70 | } | ||
| 71 | |||
| 72 | protected void addMethodMapping( MethodMapping methodMapping ) | ||
| 73 | { | ||
| 74 | m_methodsByObf.put( getMethodKey( methodMapping.getObfName(), methodMapping.getObfSignature() ), methodMapping ); | ||
| 75 | m_methodsByDeobf.put( getMethodKey( methodMapping.getDeobfName(), methodMapping.getDeobfSignature() ), methodMapping ); | ||
| 76 | } | ||
| 52 | 77 | ||
| 53 | public String getObfFieldName( String deobfName ) | 78 | public String getObfFieldName( String deobfName ) |
| 54 | { | 79 | { |
| 55 | return m_fieldsObfToDeobf.inverse().get( deobfName ); | 80 | FieldMapping fieldMapping = m_fieldsByDeobf.get( deobfName ); |
| 81 | if( fieldMapping != null ) | ||
| 82 | { | ||
| 83 | return fieldMapping.getObfName(); | ||
| 84 | } | ||
| 85 | return null; | ||
| 56 | } | 86 | } |
| 57 | 87 | ||
| 58 | public String getDeobfFieldName( String obfName ) | 88 | public String getDeobfFieldName( String obfName ) |
| 59 | { | 89 | { |
| 60 | return m_fieldsObfToDeobf.get( obfName ); | 90 | FieldMapping fieldMapping = m_fieldsByObf.get( obfName ); |
| 91 | if( fieldMapping != null ) | ||
| 92 | { | ||
| 93 | return fieldMapping.getDeobfName(); | ||
| 94 | } | ||
| 95 | return null; | ||
| 61 | } | 96 | } |
| 62 | 97 | ||
| 63 | public void setFieldName( String obfName, String deobfName ) | 98 | public void setFieldName( String obfName, String deobfName ) |
| 64 | { | 99 | { |
| 65 | m_fieldsObfToDeobf.put( obfName, deobfName ); | 100 | if( deobfName == null ) |
| 101 | { | ||
| 102 | throw new IllegalArgumentException( "deobf name cannot be null!" ); | ||
| 103 | } | ||
| 104 | |||
| 105 | FieldMapping fieldMapping = m_fieldsByObf.get( obfName ); | ||
| 106 | if( fieldMapping == null ) | ||
| 107 | { | ||
| 108 | fieldMapping = new FieldMapping( obfName, deobfName ); | ||
| 109 | m_fieldsByObf.put( obfName, fieldMapping ); | ||
| 110 | m_fieldsByDeobf.put( deobfName, fieldMapping ); | ||
| 111 | } | ||
| 112 | |||
| 113 | m_fieldsByDeobf.remove( fieldMapping.getDeobfName() ); | ||
| 114 | fieldMapping.setDeobfName( deobfName ); | ||
| 115 | m_fieldsByDeobf.put( deobfName, fieldMapping ); | ||
| 66 | } | 116 | } |
| 67 | 117 | ||
| 68 | public MethodIndex getMethodByObf( String obfName, String signature ) | 118 | public MethodMapping getMethodByObf( String obfName, String signature ) |
| 69 | { | 119 | { |
| 70 | return m_methodsByObf.get( getMethodKey( obfName, signature ) ); | 120 | return m_methodsByObf.get( getMethodKey( obfName, signature ) ); |
| 71 | } | 121 | } |
| 72 | 122 | ||
| 73 | public MethodIndex getMethodByDeobf( String deobfName, String signature ) | 123 | public MethodMapping getMethodByDeobf( String deobfName, String signature ) |
| 74 | { | 124 | { |
| 75 | return m_methodsByDeobf.get( getMethodKey( deobfName, signature ) ); | 125 | return m_methodsByDeobf.get( getMethodKey( deobfName, signature ) ); |
| 76 | } | 126 | } |
| 77 | 127 | ||
| 78 | private String getMethodKey( String name, String signature ) | 128 | private String getMethodKey( String name, String signature ) |
| 79 | { | 129 | { |
| 130 | if( name == null ) | ||
| 131 | { | ||
| 132 | throw new IllegalArgumentException( "name cannot be null!" ); | ||
| 133 | } | ||
| 134 | if( signature == null ) | ||
| 135 | { | ||
| 136 | throw new IllegalArgumentException( "signature cannot be null!" ); | ||
| 137 | } | ||
| 80 | return name + signature; | 138 | return name + signature; |
| 81 | } | 139 | } |
| 82 | 140 | ||
| @@ -87,7 +145,7 @@ public class ClassIndex implements Serializable | |||
| 87 | throw new IllegalArgumentException( "deobf name cannot be null!" ); | 145 | throw new IllegalArgumentException( "deobf name cannot be null!" ); |
| 88 | } | 146 | } |
| 89 | 147 | ||
| 90 | MethodIndex methodIndex = m_methodsByObf.get( getMethodKey( obfName, obfSignature ) ); | 148 | MethodMapping methodIndex = m_methodsByObf.get( getMethodKey( obfName, obfSignature ) ); |
| 91 | if( methodIndex == null ) | 149 | if( methodIndex == null ) |
| 92 | { | 150 | { |
| 93 | methodIndex = createMethodIndex( obfName, obfSignature ); | 151 | methodIndex = createMethodIndex( obfName, obfSignature ); |
| @@ -101,30 +159,30 @@ public class ClassIndex implements Serializable | |||
| 101 | 159 | ||
| 102 | public void updateDeobfMethodSignatures( Translator translator ) | 160 | public void updateDeobfMethodSignatures( Translator translator ) |
| 103 | { | 161 | { |
| 104 | for( MethodIndex methodIndex : m_methodsByObf.values() ) | 162 | for( MethodMapping methodIndex : m_methodsByObf.values() ) |
| 105 | { | 163 | { |
| 106 | methodIndex.setDeobfSignature( translator.translateSignature( methodIndex.getObfSignature() ) ); | 164 | methodIndex.setDeobfSignature( translator.translateSignature( methodIndex.getObfSignature() ) ); |
| 107 | } | 165 | } |
| 108 | } | 166 | } |
| 109 | 167 | ||
| 110 | public void setArgumentName( String obfMethodName, String obfMethodSignature, int index, String obfName, String deobfName ) | 168 | public void setArgumentName( String obfMethodName, String obfMethodSignature, int argumentIndex, String argumentName ) |
| 111 | { | 169 | { |
| 112 | if( deobfName == null ) | 170 | if( argumentName == null ) |
| 113 | { | 171 | { |
| 114 | throw new IllegalArgumentException( "deobf name cannot be null!" ); | 172 | throw new IllegalArgumentException( "argument name cannot be null!" ); |
| 115 | } | 173 | } |
| 116 | 174 | ||
| 117 | MethodIndex methodIndex = m_methodsByObf.get( getMethodKey( obfMethodName, obfMethodSignature ) ); | 175 | MethodMapping methodIndex = m_methodsByObf.get( getMethodKey( obfMethodName, obfMethodSignature ) ); |
| 118 | if( methodIndex == null ) | 176 | if( methodIndex == null ) |
| 119 | { | 177 | { |
| 120 | methodIndex = createMethodIndex( obfMethodName, obfMethodSignature ); | 178 | methodIndex = createMethodIndex( obfMethodName, obfMethodSignature ); |
| 121 | } | 179 | } |
| 122 | methodIndex.setArgumentName( index, obfName, deobfName ); | 180 | methodIndex.setArgumentName( argumentIndex, argumentName ); |
| 123 | } | 181 | } |
| 124 | 182 | ||
| 125 | private MethodIndex createMethodIndex( String obfName, String obfSignature ) | 183 | private MethodMapping createMethodIndex( String obfName, String obfSignature ) |
| 126 | { | 184 | { |
| 127 | MethodIndex methodIndex = new MethodIndex( obfName, obfSignature, obfName, obfSignature ); | 185 | MethodMapping methodIndex = new MethodMapping( obfName, obfName, obfSignature, obfSignature ); |
| 128 | String key = getMethodKey( obfName, obfSignature ); | 186 | String key = getMethodKey( obfName, obfSignature ); |
| 129 | m_methodsByObf.put( key, methodIndex ); | 187 | m_methodsByObf.put( key, methodIndex ); |
| 130 | m_methodsByDeobf.put( key, methodIndex ); | 188 | m_methodsByDeobf.put( key, methodIndex ); |
| @@ -140,16 +198,16 @@ public class ClassIndex implements Serializable | |||
| 140 | buf.append( m_deobfName ); | 198 | buf.append( m_deobfName ); |
| 141 | buf.append( "\n" ); | 199 | buf.append( "\n" ); |
| 142 | buf.append( "Fields:\n" ); | 200 | buf.append( "Fields:\n" ); |
| 143 | for( Map.Entry<String,String> entry : m_fieldsObfToDeobf.entrySet() ) | 201 | for( FieldMapping fieldMapping : fields() ) |
| 144 | { | 202 | { |
| 145 | buf.append( "\t" ); | 203 | buf.append( "\t" ); |
| 146 | buf.append( entry.getKey() ); | 204 | buf.append( fieldMapping.getObfName() ); |
| 147 | buf.append( " <-> " ); | 205 | buf.append( " <-> " ); |
| 148 | buf.append( entry.getValue() ); | 206 | buf.append( fieldMapping.getDeobfName() ); |
| 149 | buf.append( "\n" ); | 207 | buf.append( "\n" ); |
| 150 | } | 208 | } |
| 151 | buf.append( "Methods:\n" ); | 209 | buf.append( "Methods:\n" ); |
| 152 | for( MethodIndex methodIndex : m_methodsByObf.values() ) | 210 | for( MethodMapping methodIndex : m_methodsByObf.values() ) |
| 153 | { | 211 | { |
| 154 | buf.append( methodIndex.toString() ); | 212 | buf.append( methodIndex.toString() ); |
| 155 | buf.append( "\n" ); | 213 | buf.append( "\n" ); |