Skip to content

Commit

Permalink
Merge branch 'release-0.5.7'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Feb 1, 2021
2 parents 11d35e3 + f15fbeb commit edb2b65
Show file tree
Hide file tree
Showing 15 changed files with 591 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Lorenz releases can be obtained through Maven Central:
### Gradle

```groovy
implementation 'org.cadixdev:lorenz:0.5.6'
implementation 'org.cadixdev:lorenz:0.5.7'
```

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

Expand Down
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ val isSnapshot = version.toString().endsWith("-SNAPSHOT")

allprojects {
group = "org.cadixdev"
version = "0.5.6"
version = "0.5.7"
}

subprojects {
Expand Down
14 changes: 14 additions & 0 deletions changelogs/0.5.7.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Lorenz 0.5.7
===

## Fixes

- CSRG and TSRG now ignore package mappings, rather than erroneously reading them
as class mappings.
- `MappingSet#deobfuscate(FieldType)` will now correctly de-obfuscate object types
of inner classes, where the parent class has a mapping - but the inner class
does not.
- [GH-29]\: Avoid inheriting field mappings from a parent where the child class has
a field of its own, of the same signature.

[GH-29]: https://github.com/CadixDev/Lorenz/issues/29
25 changes: 22 additions & 3 deletions lorenz/src/main/java/org/cadixdev/lorenz/MappingSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.cadixdev.lorenz.model.TopLevelClassMapping;
import org.cadixdev.lorenz.model.jar.CascadingFieldTypeProvider;
import org.cadixdev.lorenz.model.jar.FieldTypeProvider;
import org.cadixdev.lorenz.util.BinaryTool;
import org.cadixdev.lorenz.util.Reversible;

import java.util.Collection;
Expand Down Expand Up @@ -265,9 +266,27 @@ default FieldType deobfuscate(final FieldType type) {
}
else if (type instanceof ObjectType) {
final ObjectType obj = (ObjectType) type;
return this.getClassMapping(obj.getClassName())
.map(m -> new ObjectType(m.getFullDeobfuscatedName()))
.orElse(obj);

final String[] name = BinaryTool.from(obj.getClassName());

ClassMapping<?, ?> currentClass = this.getClassMapping(name[0]).orElse(null);
if (currentClass == null) {
return type;
}

for (int i = 1; i < name.length; i++) {
final ClassMapping<?, ?> thisClass = currentClass.getInnerClassMapping(name[i]).orElse(null);
if (thisClass == null) {
final String[] result = new String[name.length - i + 1];
result[0] = currentClass.getFullDeobfuscatedName();
System.arraycopy(name, i, result, 1, name.length - i);

return new ObjectType(BinaryTool.to(result));
}
currentClass = thisClass;
}

return new ObjectType(currentClass.getFullDeobfuscatedName());
}
return type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ public void complete(final InheritanceProvider provider, final InheritanceProvid
parentMappings.complete(provider, parent);

for (final FieldMapping mapping : parentMappings.getFieldMappings()) {
// If the class has its own field that satisfies the parent's signature,
// then we shouldn't inherit the mapping
if (this.computeFieldMapping(mapping.getSignature()).isPresent()) {
continue;
}

if (parent.canInherit(info, mapping.getSignature())) {
this.fields.putIfAbsent(mapping.getSignature(), mapping);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,16 @@ protected Processor(final MappingSet mappings) {
this.mappings = mappings;
}

/**
* Gets the mapping set being read into by the processor.
*
* @return The mappings
* @since 0.5.7
*/
public MappingSet getMappings() {
return this.mappings;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,22 @@ public void accept(final String rawLine) {
final String[] split = SPACE.split(line);
final int len = split.length;

// Process class mappings
// Process class/package mappings
if (len == CLASS_MAPPING_ELEMENT_COUNT) {
final String obfuscatedName = split[0];
final String deobfuscatedName = split[1];

// Get mapping, and set de-obfuscated name
this.mappings.getOrCreateClassMapping(obfuscatedName)
.setDeobfuscatedName(deobfuscatedName);
// Package mappings
if (obfuscatedName.endsWith("/")) {
// Lorenz doesn't currently support package mappings, though they are an SRG feature.
// For now, Lorenz will just silently ignore those mappings.
}
// Class mappings
else {
// Get mapping, and set de-obfuscated name
this.mappings.getOrCreateClassMapping(obfuscatedName)
.setDeobfuscatedName(deobfuscatedName);
}
}
// Process field mapping
else if (len == FIELD_MAPPING_ELEMENT_COUNT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,22 @@ public void accept(final String rawLine) {
final String[] split = SPACE.split(line);
final int len = split.length;

// Process class mappings
// Process class/package mappings
if (!split[0].startsWith("\t") && len == CLASS_MAPPING_ELEMENT_COUNT) {
final String obfuscatedName = split[0];
final String deobfuscatedName = split[1];

// Get mapping, and set de-obfuscated name
this.currentClass = this.mappings.getOrCreateClassMapping(obfuscatedName);
this.currentClass.setDeobfuscatedName(deobfuscatedName);
// Package mappings
if (obfuscatedName.endsWith("/")) {
// Lorenz doesn't currently support package mappings, though they are an SRG feature.
// For now, Lorenz will just silently ignore those mappings.
}
// Class mappings
else {
// Get mapping, and set de-obfuscated name
this.currentClass = this.mappings.getOrCreateClassMapping(obfuscatedName);
this.currentClass.setDeobfuscatedName(deobfuscatedName);
}
}
else if (split[0].startsWith("\t") && this.currentClass != null) {
final String obfuscatedName = split[0].replace("\t", "");
Expand Down
72 changes: 72 additions & 0 deletions lorenz/src/main/java/org/cadixdev/lorenz/util/BinaryTool.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This file is part of Lorenz, licensed under the MIT License (MIT).
*
* Copyright (c) Jamie Mansfield <https://www.jamierocks.uk/>
* Copyright (c) contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.cadixdev.lorenz.util;

/**
* A utility for working with binary names in Lorenz.
*
* @author Jamie Mansfield
* @since 0.5.7
*/
public final class BinaryTool {

/**
* Gets the split hierarchy of a binary name.
* <p>
* For example, calling {@code from("a$b$c"}} would produce
* {@code ["a", "b", "c"]}.
*
* @param binaryName The binary name
* @return The name hierarchy
*/
public static String[] from(final String binaryName) {
return binaryName.split("\\$");
}

/**
* Gets the binary name for a split hierarchy.
*
* @param name The hierarchy
* @return The binary name
*/
public static String to(final String[] name) {
final StringBuilder builder = new StringBuilder();

for (int i = 0; i < name.length; i++) {
builder.append(name[i]);

if (i != name.length - 1) {
builder.append('$');
}
}

return builder.toString();
}

private BinaryTool() {
}

}
Loading

0 comments on commit edb2b65

Please sign in to comment.