From 5cc12d0228186abd4322e7f22179fe63705a6152 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 25 Sep 2015 14:17:15 -0400 Subject: [PATCH] More multi fixes. Spinning is back with multiplication deobfuscator.. --- src/main/java/net/runelite/deob/Deob.java | 4 ++-- .../MultiplicationDeobfuscator.java | 22 ++++++++++++++++++- .../arithmetic/MultiplyOneDeobfuscator.java | 4 +++- .../arithmetic/MultiplyZeroDeobfuscator.java | 14 ------------ 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index d784ebc8bb..f39768c3d4 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -84,9 +84,9 @@ public class Deob //new ModArith().run(group); - //new MultiplicationDeobfuscator().run(group); + //new MultiplicationDeobfuscator().run(group); // this causes spinning? - //new MultiplyOneDeobfuscator().run(group); + new MultiplyOneDeobfuscator().run(group); new MultiplyZeroDeobfuscator().run(group); diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java index f228de9490..15a865fee6 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -10,6 +10,7 @@ import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.Instructions; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.attributes.code.instructions.IMul; +import net.runelite.deob.attributes.code.instructions.SiPush; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; @@ -57,6 +58,21 @@ public class MultiplicationDeobfuscator implements Deobfuscator return l; } + private boolean isOnlyPath(Execution execution, Frame frame, InstructionContext ctx) + { + for (Frame f : execution.processedFrames) + if (f.getMethod() == frame.getMethod()) + for (InstructionContext i : f.getInstructions()) + if (i.getInstruction() == ctx.getInstruction()) + { + if (!i.equals(ctx)) + { + return false; + } + } + return true; + } + private int runOnce() { group.buildClassGraph(); @@ -77,7 +93,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator if (!(instruction instanceof IMul)) continue; - + List ins = getConstants(ictx); if (ins.size() == 1) @@ -91,6 +107,10 @@ public class MultiplicationDeobfuscator implements Deobfuscator } } + // there can only be one path to here, or else combinging would change code logic + if (!isOnlyPath(e, frame, ictx)) + continue; + int result = 1; // calculate result diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java index dadd29970e..f4bd559d39 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java @@ -7,6 +7,7 @@ import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.Instructions; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.attributes.code.instructions.IMul; +import net.runelite.deob.attributes.code.instructions.NOP; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; @@ -58,7 +59,8 @@ public class MultiplyOneDeobfuscator implements Deobfuscator continue; ictx.removeStack(removeIdx); - ins.remove(ictx.getInstruction()); + ins.replace(ictx.getInstruction(), new NOP(ins)); + //ins.remove(ictx.getInstruction()); ++count; } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java index 1e7df51d45..916640c935 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java @@ -32,12 +32,6 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator Instruction instruction = ictx.getInstruction(); Instructions ins = instruction.getInstructions(); - if (frame.getMethod().getName().equals("method3678")) - //if (ins.getCode().getAttributes().getMethod().getName().equals("method3678")) - { - int i = 5; - } - if (!(instruction instanceof IMul)) continue; @@ -57,10 +51,6 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator if (value == 0) remove = true; - if (value == -1408052237) - { - int i = 5; - } } if (itwo instanceof PushConstantInstruction) { @@ -69,10 +59,6 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator if (value == 0) remove = true; - if (value == -1408052237) - { - int i = 5; - } } if (remove == false)