Cleanup some of the old encr stuff
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -50,18 +50,6 @@ public class GetStatic extends Instruction implements GetFieldInstruction
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
stack.push(ctx);
|
||||
|
||||
ins.push(ctx);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<StackContext> 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<StackContext> 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<StackContext> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
{
|
||||
@@ -46,122 +40,6 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
||||
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<Instruction> 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<StackContext> 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<StackContext> 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<StackContext> 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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<PushConstantInstruction> pending = new HashSet<>();
|
||||
}
|
||||
|
||||
private Map<Field, Pair> fields = new HashMap<>();
|
||||
private Map<PushConstantInstruction, Integer> changes = new HashMap<>();
|
||||
private Stack<PendingStack> stack = new Stack<>();
|
||||
private final Map<Field, Pair> 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<PushConstantInstruction, Integer> 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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Instruction> 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<Instruction> 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);
|
||||
|
||||
@@ -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<InstructionContext> 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;
|
||||
|
||||
@@ -12,7 +12,6 @@ public class MultiplicationExpression
|
||||
dupedInstructions = new ArrayList<>();
|
||||
List<MultiplicationExpression> 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
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ public class InstructionContext
|
||||
private List<StackContext> pushes = new ArrayList<>(); // stack contexts pushed by instruction execution
|
||||
private List<VariableContext> reads = new ArrayList<>(); // lvt reads
|
||||
private List<Method> invokes = new ArrayList<>(); // invokes
|
||||
public long frameNum;
|
||||
|
||||
public InstructionContext(Instruction i, Frame f)
|
||||
{
|
||||
|
||||
@@ -9,7 +9,6 @@ public class StackContext
|
||||
public List<InstructionContext> 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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user