long work

This commit is contained in:
Adam
2015-10-30 20:28:10 -04:00
parent 1f716bf10d
commit 8e68963f65
3 changed files with 52 additions and 27 deletions

View File

@@ -158,4 +158,9 @@ public class LDC_W extends Instruction implements PushConstantInstruction
{ {
return (int) value.getObject(); return (int) value.getObject();
} }
public Number getNumber()
{
return (Number) value.getObject();
}
} }

View File

@@ -40,4 +40,22 @@ public class DMath
return (val & 0x7FF00000) != 0; return (val & 0x7FF00000) != 0;
} }
private static boolean isBig(long val)
{
if ((val & 0x8000000000000000L) != 0L)
val = ~val + 1L;
return (val & 0x7FF0000000000000L) != 0L;
}
public static boolean isBig(Number value)
{
if (value instanceof Integer)
return isBig((int) value);
else if (value instanceof Long)
return isBig((long) value);
else
throw new IllegalArgumentException();
}
} }

View File

@@ -22,6 +22,7 @@ import net.runelite.deob.attributes.code.instruction.types.PushConstantInstructi
import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction; import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction;
import net.runelite.deob.attributes.code.instructions.IMul; import net.runelite.deob.attributes.code.instructions.IMul;
import net.runelite.deob.attributes.code.instructions.LDC_W; import net.runelite.deob.attributes.code.instructions.LDC_W;
import net.runelite.deob.attributes.code.instructions.LMul;
import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.Frame;
import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.InstructionContext;
@@ -32,7 +33,7 @@ public class ModArith implements Deobfuscator
{ {
private ClassGroup group; private ClassGroup group;
private Execution execution; private Execution execution;
private MultiValueMap<Field, Integer> constantGetters = new MultiValueMap<>(), private MultiValueMap<Field, Number> constantGetters = new MultiValueMap<>(),
constantSetters = new MultiValueMap<>(); constantSetters = new MultiValueMap<>();
private List<Pair> pairs = new ArrayList<>(); private List<Pair> pairs = new ArrayList<>();
@@ -78,15 +79,15 @@ public class ModArith implements Deobfuscator
if (pushedsfi.getInstruction() instanceof LDC_W) if (pushedsfi.getInstruction() instanceof LDC_W)
{ {
LDC_W ldc = (LDC_W) pushedsfi.getInstruction(); LDC_W ldc = (LDC_W) pushedsfi.getInstruction();
if (ldc.getConstant().getObject() instanceof Integer) if (ldc.getConstant().getObject() instanceof Integer || ldc.getConstant().getObject() instanceof Long)
{ {
int it = ldc.getConstantAsInt(); Number it = ldc.getNumber();
if (DMath.isBig(it)) if (DMath.isBig(it))
// field = constant // field = constant
return true; return true;
} }
} }
else if (pushedsfi.getInstruction() instanceof IMul) else if (pushedsfi.getInstruction() instanceof IMul || pushedsfi.getInstruction() instanceof LMul)
{ {
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();
@@ -107,9 +108,9 @@ public class ModArith implements Deobfuscator
if (pci != null if (pci != null
&& !(other instanceof GetFieldInstruction)) && !(other instanceof GetFieldInstruction))
{ {
if (pci.getConstant().getObject() instanceof Integer) if (pci.getConstant().getObject() instanceof Integer || pci.getConstant().getObject() instanceof Long)
{ {
int i = pci.getConstantAsInt(); Number i = pci.getNumber();
if (DMath.isBig(i)) if (DMath.isBig(i))
// field = constant * not other field // field = constant * not other field
return true; return true;
@@ -120,7 +121,7 @@ public class ModArith implements Deobfuscator
} }
// field * imul // field * imul
if (!(ctx.getInstruction() instanceof IMul)) if (!(ctx.getInstruction() instanceof IMul) && !(ctx.getInstruction() instanceof LMul))
continue; continue;
Instruction one = ctx.getPops().get(0).getPushed().getInstruction(); Instruction one = ctx.getPops().get(0).getPushed().getInstruction();
@@ -147,10 +148,10 @@ public class ModArith implements Deobfuscator
if (other.getMyField() != null && other.getMyField() != field) if (other.getMyField() != null && other.getMyField() != field)
continue; continue;
if (!(pc.getConstant().getObject() instanceof Integer)) if (!(pc.getConstant().getObject() instanceof Integer) && !(pc.getConstant().getObject() instanceof Long))
continue; continue;
int ivalue = pc.getConstantAsInt(); Number ivalue = pc.getNumber();
if (!DMath.isBig(ivalue)) if (!DMath.isBig(ivalue))
continue; continue;
@@ -183,7 +184,7 @@ public class ModArith implements Deobfuscator
static class AssociatedConstant static class AssociatedConstant
{ {
int value; Number value;
boolean other; boolean other;
} }
private MultiValueMap<Field, AssociatedConstant> constants = new MultiValueMap(); private MultiValueMap<Field, AssociatedConstant> constants = new MultiValueMap();
@@ -200,7 +201,8 @@ public class ModArith implements Deobfuscator
if (fi.getMyField() == null) if (fi.getMyField() == null)
continue; continue;
if (!fi.getField().getNameAndType().getDescriptorType().getType().equals("I") if ((!fi.getField().getNameAndType().getDescriptorType().getType().equals("I")
&& !fi.getField().getNameAndType().getDescriptorType().getType().equals("J"))
|| fi.getField().getNameAndType().getDescriptorType().getArrayDims() != 0) || fi.getField().getNameAndType().getDescriptorType().getArrayDims() != 0)
continue; continue;
@@ -226,10 +228,10 @@ public class ModArith implements Deobfuscator
if (i.getInstruction() instanceof LDC_W) if (i.getInstruction() instanceof LDC_W)
{ {
LDC_W w = (LDC_W) i.getInstruction(); LDC_W w = (LDC_W) i.getInstruction();
if (w.getConstant().getObject() instanceof Integer) if (w.getConstant().getObject() instanceof Integer || w.getConstant().getObject() instanceof Long)
{ {
AssociatedConstant n = new AssociatedConstant(); AssociatedConstant n = new AssociatedConstant();
n.value = w.getConstantAsInt(); n.value = w.getNumber();
n.other = other; n.other = other;
constants.put(fi.getMyField(), n); constants.put(fi.getMyField(), n);
} }
@@ -244,7 +246,7 @@ public class ModArith implements Deobfuscator
for (Frame f : execution.processedFrames) for (Frame f : execution.processedFrames)
for (InstructionContext ctx : f.getInstructions()) for (InstructionContext ctx : f.getInstructions())
{ {
if (ctx.getInstruction() instanceof IMul) if (ctx.getInstruction() instanceof IMul || ctx.getInstruction() instanceof LMul)
{ {
Instruction one = ctx.getPops().get(0).getPushed().getInstruction(); Instruction one = ctx.getPops().get(0).getPushed().getInstruction();
Instruction two = ctx.getPops().get(1).getPushed().getInstruction(); Instruction two = ctx.getPops().get(1).getPushed().getInstruction();
@@ -269,9 +271,9 @@ public class ModArith implements Deobfuscator
if (field == null) if (field == null)
continue; continue;
int value = (int) pc.getConstant().getObject(); Number value = (Number) pc.getConstant().getObject();
if (value == 1 || value == 0) if ((int) value == 1 || (int) value == 0)
continue; continue;
// field * constant // field * constant
@@ -286,15 +288,15 @@ public class ModArith implements Deobfuscator
continue; continue;
StackContext value = ctx.getPops().get(0); // the first thing popped from both putfield and putstatic is the value StackContext value = ctx.getPops().get(0); // the first thing popped from both putfield and putstatic is the value
if (!(value.getPushed().getInstruction() instanceof IMul)) if (!(value.getPushed().getInstruction() instanceof IMul) && !(value.getPushed().getInstruction() instanceof LMul))
{ {
if (value.getPushed().getInstruction() instanceof LDC_W) if (value.getPushed().getInstruction() instanceof LDC_W)
{ {
LDC_W ldc = (LDC_W) value.getPushed().getInstruction(); LDC_W ldc = (LDC_W) value.getPushed().getInstruction();
if (ldc.getConstant().getObject() instanceof Integer) if (ldc.getConstant().getObject() instanceof Integer || ldc.getConstant().getObject() instanceof Long)
{ {
int i = ldc.getConstantAsInt(); Number i = ldc.getNumber();
if (DMath.isBig(i)) if (DMath.isBig(i))
// field = constant // field = constant
@@ -323,9 +325,9 @@ public class ModArith implements Deobfuscator
if (pc == null) if (pc == null)
continue; continue;
int value2 = (int) pc.getConstant().getObject(); Number value2 = (Number) pc.getConstant().getObject();
if (value2 == 1 || value2 == 0) if ((int) value2 == 1 || (int) value2 == 0)
continue; continue;
// field = something * constant // field = something * constant
@@ -334,7 +336,7 @@ public class ModArith implements Deobfuscator
} }
} }
private Pair guess(Field field, Collection<Integer> constants) private Pair guess(Field field, Collection<Number> constants)
{ {
// multiply each by each, // multiply each by each,
// lowest number wins // lowest number wins
@@ -478,12 +480,12 @@ public class ModArith implements Deobfuscator
} }
// remove duplicates from a collection // remove duplicates from a collection
private void removeDupes(Collection<Integer> in) private <T> void removeDupes(Collection<T> in)
{ {
Set set = new HashSet(); Set set = new HashSet();
for (Iterator<Integer> it = in.iterator(); it.hasNext();) for (Iterator<T> it = in.iterator(); it.hasNext();)
{ {
int i = it.next(); T i = it.next();
if (set.contains(i)) if (set.contains(i))
{ {
@@ -508,8 +510,8 @@ public class ModArith implements Deobfuscator
Collection<AssociatedConstant> col2 = col.stream().filter(i -> DMath.isBig(i.value)).collect(Collectors.toList()); Collection<AssociatedConstant> col2 = col.stream().filter(i -> DMath.isBig(i.value)).collect(Collectors.toList());
// filer out ones that have another field in the expression // filer out ones that have another field in the expression
Collection<Integer> noOther = col2.stream().filter(i -> !i.other).map(i -> i.value).collect(Collectors.toList()); Collection<Number> noOther = col2.stream().filter(i -> !i.other).map(i -> i.value).collect(Collectors.toList());
Collection<Integer> other = col2.stream().filter(i -> i.other).map(i -> i.value).collect(Collectors.toList()); Collection<Number> other = col2.stream().filter(i -> i.other).map(i -> i.value).collect(Collectors.toList());
other.addAll(noOther); other.addAll(noOther);
removeDupes(noOther); removeDupes(noOther);