-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
406 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# The Basics | ||
dist: trusty | ||
language: java | ||
jdk: | ||
- oraclejdk8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ subprojects { | |
|
||
group = 'org.cadixdev' | ||
archivesBaseName = project.name.toLowerCase() | ||
version = '0.5.0' | ||
version = '0.5.1' | ||
|
||
repositories { | ||
mavenCentral() | ||
|
@@ -120,7 +120,7 @@ subprojects { | |
developer { | ||
id = 'jamierocks' | ||
name = 'Jamie Mansfield' | ||
email = '[email protected]' | ||
email = '[email protected]' | ||
url = 'https://www.jamiemansfield.me/' | ||
timezone = 'Europe/London' | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
102 changes: 102 additions & 0 deletions
102
lorenz-io-proguard/src/main/java/org/cadixdev/lorenz/io/proguard/PGTypeReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
lorenz-io-proguard/src/main/java/org/cadixdev/lorenz/io/proguard/ProGuardConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
lorenz-io-proguard/src/main/java/org/cadixdev/lorenz/io/proguard/ProGuardFormat.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
lorenz-io-proguard/src/main/java/org/cadixdev/lorenz/io/proguard/ProGuardReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
} |
Oops, something went wrong.