This commit is contained in:
Adam
2015-08-26 19:10:56 -04:00
parent 1fd79174ea
commit 227606a065
5 changed files with 84 additions and 21 deletions

View File

@@ -8,6 +8,7 @@ import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
public class Field
{
@@ -95,4 +96,10 @@ public class Field
{
return attributes;
}
@Override
public int hashCode()
{
return name.hashCode();
}
}

View File

@@ -18,6 +18,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.List;
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;
@@ -40,6 +41,33 @@ public class PutStatic extends Instruction implements SetFieldInstruction
super.write(out);
out.writeShort(this.getPool().make(field));
}
private 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;
}
@Override
public void execute(Frame frame)
@@ -92,25 +120,11 @@ public class PutStatic extends Instruction implements SetFieldInstruction
StackContext one = stackCtx.get(0), two = stackCtx.get(1);
if (one.getPushed().getInstruction() instanceof PushConstantInstruction)
StackContext magicStack = findMagic(one, two);
if (magicStack != null)
{
PushConstantInstruction pci = (PushConstantInstruction) one.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);
}
}
else if (two.getPushed().getInstruction() instanceof PushConstantInstruction)
{
PushConstantInstruction pci = (PushConstantInstruction) two.getPushed().getInstruction();
PushConstantInstruction pci = (PushConstantInstruction) magicStack.getPushed().getInstruction();
int value = (int) pci.getConstant().getObject();
// field is encrypted with pair
@@ -123,8 +137,40 @@ public class PutStatic extends Instruction implements SetFieldInstruction
encryption.change(pci, value);
}
}
else
assert false;
// if (one.getPushed().getInstruction() instanceof PushConstantInstruction)
// {
// PushConstantInstruction pci = (PushConstantInstruction) one.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);
// }
//
// }
// else if (two.getPushed().getInstruction() instanceof PushConstantInstruction)
// {
// PushConstantInstruction pci = (PushConstantInstruction) two.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);
// }
// }
// else
// assert false;
}
}

View File

@@ -32,4 +32,9 @@ public class DMath
return false;
}
}
public static boolean isBig(int val)
{
return (val & 0xFFF00000) != 0;
}
}

View File

@@ -5,6 +5,7 @@ import java.util.Map;
import java.util.Map.Entry;
import net.runelite.deob.Field;
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
import net.runelite.deob.attributes.code.instructions.SiPush;
public class Encryption
{
@@ -42,6 +43,10 @@ public class Encryption
public void change(PushConstantInstruction pci, int value)
{
if (pci instanceof SiPush)
{
int i =5;
}
assert !changes.containsKey(pci) || changes.get(pci) == value;
changes.put(pci, value);
}

View File

@@ -239,7 +239,7 @@ public class ModArith implements Deobfuscator
System.out.println("Processing " + field.getName());
int getter = constants.getCollection(field).iterator().next();
if (i > 5)
if (i > 50)
break;
Pair pair = new Pair();