From 4aa8b23dfd3631b86092aae726e9d855bbe53881 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 1 Feb 2016 20:14:57 -0500 Subject: [PATCH] well this gets further --- .../deob/attributes/code/instructions/If.java | 1 + .../attributes/code/instructions/If0.java | 1 + .../code/instructions/InvokeInterface.java | 3 +- .../code/instructions/InvokeSpecial.java | 3 +- .../code/instructions/InvokeStatic.java | 3 +- .../code/instructions/LookupSwitch.java | 14 +++-- .../code/instructions/TableSwitch.java | 15 +++-- .../rename/MappingExecutorUtil.java | 19 ++++++- .../net/runelite/deob/execution/Frame.java | 14 ++++- .../execution/ParallellMappingExecutor.java | 55 ++++++++++++++++--- 10 files changed, 103 insertions(+), 25 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java index 8184596b3b..d0a1e2eb5b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If.java @@ -78,6 +78,7 @@ public abstract class If extends Instruction implements JumpingInstruction, Comp Frame other = frame.dup(); other.created = this; + other.forking = ins; other.jump(ins, to); ins.branch(other); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java index a7cdf417f9..8914b64969 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/If0.java @@ -79,6 +79,7 @@ public abstract class If0 extends Instruction implements JumpingInstruction, Com Frame other = frame.dup(); other.created = this; + other.forking = ins; other.jump(ins, to); ins.branch(other); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java index 5e92c88f1f..dcdb4a2115 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeInterface.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; +import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -181,6 +182,6 @@ public class InvokeInterface extends Instruction implements InvokeInstruction @Override public boolean canMap() { - return true; + return MappingExecutorUtil.isMappable(this); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java index 2942721269..cf1503e76e 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeSpecial.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; +import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -182,6 +183,6 @@ public class InvokeSpecial extends Instruction implements InvokeInstruction @Override public boolean canMap() { - return true; + return MappingExecutorUtil.isMappable(this); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java index ced225a714..52b23b3f44 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/InvokeStatic.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; import net.runelite.deob.attributes.code.instruction.types.MappableInstruction; +import net.runelite.deob.deobfuscators.rename.MappingExecutorUtil; import net.runelite.deob.deobfuscators.rename.ParallelExecutorMapping; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Value; @@ -184,6 +185,6 @@ public class InvokeStatic extends Instruction implements InvokeInstruction @Override public boolean canMap() { - return true; + return MappingExecutorUtil.isMappable(this); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java index a12769b0c6..77a40d5748 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LookupSwitch.java @@ -118,12 +118,16 @@ public class LookupSwitch extends Instruction implements JumpingInstruction StackContext value = stack.pop(); ins.pop(value); - for (Instruction i : branchi) + if (!frame.getExecution().step) { - Frame other = frame.dup(); - other.jump(ins, i); - - ins.branch(other); + for (Instruction i : branchi) + { + Frame other = frame.dup(); + other.forking = ins; + other.jump(ins, i); + + ins.branch(other); + } } frame.jump(ins, defi); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java b/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java index e753a3725b..7a2e62268a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/TableSwitch.java @@ -113,13 +113,16 @@ public class TableSwitch extends Instruction implements JumpingInstruction StackContext value = stack.pop(); ins.pop(value); - - for (Instruction i : branchi) + + if (!frame.getExecution().step) { - Frame other = frame.dup(); - other.jump(ins, i); - - ins.branch(other); + for (Instruction i : branchi) + { + Frame other = frame.dup(); + other.jump(ins, i); + + ins.branch(other); + } } frame.jump(ins, defi); diff --git a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java index aa1c5c3c6f..16e0436ffe 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java +++ b/src/main/java/net/runelite/deob/deobfuscators/rename/MappingExecutorUtil.java @@ -120,8 +120,23 @@ public class MappingExecutorUtil public static boolean isMappable(InvokeInstruction ii) { - net.runelite.deob.pool.Method m = (net.runelite.deob.pool.Method) ii.getMethod(); - String className = m.getClassEntry().getName(); + String className; + + if (ii.getMethod() instanceof net.runelite.deob.pool.Method) + { + net.runelite.deob.pool.Method m = (net.runelite.deob.pool.Method) ii.getMethod(); + className = m.getClassEntry().getName(); + } + else if (ii.getMethod() instanceof net.runelite.deob.pool.InterfaceMethod) + { + net.runelite.deob.pool.InterfaceMethod m = (net.runelite.deob.pool.InterfaceMethod) ii.getMethod(); + className = m.getClassEntry().getName(); + } + else + { + assert false; + return false; + } if (className.startsWith("java/") || className.startsWith("netscape/")) return false; diff --git a/src/main/java/net/runelite/deob/execution/Frame.java b/src/main/java/net/runelite/deob/execution/Frame.java index a70271101f..38596d5409 100644 --- a/src/main/java/net/runelite/deob/execution/Frame.java +++ b/src/main/java/net/runelite/deob/execution/Frame.java @@ -33,6 +33,9 @@ public class Frame public Frame returnTo; // is this the same as caller? public Frame otherStatic; public Instruction created; + public InstructionContext forking; + public boolean initial; + public boolean isdup,iscopy; public Frame(Execution execution, Method method) { @@ -57,7 +60,8 @@ public class Frame } public void initialize() - { + { + initial = true; // initialize LVT int pos = 0; if (!method.isStatic()) @@ -76,6 +80,7 @@ public class Frame public void initialize(InstructionContext ctx) { + created = ctx.getInstruction(); // initialize frame from invoking context assert ctx.getInstruction() instanceof InvokeInstruction; @@ -111,6 +116,7 @@ public class Frame protected Frame(Frame other) { + iscopy=true; this.execution = other.execution; this.method = other.method; this.executing = other.executing; @@ -121,12 +127,18 @@ public class Frame this.nonStatic = other.nonStatic; this.caller = other.caller; if (other.returnTo != null) + { this.returnTo = new Frame(other.returnTo); + this.returnTo.instructions.addAll(other.returnTo.instructions); + } + this.created = other.created; + this.forking = other.forking; } public Frame dup() { Frame other = new Frame(this); + other.isdup=true; execution.frames.add(other); return other; } diff --git a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java index 314c9db8fe..90fbe8b93b 100644 --- a/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java +++ b/src/main/java/net/runelite/deob/execution/ParallellMappingExecutor.java @@ -25,7 +25,7 @@ public class ParallellMappingExecutor ++count; - if (count == 685) + if (count == 18223) { int i = 5; } @@ -55,12 +55,36 @@ public class ParallellMappingExecutor assert f1.returnTo == null || !e.frames.contains(f1.returnTo); assert f2.returnTo == null || !e2.frames.contains(f2.returnTo); - // Due to jump ob one side can stop while the other side jumps - if (f1.getInstructions().size() > 0) + InstructionContext fork1 = f1.getInstructions().isEmpty() ? f1.forking : f1.getInstructions().get(f1.getInstructions().size() - 1); + InstructionContext fork2 = f2.getInstructions().isEmpty() ? f2.forking : f2.getInstructions().get(f2.getInstructions().size() - 1); + + assert fork1 != null; + assert fork2 != null; + + if (!(f1.getInstructions().isEmpty() == f2.getInstructions().isEmpty())) { - p1 = f1.getInstructions().get(f1.getInstructions().size() - 1); + int i = 5; + } + + // Due to jump ob one side can stop while the other side jumps + //if (f1.getInstructions().size() > 0) + if (fork1 == f1.forking) + { + assert fork1.getBranches().size() == 1; + //assert fork1.getBranches().get(0) == f1; + + int i1 = e.frames.indexOf(fork1.getFrame()); + int i2 = e.frames.indexOf(fork1.getBranches().get(0)); + + // remove fork1.frame + e.frames.remove(fork1.getFrame()); + //e.frames.remove(fork1.getBranches().get(0)); + } + else + { + //p1 = f1.getInstructions().get(f1.getInstructions().size() - 1); - for (Frame branch : p1.getBranches()) + for (Frame branch : fork1.getBranches()) { e.frames.remove(branch); } @@ -68,11 +92,23 @@ public class ParallellMappingExecutor // this is empty but should be removing a branch, because of the map other, theres no prev instruction. // should always populate prev instruction - if (f2.getInstructions().size() > 0) + //if (f2.getInstructions().size() > 0) + if (fork2 == f2.forking) { - p2 = f2.getInstructions().get(f2.getInstructions().size() - 1); + assert fork2.getBranches().size() == 1; + //assert fork2.getBranches().get(0) == f2; - for (Frame branch : p2.getBranches()) + int i1 = e2.frames.indexOf(fork2.getFrame()); + int i2 = e2.frames.indexOf(fork2.getBranches().get(0)); + + e2.frames.remove(fork2.getFrame()); + //e.frames.remove(fork2.getBranches().get(0)); + } + else + { + //p2 = f2.getInstructions().get(f2.getInstructions().size() - 1); + + for (Frame branch : fork2.getBranches()) { e2.frames.remove(branch); } @@ -267,6 +303,7 @@ public class ParallellMappingExecutor Method to = methods.get(0); Frame f2 = new Frame(e, to); + f2.created = is; f2.initialize(i); e.frames.remove(0); // old frame goes away @@ -280,6 +317,8 @@ public class ParallellMappingExecutor f.other = null; f2.returnTo = new Frame(f); // where to go when we're done + assert f.getInstructions().isEmpty() == false; + f2.returnTo.getInstructions().addAll(f.getInstructions()); return f2; }