Temp fix for downstream SRGs not remapping members, fixes #99

This commit is contained in:
Mumfrey committed 2016-01-26 17:29:48 +00:00
1 parent d8e07fcb27
commit 54fa0f4e76
5 files changed
+125 -9

No files matched your search

@@ -37,6 +37,7 @@ import javax.tools.StandardLocation;
import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.asm.obfuscation.SrgField;
import org.spongepowered.asm.obfuscation.SrgMethod;
import org.spongepowered.asm.util.Constants;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
@@ -281,9 +282,9 @@ public class ObfuscationManager implements IObfuscationManager {
ObfuscationData<String> data = new ObfuscationData<String>();
for (TargetObfuscationEnvironment targetEnv : this.targetEnvironments) {
String obfField = targetEnv.getObfField(field);
SrgField obfField = targetEnv.getObfField(field);
if (obfField != null) {
data.add(targetEnv.getType(), obfField);
data.add(targetEnv.getType(), obfField.toString());
}
}
@@ -45,6 +45,7 @@ import org.spongepowered.asm.mixin.injection.struct.MemberInfo;
import org.spongepowered.asm.mixin.injection.struct.ReferenceMapper;
import org.spongepowered.asm.obfuscation.SrgMethod;
import org.spongepowered.asm.obfuscation.SrgContainer;
import org.spongepowered.asm.obfuscation.SrgField;
import org.spongepowered.asm.util.ObfuscationUtil;
import org.spongepowered.asm.util.ObfuscationUtil.IClassRemapper;
import org.spongepowered.tools.obfuscation.interfaces.IMixinAnnotationProcessor;
@@ -198,7 +199,17 @@ class TargetObfuscationEnvironment {
*/
public SrgMethod getObfMethod(SrgMethod method) {
if (this.initSrgs()) {
return this.srgs.getMethodMapping(method);
SrgMethod originalMethod = method.copy();
SrgMethod methodMapping = this.srgs.getMethodMapping(method);
// If no obf mapping, we can attempt to remap the owner class
if (methodMapping == null) {
methodMapping = originalMethod;
}
String remappedOwner = this.getObfClass(methodMapping.getOwner());
if (remappedOwner == null || remappedOwner.equals(method.getOwner()) || remappedOwner.equals(methodMapping.getOwner())) {
return methodMapping != originalMethod ? methodMapping : null;
}
return methodMapping.move(remappedOwner);
}
return null;
}
@@ -236,9 +247,19 @@ class TargetObfuscationEnvironment {
/**
* Get an obfuscation mapping for a field
*/
public String getObfField(String field) {
public SrgField getObfField(String field) {
if (this.initSrgs()) {
return this.srgs.getFieldMapping(field);
SrgField originalField = new SrgField(field);
SrgField fieldMapping = this.srgs.getFieldMapping(originalField);
// If no obf mapping, we can attempt to remap the owner class
if (fieldMapping == null) {
fieldMapping = originalField;
}
String remappedOwner = this.getObfClass(fieldMapping.getOwner());
if (remappedOwner == null || remappedOwner.equals(originalField.getOwner()) || remappedOwner.equals(fieldMapping.getOwner())) {
return fieldMapping != originalField ? fieldMapping : null;
}
return fieldMapping.move(remappedOwner);
}
return null;
}
@@ -41,9 +41,9 @@ import joptsimple.internal.Strings;
*/
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<String, String> classMap = HashBiMap.create();
private final BiMap<SrgField, SrgField> fieldMap = HashBiMap.create();
private final BiMap<SrgMethod, SrgMethod> methodMap = HashBiMap.create();
public void readSrg(File srg) throws IOException {
@@ -60,7 +60,7 @@ public class SrgContainer {
} else if (type.equals("CL")) {
this.classMap.forcePut(args[0], args[1]);
} else if (type.equals("FD")) {
this.fieldMap.forcePut(args[0], args[1]);
this.fieldMap.forcePut(new SrgField(args[0]), new SrgField(args[1]));
} else if (type.equals("MD")) {
this.methodMap.forcePut(new SrgMethod(args[0], args[1]), new SrgMethod(args[2], args[3]));
} else {
@@ -73,7 +73,7 @@ public class SrgContainer {
return this.methodMap.get(methodName);
}
public String getFieldMapping(String fieldName) {
public SrgField getFieldMapping(SrgField fieldName) {
return this.fieldMap.get(fieldName);
}
@@ -0,0 +1,86 @@
/*
* 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 SrgField {
private final String mapping;
public SrgField(String mapping) {
this.mapping = mapping;
}
public String getName() {
if (this.mapping == null) {
return null;
}
int pos = this.mapping.lastIndexOf('/');
return pos > -1 ? this.mapping.substring(pos + 1) : this.mapping;
}
public String getOwner() {
if (this.mapping == null) {
return null;
}
int pos = this.mapping.lastIndexOf('/');
return pos > -1 ? this.mapping.substring(0, pos) : null;
}
public String getMapping() {
return this.mapping;
}
public SrgField move(String newOwner) {
return new SrgField((newOwner != null ? newOwner + "/" : "") + this.getName());
}
public SrgField copy() {
return new SrgField(this.mapping);
}
@Override
public int hashCode() {
return Objects.hashCode(this.mapping);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj instanceof SrgField) {
return Objects.equal(this.mapping, ((SrgField)obj).mapping);
}
return false;
}
@Override
public String toString() {
return this.mapping;
}
}
@@ -60,6 +60,14 @@ public final class SrgMethod {
return this.desc;
}
public SrgMethod move(String newOwner) {
return new SrgMethod((newOwner != null ? newOwner + "/" : "") + this.getSimpleName(), this.desc);
}
public SrgMethod copy() {
return new SrgMethod(this.name, this.desc);
}
@Override
public int hashCode() {
return Objects.hashCode(this.name, this.desc);