Get rid of most hard type comparisons in mapper

This commit is contained in:
Adam
2016-03-27 10:44:55 -04:00
parent d7abcdf569
commit e3a6310572
13 changed files with 90 additions and 54 deletions

View File

@@ -162,7 +162,7 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
{
Field f1 = f1s.get(0), f2 = f2s.get(0);
assert f1.getType().equals(f2.getType());
assert MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
mapping.map(f1, f2);
@@ -186,7 +186,10 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
Field j1 = f1s.get(1), j2 = f2s.get(1);
assert !(couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2));
if (couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2))
{
return; // ambiguous
}
if (couldBeSame(f1, f2) && couldBeSame(j1, j2))
{
@@ -250,10 +253,10 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
return false;
if (!f1.isStatic())
if (!f1.getFields().getClassFile().getName().equals(f2.getFields().getClassFile().getName()))
if (!MappingExecutorUtil.isMaybeEqual(f1.getFields().getClassFile(), f2.getFields().getClassFile()))
return false;
return f1.getType().equals(f2.getType());
return MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
}
protected boolean isSameField(InstructionContext thisIc, InstructionContext otherIc)
@@ -277,7 +280,7 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp
Field j1 = f1s.get(1), j2 = f2s.get(1);
if (couldBeSame(f1, f2) && couldBeSame(j1, j2) && couldBeSame(f1, j2) && couldBeSame(j1, f2))
return false; // ambiguous
return true;
if (couldBeSame(f1, f2) && couldBeSame(j1, j2))
return true;

View File

@@ -135,20 +135,6 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
f2.other = branch1;
branch1.other = f2;
// switch frame order in executor frame list
// Execution e = f1.getExecution(),
// e2 = f2.getExecution();
//
// int i = e2.frames.indexOf(f2),
// i2 = e2.frames.indexOf(branch2);
//
// e2.frames.remove(i);
// e2.frames.add(i, branch2);
//
// e2.frames.remove(i2);
// e2.frames.add(i2, f2);
this.mapArguments(mapping, ctx, other);
}
@@ -157,8 +143,8 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
Field f1 = getComparedField(ctx), f2 = getComparedField(other);
if (f1 == null || f2 == null)
return;
assert f1.getType().equals(f2.getType());
assert MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
mapping.map(f1, f2);
}
@@ -199,10 +185,10 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com
return false;
if (!f1.isStatic())
if (!f1.getFields().getClassFile().getName().equals(f2.getFields().getClassFile().getName()))
if (!MappingExecutorUtil.isMaybeEqual(f1.getFields().getClassFile(), f2.getFields().getClassFile()))
return false;
return f1.getType().equals(f2.getType());
return MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
}
@Override

View File

@@ -242,8 +242,8 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
InvokeInterface thisIi = (InvokeInterface) thisIc.getInstruction(),
otherIi = (InvokeInterface) otherIc.getInstruction();
if (!thisIi.method.getNameAndType().getDescriptor().equals(otherIi.method.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(thisIi.method.getNameAndType().getDescriptor(), otherIi.method.getNameAndType().getDescriptor()))
return false;
List<net.runelite.asm.Method> thisMethods = thisIi.getMethods(),
@@ -262,11 +262,11 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
{
net.runelite.asm.Method m1 = thisMethods.get(i);
net.runelite.asm.Method m2 = otherMethods.get(i);
if (!m1.getMethods().getClassFile().getPoolClass().equals(m2.getMethods().getClassFile().getPoolClass()))
if (!MappingExecutorUtil.isMaybeEqual(m1.getMethods().getClassFile(), m2.getMethods().getClassFile()))
return false;
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(m1.getNameAndType().getDescriptor(), m2.getNameAndType().getDescriptor()))
return false;
}

View File

