diff options
| author | 2018-07-05 13:02:28 +0200 | |
|---|---|---|
| committer | 2018-07-05 13:02:28 +0200 | |
| commit | 6aafa87757ab80a164a30f3601bcfb83ae48f559 (patch) | |
| tree | 86f6d7d2de7b28f43908994313390cb5fea99f31 | |
| parent | Fix old mappings not properly being removed (diff) | |
| download | enigma-6aafa87757ab80a164a30f3601bcfb83ae48f559.tar.gz enigma-6aafa87757ab80a164a30f3601bcfb83ae48f559.tar.xz enigma-6aafa87757ab80a164a30f3601bcfb83ae48f559.zip | |
Fix old mappings not properly being removed
3 files changed, 96 insertions, 78 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java index be9e7416..8f3f2b2b 100644 --- a/src/main/java/cuchaz/enigma/mapping/ClassMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/ClassMapping.java | |||
| @@ -573,6 +573,22 @@ public class ClassMapping implements Comparable<ClassMapping> { | |||
| 573 | return this; | 573 | return this; |
| 574 | } | 574 | } |
| 575 | 575 | ||
| 576 | public ClassMapping copy() { | ||
| 577 | ClassMapping copied = new ClassMapping(this.obfFullName); | ||
| 578 | copied.obfSimpleName= this.obfSimpleName; | ||
| 579 | copied.modifier = this.modifier; | ||
| 580 | copied.deobfFullName = this.deobfFullName; | ||
| 581 | copied.deobfName = this.deobfName; | ||
| 582 | copied.innerClassesByDeobf = this.innerClassesByDeobf; | ||
| 583 | copied.innerClassesByObfFull = this.innerClassesByObfFull; | ||
| 584 | copied.innerClassesByObfSimple = this.innerClassesByObfSimple; | ||
| 585 | copied.fieldsByObf = this.fieldsByObf; | ||
| 586 | copied.fieldsByDeobf = this.fieldsByDeobf; | ||
| 587 | copied.methodsByObf = this.methodsByObf; | ||
| 588 | copied.methodsByDeobf = this.methodsByDeobf; | ||
| 589 | return copied; | ||
| 590 | } | ||
| 591 | |||
| 576 | @Override | 592 | @Override |
| 577 | public int hashCode() { | 593 | public int hashCode() { |
| 578 | return this.obfFullName.hashCode(); | 594 | return this.obfFullName.hashCode(); |
diff --git a/src/main/java/cuchaz/enigma/mapping/Mappings.java b/src/main/java/cuchaz/enigma/mapping/Mappings.java index 307b1bd4..3ef1be52 100644 --- a/src/main/java/cuchaz/enigma/mapping/Mappings.java +++ b/src/main/java/cuchaz/enigma/mapping/Mappings.java | |||
| @@ -23,6 +23,7 @@ import cuchaz.enigma.throwables.MappingConflict; | |||
| 23 | import java.io.File; | 23 | import java.io.File; |
| 24 | import java.io.IOException; | 24 | import java.io.IOException; |
| 25 | import java.util.*; | 25 | import java.util.*; |
| 26 | import java.util.stream.Collectors; | ||
| 26 | 27 | ||
| 27 | public class Mappings { | 28 | public class Mappings { |
| 28 | 29 | ||
| @@ -47,10 +48,6 @@ public class Mappings { | |||
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | public void addClassMapping(ClassMapping classMapping) throws MappingConflict { | 50 | public void addClassMapping(ClassMapping classMapping) throws MappingConflict { |
| 50 | if (classMapping.isObfuscated()) { | ||
| 51 | return; | ||
| 52 | } | ||
| 53 | |||
| 54 | if (this.classesByObf.containsKey(classMapping.getObfFullName())) { | 51 | if (this.classesByObf.containsKey(classMapping.getObfFullName())) { |
| 55 | throw new MappingConflict("class", classMapping.getObfFullName(), this.classesByObf.get(classMapping.getObfFullName()).getObfFullName()); | 52 | throw new MappingConflict("class", classMapping.getObfFullName(), this.classesByObf.get(classMapping.getObfFullName()).getObfFullName()); |
| 56 | } | 53 | } |
| @@ -217,8 +214,14 @@ public class Mappings { | |||
| 217 | 214 | ||
| 218 | public void savePreviousState() { | 215 | public void savePreviousState() { |
| 219 | this.previousState = new Mappings(this.originMapping); | 216 | this.previousState = new Mappings(this.originMapping); |
| 220 | this.previousState.classesByDeobf = Maps.newHashMap(this.classesByDeobf); | 217 | this.previousState.classesByDeobf = new HashMap<>(); |
| 221 | this.previousState.classesByObf = Maps.newHashMap(this.classesByObf); | 218 | for (Map.Entry<String, ClassMapping> entry : this.classesByDeobf.entrySet()) { |
| 219 | this.previousState.classesByDeobf.put(entry.getKey(), entry.getValue().copy()); | ||
| 220 | } | ||
| 221 | this.previousState.classesByObf = new HashMap<>(); | ||
| 222 | for (Map.Entry<String, ClassMapping> entry : this.classesByObf.entrySet()) { | ||
| 223 | this.previousState.classesByObf.put(entry.getKey(), entry.getValue().copy()); | ||
| 224 | } | ||
| 222 | classesByDeobf.values().forEach(ClassMapping::resetDirty); | 225 | classesByDeobf.values().forEach(ClassMapping::resetDirty); |
| 223 | classesByObf.values().forEach(ClassMapping::resetDirty); | 226 | classesByObf.values().forEach(ClassMapping::resetDirty); |
| 224 | } | 227 | } |
diff --git a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java index d1d5634a..a53793d3 100644 --- a/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java +++ b/src/main/java/cuchaz/enigma/mapping/MappingsEnigmaReader.java | |||
| @@ -39,88 +39,87 @@ public class MappingsEnigmaReader { | |||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | public Mappings readFile(Mappings mappings, File file) throws IOException, MappingParseException { | 41 | public Mappings readFile(Mappings mappings, File file) throws IOException, MappingParseException { |
| 42 | try (BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8))) { | ||
| 43 | Deque<Object> mappingStack = Queues.newArrayDeque(); | ||
| 44 | |||
| 45 | int lineNumber = 0; | ||
| 46 | String line; | ||
| 47 | while ((line = in.readLine()) != null) { | ||
| 48 | lineNumber++; | ||
| 49 | |||
| 50 | // strip comments | ||
| 51 | int commentPos = line.indexOf('#'); | ||
| 52 | if (commentPos >= 0) { | ||
| 53 | line = line.substring(0, commentPos); | ||
| 54 | } | ||
| 42 | 55 | ||
| 43 | BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), Charsets.UTF_8)); | 56 | // skip blank lines |
| 44 | Deque<Object> mappingStack = Queues.newArrayDeque(); | 57 | if (line.trim().length() <= 0) { |
| 45 | 58 | continue; | |
| 46 | int lineNumber = 0; | 59 | } |
| 47 | String line; | ||
| 48 | while ((line = in.readLine()) != null) { | ||
| 49 | lineNumber++; | ||
| 50 | |||
| 51 | // strip comments | ||
| 52 | int commentPos = line.indexOf('#'); | ||
| 53 | if (commentPos >= 0) { | ||
| 54 | line = line.substring(0, commentPos); | ||
| 55 | } | ||
| 56 | |||
| 57 | // skip blank lines | ||
| 58 | if (line.trim().length() <= 0) { | ||
| 59 | continue; | ||
| 60 | } | ||
| 61 | 60 | ||
| 62 | // get the indent of this line | 61 | // get the indent of this line |
| 63 | int indent = 0; | 62 | int indent = 0; |
| 64 | for (int i = 0; i < line.length(); i++) { | 63 | for (int i = 0; i < line.length(); i++) { |
| 65 | if (line.charAt(i) != '\t') { | 64 | if (line.charAt(i) != '\t') { |
| 66 | break; | 65 | break; |
| 66 | } | ||
| 67 | indent++; | ||
| 67 | } | 68 | } |
| 68 | indent++; | ||
| 69 | } | ||
| 70 | 69 | ||
| 71 | // handle stack pops | 70 | // handle stack pops |
| 72 | while (indent < mappingStack.size()) { | 71 | while (indent < mappingStack.size()) { |
| 73 | mappingStack.pop(); | 72 | mappingStack.pop(); |
| 74 | } | 73 | } |
| 75 | 74 | ||
| 76 | String[] parts = line.trim().split("\\s"); | 75 | String[] parts = line.trim().split("\\s"); |
| 77 | try { | 76 | try { |
| 78 | // read the first token | 77 | // read the first token |
| 79 | String token = parts[0]; | 78 | String token = parts[0]; |
| 80 | 79 | ||
| 81 | if (token.equalsIgnoreCase("CLASS")) { | 80 | if (token.equalsIgnoreCase("CLASS")) { |
| 82 | ClassMapping classMapping; | 81 | ClassMapping classMapping; |
| 83 | if (indent <= 0) { | 82 | if (indent <= 0) { |
| 84 | // outer class | 83 | // outer class |
| 85 | classMapping = readClass(parts, false); | 84 | classMapping = readClass(parts, false); |
| 86 | mappings.addClassMapping(classMapping); | 85 | mappings.addClassMapping(classMapping); |
| 87 | } else { | 86 | } else { |
| 88 | 87 | ||
| 89 | // inner class | 88 | // inner class |
| 90 | if (!(mappingStack.peek() instanceof ClassMapping)) { | 89 | if (!(mappingStack.peek() instanceof ClassMapping)) { |
| 91 | throw new MappingParseException(file, lineNumber, "Unexpected CLASS entry here!"); | 90 | throw new MappingParseException(file, lineNumber, "Unexpected CLASS entry here!"); |
| 91 | } | ||
| 92 | |||
| 93 | classMapping = readClass(parts, true); | ||
| 94 | ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping); | ||
| 92 | } | 95 | } |
| 93 | 96 | mappingStack.push(classMapping); | |
| 94 | classMapping = readClass(parts, true); | 97 | } else if (token.equalsIgnoreCase("FIELD")) { |
| 95 | ((ClassMapping) mappingStack.peek()).addInnerClassMapping(classMapping); | 98 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { |
| 96 | } | 99 | throw new MappingParseException(file, lineNumber, "Unexpected FIELD entry here!"); |
| 97 | mappingStack.push(classMapping); | 100 | } |
| 98 | } else if (token.equalsIgnoreCase("FIELD")) { | 101 | ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts)); |
| 99 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { | 102 | } else if (token.equalsIgnoreCase("METHOD")) { |
| 100 | throw new MappingParseException(file, lineNumber, "Unexpected FIELD entry here!"); | 103 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { |
| 101 | } | 104 | throw new MappingParseException(file, lineNumber, "Unexpected METHOD entry here!"); |
| 102 | ((ClassMapping) mappingStack.peek()).addFieldMapping(readField(parts)); | 105 | } |
| 103 | } else if (token.equalsIgnoreCase("METHOD")) { | 106 | MethodMapping methodMapping = readMethod(parts); |
| 104 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof ClassMapping)) { | 107 | ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping); |
| 105 | throw new MappingParseException(file, lineNumber, "Unexpected METHOD entry here!"); | 108 | mappingStack.push(methodMapping); |
| 106 | } | 109 | } else if (token.equalsIgnoreCase("ARG")) { |
| 107 | MethodMapping methodMapping = readMethod(parts); | 110 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) { |
| 108 | ((ClassMapping) mappingStack.peek()).addMethodMapping(methodMapping); | 111 | throw new MappingParseException(file, lineNumber, "Unexpected ARG entry here!"); |
| 109 | mappingStack.push(methodMapping); | 112 | } |
| 110 | } else if (token.equalsIgnoreCase("ARG")) { | 113 | ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts)); |
| 111 | if (mappingStack.isEmpty() || !(mappingStack.peek() instanceof MethodMapping)) { | ||
| 112 | throw new MappingParseException(file, lineNumber, "Unexpected ARG entry here!"); | ||
| 113 | } | 114 | } |
| 114 | ((MethodMapping) mappingStack.peek()).addArgumentMapping(readArgument(parts)); | 115 | } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { |
| 116 | throw new MappingParseException(file, lineNumber, "Malformed line:\n" + line); | ||
| 117 | } catch (MappingConflict e) { | ||
| 118 | throw new MappingParseException(file, lineNumber, e.getMessage()); | ||
| 115 | } | 119 | } |
| 116 | } catch (ArrayIndexOutOfBoundsException | IllegalArgumentException ex) { | ||
| 117 | throw new MappingParseException(file, lineNumber, "Malformed line:\n" + line); | ||
| 118 | } catch (MappingConflict e) { | ||
| 119 | throw new MappingParseException(file, lineNumber, e.getMessage()); | ||
| 120 | } | 120 | } |
| 121 | return mappings; | ||
| 121 | } | 122 | } |
| 122 | in.close(); | ||
| 123 | return mappings; | ||
| 124 | } | 123 | } |
| 125 | 124 | ||
| 126 | private LocalVariableMapping readArgument(String[] parts) { | 125 | private LocalVariableMapping readArgument(String[] parts) { |