Skip to content

Commit

Permalink
Merge branch 'release-0.5.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Jul 3, 2020
2 parents 48a0422 + 3dc61e1 commit c6e3cc3
Show file tree
Hide file tree
Showing 26 changed files with 708 additions and 40 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ Lorenz is a library intended for creating and altering de-obfuscation mappings f
programs (compiled or otherwise), this is done independent of the format being used. Lorenz
supports a variety of mapping formats:

- SRG
- CSRG
- TSRG
- SRG and its variants (CSRG, TSRG, and XSRG)
- Enigma (through `lorenz-io-enigma`)
- JAM (through `lorenz-io-jam`)
- Kin (through `lorenz-io-kin`)
Expand All @@ -33,7 +31,7 @@ Lorenz releases can be obtained through Maven Central:
### Gradle

```groovy
implementation 'org.cadixdev:lorenz:0.5.1'
implementation 'org.cadixdev:lorenz:0.5.3'
```

### Maven
Expand All @@ -42,7 +40,7 @@ implementation 'org.cadixdev:lorenz:0.5.1'
<dependency>
<groupId>org.cadixdev</groupId>
<artifactId>lorenz</artifactId>
<version>0.5.1</version>
<version>0.5.3</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ subprojects {

group = 'org.cadixdev'
archivesBaseName = project.name.toLowerCase()
version = '0.5.2'
version = '0.5.3'

repositories {
mavenCentral()
Expand Down
42 changes: 42 additions & 0 deletions changelogs/0.5.3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Lorenz 0.5.3
============

Lorenz 0.5.3 includes yet-another set of bug-fixes:

- [Mercury/GH-14]: Inheritance completion now considers elevated return types
- [Bombe/GH-11]: Bump Bombe dependency to 0.3.2, including a fix for remapping
manifests without a `Main-Class` attribute
- [Lorenz/GH-30]: Don't wrap `Writer`s in `TextMappingsWriter`, allowing files
larger than `BufferedWriter`s buffer to be written (thanks to @phase for this
bug-fix)
- [Lorenz/GH-32]: Support blank comments in IO readers (affects SRG formats, JAM,
and Enigma)

Support for yet-another SRG variant, XSRG, has also been introduced with this
release - the format is the same as the SRG format, though has field types
([Lorenz/GH-33]).

Thanks to @phase and @DemonWav for their contributions towards this release.

### Registries

`Registry` has been expanded to expose more of the underlying `Map`'s data:

- `Registry#keys()`, returning a `Set` of `String`s which correspond to the
identifier of registered values.
- `Registry#entries()`, returning a `Set` of `Map.Entry`s.

### Imrpoved Mapping Merging

Mapping Merging, introduced with Lorenz 0.5.0, has always been a fairly
lacklustre implementation - dropping mappings present on the b mapping set, if
there wasn't a mapping in the a mapping set.

Thanks to @DemonWav, that has now been resolved (see [Lorenz/GH-36]).

[Mercury/GH-14]: https://github.com/CadixDev/Mercury/issues/14
[Bombe/GH-11]: https://github.com/CadixDev/Bombe/issues/11
[Lorenz/GH-30]: https://github.com/CadixDev/Lorenz/pull/30
[Lorenz/GH-32]: https://github.com/CadixDev/Lorenz/issues/32
[Lorenz/GH-33]: https://github.com/CadixDev/Lorenz/issues/33
[Lorenz/GH-36]: https://github.com/CadixDev/Lorenz/pull/36
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ url = https://www.jamiemansfield.me/projects/lorenz
inceptionYear = 2016

# Build Settings
bombeVersion = 0.3.0
bombeVersion = 0.3.2
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class EnigmaConstants {
/**
* A regex expression used to remove comments from lines.
*/
private static final Pattern HASH_COMMENT = Pattern.compile("#.+");
private static final Pattern HASH_COMMENT = Pattern.compile("#.*");

/**
* The standard file extension used with the Enigma format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.signature.FieldSignature;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.io.MappingFormats;
import org.cadixdev.lorenz.io.MappingsReader;
Expand All @@ -38,9 +41,6 @@
import org.cadixdev.lorenz.model.MethodMapping;
import org.cadixdev.lorenz.model.MethodParameterMapping;
import org.cadixdev.lorenz.model.TopLevelClassMapping;
import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.signature.FieldSignature;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -58,12 +58,24 @@ public EnigmaReaderTest() throws IOException {
@Test
public void commentRemoval() {
// 1. Check an all comments line
final String emptyLine = "# This is a comment";
assertEquals("", EnigmaConstants.removeComments(emptyLine).trim());
assertEquals(
"",
EnigmaConstants.removeComments("#").trim()
);
assertEquals(
"",
EnigmaConstants.removeComments("# This is a comment").trim()
);

// 2. Check a mixed line
final String mixedLine = "blah blah blah # This is a comment";
assertEquals("blah blah blah", EnigmaConstants.removeComments(mixedLine).trim());
assertEquals(
"blah blah blah",
EnigmaConstants.removeComments("blah blah blah #").trim()
);
assertEquals(
"blah blah blah",
EnigmaConstants.removeComments("blah blah blah # This is a comment").trim()
);

// 3. Check that SrgParser#processLine(String) won't accept comments
assertFalse(this.mappings.hasTopLevelClassMapping("yu"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class JamConstants {
/**
* A regex expression used to remove comments from lines.
*/
private static final Pattern HASH_COMMENT = Pattern.compile("#.+");
private static final Pattern HASH_COMMENT = Pattern.compile("#.*");

/**
* The standard file extension used with the JAM format.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.signature.FieldSignature;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.io.MappingFormats;
import org.cadixdev.lorenz.io.MappingsReader;
Expand All @@ -38,10 +41,6 @@
import org.cadixdev.lorenz.model.MethodMapping;
import org.cadixdev.lorenz.model.MethodParameterMapping;
import org.cadixdev.lorenz.model.TopLevelClassMapping;
import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.signature.FieldSignature;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.IOException;
Expand All @@ -59,12 +58,24 @@ public JamReaderTest() throws IOException {
@Test
public void commentRemoval() {
// 1. Check an all comments line
final String emptyLine = "# This is a comment";
Assertions.assertEquals("", JamConstants.removeComments(emptyLine).trim());
assertEquals(
"",
JamConstants.removeComments("#").trim()
);
assertEquals(
"",
JamConstants.removeComments("# This is a comment").trim()
);

// 2. Check a mixed line
final String mixedLine = "blah blah blah # This is a comment";
assertEquals("blah blah blah", JamConstants.removeComments(mixedLine).trim());
assertEquals(
"blah blah blah",
JamConstants.removeComments("blah blah blah #").trim()
);
assertEquals(
"blah blah blah",
JamConstants.removeComments("blah blah blah # This is a comment").trim()
);

// 3. Check that SrgParser#processLine(String) won't accept comments
assertFalse(this.mappings.hasTopLevelClassMapping("yu"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
package org.cadixdev.lorenz.impl.model;

import org.cadixdev.bombe.analysis.InheritanceProvider;
import org.cadixdev.bombe.analysis.InheritanceType;
import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.signature.FieldSignature;
import org.cadixdev.bombe.type.signature.MethodSignature;
import org.cadixdev.lorenz.MappingSet;
Expand All @@ -36,9 +38,12 @@

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.StringJoiner;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -210,6 +215,12 @@ public void complete(final InheritanceProvider provider, final InheritanceProvid
return;
}

final Map<String, Set<MethodSignature>> nameToMethods = new HashMap<>();
for (final Map.Entry<MethodSignature, InheritanceType> method : info.getMethods().entrySet()) {
final Set<MethodSignature> methods = nameToMethods.computeIfAbsent(method.getKey().getName(), name -> new HashSet<>());
methods.add(method.getKey());
}

for (final InheritanceProvider.ClassInfo parent : info.provideParents(provider)) {
final ClassMapping<?, ?> parentMappings = this.getMappings().getOrCreateClassMapping(parent.getName());
parentMappings.complete(provider, parent);
Expand All @@ -224,6 +235,25 @@ public void complete(final InheritanceProvider provider, final InheritanceProvid
if (parent.canInherit(info, mapping.getSignature())) {
this.methods.putIfAbsent(mapping.getSignature(), mapping);
}

// Check if there are any methods here that override the return type of a parent
// method.
if (nameToMethods.containsKey(mapping.getObfuscatedName())) {
for (final MethodSignature methodSignature : nameToMethods.get(mapping.getObfuscatedName())) {
final MethodDescriptor methodDescriptor = methodSignature.getDescriptor();

final MethodSignature mappingSignature = mapping.getSignature();
final MethodDescriptor mappingDescriptor = mappingSignature.getDescriptor();

// The method MUST have the same parameters
// TODO: handle generic params
if (!Objects.equals(methodDescriptor.getParamTypes(), mappingDescriptor.getParamTypes())) continue;

if (mappingDescriptor.getReturnType().isAssignableFrom(methodDescriptor.getReturnType(), provider)) {
this.methods.putIfAbsent(methodSignature, mapping);
}
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean equals(final Object obj) {

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.parent);
return Objects.hash(super.hashCode(), this.parent.getFullObfuscatedName(), this.parent.getFullDeobfuscatedName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public boolean equals(final Object obj) {

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), this.parentClass);
return Objects.hash(super.hashCode(), this.parentClass.getFullObfuscatedName(), this.parentClass.getFullDeobfuscatedName());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ public final class MappingFormats {
*/
public static final TextMappingFormat TSRG = (TextMappingFormat) byId("tsrg");

/**
* The XSRG (SRG + field types) mapping format.
*/
public static final TextMappingFormat XSRG = (TextMappingFormat) byId("xsrg");

/**
* @see Registry#byId(String)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.cadixdev.lorenz.io.srg.csrg.CSrgWriter;
import org.cadixdev.lorenz.io.srg.tsrg.TSrgWriter;

import java.io.BufferedWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
Expand Down Expand Up @@ -59,8 +58,7 @@ protected TextMappingsWriter(final Writer writer) {
if (writer instanceof PrintWriter) {
this.writer = (PrintWriter) writer;
} else {
BufferedWriter bufferedWriter = writer instanceof BufferedWriter ? (BufferedWriter) writer : new BufferedWriter(writer);
this.writer = new PrintWriter(bufferedWriter);
this.writer = new PrintWriter(writer);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class SrgConstants {
/**
* A regex expression used to remove comments from lines.
*/
private static final Pattern HASH_COMMENT = Pattern.compile("#.+");
private static final Pattern HASH_COMMENT = Pattern.compile("#.*");

/**
* The standard file extension used with the SRG format.
Expand Down Expand Up @@ -88,6 +88,24 @@ private TSrg() {

}

/**
* A collection of constants specific to the XSRG
* mapping format.
*
* @since 0.5.3
*/
public static final class XSrg {

/**
* The standard file extension used with the TSRG format.
*/
public static final String STANDARD_EXTENSION = "xsrg";

private XSrg() {
}

}

private SrgConstants() {
}

Expand Down
Loading

0 comments on commit c6e3cc3

Please sign in to comment.