diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java index 5d509854c4..50e8d56b6c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java @@ -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 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 diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java index 6b63c6c1c3..9948886f49 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java @@ -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 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 diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index af581b3b3f..d627057792 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -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 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 diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java index dbd3f93a34..b8d14e5859 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeVirtual.java @@ -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 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 diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java index 008958da53..36e87d989d 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java @@ -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("")) -// { -// //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 diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java index da493153f0..00d8ef5ce9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java @@ -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