mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-17 02:55:10 +00:00
Initial 1.7 commit
This commit is contained in:
1 parent
34154fc011
commit
ca675b5f31
72 files changed
+2967
-3335
No files matched your search
+104
-142
@@ -23,45 +23,42 @@ import com.google.common.collect.Multimap;
|
||||
import codechicken.lib.asm.InstructionComparator.InsnListSection;
|
||||
|
||||
public class ASMHelper
|
||||
{
|
||||
{
|
||||
public static class CodeBlock
|
||||
{
|
||||
public Label start = new Label();
|
||||
public Label end = new Label();
|
||||
}
|
||||
|
||||
|
||||
public static class ForBlock extends CodeBlock
|
||||
{
|
||||
public Label cmp = new Label();
|
||||
public Label inc = new Label();
|
||||
public Label body = new Label();
|
||||
}
|
||||
|
||||
|
||||
public static abstract class MethodAltercator
|
||||
{
|
||||
public final ObfMapping method;
|
||||
|
||||
public MethodAltercator(ObfMapping method)
|
||||
{
|
||||
this.method = method;
|
||||
|
||||
public MethodAltercator(ObfMapping method) {
|
||||
this.method = method.toClassloading();
|
||||
}
|
||||
|
||||
|
||||
public abstract void alter(MethodNode mv);
|
||||
}
|
||||
|
||||
|
||||
public static abstract class MethodWriter
|
||||
{
|
||||
public final int access;
|
||||
public final ObfMapping method;
|
||||
public final String[] exceptions;
|
||||
|
||||
public MethodWriter(int access, ObfMapping method)
|
||||
{
|
||||
public MethodWriter(int access, ObfMapping method) {
|
||||
this(access, method, null);
|
||||
}
|
||||
|
||||
public MethodWriter(int access, ObfMapping method, String[] exceptions)
|
||||
{
|
||||
|
||||
public MethodWriter(int access, ObfMapping method, String[] exceptions) {
|
||||
this.access = access;
|
||||
this.method = method;
|
||||
this.exceptions = exceptions;
|
||||
@@ -69,69 +66,60 @@ public class ASMHelper
|
||||
|
||||
public abstract void write(MethodNode mv);
|
||||
}
|
||||
|
||||
|
||||
public static class MethodInjector
|
||||
{
|
||||
public final ObfMapping method;
|
||||
public final InsnList needle;
|
||||
public final InsnList injection;
|
||||
public final boolean before;
|
||||
|
||||
public MethodInjector(ObfMapping method, InsnList needle, InsnList injection, boolean before)
|
||||
{
|
||||
|
||||
public MethodInjector(ObfMapping method, InsnList needle, InsnList injection, boolean before) {
|
||||
this.method = method;
|
||||
this.needle = needle;
|
||||
this.injection = injection;
|
||||
this.before = before;
|
||||
}
|
||||
}
|
||||
|
||||
public static MethodNode findMethod(ObfMapping methodmap, ClassNode cnode)
|
||||
{
|
||||
for(MethodNode mnode : cnode.methods)
|
||||
if(methodmap.matches(mnode))
|
||||
|
||||
public static MethodNode findMethod(ObfMapping methodmap, ClassNode cnode) {
|
||||
for (MethodNode mnode : cnode.methods)
|
||||
if (methodmap.matches(mnode))
|
||||
return mnode;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static FieldNode findField(ObfMapping fieldmap, ClassNode cnode)
|
||||
{
|
||||
for(FieldNode fnode : cnode.fields)
|
||||
if(fieldmap.matches(fnode))
|
||||
public static FieldNode findField(ObfMapping fieldmap, ClassNode cnode) {
|
||||
for (FieldNode fnode : cnode.fields)
|
||||
if (fieldmap.matches(fnode))
|
||||
return fnode;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ClassNode createClassNode(byte[] bytes)
|
||||
{
|
||||
public static ClassNode createClassNode(byte[] bytes) {
|
||||
return createClassNode(bytes, 0);
|
||||
}
|
||||
|
||||
public static ClassNode createClassNode(byte[] bytes, int flags)
|
||||
{
|
||||
|
||||
public static ClassNode createClassNode(byte[] bytes, int flags) {
|
||||
ClassNode cnode = new ClassNode();
|
||||
ClassReader reader = new ClassReader(bytes);
|
||||
reader.accept(cnode, flags);
|
||||
return cnode;
|
||||
}
|
||||
|
||||
public static byte[] createBytes(ClassNode cnode, int flags)
|
||||
{
|
||||
public static byte[] createBytes(ClassNode cnode, int flags) {
|
||||
ClassWriter cw = new CC_ClassWriter(flags);
|
||||
cnode.accept(cw);
|
||||
return cw.toByteArray();
|
||||
}
|
||||
|
||||
public static byte[] writeMethods(String name, byte[] bytes, Multimap<String, MethodWriter> writers)
|
||||
{
|
||||
if(writers.containsKey(name))
|
||||
{
|
||||
|
||||
public static byte[] writeMethods(String name, byte[] bytes, Multimap<String, MethodWriter> writers) {
|
||||
if (writers.containsKey(name)) {
|
||||
ClassNode cnode = createClassNode(bytes);
|
||||
|
||||
for(MethodWriter mw : writers.get(name))
|
||||
{
|
||||
|
||||
for (MethodWriter mw : writers.get(name)) {
|
||||
MethodNode mv = findMethod(mw.method, cnode);
|
||||
if(mv == null)
|
||||
if (mv == null)
|
||||
mv = (MethodNode) cnode.visitMethod(mw.access, mw.method.s_name, mw.method.s_desc, null, mw.exceptions);
|
||||
|
||||
mv.access = mw.access;
|
||||
@@ -143,41 +131,33 @@ public class ASMHelper
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static byte[] injectMethods(String name, byte[] bytes, Multimap<String, MethodInjector> injectors)
|
||||
{
|
||||
if(injectors.containsKey(name))
|
||||
{
|
||||
|
||||
public static byte[] injectMethods(String name, byte[] bytes, Multimap<String, MethodInjector> injectors) {
|
||||
if (injectors.containsKey(name)) {
|
||||
ClassNode cnode = createClassNode(bytes);
|
||||
|
||||
for(MethodInjector injector : injectors.get(name))
|
||||
{
|
||||
|
||||
for (MethodInjector injector : injectors.get(name)) {
|
||||
MethodNode method = findMethod(injector.method, cnode);
|
||||
if(method == null)
|
||||
throw new RuntimeException("Method not found: "+injector.method);
|
||||
if (method == null)
|
||||
throw new RuntimeException("Method not found: " + injector.method);
|
||||
System.out.println("Injecting into " + injector.method + "\n" + printInsnList(injector.injection));
|
||||
|
||||
|
||||
List<AbstractInsnNode> callNodes;
|
||||
if(injector.before)
|
||||
if (injector.before)
|
||||
callNodes = InstructionComparator.insnListFindStart(method.instructions, injector.needle);
|
||||
else
|
||||
callNodes = InstructionComparator.insnListFindEnd(method.instructions, injector.needle);
|
||||
|
||||
if(callNodes.size() == 0)
|
||||
{
|
||||
throw new RuntimeException("Needle not found in Haystack: " + injector.method+"\n" + printInsnList(injector.needle));
|
||||
|
||||
if (callNodes.size() == 0) {
|
||||
throw new RuntimeException("Needle not found in Haystack: " + injector.method + "\n" + printInsnList(injector.needle));
|
||||
}
|
||||
|
||||
for(AbstractInsnNode node : callNodes)
|
||||
{
|
||||
if(injector.before)
|
||||
{
|
||||
System.out.println("Injected before: "+printInsn(node));
|
||||
|
||||
for (AbstractInsnNode node : callNodes) {
|
||||
if (injector.before) {
|
||||
System.out.println("Injected before: " + printInsn(node));
|
||||
method.instructions.insertBefore(node, cloneInsnList(injector.injection));
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println("Injected after: "+printInsn(node));
|
||||
} else {
|
||||
System.out.println("Injected after: " + printInsn(node));
|
||||
method.instructions.insert(node, cloneInsnList(injector.injection));
|
||||
}
|
||||
}
|
||||
@@ -187,144 +167,126 @@ public class ASMHelper
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
public static String printInsnList(InsnList list)
|
||||
{
|
||||
InsnListPrinter p = new InsnListPrinter();
|
||||
|
||||
public static String printInsnList(InsnList list) {
|
||||
InsnListPrinter p = new InsnListPrinter();
|
||||
p.visitInsnList(list);
|
||||
return p.textString();
|
||||
}
|
||||
|
||||
public static String printInsn(AbstractInsnNode insn)
|
||||
{
|
||||
|
||||
public static String printInsn(AbstractInsnNode insn) {
|
||||
InsnListPrinter p = new InsnListPrinter();
|
||||
p.visitInsn(insn);
|
||||
return p.textString();
|
||||
}
|
||||
|
||||
public static Map<LabelNode, LabelNode> cloneLabels(InsnList insns)
|
||||
{
|
||||
|
||||
public static Map<LabelNode, LabelNode> cloneLabels(InsnList insns) {
|
||||
HashMap<LabelNode, LabelNode> labelMap = new HashMap<LabelNode, LabelNode>();
|
||||
for(AbstractInsnNode insn = insns.getFirst(); insn != null; insn = insn.getNext())
|
||||
if(insn.getType() == 8)
|
||||
for (AbstractInsnNode insn = insns.getFirst(); insn != null; insn = insn.getNext())
|
||||
if (insn.getType() == 8)
|
||||
labelMap.put((LabelNode) insn, new LabelNode());
|
||||
return labelMap;
|
||||
}
|
||||
|
||||
public static InsnList cloneInsnList(InsnList insns)
|
||||
{
|
||||
|
||||
public static InsnList cloneInsnList(InsnList insns) {
|
||||
return cloneInsnList(cloneLabels(insns), insns);
|
||||
}
|
||||
|
||||
public static InsnList cloneInsnList(Map<LabelNode, LabelNode> labelMap, InsnList insns)
|
||||
{
|
||||
|
||||
public static InsnList cloneInsnList(Map<LabelNode, LabelNode> labelMap, InsnList insns) {
|
||||
InsnList clone = new InsnList();
|
||||
for(AbstractInsnNode insn = insns.getFirst(); insn != null; insn = insn.getNext())
|
||||
for (AbstractInsnNode insn = insns.getFirst(); insn != null; insn = insn.getNext())
|
||||
clone.add(insn.clone(labelMap));
|
||||
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static List<TryCatchBlockNode> cloneTryCatchBlocks(Map<LabelNode, LabelNode> labelMap, List<TryCatchBlockNode> tcblocks)
|
||||
{
|
||||
|
||||
public static List<TryCatchBlockNode> cloneTryCatchBlocks(Map<LabelNode, LabelNode> labelMap, List<TryCatchBlockNode> tcblocks) {
|
||||
ArrayList<TryCatchBlockNode> clone = new ArrayList<TryCatchBlockNode>();
|
||||
for(TryCatchBlockNode node : tcblocks)
|
||||
for (TryCatchBlockNode node : tcblocks)
|
||||
clone.add(new TryCatchBlockNode(
|
||||
labelMap.get(node.start),
|
||||
labelMap.get(node.end),
|
||||
labelMap.get(node.handler),
|
||||
labelMap.get(node.start),
|
||||
labelMap.get(node.end),
|
||||
labelMap.get(node.handler),
|
||||
node.type));
|
||||
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static List<LocalVariableNode> cloneLocals(Map<LabelNode, LabelNode> labelMap, List<LocalVariableNode> locals)
|
||||
{
|
||||
|
||||
public static List<LocalVariableNode> cloneLocals(Map<LabelNode, LabelNode> labelMap, List<LocalVariableNode> locals) {
|
||||
ArrayList<LocalVariableNode> clone = new ArrayList<LocalVariableNode>();
|
||||
for(LocalVariableNode node : locals)
|
||||
for (LocalVariableNode node : locals)
|
||||
clone.add(new LocalVariableNode(
|
||||
node.name, node.desc, node.signature,
|
||||
labelMap.get(node.start),
|
||||
labelMap.get(node.end),
|
||||
node.name, node.desc, node.signature,
|
||||
labelMap.get(node.start),
|
||||
labelMap.get(node.end),
|
||||
node.index));
|
||||
|
||||
|
||||
return clone;
|
||||
}
|
||||
|
||||
public static void copy(MethodNode src, MethodNode dst)
|
||||
{
|
||||
|
||||
public static void copy(MethodNode src, MethodNode dst) {
|
||||
Map<LabelNode, LabelNode> labelMap = cloneLabels(src.instructions);
|
||||
dst.instructions = cloneInsnList(labelMap, src.instructions);
|
||||
dst.tryCatchBlocks = cloneTryCatchBlocks(labelMap, src.tryCatchBlocks);
|
||||
if(src.localVariables != null)
|
||||
if (src.localVariables != null)
|
||||
dst.localVariables = cloneLocals(labelMap, src.localVariables);
|
||||
dst.visibleAnnotations = src.visibleAnnotations;
|
||||
dst.invisibleAnnotations = src.invisibleAnnotations;
|
||||
dst.visitMaxs(src.maxStack, src.maxLocals);
|
||||
}
|
||||
|
||||
public static byte[] alterMethods(String name, byte[] bytes, HashMultimap<String, MethodAltercator> altercators)
|
||||
{
|
||||
if(altercators.containsKey(name))
|
||||
{
|
||||
public static byte[] alterMethods(String name, byte[] bytes, HashMultimap<String, MethodAltercator> altercators) {
|
||||
if (altercators.containsKey(name)) {
|
||||
ClassNode cnode = createClassNode(bytes);
|
||||
|
||||
for(MethodAltercator injector : altercators.get(name))
|
||||
{
|
||||
|
||||
for (MethodAltercator injector : altercators.get(name)) {
|
||||
MethodNode method = findMethod(injector.method, cnode);
|
||||
if(method == null)
|
||||
throw new RuntimeException("Method not found: "+injector.method);
|
||||
|
||||
if (method == null)
|
||||
throw new RuntimeException("Method not found: " + injector.method);
|
||||
|
||||
injector.alter(method);
|
||||
}
|
||||
|
||||
|
||||
bytes = createBytes(cnode, ClassWriter.COMPUTE_MAXS | ClassWriter.COMPUTE_FRAMES);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
|
||||
public static String printInsnList(InsnListSection subsection)
|
||||
{
|
||||
InsnListPrinter p = new InsnListPrinter();
|
||||
|
||||
public static String printInsnList(InsnListSection subsection) {
|
||||
InsnListPrinter p = new InsnListPrinter();
|
||||
p.visitInsnList(subsection);
|
||||
return p.textString();
|
||||
}
|
||||
|
||||
public static int getLocal(List<LocalVariableNode> list, String name)
|
||||
{
|
||||
public static int getLocal(List<LocalVariableNode> list, String name) {
|
||||
int found = -1;
|
||||
for(LocalVariableNode node : list)
|
||||
{
|
||||
if(node.name.equals(name))
|
||||
{
|
||||
if(found >= 0)
|
||||
throw new RuntimeException("Duplicate local variable: "+name+" not coded to handle this scenario.");
|
||||
|
||||
for (LocalVariableNode node : list) {
|
||||
if (node.name.equals(name)) {
|
||||
if (found >= 0)
|
||||
throw new RuntimeException("Duplicate local variable: " + name + " not coded to handle this scenario.");
|
||||
|
||||
found = node.index;
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
public static void replaceMethodCode(MethodNode original, MethodNode replacement)
|
||||
{
|
||||
public static void replaceMethodCode(MethodNode original, MethodNode replacement) {
|
||||
original.instructions.clear();
|
||||
if(original.localVariables != null)
|
||||
if (original.localVariables != null)
|
||||
original.localVariables.clear();
|
||||
if(original.tryCatchBlocks != null)
|
||||
if (original.tryCatchBlocks != null)
|
||||
original.tryCatchBlocks.clear();
|
||||
replacement.accept(original);
|
||||
}
|
||||
|
||||
public static void removeBlock(InsnList insns, InsnListSection block)
|
||||
{
|
||||
public static void removeBlock(InsnList insns, InsnListSection block) {
|
||||
AbstractInsnNode insn = block.first;
|
||||
while(true)
|
||||
{
|
||||
while (true) {
|
||||
AbstractInsnNode next = insn.getNext();
|
||||
insns.remove(insn);
|
||||
if(insn == block.last)
|
||||
if (insn == block.last)
|
||||
break;
|
||||
insn = next;
|
||||
}
|
||||
|
||||
@@ -301,14 +301,14 @@ public class ASMReader
|
||||
insn = new VarInsnNode(opcode, Integer.parseInt(split[1]));
|
||||
break;
|
||||
case TYPE_INSN:
|
||||
insn = new ObfMapping(split[1]).toInsn(opcode);
|
||||
insn = new ObfMapping(split[1]).toClassloading().toInsn(opcode);
|
||||
break;
|
||||
case FIELD_INSN:
|
||||
case METHOD_INSN:
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for(int i = 1; i < split.length; i++)
|
||||
sb.append(split[i]);
|
||||
insn = ObfMapping.fromDesc(sb.toString()).toInsn(opcode);
|
||||
insn = ObfMapping.fromDesc(sb.toString()).toClassloading().toInsn(opcode);
|
||||
break;
|
||||
case INVOKE_DYNAMIC_INSN:
|
||||
throw new Exception("Found INVOKEDYNAMIC while reading");
|
||||
|
||||
+143
-123
@@ -1,8 +1,12 @@
|
||||
package codechicken.lib.asm;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.minecraft.launchwrapper.LaunchClassLoader;
|
||||
import net.minecraft.launchwrapper.Launch;
|
||||
|
||||
import org.objectweb.asm.MethodVisitor;
|
||||
import org.objectweb.asm.commons.Remapper;
|
||||
@@ -19,219 +23,235 @@ import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper;
|
||||
|
||||
public class ObfMapping
|
||||
{
|
||||
/**
|
||||
* CCC will deal with this.
|
||||
*/
|
||||
public static Remapper runtimeMapper = FMLDeobfuscatingRemapper.INSTANCE;
|
||||
public static Remapper mcpMapper = null;
|
||||
|
||||
public static final boolean obfuscated;
|
||||
|
||||
static
|
||||
public static class ObfRemapper extends Remapper
|
||||
{
|
||||
boolean obf = true;
|
||||
try
|
||||
{
|
||||
obf = ((LaunchClassLoader)ObfMapping.class.getClassLoader()).getClassBytes("net.minecraft.world.World") == null;
|
||||
private HashMap<String, String> fields = new HashMap<String, String>();
|
||||
private HashMap<String, String> funcs = new HashMap<String, String>();
|
||||
|
||||
public ObfRemapper() {
|
||||
try {
|
||||
Field rawFieldMapsField = FMLDeobfuscatingRemapper.class.getDeclaredField("rawFieldMaps");
|
||||
Field rawMethodMapsField = FMLDeobfuscatingRemapper.class.getDeclaredField("rawMethodMaps");
|
||||
rawFieldMapsField.setAccessible(true);
|
||||
rawMethodMapsField.setAccessible(true);
|
||||
Map<String, Map<String, String>> rawFieldMaps = (Map<String, Map<String, String>>) rawFieldMapsField.get(FMLDeobfuscatingRemapper.INSTANCE);
|
||||
Map<String, Map<String, String>> rawMethodMaps = (Map<String, Map<String, String>>) rawMethodMapsField.get(FMLDeobfuscatingRemapper.INSTANCE);
|
||||
|
||||
if(rawFieldMaps == null)
|
||||
throw new IllegalStateException("codechicken.lib.asm.ObfMapping loaded too early. Make sure all references are in or after the asm transformer load stage");
|
||||
|
||||
for(Map<String, String> map : rawFieldMaps.values())
|
||||
for(Entry<String, String> entry : map.entrySet())
|
||||
if(entry.getValue().startsWith("field"))
|
||||
fields.put(entry.getValue(), entry.getKey().substring(0, entry.getKey().indexOf(':')));
|
||||
for(Map<String, String> map : rawMethodMaps.values())
|
||||
for(Entry<String, String> entry : map.entrySet())
|
||||
if(entry.getValue().startsWith("func"))
|
||||
funcs.put(entry.getValue(), entry.getKey().substring(0, entry.getKey().indexOf('(')));
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
catch(IOException iox) {}
|
||||
|
||||
@Override
|
||||
public String mapMethodName(String owner, String name, String desc) {
|
||||
String s = funcs.get(name);
|
||||
return s == null ? name : s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String mapFieldName(String owner, String name, String desc) {
|
||||
String s = fields.get(name);
|
||||
return s == null ? name : s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String map(String typeName) {
|
||||
return FMLDeobfuscatingRemapper.INSTANCE.unmap(typeName);
|
||||
}
|
||||
}
|
||||
|
||||
public static ObfRemapper obfMapper = new ObfRemapper();
|
||||
public static Remapper mcpMapper = null;
|
||||
|
||||
public static final boolean obfuscated;
|
||||
|
||||
static {
|
||||
boolean obf = true;
|
||||
try {
|
||||
obf = Launch.classLoader.getClassBytes("net.minecraft.world.World") == null;
|
||||
} catch (IOException ignored) {}
|
||||
obfuscated = obf;
|
||||
}
|
||||
|
||||
|
||||
public String s_owner;
|
||||
public String s_name;
|
||||
public String s_desc;
|
||||
|
||||
public boolean runtime;
|
||||
|
||||
public ObfMapping(String owner)
|
||||
{
|
||||
|
||||
public ObfMapping(String owner) {
|
||||
this(owner, "", "");
|
||||
}
|
||||
|
||||
public ObfMapping(String owner, String name, String desc)
|
||||
{
|
||||
|
||||
public ObfMapping(String owner, String name, String desc) {
|
||||
this.s_owner = owner;
|
||||
this.s_name = name;
|
||||
this.s_desc = desc;
|
||||
|
||||
if(s_owner.contains("."))
|
||||
if (s_owner.contains("."))
|
||||
throw new IllegalArgumentException(s_owner);
|
||||
|
||||
if(mcpMapper != null)
|
||||
map(mcpMapper);
|
||||
}
|
||||
|
||||
public ObfMapping(ObfMapping descmap, String subclass)
|
||||
{
|
||||
|
||||
public ObfMapping(ObfMapping descmap, String subclass) {
|
||||
this(subclass, descmap.s_name, descmap.s_desc);
|
||||
}
|
||||
|
||||
public static ObfMapping fromDesc(String s)
|
||||
{
|
||||
public static ObfMapping fromDesc(String s) {
|
||||
int lastDot = s.lastIndexOf('.');
|
||||
if(lastDot < 0)
|
||||
if (lastDot < 0)
|
||||
return new ObfMapping(s, "", "");
|
||||
int sep = s.indexOf('(');//methods
|
||||
int sep_end = sep;
|
||||
if(sep < 0) {
|
||||
if (sep < 0) {
|
||||
sep = s.indexOf(' ');//some stuffs
|
||||
sep_end = sep+1;
|
||||
sep_end = sep + 1;
|
||||
}
|
||||
if(sep < 0) {
|
||||
if (sep < 0) {
|
||||
sep = s.indexOf(':');//fields
|
||||
sep_end = sep+1;
|
||||
sep_end = sep + 1;
|
||||
}
|
||||
if(sep < 0)
|
||||
if (sep < 0)
|
||||
return new ObfMapping(s.substring(0, lastDot), s.substring(lastDot + 1), "");
|
||||
|
||||
return new ObfMapping(s.substring(0, lastDot), s.substring(lastDot+1, sep), s.substring(sep_end));
|
||||
return new ObfMapping(s.substring(0, lastDot), s.substring(lastDot + 1, sep), s.substring(sep_end));
|
||||
}
|
||||
|
||||
public ObfMapping subclass(String subclass)
|
||||
{
|
||||
|
||||
public ObfMapping subclass(String subclass) {
|
||||
return new ObfMapping(this, subclass);
|
||||
}
|
||||
|
||||
public boolean matches(MethodNode node)
|
||||
{
|
||||
public boolean matches(MethodNode node) {
|
||||
return s_name.equals(node.name) && s_desc.equals(node.desc);
|
||||
}
|
||||
|
||||
public boolean matches(MethodInsnNode node)
|
||||
{
|
||||
|
||||
public boolean matches(MethodInsnNode node) {
|
||||
return s_owner.equals(node.owner) && s_name.equals(node.name) && s_desc.equals(node.desc);
|
||||
}
|
||||
|
||||
public AbstractInsnNode toInsn(int opcode)
|
||||
{
|
||||
if(isClass())
|
||||
public AbstractInsnNode toInsn(int opcode) {
|
||||
if (isClass())
|
||||
return new TypeInsnNode(opcode, s_owner);
|
||||
else if(isMethod())
|
||||
else if (isMethod())
|
||||
return new MethodInsnNode(opcode, s_owner, s_name, s_desc);
|
||||
else
|
||||
return new FieldInsnNode(opcode, s_owner, s_name, s_desc);
|
||||
}
|
||||
|
||||
public void visitTypeInsn(MethodVisitor mv, int opcode)
|
||||
{
|
||||
|
||||
public void visitTypeInsn(MethodVisitor mv, int opcode) {
|
||||
mv.visitTypeInsn(opcode, s_owner);
|
||||
}
|
||||
|
||||
public void visitMethodInsn(MethodVisitor mv, int opcode)
|
||||
{
|
||||
|
||||
public void visitMethodInsn(MethodVisitor mv, int opcode) {
|
||||
mv.visitMethodInsn(opcode, s_owner, s_name, s_desc);
|
||||
}
|
||||
|
||||
public void visitFieldInsn(MethodVisitor mv, int opcode)
|
||||
{
|
||||
public void visitFieldInsn(MethodVisitor mv, int opcode) {
|
||||
mv.visitFieldInsn(opcode, s_owner, s_name, s_desc);
|
||||
}
|
||||
|
||||
public boolean isClass(String name)
|
||||
{
|
||||
public boolean isClass(String name) {
|
||||
return name.replace('.', '/').equals(s_owner);
|
||||
}
|
||||
|
||||
public boolean matches(String name, String desc)
|
||||
{
|
||||
public boolean matches(String name, String desc) {
|
||||
return s_name.equals(name) && s_desc.equals(desc);
|
||||
}
|
||||
|
||||
public boolean matches(FieldNode node)
|
||||
{
|
||||
public boolean matches(FieldNode node) {
|
||||
return s_name.equals(node.name) && s_desc.equals(node.desc);
|
||||
}
|
||||
|
||||
public boolean matches(FieldInsnNode node)
|
||||
{
|
||||
|
||||
public boolean matches(FieldInsnNode node) {
|
||||
return s_owner.equals(node.owner) && s_name.equals(node.name) && s_desc.equals(node.desc);
|
||||
}
|
||||
|
||||
public String javaClass()
|
||||
{
|
||||
public String javaClass() {
|
||||
return s_owner.replace('/', '.');
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj)
|
||||
{
|
||||
if(!(obj instanceof ObfMapping))
|
||||
public boolean equals(Object obj) {
|
||||
if (!(obj instanceof ObfMapping))
|
||||
return false;
|
||||
|
||||
ObfMapping desc = (ObfMapping)obj;
|
||||
|
||||
ObfMapping desc = (ObfMapping) obj;
|
||||
return s_owner.equals(desc.s_owner) && s_name.equals(desc.s_name) && s_desc.equals(desc.s_desc);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(s_desc, s_name, s_owner);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
if(s_name.length() == 0)
|
||||
return "["+s_owner+"]";
|
||||
if(s_desc.length() == 0)
|
||||
return "["+s_owner+"."+s_name+"]";
|
||||
return "["+(isMethod() ? methodDesc() : fieldDesc())+"]";
|
||||
public String toString() {
|
||||
if (s_name.length() == 0)
|
||||
return "[" + s_owner + "]";
|
||||
if (s_desc.length() == 0)
|
||||
return "[" + s_owner + "." + s_name + "]";
|
||||
return "[" + (isMethod() ? methodDesc() : fieldDesc()) + "]";
|
||||
}
|
||||
|
||||
public String methodDesc()
|
||||
{
|
||||
return s_owner+"."+s_name+s_desc;
|
||||
public String methodDesc() {
|
||||
return s_owner + "." + s_name + s_desc;
|
||||
}
|
||||
|
||||
public String fieldDesc()
|
||||
{
|
||||
return s_owner+"."+s_name+":"+s_desc;
|
||||
public String fieldDesc() {
|
||||
return s_owner + "." + s_name + ":" + s_desc;
|
||||
}
|
||||
|
||||
public boolean isClass()
|
||||
{
|
||||
|
||||
public boolean isClass() {
|
||||
return s_name.length() == 0;
|
||||
}
|
||||
|
||||
public boolean isMethod()
|
||||
{
|
||||
|
||||
public boolean isMethod() {
|
||||
return s_desc.contains("(");
|
||||
}
|
||||
|
||||
public boolean isField()
|
||||
{
|
||||
|
||||
public boolean isField() {
|
||||
return !isClass() && !isMethod();
|
||||
}
|
||||
|
||||
public ObfMapping map(Remapper mapper)
|
||||
{
|
||||
if(isMethod())
|
||||
|
||||
public ObfMapping map(Remapper mapper) {
|
||||
if(mapper == null)
|
||||
return this;
|
||||
|
||||
if (isMethod())
|
||||
s_name = mapper.mapMethodName(s_owner, s_name, s_desc);
|
||||
else if(isField())
|
||||
else if (isField())
|
||||
s_name = mapper.mapFieldName(s_owner, s_name, s_desc);
|
||||
|
||||
|
||||
s_owner = mapper.mapType(s_owner);
|
||||
|
||||
if(isMethod())
|
||||
|
||||
if (isMethod())
|
||||
s_desc = mapper.mapMethodDesc(s_desc);
|
||||
else if(s_desc.length() > 0)
|
||||
else if (s_desc.length() > 0)
|
||||
s_desc = mapper.mapDesc(s_desc);
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfMapping toRuntime()
|
||||
{
|
||||
if(!runtime)
|
||||
map(runtimeMapper);
|
||||
|
||||
runtime = true;
|
||||
|
||||
public ObfMapping toRuntime() {
|
||||
map(mcpMapper);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfMapping copy()
|
||||
{
|
||||
|
||||
public ObfMapping toClassloading() {
|
||||
map(obfuscated ? obfMapper : mcpMapper);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ObfMapping copy() {
|
||||
return new ObfMapping(s_owner, s_name, s_desc);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user