From 60d68dd7c6c542d846f84747e5d40f1859c1d3b5 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sat, 27 Oct 2018 13:41:37 +0100 Subject: [PATCH 1/4] 0.4.3: Prep for next dev cycle I messed up with 0.4.2... opps. To prevent another dodgy release, I'm going to take this one a little bit slower. I'm also going to take the opportunity to improve the Enigma support and unit tests, so that issues are discovered quicker :) --- build.gradle | 2 +- changelogs/0.4.3.md | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 changelogs/0.4.3.md diff --git a/build.gradle b/build.gradle index 62aac60..af1c3a3 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ subprojects { group = 'me.jamiemansfield' archivesBaseName = project.name.toLowerCase() - version = '0.4.2' + version = '0.4.3-SNAPSHOT' repositories { mavenCentral() diff --git a/changelogs/0.4.3.md b/changelogs/0.4.3.md new file mode 100644 index 0000000..c7f3957 --- /dev/null +++ b/changelogs/0.4.3.md @@ -0,0 +1,6 @@ +Lorenz 0.4.3 +============ + +This version of Lorenz introduces a number of improvements to the Enigma IO classes, namely +fixing support that has been broken under 0.4.x. This version will also bring the Enigma +writer's output more inline with its counterpart in Enigma. From 286d16821a0626cecdd22bdde8eddd7807e157b4 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sat, 27 Oct 2018 13:54:57 +0100 Subject: [PATCH 2/4] Extend Enigma test file, to trigger broken reader I have additionally changed EnigmaReader to use Deque rather than Stack, for good practise. --- .../me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java | 5 +++-- lorenz/src/test/resources/test.enigma | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java b/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java index b38aaaa..d67bb47 100644 --- a/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java +++ b/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java @@ -37,7 +37,8 @@ import me.jamiemansfield.lorenz.model.MethodMapping; import java.io.Reader; -import java.util.Stack; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.stream.Collectors; /** @@ -110,7 +111,7 @@ private static MethodDescriptor handleNonePrefix(final MethodDescriptor descript ); } - private final Stack> stack = new Stack<>(); + private final Deque> stack = new ArrayDeque<>(); private MethodMapping currentMethod = null; private int lastIndentLevel = 0; diff --git a/lorenz/src/test/resources/test.enigma b/lorenz/src/test/resources/test.enigma index 2d227ff..66596ed 100644 --- a/lorenz/src/test/resources/test.enigma +++ b/lorenz/src/test/resources/test.enigma @@ -2,10 +2,16 @@ CLASS uih uk/jamierocks/CommentTest # CLASS op uk/jr/Operator CLASS ght uk/jamierocks/Test CLASS ght$ds Example + CLASS ght$ds$bg Inner + METHOD dup print (I)Z + ARG 0 num FIELD juh server Luk/jamierocks/Server; METHOD hyuip isOdd (I)Z ARG 0 num - CLASS ght$ds$bg Inner + CLASS ght$beep Beep + CLASS ght$beep$boop Boop + METHOD dup print (I)Z + ARG 0 num FIELD rft log Ljava/util/logging/Logger; METHOD hyuip isEven (I)Z ARG 0 num From f0a27978845382e5398f592f1b25f00771453092 Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sat, 27 Oct 2018 14:14:50 +0100 Subject: [PATCH 3/4] Fix Enigma reader Resolved by removing the complicated logic required to avoid putting methods on the stack. The stack is now shared by classes and methods :) --- .../lorenz/io/enigma/EnigmaReader.java | 45 +++++++++---------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java b/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java index d67bb47..c536d4a 100644 --- a/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java +++ b/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java @@ -34,6 +34,7 @@ import me.jamiemansfield.lorenz.io.MappingsReader; import me.jamiemansfield.lorenz.io.TextMappingsReader; import me.jamiemansfield.lorenz.model.ClassMapping; +import me.jamiemansfield.lorenz.model.Mapping; import me.jamiemansfield.lorenz.model.MethodMapping; import java.io.Reader; @@ -111,9 +112,7 @@ private static MethodDescriptor handleNonePrefix(final MethodDescriptor descript ); } - private final Deque> stack = new ArrayDeque<>(); - private MethodMapping currentMethod = null; - private int lastIndentLevel = 0; + private final Deque> stack = new ArrayDeque<>(); public Processor(final MappingSet mappings) { super(mappings); @@ -129,21 +128,13 @@ public void accept(final String rawLine) { // If there is a change in the indentation level, we will need to alter the // state as need be. - final int classLevel = indentLevel - (this.currentMethod == null ? 0 : 1); - if (classLevel < this.stack.size()) { - final int difference = this.stack.size() - classLevel; - final int indentDifference = this.lastIndentLevel - indentLevel; - - // as the stack is exclusive to classes, don't pop anything when a method - // is the container - if (!(this.currentMethod != null && indentDifference == 1)) { - for (int i = 0; i < difference; i++) { - this.stack.pop(); - } - } + if (indentLevel < this.stack.size()) { + final int difference = this.stack.size() - indentLevel; - // wipe the current method - this.currentMethod = null; + // Pop all the mappings as needed + for (int i = 0; i < difference; i++) { + this.stack.pop(); + } } final String line = EnigmaConstants.removeComments(rawLine).trim(); @@ -169,29 +160,37 @@ else if (key.equals(FIELD_MAPPING_KEY) && len == FIELD_MAPPING_ELEMENT_COUNT) { final String obfName = split[1]; final String deobfName = split[2]; final String type = handleNonePrefix(FieldType.of(split[3])).toString(); - this.stack.peek().getOrCreateFieldMapping(obfName, type) + this.peekClass().getOrCreateFieldMapping(obfName, type) .setDeobfuscatedName(deobfName); } else if (key.equals(METHOD_MAPPING_KEY) && len == METHOD_MAPPING_ELEMENT_WITHOUT_DEOBF_COUNT) { final String obfName = split[1]; final String descriptor = handleNonePrefix(MethodDescriptor.of(split[2])).toString(); - this.currentMethod = this.stack.peek().getOrCreateMethodMapping(obfName, descriptor); + this.stack.push(this.peekClass().getOrCreateMethodMapping(obfName, descriptor)); } else if (key.equals(METHOD_MAPPING_KEY) && len == METHOD_MAPPING_ELEMENT_WITH_DEOBF_COUNT) { final String obfName = split[1]; final String deobfName = split[2]; final String descriptor = handleNonePrefix(MethodDescriptor.of(split[3])).toString(); - this.currentMethod = this.stack.peek().getOrCreateMethodMapping(obfName, descriptor) - .setDeobfuscatedName(deobfName); + this.stack.push(this.peekClass().getOrCreateMethodMapping(obfName, descriptor) + .setDeobfuscatedName(deobfName)); } else if (key.equals(PARAM_MAPPING_KEY) && len == PARAM_MAPPING_ELEMENT_COUNT) { final int index = Integer.parseInt(split[1]); final String deobfName = split[2]; - this.currentMethod.getOrCreateParameterMapping(index) + this.peekMethod().getOrCreateParameterMapping(index) .setDeobfuscatedName(deobfName); } + } + + protected ClassMapping peekClass() { + if (!(this.stack.peek() instanceof ClassMapping)) throw new UnsupportedOperationException("Not a class on the stack!"); + return (ClassMapping) this.stack.peek(); + } - this.lastIndentLevel = indentLevel; + protected MethodMapping peekMethod() { + if (!(this.stack.peek() instanceof MethodMapping)) throw new UnsupportedOperationException("Not a method on the stack!"); + return (MethodMapping) this.stack.peek(); } } From 32253f052fee57ddcf3de5bd14eeee432541f29b Mon Sep 17 00:00:00 2001 From: Jamie Mansfield Date: Sat, 27 Oct 2018 14:48:37 +0100 Subject: [PATCH 4/4] 0.4.3: Release Time --- README.md | 4 ++-- build.gradle | 2 +- changelogs/0.4.3.md | 3 +-- .../lorenz/io/enigma/EnigmaReader.java | 13 ++++--------- 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index dd42d72..342fe83 100644 --- a/README.md +++ b/README.md @@ -35,14 +35,14 @@ Lorenz releases can be obtained through Maven Central: me.jamiemansfield lorenz - 0.4.2 + 0.4.3 ``` ### Gradle ```groovy -compile 'me.jamiemansfield:lorenz:0.4.2' +compile 'me.jamiemansfield:lorenz:0.4.3' ``` You may also find snapshot artifacts on [Sonatype's OSS repository], and for older diff --git a/build.gradle b/build.gradle index af1c3a3..e3e9209 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ subprojects { group = 'me.jamiemansfield' archivesBaseName = project.name.toLowerCase() - version = '0.4.3-SNAPSHOT' + version = '0.4.3' repositories { mavenCentral() diff --git a/changelogs/0.4.3.md b/changelogs/0.4.3.md index c7f3957..07cf7fc 100644 --- a/changelogs/0.4.3.md +++ b/changelogs/0.4.3.md @@ -2,5 +2,4 @@ Lorenz 0.4.3 ============ This version of Lorenz introduces a number of improvements to the Enigma IO classes, namely -fixing support that has been broken under 0.4.x. This version will also bring the Enigma -writer's output more inline with its counterpart in Enigma. +fixing support that has been broken under 0.4.x. diff --git a/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java b/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java index c536d4a..500d93a 100644 --- a/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java +++ b/lorenz/src/main/java/me/jamiemansfield/lorenz/io/enigma/EnigmaReader.java @@ -126,15 +126,10 @@ public Processor() { public void accept(final String rawLine) { final int indentLevel = getIndentLevel(rawLine); - // If there is a change in the indentation level, we will need to alter the - // state as need be. - if (indentLevel < this.stack.size()) { - final int difference = this.stack.size() - indentLevel; - - // Pop all the mappings as needed - for (int i = 0; i < difference; i++) { - this.stack.pop(); - } + // If there is a change in the indentation level, we will need to pop the stack + // as needed + while (indentLevel < this.stack.size()) { + this.stack.pop(); } final String line = EnigmaConstants.removeComments(rawLine).trim();