Obf changes, remove srg2source, add ctors to refmap, fixes #96 fixes #97

This commit is contained in:
Mumfrey committed 2016-01-26 13:41:16 +00:00
1 parent 2c9e3d1d39
commit 5afccbd4dd
15 files changed
+382 -85

No files matched your search

@@ -60,7 +60,7 @@ public abstract class MixinBootstrap {
/**
* Subsystem version
*/
public static final String VERSION = "0.4.16";
public static final String VERSION = "0.4.17";
/**
* Blackboard key where the subsystem version will be stored to indicate
@@ -29,10 +29,9 @@ import org.spongepowered.asm.lib.tree.AbstractInsnNode;
import org.spongepowered.asm.lib.tree.FieldInsnNode;
import org.spongepowered.asm.lib.tree.MethodInsnNode;
import org.spongepowered.asm.mixin.transformer.IReferenceMapperContext;
import org.spongepowered.asm.obfuscation.MethodData;
import org.spongepowered.asm.util.SignaturePrinter;
import net.minecraftforge.srg2source.rangeapplier.MethodData;
/**
* <p>Information bundle about a member (method or field) parsed from a String
* token in another annotation, this is used where target members need to be
@@ -168,11 +167,10 @@ public class MemberInfo {
*
* @param methodData MethodData object to copy values from
*/
private MemberInfo(MethodData methodData) {
int slashPos = methodData.name.lastIndexOf('/');
this.owner = methodData.name.substring(0, slashPos);
this.name = methodData.name.substring(slashPos + 1);
this.desc = methodData.sig;
public MemberInfo(MethodData methodData) {
this.owner = methodData.getOwner();
this.name = methodData.getSimpleName();
this.desc = methodData.getDesc();
this.matchAll = false;
}
@@ -182,10 +180,9 @@ public class MemberInfo {
* @param methodData MethodData object to copy values from
*/
private MemberInfo(MemberInfo remapped, MethodData methodData, boolean setOwner) {
int slashPos = methodData.name.lastIndexOf('/');
this.owner = setOwner ? methodData.name.substring(0, slashPos) : remapped.owner;
this.name = methodData.name.substring(slashPos + 1);
this.desc = methodData.sig;
this.owner = setOwner ? methodData.getOwner() : remapped.owner;
this.name = methodData.getSimpleName();
this.desc = methodData.getDesc();
this.matchAll = remapped.matchAll;
}
@@ -0,0 +1,84 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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.spongepowered.asm.obfuscation;
import com.google.common.base.Objects;
public final class MethodData {
private final String name;
private final String desc;
public MethodData(String name, String sig) {
this.name = name;
this.desc = sig;
}
public String getName() {
return this.name;
}
public String getSimpleName() {
if (this.name == null) {
return null;
}
int pos = this.name.lastIndexOf('/');
return pos > -1 ? this.name.substring(pos + 1) : this.name;
}
public String getOwner() {
if (this.name == null) {
return null;
}
int pos = this.name.lastIndexOf('/');
return pos > -1 ? this.name.substring(0, pos) : null;
}
public String getDesc() {
return this.desc;
}
@Override
public int hashCode() {
return Objects.hashCode(this.name, this.desc);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof MethodData) {
return Objects.equal(this.name, ((MethodData)obj).name) && Objects.equal(this.desc, ((MethodData)obj).desc);
}
return false;
}
@Override
public String toString() {
return String.format("%s %s", this.name, this.desc);
}
}
@@ -0,0 +1,88 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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.spongepowered.asm.obfuscation;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.io.Files;
import joptsimple.internal.Strings;
/**
* Ported from <strong>Srg2Source</strong> (
* <a href=\"https://github.com/MinecraftForge/Srg2Source\">
* github.com/MinecraftForge/Srg2Source</a>).
*/
public class SrgContainer {
private final BiMap<String, String> classMap = HashBiMap.create();
private final BiMap<String, String> fieldMap = HashBiMap.create();
private final BiMap<String, String> packageMap = HashBiMap.create();
private final BiMap<MethodData, MethodData> methodMap = HashBiMap.create();
public void readSrg(File srg) throws IOException {
for (String line : Files.readLines(srg, Charset.defaultCharset())) {
if (Strings.isNullOrEmpty(line) || line.startsWith("#")) {
continue;
}
String type = line.substring(0, 2);
String[] args = line.substring(4).split(" ");
if (type.equals("PK")) {
this.packageMap.forcePut(args[0], args[1]);
} else if (type.equals("CL")) {
this.classMap.forcePut(args[0], args[1]);
} else if (type.equals("FD")) {
this.fieldMap.forcePut(args[0], args[1]);
} else if (type.equals("MD")) {
this.methodMap.forcePut(new MethodData(args[0], args[1]), new MethodData(args[2], args[3]));
} else {
throw new RuntimeException("Invalid SRG file: " + srg);
}
}
}
public MethodData getMethodMapping(MethodData methodName) {
return this.methodMap.get(methodName);
}
public String getFieldMapping(String fieldName) {
return this.fieldMap.get(fieldName);
}
public String getClassMapping(String className) {
return this.classMap.get(className);
}
public String getPackageMapping(String packageName) {
return this.packageMap.get(packageName);
}
}
@@ -0,0 +1,93 @@
/*
* This file is part of Mixin, licensed under the MIT License (MIT).
*
* Copyright (c) SpongePowered <https://www.spongepowered.org>
* 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.spongepowered.asm.util;
public abstract class ObfuscationUtil {
public interface IClassRemapper {
/**
* Map type name to the new name. Subclasses can override.
*
* @param typeName Class name to convert
* @return new name for the class
*/
public abstract String map(String typeName);
/**
* Convert a mapped type name back to the original obfuscated name
*
* @param typeName Class name to convert
* @return old name for the class
*/
public abstract String unmap(String typeName);
}
private ObfuscationUtil() {}
public static String mapDescriptor(String desc, IClassRemapper remapper) {
return ObfuscationUtil.remapDescriptor(desc, remapper, false);
}
public static String unmapDescriptor(String desc, IClassRemapper remapper) {
return ObfuscationUtil.remapDescriptor(desc, remapper, true);
}
private static String remapDescriptor(String desc, IClassRemapper remapper, boolean unmap) {
StringBuilder sb = new StringBuilder();
StringBuilder token = null;
for (int pos = 0; pos < desc.length(); pos++) {
char c = desc.charAt(pos);
if (token != null) {
if (c == ';') {
sb.append('L').append(ObfuscationUtil.remap(token.toString(), remapper, unmap)).append(';');
token = null;
} else {
token.append(c);
}
continue;
}
if (c == 'L') {
token = new StringBuilder();
} else {
sb.append(c);
}
}
if (token != null) {
throw new IllegalArgumentException("Invalid descriptor '" + desc + "', missing ';'");
}
return sb.toString();
}
private static Object remap(String typeName, IClassRemapper remapper, boolean unmap) {
String result = unmap ? remapper.unmap(typeName) : remapper.map(typeName);
return result != null ? result : typeName;
}
}