diff --git a/src/main/java/net/runelite/deob/Field.java b/src/main/java/net/runelite/deob/Field.java index 07e883acd8..74d2916598 100644 --- a/src/main/java/net/runelite/deob/Field.java +++ b/src/main/java/net/runelite/deob/Field.java @@ -8,6 +8,7 @@ import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Objects; public class Field { @@ -95,4 +96,10 @@ public class Field { return attributes; } + + @Override + public int hashCode() + { + return name.hashCode(); + } } \ No newline at end of file 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 0dd9038839..a51c1402d9 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 @@ -18,6 +18,7 @@ import java.io.DataOutputStream; import java.io.IOException; import java.util.List; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; +import net.runelite.deob.deobfuscators.arithmetic.DMath; import net.runelite.deob.deobfuscators.arithmetic.Encryption; import net.runelite.deob.deobfuscators.arithmetic.Pair; @@ -40,6 +41,33 @@ public class PutStatic extends Instruction implements SetFieldInstruction super.write(out); out.writeShort(this.getPool().make(field)); } + + private static StackContext findMagic(StackContext one, StackContext two) + { + if (one.getPushed().getInstruction() instanceof PushConstantInstruction) + { + PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); + int value1 = (int) pci.getConstant().getObject(); + + if (DMath.isBig(value1)) + { + return one; + } + } + + if (two.getPushed().getInstruction() instanceof PushConstantInstruction) + { + PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction(); + int value2 = (int) pci.getConstant().getObject(); + + if (DMath.isBig(value2)) + { + return two; + } + } + + return null; + } @Override public void execute(Frame frame) @@ -92,25 +120,11 @@ public class PutStatic extends Instruction implements SetFieldInstruction StackContext one = stackCtx.get(0), two = stackCtx.get(1); - if (one.getPushed().getInstruction() instanceof PushConstantInstruction) + StackContext magicStack = findMagic(one, two); + + if (magicStack != null) { - PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); - int value = (int) pci.getConstant().getObject(); - - // field is encrypted with pair - // divide value by setter - - if (value != 0 && value != 1) - { - value = value * pair.getter; - - encryption.change(pci, value); - } - - } - else if (two.getPushed().getInstruction() instanceof PushConstantInstruction) - { - PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction(); + PushConstantInstruction pci = (PushConstantInstruction) magicStack.getPushed().getInstruction(); int value = (int) pci.getConstant().getObject(); // field is encrypted with pair @@ -123,8 +137,40 @@ public class PutStatic extends Instruction implements SetFieldInstruction encryption.change(pci, value); } } - else - assert false; + +// if (one.getPushed().getInstruction() instanceof PushConstantInstruction) +// { +// PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); +// int value = (int) pci.getConstant().getObject(); +// +// // field is encrypted with pair +// // divide value by setter +// +// if (value != 0 && value != 1) +// { +// value = value * pair.getter; +// +// encryption.change(pci, value); +// } +// +// } +// else if (two.getPushed().getInstruction() instanceof PushConstantInstruction) +// { +// PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction(); +// int value = (int) pci.getConstant().getObject(); +// +// // field is encrypted with pair +// // divide value by setter +// +// if (value != 0 && value != 1) +// { +// value = value * pair.getter; +// +// encryption.change(pci, value); +// } +// } +// else +// assert false; } } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java index bb3aa9fbb5..84496a5c93 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java @@ -32,4 +32,9 @@ public class DMath return false; } } + + public static boolean isBig(int val) + { + return (val & 0xFFF00000) != 0; + } } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java index a9abba21c5..ec055c10cc 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java @@ -5,6 +5,7 @@ import java.util.Map; import java.util.Map.Entry; import net.runelite.deob.Field; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; +import net.runelite.deob.attributes.code.instructions.SiPush; public class Encryption { @@ -42,6 +43,10 @@ public class Encryption public void change(PushConstantInstruction pci, int value) { + if (pci instanceof SiPush) + { + int i =5; + } assert !changes.containsKey(pci) || changes.get(pci) == value; changes.put(pci, value); } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java index 5b4671dadb..9ac0613472 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java @@ -239,7 +239,7 @@ public class ModArith implements Deobfuscator System.out.println("Processing " + field.getName()); int getter = constants.getCollection(field).iterator().next(); - if (i > 5) + if (i > 50) break; Pair pair = new Pair();