From 5be7604ee95d2220786f6f74963249e1467cddd4 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 25 Sep 2015 12:40:47 -0400 Subject: [PATCH] IT GETS ME EVERY TIME --- src/main/java/net/runelite/deob/Deob.java | 5 +- .../deob/deobfuscators/UnreachedCode.java | 1 - .../MultiplicationDeobfuscator.java | 2 + .../arithmetic/MultiplyOneDeobfuscator.java | 4 +- .../arithmetic/MultiplyZeroDeobfuscator.java | 98 +++++++++++++++++++ 5 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index ffb367d10e..d784ebc8bb 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -28,6 +28,7 @@ import net.runelite.deob.deobfuscators.UnusedParameters; import net.runelite.deob.deobfuscators.arithmetic.ModArith; import net.runelite.deob.deobfuscators.arithmetic.MultiplicationDeobfuscator; import net.runelite.deob.deobfuscators.arithmetic.MultiplyOneDeobfuscator; +import net.runelite.deob.deobfuscators.arithmetic.MultiplyZeroDeobfuscator; import net.runelite.deob.execution.Execution; public class Deob @@ -85,7 +86,9 @@ public class Deob //new MultiplicationDeobfuscator().run(group); - new MultiplyOneDeobfuscator().run(group); + //new MultiplyOneDeobfuscator().run(group); + + new MultiplyZeroDeobfuscator().run(group); saveJar(group, args[1]); diff --git a/src/main/java/net/runelite/deob/deobfuscators/UnreachedCode.java b/src/main/java/net/runelite/deob/deobfuscators/UnreachedCode.java index 7a603a2653..e7eb79b840 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/UnreachedCode.java +++ b/src/main/java/net/runelite/deob/deobfuscators/UnreachedCode.java @@ -22,7 +22,6 @@ public class UnreachedCode implements Deobfuscator List insCopy = new ArrayList<>(ins.getInstructions()); for (int j = 0; j < insCopy.size(); ++j) - //for (Instruction i : new ArrayList<>(ins.getInstructions())) { Instruction i = insCopy.get(j); 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 aed381fe40..f228de9490 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -59,6 +59,8 @@ public class MultiplicationDeobfuscator implements Deobfuscator private int runOnce() { + group.buildClassGraph(); + Execution e = new Execution(group); e.populateInitialMethods(); e.run(); 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 03f7d45f5d..dadd29970e 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java @@ -17,6 +17,8 @@ public class MultiplyOneDeobfuscator implements Deobfuscator @Override public void run(ClassGroup group) { + group.buildClassGraph(); + Execution e = new Execution(group); e.populateInitialMethods(); e.run(); @@ -61,7 +63,7 @@ public class MultiplyOneDeobfuscator implements Deobfuscator ++count; } - System.out.println("Removed " + count + " multiplications"); + System.out.println("Removed " + count + " 1 multiplications"); } } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java new file mode 100644 index 0000000000..1e7df51d45 --- /dev/null +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java @@ -0,0 +1,98 @@ +package net.runelite.deob.deobfuscators.arithmetic; + +import java.util.List; +import net.runelite.deob.ClassGroup; +import net.runelite.deob.Deobfuscator; +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.LDC_W; +import net.runelite.deob.execution.Execution; +import net.runelite.deob.execution.Frame; +import net.runelite.deob.execution.InstructionContext; +import net.runelite.deob.execution.StackContext; + +public class MultiplyZeroDeobfuscator implements Deobfuscator +{ + @Override + public void run(ClassGroup group) + { + group.buildClassGraph(); + + Execution e = new Execution(group); + e.populateInitialMethods(); + e.run(); + + int count = 0; + + for (Frame frame : e.processedFrames) + for (InstructionContext ictx : frame.getInstructions()) + { + 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; + + List ilist = ins.getInstructions(); + + StackContext one = ictx.getPops().get(0); + StackContext two = ictx.getPops().get(1); + + Instruction ione = one.getPushed().getInstruction(), + itwo = two.getPushed().getInstruction(); + + boolean remove = false; + if (ione instanceof PushConstantInstruction) + { + PushConstantInstruction pci = (PushConstantInstruction) ione; + int value = (int) pci.getConstant().getObject(); + + if (value == 0) + remove = true; + if (value == -1408052237) + { + int i = 5; + } + } + if (itwo instanceof PushConstantInstruction) + { + PushConstantInstruction pci = (PushConstantInstruction) itwo; + int value = (int) pci.getConstant().getObject(); + + if (value == 0) + remove = true; + if (value == -1408052237) + { + int i = 5; + } + } + + if (remove == false) + { + continue; + } + + if (!ilist.contains(instruction)) + continue; // already done + + // remove both, remove imul, push 0 + + ictx.removeStack(1); + ictx.removeStack(0); + + ins.replace(instruction, new LDC_W(ins, new net.runelite.deob.pool.Integer(0))); + + ++count; + } + + System.out.println("Removed " + count + " 0 multiplications"); + } +}