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 62aac60..e3e9209 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' repositories { mavenCentral() diff --git a/changelogs/0.4.3.md b/changelogs/0.4.3.md new file mode 100644 index 0000000..07cf7fc --- /dev/null +++ b/changelogs/0.4.3.md @@ -0,0 +1,5 @@ +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. 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..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 @@ -34,10 +34,12 @@ 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; -import java.util.Stack; +import java.util.ArrayDeque; +import java.util.Deque; import java.util.stream.Collectors; /** @@ -110,9 +112,7 @@ private static MethodDescriptor handleNonePrefix(final MethodDescriptor descript ); } - private final Stack> stack = new Stack<>(); - private MethodMapping currentMethod = null; - private int lastIndentLevel = 0; + private final Deque> stack = new ArrayDeque<>(); public Processor(final MappingSet mappings) { super(mappings); @@ -126,23 +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. - 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(); - } - } - - // wipe the current method - this.currentMethod = null; + // 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(); @@ -168,29 +155,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(); } } 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