class172/field2976 passed to invoke is not simplified

This commit is contained in:
Adam
2015-10-11 19:38:36 -04:00
parent a0cb4c96d6
commit 99985d7d6f
10 changed files with 237 additions and 15 deletions

View File

@@ -9,6 +9,7 @@ import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Objects;
import net.runelite.deob.pool.NameAndType;
public class Field
{
@@ -41,6 +42,15 @@ public class Field
attributes = new Attributes(this, is);
}
public Field(Fields fields, String name, Type type)
{
this.fields = fields;
this.name = name;
this.type = type;
attributes = new Attributes(this);
}
public void write(DataOutputStream out) throws IOException
{
ConstantPool pool = fields.getClassFile().getPool();
@@ -70,6 +80,11 @@ public class Field
{
return (accessFlags & ACC_STATIC) != 0;
}
public void setStatic()
{
accessFlags |= ACC_STATIC;
}
public String getName()
{
@@ -95,6 +110,14 @@ public class Field
{
return attributes;
}
public net.runelite.deob.pool.Field getPoolField()
{
return new net.runelite.deob.pool.Field(
new net.runelite.deob.pool.Class(this.getFields().getClassFile().getName()),
new NameAndType(this.getName(), this.getType())
);
}
@Override
public int hashCode()

View File

@@ -40,6 +40,11 @@ public class Fields
{
return classFile;
}
public void addField(Field field)
{
fields.add(field);
}
public List<Field> getFields()
{

View File

@@ -145,5 +145,13 @@ public class Method
}
return list;
}
}
public net.runelite.deob.pool.Method getPoolMethod()
{
return new net.runelite.deob.pool.Method(
new net.runelite.deob.pool.Class(this.getMethods().getClassFile().getName()),
new NameAndType(this.getName(), this.getDescriptor())
);
}
}

View File

@@ -37,6 +37,11 @@ public class Attributes
load(is);
}
public Attributes(Field f)
{
field = f;
}
public Attributes(Method m)
{

View File

@@ -29,6 +29,13 @@ public class GetStatic extends Instruction implements GetFieldInstruction
super(instructions, type, pc);
}
public GetStatic(Instructions instructions, Field field)
{
super(instructions, InstructionType.GETSTATIC, -1);
this.field = field;
}
@Override
public void load(DataInputStream is) throws IOException
{

View File

@@ -33,6 +33,13 @@ public class InvokeStatic extends Instruction implements InvokeInstruction
super(instructions, type, pc);
}
public InvokeStatic(Instructions instructions, Method method)
{
super(instructions, InstructionType.INVOKESTATIC, -1);
this.method = method;
}
@Override
public void load(DataInputStream is) throws IOException
{

View File

@@ -35,6 +35,9 @@ public class DMath
public static boolean isBig(int val)
{
return (val & 0xFFF00000) != 0;
if ((val & 0x80000000) != 0)
val = ~val + 1;
return (val & 0x7FF00000) != 0;
}
}

View File

@@ -37,6 +37,76 @@ public class ModArith implements Deobfuscator
private List<Pair> pairs = new ArrayList<>();
private Set<Field> deobfuscatedFields = new HashSet<>();
private List<InstructionContext> getInsInExpr(InstructionContext ctx, Set<Instruction> set)
{
List<InstructionContext> l = new ArrayList<>();
if (ctx == null || set.contains(ctx.getInstruction()))
return l;
set.add(ctx.getInstruction());
l.add(ctx);
for (StackContext s : ctx.getPops())
l.addAll(getInsInExpr(s.getPushed(), set));
for (StackContext s : ctx.getPushes())
for (InstructionContext i : s.getPopped())
l.addAll(getInsInExpr(i, set));
return l;
}
private boolean isFieldObfuscated(Execution e, Field field)
{
// field isn't obfuscated if there are no usages with big constants and no other fields
for (Frame f : execution.processedFrames)
outer:
for (InstructionContext ctx : f.getInstructions())
{
if (!(ctx.getInstruction() instanceof FieldInstruction))
continue;
FieldInstruction fi = (FieldInstruction) ctx.getInstruction();
if (fi.getMyField() != field)
continue;
List<InstructionContext> ins = getInsInExpr(ctx, new HashSet());
// continue if expr contains another ins
for (InstructionContext i : ins)
{
if (i.getInstruction() instanceof FieldInstruction)
{
FieldInstruction ifi = (FieldInstruction) i.getInstruction();
if (ifi.getMyField() != field)
continue outer;
}
}
// find big constant
for (InstructionContext i : ins)
{
if (i.getInstruction() instanceof LDC_W)
{
LDC_W ldc = (LDC_W) i.getInstruction();
if (ldc.getConstant().getObject() instanceof Integer)
{
int value = ldc.getConstantAsInt();
if (DMath.isBig(value))
return true;
}
}
}
}
return false;
}
private List<Integer> findAssocConstants(Field field, InstructionContext ctx) throws OtherFieldException
{
// starts with ctx = setfield
@@ -97,11 +167,6 @@ public class ModArith implements Deobfuscator
if (field == null)
continue;
if (field.getName().equals("field2201"))
{
int k=7;
}
int value = (int) pc.getConstant().getObject();
if (value == 1 || value == 0)
@@ -302,7 +367,7 @@ public class ModArith implements Deobfuscator
Collection<Integer> getters = constantGetters.getCollection(f),
setters = constantSetters.getCollection(f);
if (f.getName().equals("field551"))
if (f.getName().equals("field2976"))
{
int k=5;
}
@@ -322,6 +387,12 @@ public class ModArith implements Deobfuscator
if (answer == null)
continue;
if (!this.isFieldObfuscated(execution, f))
{
System.out.println("Skipping field " + f.getName() + " which isnt obfuscated");
continue;
}
answer.field = f;
pairs.add(answer);
}