From 9404e1d9afe7758e02f181ffd194bac3af82977f Mon Sep 17 00:00:00 2001 From: Adam Date: Tue, 8 Sep 2015 20:45:57 -0400 Subject: [PATCH] Carry encryption over in iadd and dup x1, this needs to be handled a better way. --- .../attributes/code/instructions/Dup_X1.java | 3 ++ .../attributes/code/instructions/IAdd.java | 48 +++++++++++++++++++ 2 files changed, 51 insertions(+) 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 173f138e5b..defb3440de 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 @@ -29,16 +29,19 @@ public class Dup_X1 extends Instruction ins.pop(one, two); StackContext ctx = new StackContext(ins, one.getType()); + ctx.encryption = one.encryption; stack.push(ctx); ins.push(ctx); ctx = new StackContext(ins, two.getType()); + ctx.encryption = two.encryption; stack.push(ctx); ins.push(ctx); ctx = new StackContext(ins, one.getType()); + ctx.encryption = one.encryption; stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java index 286ff4e5c3..960d709e74 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IAdd.java @@ -3,6 +3,9 @@ package net.runelite.deob.attributes.code.instructions; import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.InstructionType; import net.runelite.deob.attributes.code.Instructions; +import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; +import net.runelite.deob.deobfuscators.arithmetic.DMath; +import net.runelite.deob.deobfuscators.arithmetic.Encryption; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; @@ -26,7 +29,52 @@ public class IAdd extends Instruction ins.pop(two, one); + Encryption encryption = frame.getExecution().getEncryption(); + int encKey = 0; + if (encryption != null) + { + if (one.encryption != 0) + { + assert two.encryption == 0; + + if (two.getPushed().getInstruction() instanceof PushConstantInstruction) + { + PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction(); + int value = (int) pci.getConstant().getObject(); + + if (value != 0 && value != 1) + { + int o = value * one.encryption; + + encryption.change(pci, o); + } + } + + encKey = one.encryption; + } + else if (two.encryption != 0) + { + assert one.encryption == 0; + + if (one.getPushed().getInstruction() instanceof PushConstantInstruction) + { + PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); + int value = (int) pci.getConstant().getObject(); + + if (value != 0 && value != 1) + { + int o = value * two.encryption; + + encryption.change(pci, o); + } + } + + encKey = two.encryption; + } + } + StackContext ctx = new StackContext(ins, int.class); + ctx.encryption = encKey; stack.push(ctx); ins.push(ctx);