From d61d006b34c106c2ed9265e83f7726ddc0e8b08d Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 30 Sep 2015 20:39:35 -0400 Subject: [PATCH] Fix some of the dup stuff, works a little better? --- .../attributes/code/instructions/Dup.java | 1 + .../MultiplicationDeobfuscator.java | 9 +++- .../arithmetic/MultiplicationExpression.java | 47 +++++++++++++++---- 3 files changed, 45 insertions(+), 12 deletions(-) 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 5b98e3419b..2a984d6a44 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 @@ -65,6 +65,7 @@ public class Dup extends Instruction implements DupInstruction // ctx = stack pushed by this instruction, return stack popped by this instruction InstructionContext ctx = sctx.getPushed(); assert ctx.getInstruction() == this; + assert ctx.getPushes().contains(sctx); return ctx.getPops().get(0); } 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 55cb4cd775..e334bab948 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -120,7 +120,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator } else if (i.getInstruction() instanceof DupInstruction) { - if(true) throw new IllegalStateException(); + //if(true) throw new IllegalStateException(); DupInstruction dup = (DupInstruction) i.getInstruction(); //if (dup instanceof Dup || dup instanceof Dup_X1) @@ -144,7 +144,12 @@ public class MultiplicationDeobfuscator implements Deobfuscator try { MultiplicationExpression other = parseExpression(orig.getPushed()); - me.subexpressions.add(other); + // this expression is used elsewhere like 'pushConstant' so any changes + // done to it affect that, too. so multiply it by existing values? + me.instructions.addAll(other.instructions); + me.dupedInstructions.addAll(other.instructions); + me.subexpressions.addAll(other.subexpressions); + //me.subexpressions.add(other); } catch (IllegalStateException ex) { diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java index 9896b7e0c3..6ee8e16dbe 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java @@ -8,7 +8,8 @@ import net.runelite.deob.execution.InstructionContext; public class MultiplicationExpression { - List instructions = new ArrayList<>(); // push constant instructions that are being multiplied + List instructions = new ArrayList<>(), // push constant instructions that are being multiplied + dupedInstructions = new ArrayList<>(); List subexpressions = new ArrayList<>(); // for distributing, each subexpr is * by this InstructionContext dupmagic; // inverse of what is distributed to subexpressions gets set here static boolean replace; @@ -27,23 +28,49 @@ public class MultiplicationExpression result *= value; } + // assert (dupmagic != null) == !dupedInstructions.isEmpty(); + if (dupmagic != null) + { + // mul dupmagic by result of dup ins? + + PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction(); + int value = (int) pci.getConstant().getObject(); + + for (InstructionContext ic : dupedInstructions) + { + PushConstantInstruction pci2 = (PushConstantInstruction) ic.getInstruction(); + int value2 = (int) pci2.getConstant().getObject(); + + value *= value2; + } + + Instruction newIns = pci.setConstant(new net.runelite.deob.pool.Integer(value)); + System.out.println("dupmagic"); + assert newIns == (Instruction) pci; + } + // multiply subexpressions by result if (!subexpressions.isEmpty()) { for (MultiplicationExpression me : subexpressions) { +// if (me.instructions.isEmpty() && this.dupmagic != null) +// { +// assert me.dupmagic == null; +// me.dupmagic = this.dupmagic; +// } count += me.simplify(result); } - if (dupmagic != null) - { - PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction(); - int value = (int) pci.getConstant().getObject(); - - value *= DMath.modInverse(result); - - pci.setConstant(new net.runelite.deob.pool.Integer(value)); - } +// if (dupmagic != null) +// { +// PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction(); +// int value = (int) pci.getConstant().getObject(); +// +// value *= DMath.modInverse(result); +// +// pci.setConstant(new net.runelite.deob.pool.Integer(value)); +// } result = 1; // constant has been distributed, outer numbers all go to 1 }