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 | |
| 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')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsOldWriter.java | 88 | ||||
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/MappingsSRGWriter.java | 82 |
2 files changed, 170 insertions, 0 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsOldWriter.java b/src/main/java/cuchaz/enigma/mapping/MappingsOldWriter.java new file mode 100644 index 0000000..8b766a3 --- /dev/null +++ b/src/main/java/cuchaz/enigma/mapping/MappingsOldWriter.java | |||
| @@ -0,0 +1,88 @@ | |||
| 1 | /******************************************************************************* | ||
| 2 | * Copyright (c) 2015 Jeff Martin. | ||
| 3 | * All rights reserved. This program and the accompanying materials | ||
| 4 | * are made available under the terms of the GNU Lesser General Public | ||
| 5 | * License v3.0 which accompanies this distribution, and is available at | ||
| 6 | * http://www.gnu.org/licenses/lgpl.html | ||
| 7 | * | ||
| 8 | * Contributors: | ||
| 9 | * Jeff Martin - initial API and implementation | ||
| 10 | ******************************************************************************/ | ||
| 11 | package cuchaz.enigma.mapping; | ||
| 12 | |||
| 13 | import java.io.IOException; | ||
| 14 | import java.io.PrintWriter; | ||
| 15 | import java.io.Writer; | ||
| 16 | import java.util.ArrayList; | ||
| 17 | import java.util.Collections; | ||
| 18 | import java.util.List; | ||
| 19 | |||
| 20 | public class MappingsOldWriter { | ||
| 21 | |||
| 22 | public void write(Writer out, Mappings mappings) throws IOException { | ||
| 23 | write(new PrintWriter(out), mappings); | ||
| 24 | } | ||
| 25 | |||
| 26 | public void write(PrintWriter out, Mappings mappings) throws IOException { | ||
| 27 | for (ClassMapping classMapping : sorted(mappings.classes())) { | ||
| 28 | write(out, classMapping, 0); | ||
| 29 | } | ||
| 30 | } | ||
| 31 | |||
| 32 | private void write(PrintWriter out, ClassMapping classMapping, int depth) throws IOException { | ||
| 33 | if (classMapping.getDeobfName() == null) { | ||
| 34 | out.format("%sCLASS %s\n", getIndent(depth), classMapping.getObfFullName()); | ||
| 35 | } else { | ||
| 36 | out.format("%sCLASS %s %s\n", getIndent(depth), classMapping.getObfFullName(), classMapping.getDeobfName()); | ||
| 37 | } | ||
| 38 | |||
| 39 | for (ClassMapping innerClassMapping : sorted(classMapping.innerClasses())) { | ||
| 40 | write(out, innerClassMapping, depth + 1); | ||
| 41 | } | ||
| 42 | |||
| 43 | for (FieldMapping fieldMapping : sorted(classMapping.fields())) { | ||
| 44 | write(out, fieldMapping, depth + 1); | ||
| 45 | } | ||
| 46 | |||
| 47 | for (MethodMapping methodMapping : sorted(classMapping.methods())) { | ||
| 48 | write(out, methodMapping, depth + 1); | ||
| 49 | } | ||
| 50 | } | ||
| 51 | |||
| 52 | private void write(PrintWriter out, FieldMapping fieldMapping, int depth) throws IOException { | ||
| 53 | out.format("%sFIELD %s %s %s\n", getIndent(depth), fieldMapping.getObfName(), fieldMapping.getDeobfName(), fieldMapping.getObfType().toString()); | ||
| 54 | } | ||
| 55 | |||
| 56 | private void write(PrintWriter out, MethodMapping methodMapping, int depth) throws IOException { | ||
| 57 | if (methodMapping.getDeobfName() == null) { | ||
| 58 | out.format("%sMETHOD %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getObfSignature()); | ||
| 59 | } else { | ||
| 60 | out.format("%sMETHOD %s %s %s\n", getIndent(depth), methodMapping.getObfName(), methodMapping.getDeobfName(), methodMapping.getObfSignature()); | ||
| 61 | } | ||
| 62 | |||
| 63 | for (ArgumentMapping argumentMapping : sorted(methodMapping.arguments())) { | ||
| 64 | write(out, argumentMapping, depth + 1); | ||
| 65 | } | ||
| 66 | } | ||
| 67 | |||
| 68 | private void write(PrintWriter out, ArgumentMapping argumentMapping, int depth) throws IOException { | ||
| 69 | out.format("%sARG %d %s\n", getIndent(depth), argumentMapping.getIndex(), argumentMapping.getName()); | ||
| 70 | } | ||
| 71 | |||
| 72 | private <T extends Comparable<T>> List<T> sorted(Iterable<T> classes) { | ||
| 73 | List<T> out = new ArrayList<T>(); | ||
| 74 | for (T t : classes) { | ||
| 75 | out.add(t); | ||
| 76 | } | ||
| 77 | Collections.sort(out); | ||
| 78 | return out; | ||
| 79 | } | ||
| 80 | |||
| 81 | private String getIndent(int depth) { | ||
| 82 | StringBuilder buf = new StringBuilder(); | ||
| 83 | for (int i = 0; i < depth; i++) { | ||
| 84 | buf.append("\t"); | ||
| 85 | } | ||
| 86 | return buf.toString(); | ||
| 87 | } | ||
| 88 | } | ||
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 | } | ||