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

@@ -31,47 +31,47 @@ public class Deob
ClassGroup group = JarUtil.loadJar(new File(args[0])); ClassGroup group = JarUtil.loadJar(new File(args[0]));
run(group, new RenameUnique()); // run(group, new RenameUnique());
//
// remove except RuntimeException // // remove except RuntimeException
run(group, new RuntimeExceptions()); // run(group, new RuntimeExceptions());
//
// remove unused methods // // remove unused methods
run(group, new UnreachedCode()); // run(group, new UnreachedCode());
run(group, new UnusedMethods()); // run(group, new UnusedMethods());
//
// remove illegal state exceptions, frees up some parameters // // remove illegal state exceptions, frees up some parameters
run(group, new IllegalStateExceptions()); // run(group, new IllegalStateExceptions());
//
// remove constant logically dead parameters // // remove constant logically dead parameters
run(group, new ConstantParameter()); // run(group, new ConstantParameter());
//
// remove unhit blocks // // remove unhit blocks
run(group, new UnreachedCode()); // run(group, new UnreachedCode());
run(group, new UnusedMethods()); // run(group, new UnusedMethods());
//
// remove unused parameters // // remove unused parameters
run(group, new UnusedParameters()); // run(group, new UnusedParameters());
//
// remove unused fields // // remove unused fields
run(group, new UnusedFields()); // run(group, new UnusedFields());
//
// remove unused methods, again? // // remove unused methods, again?
run(group, new UnusedMethods()); // run(group, new UnusedMethods());
//
// run(group, new MethodInliner()); //// run(group, new MethodInliner());
// run(group, new UnusedMethods()); // inliner might leave unused methods //// run(group, new UnusedMethods()); // inliner might leave unused methods
//
// // broken because rename was removed //// // broken because rename was removed
// //run(group, new MethodMover()); //// //run(group, new MethodMover());
//
run(group, new FieldInliner()); // run(group, new FieldInliner());
//
// // XXX this is broken because when moving clinit around, some fields can depend on other fields //// // XXX this is broken because when moving clinit around, some fields can depend on other fields
// // (like multianewarray) //// // (like multianewarray)
// //new FieldMover().run(group); //// //new FieldMover().run(group);
//
run(group, new UnusedClass()); // run(group, new UnusedClass());
ModArith mod = new ModArith(); ModArith mod = new ModArith();
mod.run(group); mod.run(group);

View File

@@ -695,4 +695,9 @@ public class ModArith implements Deobfuscator
} }
} }
} }
public Encryption getEncryption()
{
return encryption;
}
} }

View File

@@ -124,15 +124,7 @@ public class Execution
methods.add(frame.getMethod()); methods.add(frame.getMethod());
if (!frame.isExecuting())
{
frames.remove(0);
processedFrames.add(frame);
continue;
}
++fcount; ++fcount;
assert frame.isExecuting();
frame.execute(); frame.execute();
assert frames.get(0) == frame; assert frames.get(0) == frame;

View File

@@ -16,7 +16,10 @@ import org.junit.Test;
class TestClass class TestClass
{ {
private static int dummy(Object... args) { return 0; } private static int dummy(Object... args)
{
return 0;
}
private int field1051 = -1611704481; private int field1051 = -1611704481;
private int field2701; private int field2701;
@@ -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 public class ModArithTest
{ {
private void checkConstants(ClassFile cf) private void checkConstants(ClassFile cf)
@@ -56,13 +80,16 @@ public class ModArithTest
Code code = m.getCode(); Code code = m.getCode();
Instructions instructions = code.getInstructions(); Instructions instructions = code.getInstructions();
for (Instruction i : instructions.getInstructions()) for (Instruction i : instructions.getInstructions())
{
if (i instanceof LDC_W) if (i instanceof LDC_W)
{ {
LDC_W ldc = (LDC_W) i; LDC_W ldc = (LDC_W) i;
Assert.assertFalse(DMath.isBig(ldc.getConstantAsInt())); Assert.assertFalse(DMath.isBig(ldc.getConstantAsInt()));
} }
}
} }
} }
@Test @Test
public void test() throws IOException public void test() throws IOException
{ {
@@ -83,4 +110,41 @@ public class ModArithTest
this.checkConstants(cf); 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);
}
} }