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 2a984d6a44..f24a9803c9 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 @@ -28,13 +28,11 @@ public class Dup extends Instruction implements DupInstruction ins.pop(obj); StackContext ctx = new StackContext(ins, obj.getType()); - ctx.encryption = obj.encryption; stack.push(ctx); ins.push(ctx); ctx = new StackContext(ins, obj.getType()); - ctx.encryption = obj.encryption; stack.push(ctx); ins.push(ctx); 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 f7237716d1..348e361a30 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 @@ -36,14 +36,12 @@ public class Dup2 extends Instruction implements DupInstruction if (two != null) { StackContext ctx = new StackContext(ins, two.getType()); - ctx.encryption = two.encryption; stack.push(ctx); ins.push(ctx); } StackContext ctx = new StackContext(ins, one.getType()); - ctx.encryption = one.encryption; stack.push(one); ins.push(ctx); @@ -51,14 +49,12 @@ public class Dup2 extends Instruction implements DupInstruction if (two != null) { 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(one); ins.push(ctx); 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 30672b0374..0f0f13afc7 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 @@ -38,20 +38,17 @@ public class Dup2_X1 extends Instruction implements DupInstruction if (two != null) { StackContext ctx = new StackContext(ins, two.getType()); - ctx.encryption = two.encryption; stack.push(ctx); ins.push(ctx); } StackContext ctx = new StackContext(ins, one.getType()); - ctx.encryption = one.encryption; stack.push(ctx); ins.push(ctx); ctx = new StackContext(ins, three.getType()); - ctx.encryption = three.encryption; stack.push(ctx); ins.push(ctx); @@ -59,14 +56,12 @@ public class Dup2_X1 extends Instruction implements DupInstruction if (two != null) { 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/Dup2_X2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X2.java index ffa13fecc7..e4ca17c5ef 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 @@ -43,14 +43,12 @@ public class Dup2_X2 extends Instruction implements DupInstruction if (two != null) { StackContext ctx = new StackContext(ins, two.getType()); - ctx.encryption = two.encryption; stack.push(ctx); ins.push(ctx); } StackContext ctx = new StackContext(ins, one.getType()); - ctx.encryption = one.encryption; stack.push(one); ins.push(ctx); @@ -58,14 +56,12 @@ public class Dup2_X2 extends Instruction implements DupInstruction if (four != null) { ctx = new StackContext(ins, four.getType()); - ctx.encryption = four.encryption; stack.push(ctx); ins.push(ctx); } ctx = new StackContext(ins, three.getType()); - ctx.encryption = three.encryption; stack.push(one); ins.push(ctx); @@ -73,14 +69,12 @@ public class Dup2_X2 extends Instruction implements DupInstruction if (two != null) { 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(one); ins.push(ctx); 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 41a82e5ac3..4e0ce8ded2 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 @@ -34,19 +34,16 @@ public class Dup_X1 extends Instruction implements DupInstruction 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/Dup_X2.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup_X2.java index df3c12f98a..8c300c0c74 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 @@ -35,7 +35,6 @@ public class Dup_X2 extends Instruction implements DupInstruction ins.pop(three); StackContext ctx = new StackContext(ins, one.getType()); - ctx.encryption = one.encryption; stack.push(ctx); ins.push(ctx); @@ -43,20 +42,17 @@ public class Dup_X2 extends Instruction implements DupInstruction if (three != null) { ctx = new StackContext(ins, three.getType()); - ctx.encryption = three.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/GetField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java index 9cc68e0150..318645a9ad 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GetField.java @@ -53,18 +53,6 @@ public class GetField extends Instruction implements GetFieldInstruction ins.pop(object); StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType()); - - Encryption encryption = frame.getExecution().getEncryption(); - net.runelite.deob.Field f = getMyField(); - if (encryption != null && f != null) - { - Pair pair = encryption.getField(f); - if (pair != null) - { - ctx.encryption = pair.getter; - } - } - stack.push(ctx); ins.push(ctx); diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java index fcc8bde040..3cd81d4496 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/GetStatic.java @@ -49,19 +49,7 @@ public class GetStatic extends Instruction implements GetFieldInstruction InstructionContext ins = new InstructionContext(this, frame); Stack stack = frame.getStack(); - StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType()); - - Encryption encryption = frame.getExecution().getEncryption(); - net.runelite.deob.Field f = getMyField(); - if (f != null && encryption != null) - { - Pair pair = encryption.getField(f); - if (pair != null) - { - ctx.encryption = pair.getter; - } - } - + StackContext ctx = new StackContext(ins, new Type(field.getNameAndType().getDescriptorType()).toStackType()); 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 25e6501ac5..053a76de47 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 @@ -34,55 +34,7 @@ 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, false); - } - // field is no longer encrypted - encKey = 1; - } - //else - // 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, false); - } - encKey = 1; - } - - //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/IMul.java b/src/main/java/net/runelite/deob/attributes/code/instructions/IMul.java index d9c347ca83..73e6f27e58 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 @@ -35,47 +35,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) - { - assert two.encryption == 0; - PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction(); - int other = (int) pci.getConstant().getObject(); - - // 'one' is encrypted and we want to decrypt it by dividing by one.encryption - - if (other != 0) - { - int o = other * DMath.modInverse(one.encryption); - - encryption.change(pci, o, false); - } - - encKey = 1; - } - else if (two.encryption != 0) - { - assert one.encryption == 0; - - PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); - int other = (int) pci.getConstant().getObject(); - - if (other != 0) - { - int o = other * DMath.modInverse(two.encryption); - - encryption.change(pci, o, false); - } - - encKey = 1; - } - } - 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 a1c1b448f9..c1e2b73ceb 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 @@ -28,54 +28,7 @@ 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, false); - } - encKey = 1; - } - - // 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, false); - } - encKey = 1; - } - - //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/PutField.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java index 99cc4246e2..1b4664e3d5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutField.java @@ -52,88 +52,6 @@ public class PutField extends Instruction implements SetFieldInstruction StackContext object = stack.pop(); ins.pop(value, object); - Encryption encryption = frame.getExecution().getEncryption(); - net.runelite.deob.Field myField = getMyField(); - if (encryption != null && myField != null) - { - Pair pair = encryption.getField(myField); - //if (pair != null) - // translate(encryption, pair, ins, new HashSet()); -// XXX move translate() here -// InstructionContext ctx = value.getPushed(); -// if (ctx.getInstruction() instanceof IAdd && pair != null) -// { -// // field += constant * crap; -// // in bytecode is really -// // field = field + constant * crap -// -// List pops = ctx.getPops(); -// -// if (pops.get(0).getPushed().getInstruction() instanceof IMul) -// { -// ctx = pops.get(0).getPushed(); -// } -// else if (pops.get(1).getPushed().getInstruction() instanceof IMul) -// { -// ctx = pops.get(1).getPushed(); -// } -// } -// if (ctx.getInstruction() instanceof PushConstantInstruction && pair != null) -// { -// // field = encryptedvalue -// // decrypt value by * getter -// -// PushConstantInstruction pci = (PushConstantInstruction) ctx.getInstruction(); -// int v = (int) pci.getConstant().getObject(); -// -// if (v != 0 && v != 1) -// { -// v = v * pair.getter; -// -// encryption.change(pci, v); -// } -// } -// if (ctx.getInstruction() instanceof ISub) -// { -// List stackCtx = ctx.getPops(); -// -// StackContext one = stackCtx.get(0), two = stackCtx.get(1); -// -// if (one.getPushed().getInstruction() instanceof IMul) -// { -// ctx = one.getPushed(); -// } -// else if (two.getPushed().getInstruction() instanceof IMul) -// { -// ctx = two.getPushed(); -// } -// } -// if (ctx.getInstruction() instanceof IMul && pair != null) -// { -// List stackCtx = ctx.getPops(); -// -// StackContext one = stackCtx.get(0), two = stackCtx.get(1); -// -// StackContext magicStack = PutStatic.findMagic(one, two); -// -// if (magicStack != null) -// { -// PushConstantInstruction pci = (PushConstantInstruction) magicStack.getPushed().getInstruction(); -// int v = (int) pci.getConstant().getObject(); -// -// // field is encrypted with pair -// // divide value by setter -// -// if (v != 0 && v != 1) -// { -// v = v * pair.getter; -// -// encryption.change(pci, v); -// } -// } -// } - } - frame.addInstructionContext(ins); } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java index 3b6a7aab36..ce1d31b2f7 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/PutStatic.java @@ -16,12 +16,6 @@ import net.runelite.deob.pool.NameAndType; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; -import java.util.Set; -import net.runelite.deob.attributes.code.instruction.types.DupInstruction; -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.deobfuscators.arithmetic.Pair; public class PutStatic extends Instruction implements SetFieldInstruction { @@ -45,122 +39,6 @@ public class PutStatic extends Instruction implements SetFieldInstruction super.write(out); out.writeShort(this.getPool().make(field)); } - - protected static StackContext findMagic(StackContext one, StackContext two) - { - if (one.getPushed().getInstruction() instanceof PushConstantInstruction) - { - PushConstantInstruction pci = (PushConstantInstruction) one.getPushed().getInstruction(); - int value1 = (int) pci.getConstant().getObject(); - - if (DMath.isBig(value1)) - { - return one; - } - } - - if (two.getPushed().getInstruction() instanceof PushConstantInstruction) - { - PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction(); - int value2 = (int) pci.getConstant().getObject(); - - if (DMath.isBig(value2)) - { - return two; - } - } - - return null; - } - - public static boolean translate(Encryption encryption, Pair pair, InstructionContext ctx, Set visited) - { - if (visited.contains(ctx.getInstruction())) - return true; - - visited.add(ctx.getInstruction()); - - if (ctx.getInstruction() instanceof PushConstantInstruction) - { - PushConstantInstruction pci = (PushConstantInstruction) ctx.getInstruction(); - - if (pci.getConstant().getObject() instanceof Integer) - { - int value = (int) pci.getConstant().getObject(); - - if (encryption.hasChange(pci)) - return true; - - if (value != 0) - { - value = value * pair.getter; - - encryption.change(pci, value, true); - } - - return true; - } - } - - boolean ok = ctx.getInstruction() instanceof IAdd || - ctx.getInstruction() instanceof ISub || - ctx.getInstruction() instanceof IMul || - ctx.getInstruction() instanceof SetFieldInstruction || - ctx.getInstruction() instanceof DupInstruction; - - if (!ok) - return false; - - boolean multipleBranches = ctx.getInstruction() instanceof IAdd || - ctx.getInstruction() instanceof ISub; - boolean retVal = false; - - encryption.begin(); - - for (StackContext sctx : ctx.getPops()) - { - InstructionContext i = sctx.getPushed(); - - if (translate(encryption, pair, i, visited)) - { - retVal = true; - - if (!multipleBranches) // only need to translate the one branch, which we have, return. - break; - } - else - { - if (multipleBranches) - { - // we can't translate both branches so rollback - encryption.rollback(); - retVal = false; - break; - } - // else this is okay, we can try another - } - } - - encryption.end(); - -// for (StackContext sctx : ctx.getPushes()) -// { -// InstructionContext i = sctx.getPopped(); -// -// if (i != null) -// { -// boolean b = translate(encryption, pair, i, visited); // XXX? -// //System.out.println("up translate res " + b); -// } -// else -// assert false; -// // this hasn't been popped yet, so it hasn't been executed yet, -// // so mark it as encrypted so that when it is executed, we will decrypt it -// //sctx.encryption = pair.getter; -// } - - return retVal; - } @Override public void execute(Frame frame) @@ -171,87 +49,6 @@ public class PutStatic extends Instruction implements SetFieldInstruction StackContext object = stack.pop(); ins.pop(object); - Encryption encryption = frame.getExecution().getEncryption(); - net.runelite.deob.Field myField = getMyField(); - if (encryption != null && myField != null) - { - Pair pair = encryption.getField(myField); - //if (pair != null) - // translate(encryption, pair, ins, new HashSet()); -// InstructionContext ctx = object.getPushed(); -// if (ctx.getInstruction() instanceof IAdd && pair != null) -// { -// // field += constant * crap; -// // in bytecode is really -// // field = field + constant * crap -// -// List pops = ctx.getPops(); -// -// if (pops.get(0).getPushed().getInstruction() instanceof IMul) -// { -// ctx = pops.get(0).getPushed(); -// } -// else if (pops.get(1).getPushed().getInstruction() instanceof IMul) -// { -// ctx = pops.get(1).getPushed(); -// } -// } -// if (ctx.getInstruction() instanceof PushConstantInstruction && pair != null) -// { -// // field = encryptedvalue -// // decrypt value by * getter -// -// PushConstantInstruction pci = (PushConstantInstruction) ctx.getInstruction(); -// int value = (int) pci.getConstant().getObject(); -// -// if (value != 0 && value != 1) -// { -// value = value * pair.getter; -// -// encryption.change(pci, value); -// } -// } -// if (ctx.getInstruction() instanceof ISub) -// { -// List stackCtx = ctx.getPops(); -// -// StackContext one = stackCtx.get(0), two = stackCtx.get(1); -// -// if (one.getPushed().getInstruction() instanceof IMul) -// { -// ctx = one.getPushed(); -// } -// else if (two.getPushed().getInstruction() instanceof IMul) -// { -// ctx = two.getPushed(); -// } -// } -// if (ctx.getInstruction() instanceof IMul && pair != null) -// { -// List stackCtx = ctx.getPops(); -// -// StackContext one = stackCtx.get(0), two = stackCtx.get(1); -// -// StackContext magicStack = findMagic(one, two); -// -// if (magicStack != null) -// { -// PushConstantInstruction pci = (PushConstantInstruction) magicStack.getPushed().getInstruction(); -// int value = (int) pci.getConstant().getObject(); -// -// // field is encrypted with pair -// // divide value by setter -// -// if (value != 0 && value != 1) -// { -// value = value * pair.getter; -// -// encryption.change(pci, value); -// } -// } -// } - } - frame.addInstructionContext(ins); } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java index db58756b34..e626e94835 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/Encryption.java @@ -1,25 +1,12 @@ package net.runelite.deob.deobfuscators.arithmetic; import java.util.HashMap; -import java.util.HashSet; import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.Stack; import net.runelite.deob.Field; -import net.runelite.deob.attributes.code.Instruction; -import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; public class Encryption -{ - private static class PendingStack - { - private Set pending = new HashSet<>(); - } - - private Map fields = new HashMap<>(); - private Map changes = new HashMap<>(); - private Stack stack = new Stack<>(); +{ + private final Map fields = new HashMap<>(); public void addPair(Pair pair) { @@ -30,59 +17,4 @@ public class Encryption { return fields.get(field); } - - public boolean hasChange(PushConstantInstruction pci) - { - return changes.containsKey(pci); - } - - public void change(PushConstantInstruction pci, int value, boolean mul) - { - //Integer i = changes.get(pci); - assert !changes.containsKey(pci) || changes.get(pci) == value; -// if (i == null) -// changes.put(pci, value); -// else if (mul) -// changes.put(pci, value * i); -// else - changes.put(pci, value); - // assert i == value; - - if (stack.isEmpty()) - return; - PendingStack ps = stack.peek(); - ps.pending.add(pci); - } - - public void doChange() - { - for (Entry e : changes.entrySet()) - { - PushConstantInstruction pci = e.getKey(); - int value = e.getValue(); - - Instruction oldi = (Instruction) pci; - Instruction newi = pci.setConstant(new net.runelite.deob.pool.Integer(value)); - - if (oldi != newi) - oldi.getInstructions().replace(oldi, newi); - } - } - - public void begin() - { - stack.push(new PendingStack()); - } - - public void end() - { - stack.pop(); - } - - public void rollback() - { - PendingStack ps = stack.peek(); - for (PushConstantInstruction pci : ps.pending) - changes.remove(pci); - } } 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 77fd0b938c..1f3f53f9e5 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java @@ -21,7 +21,6 @@ import net.runelite.deob.attributes.code.instruction.types.PushConstantInstructi import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction; import net.runelite.deob.attributes.code.instructions.IMul; import net.runelite.deob.attributes.code.instructions.LDC_W; -import net.runelite.deob.attributes.code.instructions.PutStatic; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; @@ -29,10 +28,6 @@ import net.runelite.deob.execution.StackContext; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.map.MultiValueMap; -/* -store an encryption context on stack context that shows the value the ctx is encrypted with -*/ - public class ModArith implements Deobfuscator { private ClassGroup group; @@ -321,22 +316,22 @@ public class ModArith implements Deobfuscator } System.out.println("Finished arith deob on " + total + " fields in " + passes + " passes"); } - - private void translateSetFields(Execution e) - { - //Set visited = new HashSet<>(); - for (Frame f : e.processedFrames) - for (InstructionContext ins : f.getInstructions()) - if (ins.getInstruction() instanceof SetFieldInstruction) - { - SetFieldInstruction sfi = (SetFieldInstruction) ins.getInstruction(); - Pair pair = e.getEncryption().getField(sfi.getMyField()); - - if (pair != null) - PutStatic.translate(e.getEncryption(), pair, ins, new HashSet()); - // - } - } +// +// private void translateSetFields(Execution e) +// { +// //Set visited = new HashSet<>(); +// for (Frame f : e.processedFrames) +// for (InstructionContext ins : f.getInstructions()) +// if (ins.getInstruction() instanceof SetFieldInstruction) +// { +// SetFieldInstruction sfi = (SetFieldInstruction) ins.getInstruction(); +// Pair pair = e.getEncryption().getField(sfi.getMyField()); +// +// if (pair != null) +// PutStatic.translate(e.getEncryption(), pair, ins, new HashSet()); +// // +// } +// } private void insertGetterSetterMuls(Encryption encr) { @@ -410,6 +405,12 @@ public class ModArith implements Deobfuscator findUses(); reduce(); +// Encryption encr = new Encryption(); +// for (Pair pair : pairs) +// encr.addPair(pair); +// +// insertGetterSetterMuls(encr); + int i = 0; for (Pair pair : pairs) { @@ -429,26 +430,6 @@ public class ModArith implements Deobfuscator encr.addPair(pair); insertGetterSetterMuls(encr); -// -// execution = new Execution(group); -// execution.populateInitialMethods(); -// execution.setEncryption(encr); -// execution.run(); -// -// encr.doChange(); -// -// insertSetterMuls(encr); - -// execution = new Execution(group); -// execution.populateInitialMethods(); -// execution.run(); -// -// encr = new Encryption(); -// encr.addPair(pair); -// execution.setEncryption(encr); -// translateSetFields(execution); -// -// encr.doChange(); System.out.println("Changed " + ++i); //assert !deobfuscatedFields.contains(field); 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 11d6425065..f85a9f15a0 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -1,10 +1,8 @@ package net.runelite.deob.deobfuscators.arithmetic; -import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.List; -import java.util.Objects; import java.util.Set; import net.runelite.deob.ClassGroup; import net.runelite.deob.Deobfuscator; @@ -22,7 +20,6 @@ import net.runelite.deob.attributes.code.instructions.SiPush; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; -import net.runelite.deob.execution.Stack; import net.runelite.deob.execution.StackContext; public class MultiplicationDeobfuscator implements Deobfuscator @@ -392,56 +389,6 @@ public class MultiplicationDeobfuscator implements Deobfuscator done.add(instruction); count += expression.simplify(1); - if (MultiplicationExpression.replace) - { - assert false; - MultiplicationExpression.replace = false; - return count; - } - //break; -// List ins = getConstants(ictx); -// -// if (ins.size() == 1) -// continue; -// -// for (InstructionContext i : ins) -// { -// if (done.contains(i.getInstruction())) -// { -// continue outer; -// } -// } -// -// // there can only be one path to here, or else combinging would change code logic -// if (!isOnlyPath(e, frame, ictx)) -// continue; -// -// int result = 1; -// -// // calculate result -// for (InstructionContext i : ins) -// { -// PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction(); -// int value = (int) pci.getConstant().getObject(); -// -// result *= value; -// } -// -// // set result on ins -// for (InstructionContext i : ins) -// { -// PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction(); -// Instruction newIns = pci.setConstant(new net.runelite.deob.pool.Integer(result)); -// ++count; -// if (newIns != pci) -// { -// instructions.replace((Instruction) pci, newIns); -// } -// result = 1; // rest of the results go to 1 -// } -// -// for (InstructionContext i : ins) -// done.add(i.getInstruction()); } return count; 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 f8ac40cfac..0cab866840 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java @@ -12,7 +12,6 @@ public class MultiplicationExpression 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; int simplify(int start) { @@ -54,11 +53,6 @@ public class MultiplicationExpression { for (MultiplicationExpression me : subexpressions) { -// if (me.instructions.isEmpty() && this.dupmagic != null) -// { -// assert me.dupmagic == null; -// me.dupmagic = this.dupmagic; -// } count += me.simplify(result); } @@ -82,11 +76,6 @@ public class MultiplicationExpression Instruction newIns = pci.setConstant(new net.runelite.deob.pool.Integer(result)); ++count; assert newIns == pci; -// if (newIns != pci) -// { -// newIns.getInstructions().replace((Instruction) pci, newIns); -// replace = true; -// } result = 1; // rest of the results go to 1 } diff --git a/src/main/java/net/runelite/deob/execution/InstructionContext.java b/src/main/java/net/runelite/deob/execution/InstructionContext.java index fad054668b..737f3df0a6 100644 --- a/src/main/java/net/runelite/deob/execution/InstructionContext.java +++ b/src/main/java/net/runelite/deob/execution/InstructionContext.java @@ -16,7 +16,6 @@ public class InstructionContext private List pushes = new ArrayList<>(); // stack contexts pushed by instruction execution private List reads = new ArrayList<>(); // lvt reads private List invokes = new ArrayList<>(); // invokes - public long frameNum; public InstructionContext(Instruction i, Frame f) { diff --git a/src/main/java/net/runelite/deob/execution/StackContext.java b/src/main/java/net/runelite/deob/execution/StackContext.java index 157fb947d9..27cd190364 100644 --- a/src/main/java/net/runelite/deob/execution/StackContext.java +++ b/src/main/java/net/runelite/deob/execution/StackContext.java @@ -9,7 +9,6 @@ public class StackContext public List poppeds = new ArrayList<>(); // instructions which popped this public Type type; // type of this public boolean removed; - public int encryption; // if this value is encrypted, this is the key to get the real value public StackContext(InstructionContext pushed, Type type) {