From d43dc0451997c27457f8b5e23b85eee1ad2d1b13 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 27 Sep 2015 21:26:05 -0400 Subject: [PATCH] something is wrong somewhere but I don't see anything --- .../instruction/types/DupInstruction.java | 2 +- .../attributes/code/instructions/Dup.java | 2 +- .../attributes/code/instructions/Dup2.java | 2 +- .../attributes/code/instructions/Dup2_X1.java | 2 +- .../attributes/code/instructions/Dup2_X2.java | 2 +- .../attributes/code/instructions/Dup_X1.java | 2 +- .../attributes/code/instructions/Dup_X2.java | 43 +++++++++++++++++-- .../MultiplicationDeobfuscator.java | 8 ++-- 8 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instruction/types/DupInstruction.java b/src/main/java/net/runelite/deob/attributes/code/instruction/types/DupInstruction.java index 4b3adb6d80..b9fd1a5c83 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instruction/types/DupInstruction.java +++ b/src/main/java/net/runelite/deob/attributes/code/instruction/types/DupInstruction.java @@ -4,7 +4,7 @@ import net.runelite.deob.execution.StackContext; public interface DupInstruction { - public StackContext resolve(StackContext sctx); + public StackContext getOriginal(StackContext sctx); public StackContext getOtherBranch(StackContext sctx); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java index 5a4cc85d6f..5b98e3419b 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup.java @@ -60,7 +60,7 @@ public class Dup extends Instruction implements DupInstruction } @Override - public StackContext resolve(StackContext sctx) + public StackContext getOriginal(StackContext sctx) { // ctx = stack pushed by this instruction, return stack popped by this instruction InstructionContext ctx = sctx.getPushed(); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java index d34b9abdda..f7237716d1 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2.java @@ -73,7 +73,7 @@ public class Dup2 extends Instruction implements DupInstruction } @Override - public StackContext resolve(StackContext ctx) + public StackContext getOriginal(StackContext ctx) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java index 3173636251..30672b0374 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java @@ -81,7 +81,7 @@ public class Dup2_X1 extends Instruction implements DupInstruction } @Override - public StackContext resolve(StackContext ctx) + public StackContext getOriginal(StackContext ctx) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java index 2bca24412f..ffa13fecc7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java @@ -95,7 +95,7 @@ public class Dup2_X2 extends Instruction implements DupInstruction } @Override - public StackContext resolve(StackContext ctx) + public StackContext getOriginal(StackContext ctx) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java index dca4875579..7c26c66d76 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X1.java @@ -56,7 +56,7 @@ public class Dup_X1 extends Instruction implements DupInstruction } @Override - public StackContext resolve(StackContext sctx) + public StackContext getOriginal(StackContext sctx) { // ctx = stack pushed by this instruction, return stack popped by this instruction InstructionContext ctx = sctx.getPushed(); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java index 623760fad3..df3c12f98a 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java @@ -71,14 +71,51 @@ public class Dup_X2 extends Instruction implements DupInstruction } @Override - public StackContext resolve(StackContext ctx) + public StackContext getOriginal(StackContext sctx) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + // 3 2 1 -> 1 3 2 1 + InstructionContext ctx = sctx.getPushed(); + assert ctx.getInstruction() == this; + + assert ctx.getPushes().contains(sctx); + int pushedIndex = ctx.getPushes().indexOf(sctx); + int poppedIndex; + + switch (pushedIndex) + { + case 0: + case 3: + poppedIndex = 0; + break; + case 1: + poppedIndex = 2; + break; + case 2: + poppedIndex = 1; + default: + throw new IllegalStateException(); + } + + return ctx.getPops().get(poppedIndex); } @Override public StackContext getOtherBranch(StackContext sctx) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + // sctx = stack pushed by this instruction, return the other branch + InstructionContext ctx = sctx.getPushed(); + assert ctx.getInstruction() == this; + + assert ctx.getPushes().contains(sctx); + int pushedIndex = ctx.getPushes().indexOf(sctx); + + // 3 2 1 -> 1 3 2 1 + + if (pushedIndex == 0) + return ctx.getPushes().get(3); + else if (pushedIndex == 3) + return ctx.getPushes().get(0); + + return null; } } 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 5878c505f3..55cb4cd775 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -120,9 +120,10 @@ public class MultiplicationDeobfuscator implements Deobfuscator } else if (i.getInstruction() instanceof DupInstruction) { + if(true) throw new IllegalStateException(); DupInstruction dup = (DupInstruction) i.getInstruction(); - if (dup instanceof Dup || dup instanceof Dup_X1) + //if (dup instanceof Dup || dup instanceof Dup_X1) { // find other branch of the dup instruction @@ -139,7 +140,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator me.dupmagic = pushConstant; - StackContext orig = dup.resolve(sctx); // original + StackContext orig = dup.getOriginal(sctx); // original try { MultiplicationExpression other = parseExpression(orig.getPushed()); @@ -152,7 +153,8 @@ public class MultiplicationDeobfuscator implements Deobfuscator } else { - System.out.println("dup ins " + i); + System.out.println("dup ins " + otherCtxI.getInstruction()); + throw new IllegalStateException(); } } }