Add remapped runtime inheritance provider
RemappedRuntimeInheritanceProvider is similar to RuntimeInheritanceProvider, providing access to inheritance information at runtime, but class names are remapped before looking up, and the inheritance is reverse-remapped before returning. This allows the inheritance to be provided from an obfuscated jar, via the cb2obf mappings. For example: java -cp target/SpecialSource-1.2-SNAPSHOT-shaded.jar:mcpc-plus-1.4.7-R0.2-SNAPSHOT-023.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg --in-jar ../IncompatiblePlugin/IncompatiblePlugin-01.jar --out-jar /tmp/sp/out.jar -L -L enables remapped runtime inheritance, in order to use the obfuscated MCPC+ jar classes to lookup the inherited classes for remapping. The same mappings are used as for remapping the plugin (--srg-in and --shade-relocation take effect). The original option, -l, in contrast does not remap on class lookup, and can be used to lookup inheritance from a jar with CraftBukkit mappings, for example: java -cp target/SpecialSource-1.2-SNAPSHOT-shaded.jar:craftbukkit-1.4.7-R0.1.jar net.md_5.specialsource.SpecialSource --shade-relocation net.minecraft.server=net.minecraft.server.v1_4_R1 --shade-relocation org.bouncycastle=net.minecraft.v1_4_R1.org.bouncycastle --srg-in ../jars/1.4.7/cb2obf.csrg --in-jar ../IncompatiblePlugin/IncompatiblePlugin-01.jar --out-jar /tmp/sp/out.jar -l
This commit is contained in:
parent
7ed216d944
commit
37ce7f0b37
@ -38,6 +38,10 @@ public class JarMapping {
|
|||||||
public final Map<String, String> fields = new HashMap<String, String>();
|
public final Map<String, String> fields = new HashMap<String, String>();
|
||||||
public final Map<String, String> methods = new HashMap<String, String>();
|
public final Map<String, String> methods = new HashMap<String, String>();
|
||||||
|
|
||||||
|
public JarMapping() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public JarMapping(File file) throws IOException {
|
public JarMapping(File file) throws IOException {
|
||||||
this(file, null);
|
this(file, null);
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ package net.md_5.specialsource;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MethodDescriptorTransformer {
|
public class MethodDescriptorTransformer {
|
||||||
|
|
||||||
private Map<String, String> packageMap;
|
private Map<String, String> packageMap;
|
||||||
private Map<String, String> classMap;
|
private Map<String, String> classMap;
|
||||||
|
|
||||||
|
@ -0,0 +1,47 @@
|
|||||||
|
package net.md_5.specialsource;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lookup class inheritance from classes at runtime, remapped through a JarMapping
|
||||||
|
*/
|
||||||
|
public class RemappedRuntimeInheritanceProvider extends RuntimeInheritanceProvider {
|
||||||
|
private final JarMapping jarMapping;
|
||||||
|
private final JarMapping inverseJarMapping;
|
||||||
|
|
||||||
|
public RemappedRuntimeInheritanceProvider(JarMapping jarMapping) {
|
||||||
|
this.jarMapping = jarMapping;
|
||||||
|
this.inverseJarMapping = new JarMapping();
|
||||||
|
|
||||||
|
// Invert the mapping
|
||||||
|
for (Map.Entry<String, String> entry : jarMapping.classes.entrySet()) {
|
||||||
|
inverseJarMapping.classes.put(entry.getValue(), entry.getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : jarMapping.packages.entrySet()) {
|
||||||
|
inverseJarMapping.packages.put(entry.getValue(), entry.getKey());
|
||||||
|
}
|
||||||
|
// TODO: methods, fields?
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> getParents(String before) {
|
||||||
|
// Remap the input (example: cb -> obf)
|
||||||
|
String after = JarRemapper.mapTypeName(before, jarMapping.packages, jarMapping.classes);
|
||||||
|
|
||||||
|
List<String> beforeParents = super.getParents(after);
|
||||||
|
if (beforeParents == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Un-remap the output (example: obf -> cb)
|
||||||
|
List<String> afterParents = new ArrayList<String>();
|
||||||
|
for (String beforeParent : beforeParents) {
|
||||||
|
afterParents.add(JarRemapper.mapTypeName(beforeParent, inverseJarMapping.packages, inverseJarMapping.classes));
|
||||||
|
}
|
||||||
|
|
||||||
|
return afterParents;
|
||||||
|
}
|
||||||
|
}
|
@ -81,6 +81,7 @@ public class SpecialSource {
|
|||||||
.withValuesSeparatedBy(',');
|
.withValuesSeparatedBy(',');
|
||||||
|
|
||||||
acceptsAll(asList("l", "live"), "Enable runtime inheritance lookup");
|
acceptsAll(asList("l", "live"), "Enable runtime inheritance lookup");
|
||||||
|
acceptsAll(asList("L", "live-remapped"), "Enable runtime inheritance lookup through a mapping");
|
||||||
|
|
||||||
acceptsAll(asList("q", "quiet"), "Quiet mode");
|
acceptsAll(asList("q", "quiet"), "Quiet mode");
|
||||||
}
|
}
|
||||||
@ -151,6 +152,11 @@ public class SpecialSource {
|
|||||||
|
|
||||||
List<IInheritanceProvider> inheritanceProviders = new ArrayList<IInheritanceProvider>();
|
List<IInheritanceProvider> inheritanceProviders = new ArrayList<IInheritanceProvider>();
|
||||||
inheritanceProviders.add(new JarInheritanceProvider(jar3));
|
inheritanceProviders.add(new JarInheritanceProvider(jar3));
|
||||||
|
|
||||||
|
if (options.has("live-remapped")) {
|
||||||
|
inheritanceProviders.add(new RemappedRuntimeInheritanceProvider(jarMapping));
|
||||||
|
}
|
||||||
|
|
||||||
if (options.has("live")) {
|
if (options.has("live")) {
|
||||||
inheritanceProviders.add(new RuntimeInheritanceProvider());
|
inheritanceProviders.add(new RuntimeInheritanceProvider());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user