some guessing, fix dup stuff via magic
This commit is contained in:
@@ -16,6 +16,7 @@ import net.runelite.deob.pool.NameAndType;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
|
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
|
||||||
import static net.runelite.deob.attributes.code.instructions.PutStatic.translate;
|
import static net.runelite.deob.attributes.code.instructions.PutStatic.translate;
|
||||||
@@ -58,7 +59,7 @@ public class PutField extends Instruction implements SetFieldInstruction
|
|||||||
{
|
{
|
||||||
Pair pair = encryption.getField(myField);
|
Pair pair = encryption.getField(myField);
|
||||||
if (pair != null)
|
if (pair != null)
|
||||||
translate(encryption, pair, ins);
|
translate(encryption, pair, ins, new HashSet());
|
||||||
// XXX move translate() here
|
// XXX move translate() here
|
||||||
// InstructionContext ctx = value.getPushed();
|
// InstructionContext ctx = value.getPushed();
|
||||||
// if (ctx.getInstruction() instanceof IAdd && pair != null)
|
// if (ctx.getInstruction() instanceof IAdd && pair != null)
|
||||||
|
|||||||
@@ -16,8 +16,9 @@ import net.runelite.deob.pool.NameAndType;
|
|||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.HashSet;
|
||||||
import net.runelite.deob.attributes.code.instruction.types.InvokeInstruction;
|
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.attributes.code.instruction.types.PushConstantInstruction;
|
||||||
import net.runelite.deob.deobfuscators.arithmetic.DMath;
|
import net.runelite.deob.deobfuscators.arithmetic.DMath;
|
||||||
import net.runelite.deob.deobfuscators.arithmetic.Encryption;
|
import net.runelite.deob.deobfuscators.arithmetic.Encryption;
|
||||||
@@ -70,8 +71,13 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static boolean translate(Encryption encryption, Pair pair, InstructionContext ctx)
|
protected 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 LDC_W)
|
if (ctx.getInstruction() instanceof LDC_W)
|
||||||
{
|
{
|
||||||
LDC_W pci = (LDC_W) ctx.getInstruction();
|
LDC_W pci = (LDC_W) ctx.getInstruction();
|
||||||
@@ -90,21 +96,17 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (ctx.getInstruction() instanceof InvokeInstruction)
|
|
||||||
// return false;
|
|
||||||
//
|
|
||||||
// if (ctx.getInstruction() instanceof IDiv)
|
|
||||||
// return false;
|
|
||||||
|
|
||||||
boolean ok = ctx.getInstruction() instanceof IAdd ||
|
boolean ok = ctx.getInstruction() instanceof IAdd ||
|
||||||
ctx.getInstruction() instanceof ISub ||
|
ctx.getInstruction() instanceof ISub ||
|
||||||
ctx.getInstruction() instanceof IMul ||
|
ctx.getInstruction() instanceof IMul ||
|
||||||
ctx.getInstruction() instanceof SetFieldInstruction;
|
ctx.getInstruction() instanceof SetFieldInstruction ||
|
||||||
|
ctx.getInstruction() instanceof DupInstruction;
|
||||||
|
|
||||||
if (!ok)
|
if (!ok)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
boolean multipleBranches = ctx.getInstruction() instanceof IAdd || ctx.getInstruction() instanceof ISub;
|
boolean multipleBranches = ctx.getInstruction() instanceof IAdd ||
|
||||||
|
ctx.getInstruction() instanceof ISub;
|
||||||
boolean retVal = false;
|
boolean retVal = false;
|
||||||
|
|
||||||
encryption.begin();
|
encryption.begin();
|
||||||
@@ -113,7 +115,7 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
|||||||
{
|
{
|
||||||
InstructionContext i = sctx.getPushed();
|
InstructionContext i = sctx.getPushed();
|
||||||
|
|
||||||
if (translate(encryption, pair, i))
|
if (translate(encryption, pair, i, visited))
|
||||||
{
|
{
|
||||||
retVal = true;
|
retVal = true;
|
||||||
|
|
||||||
@@ -135,6 +137,18 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
|||||||
|
|
||||||
encryption.end();
|
encryption.end();
|
||||||
|
|
||||||
|
for (StackContext sctx : ctx.getPushes())
|
||||||
|
{
|
||||||
|
InstructionContext i = sctx.getPopped();
|
||||||
|
|
||||||
|
if (i != null)
|
||||||
|
translate(encryption, pair, i, visited); // XXX?
|
||||||
|
else
|
||||||
|
// 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;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,7 +167,7 @@ public class PutStatic extends Instruction implements SetFieldInstruction
|
|||||||
{
|
{
|
||||||
Pair pair = encryption.getField(myField);
|
Pair pair = encryption.getField(myField);
|
||||||
if (pair != null)
|
if (pair != null)
|
||||||
translate(encryption, pair, ins);
|
translate(encryption, pair, ins, new HashSet());
|
||||||
// InstructionContext ctx = object.getPushed();
|
// InstructionContext ctx = object.getPushed();
|
||||||
// if (ctx.getInstruction() instanceof IAdd && pair != null)
|
// if (ctx.getInstruction() instanceof IAdd && pair != null)
|
||||||
// {
|
// {
|
||||||
|
|||||||
@@ -113,15 +113,14 @@ public class ModArith implements Deobfuscator
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
List<Integer> constants = null;
|
List<Integer> constants = null;
|
||||||
// try
|
try
|
||||||
// {
|
{
|
||||||
// constants = findAssocConstants(field, ctx);
|
constants = findAssocConstants(field, ctx);
|
||||||
// System.out.println(field.getName() + " " + constants);
|
for (int i : constants)
|
||||||
// for (int i : constants)
|
if (i != 1 && i != 0)
|
||||||
// if (i != 1 && i != 0)
|
constantSetters.put(field, i);
|
||||||
// constantSetters.put(field, i);
|
}
|
||||||
// }
|
catch (OtherFieldException ex) { }
|
||||||
// catch (OtherFieldException ex) { }
|
|
||||||
|
|
||||||
StackContext value = ctx.getPops().get(0); // the first thing poppe from both putfield and putstatic is the value
|
StackContext value = ctx.getPops().get(0); // the first thing poppe from both putfield and putstatic is the value
|
||||||
if (!(value.getPushed().getInstruction() instanceof IMul))
|
if (!(value.getPushed().getInstruction() instanceof IMul))
|
||||||
@@ -250,22 +249,15 @@ public class ModArith implements Deobfuscator
|
|||||||
Collection<Integer> getters = constantGetters.getCollection(f),
|
Collection<Integer> getters = constantGetters.getCollection(f),
|
||||||
setters = constantSetters.getCollection(f);
|
setters = constantSetters.getCollection(f);
|
||||||
|
|
||||||
if (f.getName().equals("field605"))
|
|
||||||
{
|
|
||||||
int i =4;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getters == null || setters == null)
|
if (getters == null || setters == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Pair answer = reduce(getters, setters);
|
Pair answer = reduce(getters, setters);
|
||||||
if (answer == null)
|
if (answer == null)
|
||||||
{
|
{
|
||||||
// answer = guess(getters);
|
answer = guess(getters);
|
||||||
if (answer == null)
|
if (answer == null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
System.out.println("Guessing getter for " + f.getName() + " is " + answer.getter + " setter " + answer.setter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
answer.field = f;
|
answer.field = f;
|
||||||
@@ -273,61 +265,6 @@ public class ModArith implements Deobfuscator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// private List<Field> getFieldsInExpression(InstructionContext ctx, List<Integer> constants)
|
|
||||||
// {
|
|
||||||
// return check(ctx, new HashSet<InstructionContext>(), constants);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private List<Field> check(InstructionContext context, Set<InstructionContext> visited, List<Integer> constants)
|
|
||||||
// {
|
|
||||||
// List<Field> 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
|
@Override
|
||||||
public void run(ClassGroup group)
|
public void run(ClassGroup group)
|
||||||
{
|
{
|
||||||
@@ -351,16 +288,16 @@ public class ModArith implements Deobfuscator
|
|||||||
reduce();
|
reduce();
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
int start = 0, end = pairs.size(); // 0-64 ok
|
int start = 0, end = pairs.size();
|
||||||
for (int j = start; j < end; ++j)
|
for (int j = start; j < end; ++j)
|
||||||
//for (Pair pair : pairs)
|
//for (Pair pair : pairs)
|
||||||
{
|
{
|
||||||
Pair pair = pairs.get(j);
|
Pair pair = pairs.get(j);
|
||||||
Field field = pair.field;
|
Field field = pair.field;
|
||||||
|
|
||||||
if (!field.getName().equals("field2982") && !field.getName().equals("field2963"))
|
if (!field.getName().equals("field1980") && !field.getName().equals("field1961"))
|
||||||
{
|
{
|
||||||
// continue;
|
// continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("Processing " + field.getName() + " getter " + pair.getter + " setter " + pair.setter);
|
System.out.println("Processing " + field.getName() + " getter " + pair.getter + " setter " + pair.setter);
|
||||||
|
|||||||
Reference in New Issue
Block a user