From ae8544cea1608f2ba2c5a36340ef54f4ea7f3d90 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 25 Sep 2015 11:23:20 -0400 Subject: [PATCH] beginning work on removing *1 --- src/main/java/net/runelite/deob/Deob.java | 12 ++-- .../MultiplicationDeobfuscator.java | 27 -------- .../arithmetic/MultiplyOneDeobfuscator.java | 67 +++++++++++++++++++ 3 files changed, 71 insertions(+), 35 deletions(-) create mode 100644 src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index 226e008c05..ffb367d10e 100644 --- a/src/main/java/net/runelite/deob/Deob.java +++ b/src/main/java/net/runelite/deob/Deob.java @@ -27,15 +27,9 @@ import net.runelite.deob.deobfuscators.UnusedMethods; 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.execution.Execution; -//move static methods -//move static fields -//math deob -//remove dead classes -//inline constant fields -//compare old and new - public class Deob { public static void main(String[] args) throws IOException @@ -89,7 +83,9 @@ public class Deob //new ModArith().run(group); - new MultiplicationDeobfuscator().run(group); + //new MultiplicationDeobfuscator().run(group); + + new MultiplyOneDeobfuscator().run(group); saveJar(group, args[1]); 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 09823f35b8..aed381fe40 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -115,33 +115,6 @@ public class MultiplicationDeobfuscator implements Deobfuscator for (InstructionContext i : ins) done.add(i.getInstruction()); - -// Instructions ins = ictx.getInstruction().getInstructions(); -// List ilist = ins.getInstructions(); -// -// if (!ilist.contains(ictx.getInstruction())) -// continue; // already done -// -// StackContext one = ictx.getPops().get(0); -// StackContext two = ictx.getPops().get(1); -// -// if (one.getPushed().getInstruction() instanceof PushConstantInstruction -// && two.getPushed().getInstruction() instanceof PushConstantInstruction) -// { -// PushConstantInstruction pci1 = (PushConstantInstruction) one.getPushed().getInstruction(), -// pci2 = (PushConstantInstruction) two.getPushed().getInstruction(); -// -// int i1 = (int) pci1.getConstant().getObject(), -// i2 = (int) pci2.getConstant().getObject(); -// -// int result = i1 * i2; -// -// ictx.removeStack(1); -// ictx.removeStack(0); -// -// ins.replace(ictx.getInstruction(), new LDC_W(ins, new net.runelite.deob.pool.Integer(result))); -// ++count; -// } } return count; diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java new file mode 100644 index 0000000000..03f7d45f5d --- /dev/null +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java @@ -0,0 +1,67 @@ +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.execution.Execution; +import net.runelite.deob.execution.Frame; +import net.runelite.deob.execution.InstructionContext; +import net.runelite.deob.execution.StackContext; + +public class MultiplyOneDeobfuscator implements Deobfuscator +{ + @Override + public void run(ClassGroup group) + { + 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(); + + if (!(instruction instanceof IMul)) + continue; + + Instructions ins = ictx.getInstruction().getInstructions(); + List ilist = ins.getInstructions(); + + if (!ilist.contains(ictx.getInstruction())) + continue; // already done + + StackContext one = ictx.getPops().get(0); + StackContext two = ictx.getPops().get(1); + + int removeIdx = -1; + if (one.getPushed().getInstruction() instanceof PushConstantInstruction + && (int) ((PushConstantInstruction) one.getPushed().getInstruction()).getConstant().getObject() == 1) + { + removeIdx = 0; + } + else if (two.getPushed().getInstruction() instanceof PushConstantInstruction + && (int) ((PushConstantInstruction) two.getPushed().getInstruction()).getConstant().getObject() == 1) + { + removeIdx = 1; + } + + if (removeIdx == -1) + continue; + + ictx.removeStack(removeIdx); + ins.remove(ictx.getInstruction()); + + ++count; + } + + System.out.println("Removed " + count + " multiplications"); + } + +}