diff options
| author | 2016-08-11 14:18:43 +0100 | |
|---|---|---|
| committer | 2016-08-11 14:18:43 +0100 | |
| commit | 6c90b5f41ec9ea8c512981e4dbe69d5d9769651f (patch) | |
| tree | 4b116a3801ea9405cace5b9f2a56b11c51c0b516 /src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java | |
| parent | Removed util (diff) | |
| download | enigma-fork-6c90b5f41ec9ea8c512981e4dbe69d5d9769651f.tar.gz enigma-fork-6c90b5f41ec9ea8c512981e4dbe69d5d9769651f.tar.xz enigma-fork-6c90b5f41ec9ea8c512981e4dbe69d5d9769651f.zip | |
Allow exporting mappings as SRG or Enigma
Diffstat (limited to 'src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java new file mode 100644 index 0000000..64da709 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | package cuchaz.enigma.mapping; | ||
| 2 | |||
| 3 | import cuchaz.enigma.Deobfuscator; | ||
| 4 | |||
| 5 | import java.io.File; | ||
| 6 | import java.io.FileWriter; | ||
| 7 | import java.io.IOException; | ||
| 8 | import java.util.ArrayList; | ||
| 9 | import java.util.Collections; | ||
| 10 | import java.util.List; | ||
| 11 | |||
| 12 | /** | ||
| 13 | * Created by Mark on 11/08/2016. | ||
| 14 | */ | ||
| 15 | public class MappingsSRGWriter { | ||
| 16 | |||
| 17 | public void write(File file, Deobfuscator deobfuscator) throws IOException { | ||
| 18 | if(file.exists()){ | ||
| 19 | file.delete(); | ||
| 20 | } | ||
| 21 | file.createNewFile(); | ||
| 22 | |||
| 23 | Mappings mappings = deobfuscator.getMappings(); | ||
| 24 | |||
| 25 | FileWriter writer = new FileWriter(file); | ||
| 26 | List<String> fieldMappings = new ArrayList<>(); | ||
| 27 | List<String> methodMappings = new ArrayList<>(); | ||
| 28 | for (ClassMapping classMapping : sorted(mappings.classes())) { | ||
| 29 | if(classMapping.getDeobfName() == null || classMapping.getObfSimpleName() == null || classMapping.getDeobfName() == null){ | ||
| 30 | continue; | ||
| 31 | } | ||
| 32 | writer.write("CL: " + classMapping.getObfSimpleName() + " " + classMapping.getDeobfName()); | ||
| 33 | writer.write(System.lineSeparator()); | ||
| 34 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { | ||
| 35 | if(innerClassMapping.getDeobfName() == null || innerClassMapping.getObfSimpleName() == null || innerClassMapping.getDeobfName() == null){ | ||
| 36 | continue; | ||
| 37 | } | ||
| 38 | String innerClassName = classMapping.getObfSimpleName() + "$" + innerClassMapping.getObfSimpleName().replace("none/", ""); | ||
| 39 | String innerDebofClassName = classMapping.getDeobfName() + "$" + innerClassMapping.getDeobfName().replace("none/", ""); | ||
| 40 | writer.write("CL: " + innerClassName + " " + classMapping.getDeobfName() + "$" + innerClassMapping.getDeobfName()); | ||
| 41 | writer.write(System.lineSeparator()); | ||
| 42 | for (FieldMapping fieldMapping : sorted(innerClassMapping.fields())) { | ||
| 43 | fieldMappings.add("FD: " + innerClassName + "/" + fieldMapping.getObfName() + " " + innerDebofClassName + "/" + fieldMapping.getDeobfName()); | ||
| 44 | } | ||
| 45 | |||
| 46 | for (MethodMapping methodMapping : sorted(innerClassMapping.methods())) { | ||
| 47 | methodMappings.add("MD: " + innerClassName + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString().replace("none/", "") + " " + innerDebofClassName + "/" + methodMapping.getDeobfName() + " " + deobfuscator.getTranslator(TranslationDirection.Deobfuscating).translateSignature(methodMapping.getObfSignature())); | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | for (FieldMapping fieldMapping : sorted(classMapping.fields())) { | ||
| 52 | fieldMappings.add("FD: " + classMapping.getObfFullName().replace("none/", "") + "/" + fieldMapping.getObfName() + " " + classMapping.getDeobfName() + "/" + fieldMapping.getDeobfName()); | ||
| 53 | } | ||
| 54 | |||
| 55 | for (MethodMapping methodMapping : sorted(classMapping.methods())) { | ||
| 56 | methodMappings.add("MD: " + classMapping.getObfFullName().replace("none/", "") + "/" + methodMapping.getObfName() + " " + methodMapping.getObfSignature().toString().replace("none/", "") + " " + classMapping.getDeobfName() + "/" + methodMapping.getDeobfName() + " " + deobfuscator.getTranslator(TranslationDirection.Deobfuscating).translateSignature(methodMapping.getObfSignature())); | ||
| 57 | } | ||
| 58 | } | ||
| 59 | for(String fd : fieldMappings){ | ||
| 60 | writer.write(fd); | ||
| 61 | writer.write(System.lineSeparator()); | ||
| 62 | } | ||
| 63 | |||
| 64 | for(String md : methodMappings){ | ||
| 65 | writer.write(md); | ||
| 66 | writer.write(System.lineSeparator()); | ||
| 67 | } | ||
| 68 | |||
| 69 | |||
| 70 | writer.close(); | ||
| 71 | } | ||
| 72 | |||
| 73 | |||
| 74 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { | ||
| 75 | List<T> out = new ArrayList<T>(); | ||
| 76 | for (T t : classes) { | ||
| 77 | out.add(t); | ||
| 78 | } | ||
| 79 | Collections.sort(out); | ||
| 80 | return out; | ||
| 81 | } | ||
| 82 | } | ||