Skip to content

Commit

Permalink
Merge branch 'release/0.5.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
jamierocks committed Apr 30, 2020
2 parents cced203 + fefcd09 commit c4d8b67
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 6 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The Basics
dist: trusty
language: java
jdk:
- oraclejdk8
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ supports a variety of mapping formats:
- Enigma (through `lorenz-io-enigma`)
- JAM (through `lorenz-io-jam`)
- Kin (through `lorenz-io-kin`)
- ProGuard (**reader only** through `lorenz-io-proguard`)

## Branches

Expand All @@ -32,7 +33,7 @@ Lorenz releases can be obtained through Maven Central:
### Gradle

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

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

Expand Down
4 changes: 2 additions & 2 deletions 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.0'
version = '0.5.1'

repositories {
mavenCentral()
Expand Down Expand Up @@ -120,7 +120,7 @@ subprojects {
developer {
id = 'jamierocks'
name = 'Jamie Mansfield'
email = 'dev@jamierocks.uk'
email = 'jmansfield@cadixdev.org'
url = 'https://www.jamiemansfield.me/'
timezone = 'Europe/London'
}
Expand Down
13 changes: 13 additions & 0 deletions changelogs/0.5.1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Lorenz 0.5.1
============

Lorenz 0.5.1 brings some minor additions, that were missed during previous dev cycles,
identified during the development of Lorenz 0.6.

## ProGuard Reader

Lorenz 0.5.1 includes a `lorenz-io-proguard` module, that allows you to read
ProGuard output files (for example, Mojang's mapping files for Minecraft). You can
obtain the ProGuard `MappingFormat` with `MappingFormats.byId("proguard")`.

Importantly, the ProGuard module **does not** support writing mapping files.
4 changes: 4 additions & 0 deletions lorenz-io-proguard/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
dependencies {
compile project(':lorenz')
compile 'me.jamiemansfield:string:0.1.0'
}
4 changes: 4 additions & 0 deletions lorenz-io-proguard/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name = Lorenz-IO-ProGuard
description = An implementation of the ProGuard mapping format for Lorenz.
url = https://www.jamiemansfield.me/projects/lorenz
inceptionYear = 2019
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* 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.io.proguard;

import me.jamiemansfield.string.StringReader;
import org.cadixdev.bombe.type.ArrayType;
import org.cadixdev.bombe.type.BaseType;
import org.cadixdev.bombe.type.FieldType;
import org.cadixdev.bombe.type.ObjectType;
import org.cadixdev.bombe.type.Type;
import org.cadixdev.bombe.type.VoidType;

public class PGTypeReader extends StringReader {

public PGTypeReader(final String source) {
super(source);
}

public Type readType() {
if (this.match("void")) return VoidType.INSTANCE;
return this.readFieldType();
}

public FieldType readFieldType() {
while (this.available() && this.peek() != '[') {
this.advance();
}
final FieldType type = getType(this.substring(0, this.index()));
if (!this.available()) return type;
int dims = 0;
while (this.available()) {
if (this.advance() == '[') {
dims++;
}
}
return new ArrayType(dims, type);
}

private boolean match(final String raw) {
for (int i = 0; i < raw.toCharArray().length; i++) {
if (raw.toCharArray()[i] != this.peek(i)) {
return false;
}
}
return true;
}

private static FieldType getType(final String raw) {
if ("byte".equals(raw)) {
return BaseType.BYTE;
}
else if ("char".equals(raw)) {
return BaseType.CHAR;
}
else if ("double".equals(raw)) {
return BaseType.DOUBLE;
}
else if ("float".equals(raw)) {
return BaseType.FLOAT;
}
else if ("int".equals(raw)) {
return BaseType.INT;
}
else if ("long".equals(raw)) {
return BaseType.LONG;
}
else if ("short".equals(raw)) {
return BaseType.SHORT;
}
else if ("boolean".equals(raw)) {
return BaseType.BOOLEAN;
}
else {
// ObjectType will replace the full stops for forward slashes
return new ObjectType(raw);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.io.proguard;

/**
* A collection of constants and utilities specific to
* the ProGuard mapping format.
*
* @author Jamie Mansfield
* @since 0.5.1
*/
public final class ProGuardConstants {

private ProGuardConstants() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* 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.io.proguard;

import org.cadixdev.lorenz.io.MappingsReader;
import org.cadixdev.lorenz.io.MappingsWriter;
import org.cadixdev.lorenz.io.TextMappingFormat;

import java.io.Reader;
import java.io.Writer;
import java.util.Optional;

public class ProGuardFormat implements TextMappingFormat {

@Override
public MappingsReader createReader(final Reader reader) {
return new ProGuardReader(reader);
}

@Override
public MappingsWriter createWriter(final Writer writer) {
throw new UnsupportedOperationException("cant write proguard");
}

@Override
public Optional<String> getStandardFileExtension() {
return Optional.empty();
}

@Override
public String toString() {
return "proguard";
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* 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.io.proguard;

import org.cadixdev.bombe.type.FieldType;
import org.cadixdev.bombe.type.MethodDescriptor;
import org.cadixdev.bombe.type.Type;
import org.cadixdev.lorenz.MappingSet;
import org.cadixdev.lorenz.io.TextMappingsReader;
import org.cadixdev.lorenz.model.ClassMapping;

import java.io.Reader;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public class ProGuardReader extends TextMappingsReader {

public ProGuardReader(final Reader reader) {
super(reader, Processor::new);
}

@Override
public MappingSet read(final MappingSet mappings) {
return super.read(mappings);
}

public static class Processor extends TextMappingsReader.Processor {

private ClassMapping currentClass;

public Processor(final MappingSet mappings) {
super(mappings);
}

@Override
public void accept(final String raw) {
// Ignore comments
if (raw.startsWith("#")) return;

final String[] params = raw.trim().split(" ");

if (params.length == 3 && params[1].equals("->")) {
final String obf = params[0].replace('.', '/');
// remove the trailing :
final String deobf = params[2].substring(0, params[2].length() - 1).replace('.', '/');

this.currentClass = this.mappings.getOrCreateClassMapping(obf)
.setDeobfuscatedName(deobf);
}

if (params.length == 4 && params[2].equals("->")) {
final String returnTypeRaw = params[0];
final String obf = params[1];
final String deobf = params[3];

// method
if (obf.contains("(")) {
// remove any line numbers
final int index = returnTypeRaw.lastIndexOf(':');
final String returnCleanRaw = index != -1 ?
returnTypeRaw.substring(index + 1) :
returnTypeRaw;
final Type returnClean = new PGTypeReader(returnCleanRaw).readType();

final String obfName = obf.substring(0, obf.indexOf('('));
final String[] obfParams = obf.substring(obf.indexOf('(') + 1, obf.length() - 1).split(",");
final List<FieldType> paramTypes = Arrays.stream(obfParams)
.filter(line -> !line.isEmpty())
.map(PGTypeReader::new)
.map(PGTypeReader::readFieldType)
.collect(Collectors.toList());

this.currentClass.getOrCreateMethodMapping(obfName, new MethodDescriptor(paramTypes, returnClean))
.setDeobfuscatedName(deobf);
}
// field
else {
this.currentClass.getOrCreateFieldMapping(obf)
.setDeobfuscatedName(deobf);
}
}
}

}

}
Loading

0 comments on commit c4d8b67

Please sign in to comment.