@@ -243,8 +243,8 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
InvokeSpecial thisIi = (InvokeSpecial) thisIc.getInstruction(),
otherIi = (InvokeSpecial) otherIc.getInstruction();
if (!thisIi.method.getNameAndType().getDescriptor().equals(otherIi.method.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(thisIi.method.getNameAndType().getDescriptor(), otherIi.method.getNameAndType().getDescriptor()))
return false;
List<net.runelite.asm.Method> thisMethods = thisIi.getMethods(),
@@ -266,11 +266,11 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
{
net.runelite.asm.Method m1 = thisMethods.get(i);
net.runelite.asm.Method m2 = otherMethods.get(i);
if (!m1.getMethods().getClassFile().getPoolClass().equals(m2.getMethods().getClassFile().getPoolClass()))
if (!MappingExecutorUtil.isMaybeEqual(m1.getMethods().getClassFile(), m2.getMethods().getClassFile()))
return false;
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(m1.getNameAndType().getDescriptor(), m2.getNameAndType().getDescriptor()))
return false;
}

View File

@@ -213,8 +213,8 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
InvokeStatic thisIi = (InvokeStatic) thisIc.getInstruction(),
otherIi = (InvokeStatic) otherIc.getInstruction();
if (!thisIi.method.getNameAndType().getDescriptor().equals(otherIi.method.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(thisIi.method.getNameAndType().getDescriptor(), otherIi.method.getNameAndType().getDescriptor()))
return false;
List<net.runelite.asm.Method> thisMethods = thisIi.getMethods(),

View File

@@ -177,8 +177,8 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
List<net.runelite.asm.Method> myMethods = this.getMethods(),
otherMethods = otherIv.getMethods();
assert method.getNameAndType().getDescriptor().equals(otherIv.method.getNameAndType().getDescriptor());
assert MappingExecutorUtil.isMaybeEqual(method.getNameAndType().getDescriptor(), otherIv.method.getNameAndType().getDescriptor());
assert myMethods.size() == otherMethods.size();
for (int i = 0; i < myMethods.size(); ++i)
@@ -186,7 +186,7 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
net.runelite.asm.Method m1 = myMethods.get(i);
net.runelite.asm.Method m2 = otherMethods.get(i);
assert m1.getMethods().getClassFile().getName().equals(m2.getMethods().getClassFile().getName());
assert MappingExecutorUtil.isMaybeEqual(m1.getMethods().getClassFile(), m2.getMethods().getClassFile());
mapping.map(m1, m2);
}
@@ -248,8 +248,8 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
InvokeVirtual thisIi = (InvokeVirtual) thisIc.getInstruction(),
otherIi = (InvokeVirtual) otherIc.getInstruction();
if (!thisIi.method.getNameAndType().getDescriptor().equals(otherIi.method.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(thisIi.method.getNameAndType().getDescriptor(), otherIi.method.getNameAndType().getDescriptor()))
return false;
List<net.runelite.asm.Method> thisMethods = thisIi.getMethods(),
@@ -268,11 +268,11 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
{
net.runelite.asm.Method m1 = thisMethods.get(i);
net.runelite.asm.Method m2 = otherMethods.get(i);
if (!m1.getMethods().getClassFile().getPoolClass().equals(m2.getMethods().getClassFile().getPoolClass()))
if (!MappingExecutorUtil.isMaybeEqual(m1.getMethods().getClassFile(), m2.getMethods().getClassFile()))
return false;
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(m1.getNameAndType().getDescriptor(), m2.getNameAndType().getDescriptor()))
return false;
}

View File

@@ -106,7 +106,7 @@ public class PutField extends Instruction implements SetFieldInstruction
net.runelite.asm.Field myField = this.getMyField();
net.runelite.asm.Field otherField = ((PutField) other.getInstruction()).getMyField();
assert myField.getType().equals(otherField.getType());
assert MappingExecutorUtil.isMaybeEqual(myField.getType(), otherField.getType());
mapping.map(myField, otherField);
@@ -149,9 +149,9 @@ public class PutField extends Instruction implements SetFieldInstruction
if ((f1 != null) != (f2 != null))
return false;
return f1.getFields().getClassFile().getPoolClass().equals(f2.getFields().getClassFile().getPoolClass())
&& f1.getType().equals(f2.getType());
return MappingExecutorUtil.isMaybeEqual(f1.getFields().getClassFile(), f2.getFields().getClassFile())
&& MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
}
@Override

