Check per pop if its multiple places or not

This commit is contained in:
Adam
2015-10-09 14:14:14 -04:00
parent 0bc49e1ec6
commit fd973a0a95
5 changed files with 132 additions and 100 deletions

View File

@@ -10,7 +10,10 @@ import net.runelite.deob.attributes.code.Instructions;
import net.runelite.deob.attributes.code.instructions.Dup_X1;
import net.runelite.deob.attributes.code.instructions.IAdd;
import net.runelite.deob.attributes.code.instructions.IConst_0;
import net.runelite.deob.attributes.code.instructions.IConst_1;
import net.runelite.deob.attributes.code.instructions.IConst_2;
import net.runelite.deob.attributes.code.instructions.IConst_3;
import net.runelite.deob.attributes.code.instructions.IDiv;
import net.runelite.deob.attributes.code.instructions.ILoad;
import net.runelite.deob.attributes.code.instructions.IMul;
import net.runelite.deob.attributes.code.instructions.IStore_0;
@@ -166,84 +169,6 @@ public class MultiplicationDeobfuscatorTest
Assert.assertEquals(1, constant4.getConstantAsInt());
}
//@Test
// public void testDupX1_3()
// {
// ClassGroup group = ClassGroupFactory.generateGroup();
// Code code = group.findClass("test").findMethod("func").getCode();
// Instructions ins = code.getInstructions();
//
// code.setMaxStack(2);
//
// Instruction[] prepareVariables = {
// new IConst_3(ins),
// new IStore_0(ins),
// new IConst_3(ins),
// new IStore_1(ins),
// new IConst_3(ins),
// new IStore_2(ins),
// };
//
// for (Instruction i : prepareVariables)
// ins.addInstruction(i);
//
// LDC_W constant1 = new LDC_W(ins, 1381104939),
// constant2 = new LDC_W(ins, 1381104939),
// constant3 = new LDC_W(ins, 981643079),
// constant4 = new LDC_W(ins, 1807370871),
// constant5 = new LDC_W(ins, 1807370871),
// constant6 = new LDC_W(ins, 981643079);
//
// NOP label1 = new NOP(ins),
// label2 = new NOP(ins);
//
// Instruction body[] = {
// new IConst_1(ins),
// new ILoad(ins, 0),
// new If(ins, label1),
// constant1,
// new ILoad(ins, 1),
// new IMul(ins),
// new Goto(ins, label2),
// label1,
// new ILoad(ins, 1),
// constant2,
// new IMul(ins),
// constant3,
// new ILoad(ins, 2),
// constant4,
// new IMul(ins),
// new IMul(ins),
// new IAdd(ins),
// new IConst_2(ins),
// new IDiv(ins),
// label2,
// constant5,
// new IMul(ins),
// constant6,
// new IMul(ins),
// new IStore(ins, 3),
// new VReturn(ins)
// };
//
// for (Instruction i : body)
// ins.addInstruction(i);
//
// Execution e = new Execution(group);
// e.populateInitialMethods();
// e.run();
//
// Deobfuscator d = new MultiplicationDeobfuscator();
// d.run(group);
//
// Assert.assertEquals(1381104939, constant1.getConstantAsInt());
// Assert.assertEquals(1381104939, constant2.getConstantAsInt());
// Assert.assertEquals(981643079, constant3.getConstantAsInt());
// Assert.assertEquals(1807370871, constant4.getConstantAsInt());
// Assert.assertEquals(1807370871, constant5.getConstantAsInt());
// Assert.assertEquals(981643079, constant6.getConstantAsInt());
// }
@Test
public void testDupX1_3()
{
@@ -311,8 +236,65 @@ public class MultiplicationDeobfuscatorTest
Assert.assertEquals(1381104939, constant1.getConstantAsInt());
Assert.assertEquals(1381104939, constant2.getConstantAsInt());
Assert.assertEquals(981643079, constant3.getConstantAsInt());
Assert.assertEquals(1, constant3.getConstantAsInt());
Assert.assertEquals(1, constant4.getConstantAsInt());
Assert.assertEquals(1, constant5.getConstantAsInt());
Assert.assertEquals(981643079, constant5.getConstantAsInt()); // assumes result is moved to the end here.
}
@Test
public void testDupX1_4()
{
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
Instruction[] prepareVariables = {
new IConst_3(ins),
new IStore_0(ins),
};
for (Instruction i : prepareVariables)
ins.addInstruction(i);
LDC_W constant1 = new LDC_W(ins, 1807370871),
constant2 = new LDC_W(ins, 981643079);
NOP label1 = new NOP(ins);
Instruction body[] = {
new ILoad(ins, 0),
new LDC_W(ins, 2),
new IMul(ins),
new IConst_0(ins),
new If0(ins, label1),
new Pop(ins),
new LDC_W(ins, 3),
label1,
constant1,
new IMul(ins),
constant2,
new IMul(ins),
new VReturn(ins)
};
for (Instruction i : body)
ins.addInstruction(i);
Execution e = new Execution(group);
e.populateInitialMethods();
e.run();
assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
}
}