Make isSame sanity check more in set/put field and invokes

This commit is contained in:
Adam
2016-02-10 20:33:45 -05:00
parent 2bfbe1f239
commit 602afc964c
6 changed files with 148 additions and 18 deletions

View File

@@ -176,7 +176,37 @@ public class InvokeInterface extends Instruction implements InvokeInstruction
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass())
return false;
InvokeInterface thisIi = (InvokeInterface) thisIc.getInstruction(),
otherIi = (InvokeInterface) otherIc.getInstruction();
List<net.runelite.deob.Method> thisMethods = thisIi.getMethods(),
otherMethods = otherIi.getMethods();
if ((thisMethods != null) != (otherMethods != null))
return false;
if (thisMethods == null || otherMethods == null)
return true; // we don't map these anyway
if (thisMethods.size() != otherMethods.size())
return false;
for (int i = 0; i < thisMethods.size(); ++i)
{
net.runelite.deob.Method m1 = thisMethods.get(i),
m2 = otherMethods.get(i);
if (!m1.getMethods().getClassFile().getPoolClass().equals(m2.getMethods().getClassFile().getPoolClass()))
return false;
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
return false;
}
return true;
}
@Override

View File

@@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution;
@@ -177,7 +176,40 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass())
return false;
InvokeSpecial thisIi = (InvokeSpecial) thisIc.getInstruction(),
otherIi = (InvokeSpecial) otherIc.getInstruction();
List<net.runelite.deob.Method> thisMethods = thisIi.getMethods(),
otherMethods = otherIi.getMethods();
if ((thisMethods != null) != (otherMethods != null))
return false;
if (thisMethods == null || otherMethods == null)
return true; // we don't map these anyway
if (thisMethods.size() != otherMethods.size())
return false;
assert thisMethods.size() == 1;
assert otherMethods.size() == 1;
for (int i = 0; i < thisMethods.size(); ++i)
{
net.runelite.deob.Method m1 = thisMethods.get(i),
m2 = otherMethods.get(i);
if (!m1.getMethods().getClassFile().getPoolClass().equals(m2.getMethods().getClassFile().getPoolClass()))
return false;
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
return false;
}
return true;
}
@Override

View File

@@ -22,7 +22,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.runelite.deob.attributes.code.instruction.types.MappableInstruction;
import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil;
import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping;
import net.runelite.deob.execution.Execution;
@@ -179,7 +178,39 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass())
return false;
InvokeStatic thisIi = (InvokeStatic) thisIc.getInstruction(),
otherIi = (InvokeStatic) otherIc.getInstruction();
List<net.runelite.deob.Method> thisMethods = thisIi.getMethods(),
otherMethods = otherIi.getMethods();
if ((thisMethods != null) != (otherMethods != null))
return false;
if (thisMethods == null || otherMethods == null)
return true; // we don't map these anyway
if (thisMethods.size() != otherMethods.size())
return false;
assert thisMethods.size() == 1;
assert otherMethods.size() == 1;
for (int i = 0; i < thisMethods.size(); ++i)
{
net.runelite.deob.Method m1 = thisMethods.get(i),
m2 = otherMethods.get(i);
/* The class names are random */
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
return false;
}
return true;
}
@Override

View File

@@ -199,7 +199,37 @@ public class InvokeVirtual extends Instruction implements InvokeInstruction
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass())
return false;
InvokeVirtual thisIi = (InvokeVirtual) thisIc.getInstruction(),
otherIi = (InvokeVirtual) otherIc.getInstruction();
List<net.runelite.deob.Method> thisMethods = thisIi.getMethods(),
otherMethods = otherIi.getMethods();
if ((thisMethods != null) != (otherMethods != null))
return false;
if (thisMethods == null || otherMethods == null)
return true; // we don't map these anyway
if (thisMethods.size() != otherMethods.size())
return false;
for (int i = 0; i < thisMethods.size(); ++i)
{
net.runelite.deob.Method m1 = thisMethods.get(i),
m2 = otherMethods.get(i);
if (!m1.getMethods().getClassFile().getPoolClass().equals(m2.getMethods().getClassFile().getPoolClass()))
return false;
if (!m1.getNameAndType().getDescriptor().equals(m2.getNameAndType().getDescriptor()))
return false;
}
return true;
}
@Override

View File

@@ -109,16 +109,7 @@ public class PutField extends Instruction implements SetFieldInstruction
net.runelite.deob.Field myField = this.getMyField(),
otherField = ((PutField) other.getInstruction()).getMyField();
// it appears ConstantValue field attributes are inlined into the constructor
// and their orders scrambled, so don't accept constant value assignments?
// if (ctx.getFrame().getMethod().getName().equals("<init>"))
// {
// //assert isConstantAssignment(ctx) == isConstantAssignment(other);
// //if (isConstantAssignment(ctx))
// return;
// }
// XXX field types must be the same
assert myField.getType().equals(otherField.getType());
mapping.map(myField, otherField);
}
@@ -126,7 +117,14 @@ public class PutField extends Instruction implements SetFieldInstruction
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass())
return false;
PutField thisPf = (PutField) thisIc.getInstruction(),
otherPf = (PutField) otherIc.getInstruction();
return thisPf.getField().getClassEntry().equals(otherPf.getField().getClassEntry())
&& thisPf.getField().getNameAndType().getDescriptorType().equals(otherPf.getField().getNameAndType().getDescriptorType());
}
@Override

View File

@@ -102,13 +102,22 @@ public class PutStatic extends Instruction implements SetFieldInstruction
net.runelite.deob.Field myField = this.getMyField(),
otherField = ((PutStatic) other.getInstruction()).getMyField();
assert myField.getType().equals(otherField.getType());
mapping.map(myField, otherField);
}
@Override
public boolean isSame(InstructionContext thisIc, InstructionContext otherIc)
{
return thisIc.getInstruction().getClass() == otherIc.getInstruction().getClass();
if (thisIc.getInstruction().getClass() != otherIc.getInstruction().getClass())
return false;
PutStatic thisPf = (PutStatic) thisIc.getInstruction(),
otherPf = (PutStatic) otherIc.getInstruction();
/* The class names are random */
return thisPf.getField().getNameAndType().getDescriptorType().equals(otherPf.getField().getNameAndType().getDescriptorType());
}
@Override