View File

@@ -103,8 +103,8 @@ public class PutStatic extends Instruction implements SetFieldInstruction
{
net.runelite.asm.Field myField = this.getMyField();
net.runelite.asm.Field otherField = ((PutStatic) other.getInstruction()).getMyField();
assert myField.getType().equals(otherField.getType());
assert MappingExecutorUtil.isMaybeEqual(myField.getType(), otherField.getType());
mapping.map(myField, otherField);
@@ -137,9 +137,15 @@ public class PutStatic extends Instruction implements SetFieldInstruction
PutStatic thisPf = (PutStatic) thisIc.getInstruction(),
otherPf = (PutStatic) otherIc.getInstruction();
net.runelite.asm.Field f1 = thisPf.getMyField();
net.runelite.asm.Field f2 = otherPf.getMyField();
if ((f1 != null) != (f2 != null))
return false;
/* The class names are random */
return thisPf.getField().getNameAndType().getDescriptorType().equals(otherPf.getField().getNameAndType().getDescriptorType());
return MappingExecutorUtil.isMaybeEqual(f1.getType(), f2.getType());
}
@Override

View File

@@ -4,6 +4,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import net.runelite.asm.ClassFile;
import net.runelite.asm.ClassGroup;
import net.runelite.asm.Method;
import net.runelite.asm.attributes.code.Instruction;
@@ -23,6 +24,7 @@ import net.runelite.asm.execution.StackContext;
import net.runelite.asm.execution.VariableContext;
import net.runelite.asm.execution.Variables;
import net.runelite.asm.signature.Signature;
import net.runelite.asm.signature.Type;
public class MappingExecutorUtil
{
@@ -292,4 +294,39 @@ public class MappingExecutorUtil
return ctx;
}
public static boolean isMaybeEqual(Type t1, Type t2)
{
if (t1.isPrimitive() != t2.isPrimitive())
return false;
if (t1.getArrayDims() != t2.getArrayDims())
return false;
return true;
}
public static boolean isMaybeEqual(Signature s1, Signature s2)
{
if (s1.size() != s2.size())
return false;
if (!isMaybeEqual(s1.getReturnValue(), s2.getReturnValue()))
return false;
for (int i = 0; i < s1.size(); ++i)
{
Type t1 = s1.getTypeOfArg(i), t2 = s2.getTypeOfArg(i);
if (!isMaybeEqual(t1, t2))
return false;
}
return true;
}
public static boolean isMaybeEqual(ClassFile cf1, ClassFile cf2)
{
return true;
}
}

View File

@@ -22,8 +22,8 @@ public class MethodSignatureMapper
{
if (m2.getCode() == null)
continue;
if (!m.getDescriptor().equals(m2.getDescriptor()))
if (!MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), m2.getDescriptor()))
continue;
boolean isConstructor2 = m2.getName().equals("<init>");

View File

@@ -26,7 +26,9 @@ public class StaticMethodSignatureMapper
private List<Method> getStaticMethodsOfSignature(ClassGroup group, Signature sig)
{
return getStaticMethods(group).stream().filter(m -> m.getDescriptor().equals(sig)).collect(Collectors.toList());
return getStaticMethods(group).stream().filter(
m -> MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), sig)
).collect(Collectors.toList());
}
public void map(ClassGroup group1, ClassGroup group2)

View File

@@ -355,6 +355,7 @@ public class Inject
Type lastGarbageArgumentType = null;
assert false;
if (!deobfuscatedMethod.getDescriptor().equals(invokeMethod.getDescriptor()))
{
// allow for obfuscated method to have a single bogus signature at the end

View File

@@ -232,6 +232,7 @@ public class InjectReplace
// Rename method to override
m.setName(obfuscatedMethodToOverride.getName());
assert false;
if (!m.getDescriptor().equals(obfuscatedMethodToOverride.getDescriptor()))
{
// Obfuscation can add garbage parameter.