diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index 9449813a8f..7a67964af2 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -92,9 +92,9 @@ public class Deob { new MultiplicationDeobfuscator().run(group); - new MultiplyOneDeobfuscator().run(group); + //new MultiplyOneDeobfuscator().run(group); - new MultiplyZeroDeobfuscator().run(group); + //new MultiplyZeroDeobfuscator().run(group); if (last == cur) { diff --git a/src/main/java/net/runelite/deob/attributes/code/Instructions.java b/src/main/java/net/runelite/deob/attributes/code/Instructions.java index 672f649217..84f50bc41f 100644 --- a/src/main/java/net/runelite/deob/attributes/code/Instructions.java +++ b/src/main/java/net/runelite/deob/attributes/code/Instructions.java @@ -84,17 +84,10 @@ public class Instructions public void remove(Instruction ins) { -// for (Instruction i : instructions) -// { -// if (i instanceof JumpingInstruction) -// { -// JumpingInstruction j = (JumpingInstruction) i; -// assert !j.getJumps().contains(ins); -// } -// } - + assert ins.getInstructions() == this; ins.remove(); instructions.remove(ins); + ins.setInstructions(null); } public void remove(Block block) @@ -293,5 +286,7 @@ public class Instructions for (net.runelite.deob.attributes.code.Exception e : code.getExceptions().getExceptions()) e.replace(oldi, newi); + + oldi.setInstructions(null); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java b/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java index 0cad63a64c..bb21093076 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/SiPush.java @@ -23,6 +23,12 @@ public class SiPush extends Instruction implements PushConstantInstruction super(instructions, type, pc); } + public SiPush(Instructions instructions, short value) + { + super(instructions, InstructionType.SIPUSH, -1); + s = value; + } + @Override public void load(DataInputStream is) throws IOException { 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 d1b0529261..c3f7bf67d3 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java @@ -474,7 +474,15 @@ public class ModArith implements Deobfuscator Pair p = this.guess2(f, col2, set); if (p != null) + { + + if (this.deobfuscatedFields.contains(f)) + continue; + pairs.add(p); + + this.deobfuscatedFields.add(f); + } } } } diff --git a/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java b/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java new file mode 100644 index 0000000000..16c72acd1b --- /dev/null +++ b/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java @@ -0,0 +1,80 @@ +package net.runelite.deob.deobfuscators.arithmetic; + +import net.runelite.deob.ClassGroup; +import net.runelite.deob.ClassGroupFactory; +import net.runelite.deob.Deobfuscator; +import net.runelite.deob.attributes.Code; +import net.runelite.deob.attributes.code.Instruction; +import net.runelite.deob.attributes.code.Instructions; +import net.runelite.deob.attributes.code.instructions.Goto; +import net.runelite.deob.attributes.code.instructions.IConst_1; +import net.runelite.deob.attributes.code.instructions.IConst_2; +import net.runelite.deob.attributes.code.instructions.IConst_3; +import net.runelite.deob.attributes.code.instructions.ILoad; +import net.runelite.deob.attributes.code.instructions.IMul; +import net.runelite.deob.attributes.code.instructions.IStore_0; +import net.runelite.deob.attributes.code.instructions.If0; +import net.runelite.deob.attributes.code.instructions.NOP; +import net.runelite.deob.attributes.code.instructions.SiPush; +import net.runelite.deob.attributes.code.instructions.VReturn; +import net.runelite.deob.execution.Execution; +import org.junit.Assert; +import org.junit.Test; + +public class MultiplyOneDeobfuscatorTest +{ + @Test + public void test() + { + ClassGroup group = ClassGroupFactory.generateGroup(); + Code code = group.findClass("test").findMethod("func").getCode(); + Instructions ins = code.getInstructions(); + + code.setMaxStack(2); + + // vars[0] = 3 + Instruction[] prepareVariables = { + new IConst_3(ins), + new IStore_0(ins) + }; + + for (Instruction i : prepareVariables) + ins.addInstruction(i); + + NOP label = new NOP(ins), + label2 = new NOP(ins); + + IConst_1 one = new IConst_1(ins); + + Instruction body[] = { + new SiPush(ins, (short) 256), + + new ILoad(ins, 0), + new If0(ins, label), + + new IConst_2(ins), + new Goto(ins, label2), + + label, + one, + + label2, + new IMul(ins), + + new VReturn(ins) + }; + + for (Instruction i : body) + ins.addInstruction(i); + + // check execution runs ok + Execution e = new Execution(group); + e.populateInitialMethods(); + e.run(); + + Deobfuscator d = new MultiplyOneDeobfuscator(); + d.run(group); + + Assert.assertTrue(one.getInstructions() != null); + } +}