From 2cfba32e287dadd43675350e14552bf616bbde8a Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 9 Sep 2015 21:24:37 -0400 Subject: [PATCH] class172.java: this.field2982 = ((1 * this.field2963 & -65536) + this.field2982 * 1) * -402105799; not working. --- .../attributes/code/instructions/IMul.java | 6 + .../attributes/code/instructions/ISub.java | 47 ++++++++ .../deobfuscators/arithmetic/ModArith.java | 108 +++++++++--------- 3 files changed, 107 insertions(+), 54 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java index 61955fb267..4e3028d8c9 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java @@ -31,6 +31,7 @@ public class IMul extends Instruction ins.pop(one, two); Encryption encryption = frame.getExecution().getEncryption(); + int encKey = 0; if (encryption != null) { if (one.encryption != 0) @@ -52,9 +53,12 @@ public class IMul extends Instruction // { // System.out.println("decrr"); // } + encKey = one.encryption; } else if (two.encryption != 0) { + assert one.encryption == 0; + PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); int other = (int) pci.getConstant().getObject(); @@ -64,10 +68,12 @@ public class IMul extends Instruction encryption.change(pci, o); } + encKey = two.encryption; } } StackContext ctx = new StackContext(ins, int.class); + ctx.encryption = encKey; stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java b/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java index 2b8519d509..1ad181a86c 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/ISub.java @@ -3,6 +3,8 @@ 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.Encryption; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.Stack; @@ -26,7 +28,52 @@ public class ISub 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); diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java index d4826a987a..1c777c0911 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java @@ -210,60 +210,60 @@ public class ModArith implements Deobfuscator // } } - private List getFieldsInExpression(InstructionContext ctx, List constants) - { - return check(ctx, new HashSet(), constants); - } - - private List check(InstructionContext context, Set visited, List constants) - { - List fields = new ArrayList<>(); - - if (visited.contains(context)) - return fields; - - visited.add(context); - - if (context.getInstruction() instanceof InvokeInstruction) - { - // field = func(field * constant), the output of the function isn't directly related to the result of field * constant - return fields; - } - - if (context.getInstruction() instanceof FieldInstruction) - { - FieldInstruction fi = (FieldInstruction) context.getInstruction(); - Field myf = fi.getMyField(); - if (myf != null) - fields.add(myf); - } - - if (context.getInstruction() instanceof PushConstantInstruction) - { - PushConstantInstruction pci = (PushConstantInstruction) context.getInstruction(); - int i = (int) pci.getConstant().getObject(); - constants.add(i); - } - - for (StackContext ctx : context.getPops()) - { - InstructionContext i = ctx.getPushed(); - - fields.addAll(check(i, visited, constants)); - } - - for (StackContext ctx : context.getPushes()) - { - InstructionContext i = ctx.getPopped(); - - if (i == null) - continue; - - fields.addAll(check(i, visited, constants)); - } - - return fields; - } +// private List getFieldsInExpression(InstructionContext ctx, List constants) +// { +// return check(ctx, new HashSet(), constants); +// } +// +// private List check(InstructionContext context, Set visited, List constants) +// { +// List fields = new ArrayList<>(); +// +// if (visited.contains(context)) +// return fields; +// +// visited.add(context); +// +// if (context.getInstruction() instanceof InvokeInstruction) +// { +// // field = func(field * constant), the output of the function isn't directly related to the result of field * constant +// return fields; +// } +// +// if (context.getInstruction() instanceof FieldInstruction) +// { +// FieldInstruction fi = (FieldInstruction) context.getInstruction(); +// Field myf = fi.getMyField(); +// if (myf != null) +// fields.add(myf); +// } +// +// if (context.getInstruction() instanceof PushConstantInstruction) +// { +// PushConstantInstruction pci = (PushConstantInstruction) context.getInstruction(); +// int i = (int) pci.getConstant().getObject(); +// constants.add(i); +// } +// +// for (StackContext ctx : context.getPops()) +// { +// InstructionContext i = ctx.getPushed(); +// +// fields.addAll(check(i, visited, constants)); +// } +// +// for (StackContext ctx : context.getPushes()) +// { +// InstructionContext i = ctx.getPopped(); +// +// if (i == null) +// continue; +// +// fields.addAll(check(i, visited, constants)); +// } +// +// return fields; +// } @Override public void run(ClassGroup group)