Try and fix some of the smaller multiplication problems. I dont know if this is right. Seems to break when multiplying long * a casted int like field3228

This commit is contained in:
Adam
2016-03-29 20:53:43 -04:00
parent a2352bdc19
commit b3efaec8e6
2 changed files with 87 additions and 21 deletions

View File

@@ -59,6 +59,16 @@ public class Type
return 1; return 1;
} }
public boolean isInt()
{
return type.equals("I") && arrayDimms == 0;
}
public boolean isLong()
{
return type.equals("J") && arrayDimms == 0;
}
public boolean isPrimitive() public boolean isPrimitive()
{ {
assert type.startsWith("L") == type.endsWith(";"); assert type.startsWith("L") == type.endsWith(";");

View File

@@ -36,6 +36,11 @@ import net.runelite.asm.pool.PoolEntry;
import net.runelite.asm.signature.Type; import net.runelite.asm.signature.Type;
import org.apache.commons.collections4.map.MultiValueMap; import org.apache.commons.collections4.map.MultiValueMap;
import net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction; import net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction;
import net.runelite.asm.attributes.code.instructions.IAdd;
import net.runelite.asm.attributes.code.instructions.If;
import net.runelite.asm.attributes.code.instructions.If0;
import net.runelite.asm.attributes.code.instructions.LAdd;
import net.runelite.asm.attributes.code.instructions.LCmp;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
public class ModArith implements Deobfuscator public class ModArith implements Deobfuscator
@@ -58,7 +63,10 @@ public class ModArith implements Deobfuscator
// invoke and array store pops are unrelated to each other // invoke and array store pops are unrelated to each other
if (ctx.getInstruction() instanceof InvokeInstruction || if (ctx.getInstruction() instanceof InvokeInstruction ||
ctx.getInstruction() instanceof ArrayStoreInstruction || ctx.getInstruction() instanceof ArrayStoreInstruction ||
ctx.getInstruction() instanceof ArrayLoad) ctx.getInstruction() instanceof ArrayLoad ||
ctx.getInstruction() instanceof If ||
ctx.getInstruction() instanceof If0 ||
ctx.getInstruction() instanceof LCmp)
return l; return l;
set.add(ctx.getInstruction()); set.add(ctx.getInstruction());
@@ -88,6 +96,7 @@ public class ModArith implements Deobfuscator
SetFieldInstruction sfi = (SetFieldInstruction) ctx.getInstruction(); SetFieldInstruction sfi = (SetFieldInstruction) ctx.getInstruction();
InstructionContext pushedsfi = ctx.getPops().get(0).getPushed(); InstructionContext pushedsfi = ctx.getPops().get(0).getPushed();
pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
if (pushedsfi.getInstruction() instanceof LDC_W || pushedsfi.getInstruction() instanceof LDC2_W) if (pushedsfi.getInstruction() instanceof LDC_W || pushedsfi.getInstruction() instanceof LDC2_W)
{ {
PushConstantInstruction ldc = (PushConstantInstruction) pushedsfi.getInstruction(); PushConstantInstruction ldc = (PushConstantInstruction) pushedsfi.getInstruction();
@@ -99,7 +108,8 @@ public class ModArith implements Deobfuscator
this.obfuscatedFields.add(sfi.getMyField()); this.obfuscatedFields.add(sfi.getMyField());
} }
} }
else if (pushedsfi.getInstruction() instanceof IMul || pushedsfi.getInstruction() instanceof LMul) else if (pushedsfi.getInstruction() instanceof IMul || pushedsfi.getInstruction() instanceof LMul
|| pushedsfi.getInstruction() instanceof IAdd || pushedsfi.getInstruction() instanceof LAdd)
{ {
Instruction one = pushedsfi.getPops().get(0).getPushed().getInstruction(); Instruction one = pushedsfi.getPops().get(0).getPushed().getInstruction();
Instruction two = pushedsfi.getPops().get(1).getPushed().getInstruction(); Instruction two = pushedsfi.getPops().get(1).getPushed().getInstruction();
@@ -117,16 +127,23 @@ public class ModArith implements Deobfuscator
other = one; other = one;
} }
if (pci != null if (pci == null)
&& !(other instanceof GetFieldInstruction)) continue;
if (other instanceof GetFieldInstruction)
{ {
if (pci.getConstant().getObject() instanceof Integer || pci.getConstant().getObject() instanceof Long) GetFieldInstruction gfi = (GetFieldInstruction) other;
{
Number i = (Number) pci.getConstant().getObject(); if (gfi.getMyField() != sfi.getMyField())
if (DMath.isBig(i)) continue;
// field = constant * not other field }
this.obfuscatedFields.add(sfi.getMyField());
} if (pci.getConstant().getObject() instanceof Integer || pci.getConstant().getObject() instanceof Long)
{
Number i = (Number) pci.getConstant().getObject();
if (DMath.isBig(i))
// field = constant * not other field
this.obfuscatedFields.add(sfi.getMyField());
} }
} }
} }
@@ -174,6 +191,17 @@ public class ModArith implements Deobfuscator
continue; continue;
} }
InstructionContext popped = ctx.getPushes().get(0).getPopped().isEmpty() ? null : ctx.getPushes().get(0).getPopped().get(0);
if (popped != null && popped.getInstruction() instanceof SetFieldInstruction)
{
SetFieldInstruction sfi = (SetFieldInstruction) popped.getInstruction();
if (sfi.getMyField() != null)// && sfi.getMyField() != field)
{
continue;
}
}
this.obfuscatedFields.add(other.getMyField()); this.obfuscatedFields.add(other.getMyField());
} }
} }
@@ -213,7 +241,25 @@ public class ModArith implements Deobfuscator
Field myField = fi2.getMyField(); Field myField = fi2.getMyField();
if (myField != null && myField != fi.getMyField()) if (myField != null && myField != fi.getMyField())
other = true; {
Type t = myField.getType();
if (t.equals(fi.getMyField().getType()))
{
other = true;
}
}
}
}
boolean constant = false;
if (fi instanceof SetFieldInstruction)
{
InstructionContext pushedsfi = ctx.getPops().get(0).getPushed(); // value being set
pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
if (pushedsfi.getInstruction() instanceof LDC_W || pushedsfi.getInstruction() instanceof LDC2_W)
{
constant = true;
} }
} }
@@ -227,6 +273,7 @@ public class ModArith implements Deobfuscator
AssociatedConstant n = new AssociatedConstant(); AssociatedConstant n = new AssociatedConstant();
n.value = (Number) w.getConstant().getObject(); n.value = (Number) w.getConstant().getObject();
n.other = other; n.other = other;
n.constant = constant;
constants.put(fi.getMyField(), n); constants.put(fi.getMyField(), n);
} }
} }
@@ -281,12 +328,15 @@ public class ModArith implements Deobfuscator
if (field == null) if (field == null)
continue; continue;
StackContext value = ctx.getPops().get(0); // the first thing popped from both putfield and putstatic is the value InstructionContext pushedsfi = ctx.getPops().get(0).getPushed(); // value being set
if (!(value.getPushed().getInstruction() instanceof IMul) && !(value.getPushed().getInstruction() instanceof LMul)) pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
if (!(pushedsfi.getInstruction() instanceof IMul) && !(pushedsfi.getInstruction() instanceof LMul)
&& !(pushedsfi.getInstruction() instanceof IAdd) && !(pushedsfi.getInstruction() instanceof LAdd))
{ {
if (value.getPushed().getInstruction() instanceof LDC_W || value.getPushed().getInstruction() instanceof LDC2_W) if (pushedsfi.getInstruction() instanceof LDC_W || pushedsfi.getInstruction() instanceof LDC2_W)
{ {
PushConstantInstruction ldc = (PushConstantInstruction) value.getPushed().getInstruction(); PushConstantInstruction ldc = (PushConstantInstruction) pushedsfi.getInstruction();
if (ldc.getConstant().getObject() instanceof Integer || ldc.getConstant().getObject() instanceof Long) if (ldc.getConstant().getObject() instanceof Integer || ldc.getConstant().getObject() instanceof Long)
{ {
@@ -300,8 +350,8 @@ public class ModArith implements Deobfuscator
continue; continue;
} }
Instruction one = value.getPushed().getPops().get(0).getPushed().getInstruction(); Instruction one = pushedsfi.getPops().get(0).getPushed().getInstruction();
Instruction two = value.getPushed().getPops().get(1).getPushed().getInstruction(); Instruction two = pushedsfi.getPops().get(1).getPushed().getInstruction();
PushConstantInstruction pc = null; PushConstantInstruction pc = null;
Instruction other = null; Instruction other = null;
@@ -324,6 +374,12 @@ public class ModArith implements Deobfuscator
if (DMath.equals(value2, 1) || DMath.equals(value2, 0)) if (DMath.equals(value2, 1) || DMath.equals(value2, 0))
continue; continue;
if (pushedsfi.getInstruction() instanceof IAdd || pushedsfi.getInstruction() instanceof LAdd)
{
if (!DMath.isBig(value2))
continue;
}
// field = something * constant // field = something * constant
constantSetters.put(field, value2); constantSetters.put(field, value2);
} }
@@ -538,8 +594,8 @@ public class ModArith implements Deobfuscator
.collect(Collectors.toList()); .collect(Collectors.toList());
// filer out ones that have another field in the expression // filer out ones that have another field in the expression
Collection<Number> noOther = col2.stream().filter(i -> !i.other).map(i -> i.value).collect(Collectors.toList()); List<Number> noOther = col2.stream().filter(i -> !i.other).filter(i -> !i.constant).map(i -> i.value).collect(Collectors.toList());
Collection<Number> other = col2.stream().filter(i -> i.other).map(i -> i.value).collect(Collectors.toList()); List<Number> other = col2.stream().filter(i -> i.other || i.constant).map(i -> i.value).collect(Collectors.toList());
other.addAll(noOther); other.addAll(noOther);
removeDupes(noOther); removeDupes(noOther);