diff options
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java index afb8c97..8002813 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsRenamer.java | |||
| @@ -10,8 +10,12 @@ | |||
| 10 | ******************************************************************************/ | 10 | ******************************************************************************/ |
| 11 | package cuchaz.enigma.mapping; | 11 | package cuchaz.enigma.mapping; |
| 12 | 12 | ||
| 13 | import java.io.IOException; | ||
| 14 | import java.io.ObjectOutputStream; | ||
| 15 | import java.io.OutputStream; | ||
| 13 | import java.util.List; | 16 | import java.util.List; |
| 14 | import java.util.Set; | 17 | import java.util.Set; |
| 18 | import java.util.zip.GZIPOutputStream; | ||
| 15 | 19 | ||
| 16 | import cuchaz.enigma.analysis.JarIndex; | 20 | import cuchaz.enigma.analysis.JarIndex; |
| 17 | import cuchaz.enigma.throwables.IllegalNameException; | 21 | import cuchaz.enigma.throwables.IllegalNameException; |
| @@ -165,6 +169,42 @@ public class MappingsRenamer { | |||
| 165 | classMapping.setArgumentName(obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), obf.getName()); | 169 | classMapping.setArgumentName(obf.getMethodName(), obf.getMethodSignature(), obf.getIndex(), obf.getName()); |
| 166 | } | 170 | } |
| 167 | 171 | ||
| 172 | public boolean moveFieldToObfClass(ClassMapping classMapping, FieldMapping fieldMapping, ClassEntry obfClass) { | ||
| 173 | classMapping.removeFieldMapping(fieldMapping); | ||
| 174 | ClassMapping targetClassMapping = getOrCreateClassMapping(obfClass); | ||
| 175 | if (!targetClassMapping.containsObfField(fieldMapping.getObfName(), fieldMapping.getObfType())) { | ||
| 176 | if (!targetClassMapping.containsDeobfField(fieldMapping.getDeobfName(), fieldMapping.getObfType())) { | ||
| 177 | targetClassMapping.addFieldMapping(fieldMapping); | ||
| 178 | return true; | ||
| 179 | } else { | ||
| 180 | System.err.println("WARNING: deobf field was already there: " + obfClass + "." + fieldMapping.getDeobfName()); | ||
| 181 | } | ||
| 182 | } | ||
| 183 | return false; | ||
| 184 | } | ||
| 185 | |||
| 186 | public boolean moveMethodToObfClass(ClassMapping classMapping, MethodMapping methodMapping, ClassEntry obfClass) { | ||
| 187 | classMapping.removeMethodMapping(methodMapping); | ||
| 188 | ClassMapping targetClassMapping = getOrCreateClassMapping(obfClass); | ||
| 189 | if (!targetClassMapping.containsObfMethod(methodMapping.getObfName(), methodMapping.getObfSignature())) { | ||
| 190 | if (!targetClassMapping.containsDeobfMethod(methodMapping.getDeobfName(), methodMapping.getObfSignature())) { | ||
| 191 | targetClassMapping.addMethodMapping(methodMapping); | ||
| 192 | return true; | ||
| 193 | } else { | ||
| 194 | System.err.println("WARNING: deobf method was already there: " + obfClass + "." + methodMapping.getDeobfName() + methodMapping.getObfSignature()); | ||
| 195 | } | ||
| 196 | } | ||
| 197 | return false; | ||
| 198 | } | ||
| 199 | |||
| 200 | public void write(OutputStream out) throws IOException { | ||
| 201 | // TEMP: just use the object output for now. We can find a more efficient storage format later | ||
| 202 | GZIPOutputStream gzipout = new GZIPOutputStream(out); | ||
| 203 | ObjectOutputStream oout = new ObjectOutputStream(gzipout); | ||
| 204 | oout.writeObject(this); | ||
| 205 | gzipout.finish(); | ||
| 206 | } | ||
| 207 | |||
| 168 | private ClassMapping getOrCreateClassMapping(ClassEntry obfClassEntry) { | 208 | private ClassMapping getOrCreateClassMapping(ClassEntry obfClassEntry) { |
| 169 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obfClassEntry); | 209 | List<ClassMapping> mappingChain = getOrCreateClassMappingChain(obfClassEntry); |
| 170 | return mappingChain.get(mappingChain.size() - 1); | 210 | return mappingChain.get(mappingChain.size() - 1); |