Added failing negative mul test

This commit is contained in:
Adam
2015-11-22 15:07:15 -06:00
parent 30ed0b4309
commit adcfdc471a
4 changed files with 118 additions and 57 deletions

View File

@@ -16,7 +16,10 @@ import org.junit.Test;
class TestClass
{
private static int dummy(Object... args) { return 0; }
private static int dummy(Object... args)
{
return 0;
}
private int field1051 = -1611704481;
private int field2701;
@@ -26,7 +29,7 @@ class TestClass
{
TestClass tc = new TestClass(); // to trick executor to call the constructor
int var = 42;
if (-1 != this.field1051 * 1928543073)
{
dummy(this.field1051 * 1928543073);
@@ -37,7 +40,7 @@ class TestClass
{
field2701 += -1868498967 * var;
}
field2138 = tc.dummy() * 1510226873;
field2130 = 572701809 * tc.field2138;
if (-1722291303 * field2130 >= var)
@@ -47,6 +50,27 @@ class TestClass
}
}
class TestClass2
{
int field2863;
int array[];
public void test()
{
TestClass2 tc = new TestClass2();
field2863 = -1446933277;
array[378529589 * tc.field2863] = 1;
int var = 32;
tc.field2863 = var * 1446933277;
array[378529589 * tc.field2863] = 1;
}
}
public class ModArithTest
{
private void checkConstants(ClassFile cf)
@@ -56,31 +80,71 @@ public class ModArithTest
Code code = m.getCode();
Instructions instructions = code.getInstructions();
for (Instruction i : instructions.getInstructions())
{
if (i instanceof LDC_W)
{
LDC_W ldc = (LDC_W) i;
Assert.assertFalse(DMath.isBig(ldc.getConstantAsInt()));
}
}
}
}
@Test
public void test() throws IOException
{
InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/deob/deobfuscators/arithmetic/TestClass.class");
Assert.assertNotNull(in);
ClassGroup group = new ClassGroup();
ClassFile cf = new ClassFile(group, new DataInputStream(in));
group.addClass(cf);
ModArith d1 = new ModArith();
d1.run(group);
d1.runOnce();
Deobfuscator d2 = new MultiplicationDeobfuscator();
d2.run(group);
this.checkConstants(cf);
}
@Test
public void test2() throws IOException
{
InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/deob/deobfuscators/arithmetic/TestClass2.class");
Assert.assertNotNull(in);
ClassGroup group = new ClassGroup();
ClassFile cf = new ClassFile(group, new DataInputStream(in));
group.addClass(cf);
ModArith d1 = new ModArith();
d1.run(group);
int last = -1, cur;
while ((cur = d1.runOnce()) > 0)
{
Deobfuscator d2 = new MultiplicationDeobfuscator();
d2.run(group);
new MultiplyOneDeobfuscator().run(group);
new MultiplyZeroDeobfuscator().run(group);
if (last == cur)
break;
last = cur;
}
Encryption e = d1.getEncryption();
Pair pair = e.getField(cf.findField("field2863").getPoolField());
Assert.assertEquals(378529589, (int) pair.getter);
}
}