From 7336c49d215bb6d755823ca7cc482d874829c711 Mon Sep 17 00:00:00 2001 From: Adam Date: Fri, 8 Apr 2016 12:59:07 -0400 Subject: [PATCH] Need to compare this to master. --- .../net/runelite/asm/execution/Execution.java | 15 +++++- .../net/runelite/asm/execution/Frame.java | 4 +- .../runelite/asm/execution/MethodContext.java | 15 +++++- .../MultiplicationDeobfuscatorTest.java | 49 ++++++++++++++++++- 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/src/main/java/net/runelite/asm/execution/Execution.java b/src/main/java/net/runelite/asm/execution/Execution.java index 23d6164bf9..a52c8e175d 100644 --- a/src/main/java/net/runelite/asm/execution/Execution.java +++ b/src/main/java/net/runelite/asm/execution/Execution.java @@ -6,6 +6,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Set; +import java.util.stream.Collectors; import net.runelite.asm.ClassFile; import net.runelite.asm.ClassGroup; import net.runelite.deob.Deob; @@ -136,9 +137,19 @@ public class Execution if (frames.isEmpty()) { + assert frame.getMethod() == frame.getMethodCtx().getMethod(); + accept(frame.getMethodCtx()); - frames.addAll(framesOther); - framesOther.clear(); + + if (framesOther.isEmpty()) + break; + + Frame begin = framesOther.remove(0); + frames.add(begin); + + List toMove = framesOther.stream().filter(f -> f.getMethod() == begin.getMethod()).collect(Collectors.toList()); + frames.addAll(toMove); + framesOther.removeAll(toMove); } } diff --git a/src/main/java/net/runelite/asm/execution/Frame.java b/src/main/java/net/runelite/asm/execution/Frame.java index e5e3b0f7ee..1a634e680d 100644 --- a/src/main/java/net/runelite/asm/execution/Frame.java +++ b/src/main/java/net/runelite/asm/execution/Frame.java @@ -38,7 +38,7 @@ public class Frame stack = new Stack(code.getMaxStack()); variables = new Variables(code.getMaxLocals()); - ctx = new MethodContext(execution); + ctx = new MethodContext(execution, method); nonStatic = method; } @@ -52,7 +52,7 @@ public class Frame stack = new Stack(code.getMaxStack()); variables = new Variables(code.getMaxLocals()); - ctx = new MethodContext(execution); + ctx = new MethodContext(execution, method); nonStatic = method; cur = i; diff --git a/src/main/java/net/runelite/asm/execution/MethodContext.java b/src/main/java/net/runelite/asm/execution/MethodContext.java index f181effcac..02ac5e60ba 100644 --- a/src/main/java/net/runelite/asm/execution/MethodContext.java +++ b/src/main/java/net/runelite/asm/execution/MethodContext.java @@ -1,18 +1,31 @@ package net.runelite.asm.execution; import java.util.Collection; +import net.runelite.asm.Method; import net.runelite.asm.attributes.code.Instruction; import org.apache.commons.collections4.map.MultiValueMap; public class MethodContext { private Execution execution; + private Method method; private MultiValueMap visited = new MultiValueMap<>(); public MultiValueMap contexts = new MultiValueMap<>(); // XXX this should move to method ctx probably - public MethodContext(Execution execution) + public MethodContext(Execution execution, Method method) { this.execution = execution; + this.method = method; + } + + public Execution getExecution() + { + return execution; + } + + public Method getMethod() + { + return method; } protected boolean hasJumped(InstructionContext from, Instruction to) diff --git a/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscatorTest.java b/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscatorTest.java index eaf9a50750..8974d23c3a 100644 --- a/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscatorTest.java +++ b/src/test/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscatorTest.java @@ -472,8 +472,6 @@ public class MultiplicationDeobfuscatorTest { ClassGroup group = ClassGroupFactory.generateGroup(); Code code = group.findClass("test").findMethod("func").getCode(); - Code code2 = group.findClass("test").findMethod("func2").getCode(); - Field field = group.findClass("test").findField("field"); Instructions ins = code.getInstructions(); code.setMaxStack(2); @@ -607,4 +605,51 @@ public class MultiplicationDeobfuscatorTest Assert.assertEquals(1L, constant2.getConstantAsLong()); Assert.assertEquals(1L, constant3.getConstantAsLong()); } + + @Test + public void test10() + { + ClassGroup group = ClassGroupFactory.generateGroup(); + Code code = group.findClass("test").findMethod("func").getCode(); + Instructions ins = code.getInstructions(); + + code.setMaxStack(5); + + // vars[0] = 3 + Instruction[] prepareVariables = { + new IConst_3(ins), + new IStore_0(ins) + }; + + for (Instruction i : prepareVariables) + ins.addInstruction(i); + + LDC_W constant1 = new LDC_W(ins, -1729723287), + constant2 = new LDC_W(ins, -143176743); + + Instruction body[] = { + new ILoad(ins, 0), + constant1, + new IMul(ins), + constant2, + 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(); + + assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1; + + Deobfuscator d = new MultiplicationDeobfuscator(); + d.run(group); + + Assert.assertEquals(1, constant1.getConstantAsInt()); + Assert.assertEquals(1, constant2.getConstantAsInt()); + } }