From 5f6b01f4a057daf56a4e6f102aaf7d86ce693311 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 22 Oct 2015 11:01:43 -0400 Subject: [PATCH] 1/0 works once again, maybe. --- src/main/java/net/runelite/deob/Deob.java | 4 +- .../arithmetic/MultiplyOneDeobfuscator.java | 9 +++ .../arithmetic/MultiplyZeroDeobfuscator.java | 5 ++ .../MultiplyOneDeobfuscatorTest.java | 56 ++++++++++++++++++- 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/src/main/java/net/runelite/deob/Deob.java b/src/main/java/net/runelite/deob/Deob.java index 7a67964af2..9449813a8f 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/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java index f4bd559d39..eb159a8345 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java @@ -1,6 +1,9 @@ package net.runelite.deob.deobfuscators.arithmetic; +import java.util.Collection; +import java.util.HashSet; import java.util.List; +import java.util.Set; import net.runelite.deob.ClassGroup; import net.runelite.deob.Deobfuscator; import net.runelite.deob.attributes.code.Instruction; @@ -35,6 +38,9 @@ public class MultiplyOneDeobfuscator implements Deobfuscator continue; Instructions ins = ictx.getInstruction().getInstructions(); + if (ins == null) + continue; + List ilist = ins.getInstructions(); if (!ilist.contains(ictx.getInstruction())) @@ -58,6 +64,9 @@ public class MultiplyOneDeobfuscator implements Deobfuscator if (removeIdx == -1) continue; + if (!MultiplicationDeobfuscator.isOnlyPath(e, ictx)) + continue; + ictx.removeStack(removeIdx); ins.replace(ictx.getInstruction(), new NOP(ins)); //ins.remove(ictx.getInstruction()); 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 916640c935..29f8b784ed 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java @@ -31,6 +31,8 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator { Instruction instruction = ictx.getInstruction(); Instructions ins = instruction.getInstructions(); + if (ins == null) + continue; if (!(instruction instanceof IMul)) continue; @@ -69,6 +71,9 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator if (!ilist.contains(instruction)) continue; // already done + if (!MultiplicationDeobfuscator.isOnlyPath(e, ictx)) + continue; + // remove both, remove imul, push 0 ictx.removeStack(1); diff --git a/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java b/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java index 16c72acd1b..7658ebad30 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscatorTest.java @@ -24,7 +24,7 @@ import org.junit.Test; public class MultiplyOneDeobfuscatorTest { @Test - public void test() + public void testDir() { ClassGroup group = ClassGroupFactory.generateGroup(); Code code = group.findClass("test").findMethod("func").getCode(); @@ -77,4 +77,58 @@ public class MultiplyOneDeobfuscatorTest Assert.assertTrue(one.getInstructions() != null); } + + @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); + IMul mul = new IMul(ins); + + Instruction body[] = { + new SiPush(ins, (short) 256), + + new ILoad(ins, 0), + new If0(ins, label), + + label, + one, + + label2, + mul, + + 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); + Assert.assertTrue(mul.getInstructions() == null); + } }