More tests/fixes I dont know if this is right
This commit is contained in:
@@ -49,4 +49,10 @@ public class IConst_M1 extends Instruction implements PushConstantInstruction
|
||||
{
|
||||
return new LDC_W(this.getInstructions(), entry);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Instruction makeGeneric()
|
||||
{
|
||||
return new LDC_W(this.getInstructions(), getConstant());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,16 +310,16 @@ public class ModArith implements Deobfuscator
|
||||
public void run(ClassGroup group)
|
||||
{
|
||||
this.group = group;
|
||||
runOnce();
|
||||
if (true) return;
|
||||
|
||||
int passes = 0, total = 0, i;
|
||||
while ((i = runOnce()) > 0)
|
||||
{
|
||||
++passes;
|
||||
total += i;
|
||||
}
|
||||
System.out.println("Finished arith deob on " + total + " fields in " + passes + " passes");
|
||||
//return runOnce();
|
||||
// if (true) return;
|
||||
//
|
||||
// int passes = 0, total = 0, i;
|
||||
// while ((i = runOnce()) > 0)
|
||||
// {
|
||||
// ++passes;
|
||||
// total += i;
|
||||
// }
|
||||
// System.out.println("Finished arith deob on " + total + " fields in " + passes + " passes");
|
||||
}
|
||||
//
|
||||
// private void translateSetFields(Execution e)
|
||||
@@ -395,7 +395,7 @@ public class ModArith implements Deobfuscator
|
||||
}
|
||||
}
|
||||
|
||||
private int runOnce()
|
||||
public int runOnce()
|
||||
{
|
||||
group.buildClassGraph();
|
||||
|
||||
|
||||
@@ -107,8 +107,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator
|
||||
{
|
||||
if (i.getInstruction() instanceof PushConstantInstruction)
|
||||
{
|
||||
if (i.getInstruction() instanceof BiPush || i.getInstruction() instanceof SiPush
|
||||
|| i.getInstruction() instanceof IConst_M1)
|
||||
if (i.getInstruction() instanceof BiPush || i.getInstruction() instanceof SiPush)
|
||||
throw new IllegalStateException();
|
||||
|
||||
// a constant of imul
|
||||
@@ -194,7 +193,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator
|
||||
else
|
||||
{
|
||||
System.out.println("dup ins " + otherCtxI.getInstruction());
|
||||
throw new IllegalStateException();
|
||||
//throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ 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.IConst_M1;
|
||||
import net.runelite.deob.attributes.code.instructions.IDiv;
|
||||
import net.runelite.deob.attributes.code.instructions.ILoad;
|
||||
import net.runelite.deob.attributes.code.instructions.IMul;
|
||||
@@ -358,4 +359,106 @@ public class MultiplicationDeobfuscatorTest
|
||||
Assert.assertEquals(1, constant2.getConstantAsInt());
|
||||
Assert.assertEquals(1, constant3.getConstantAsInt());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDupX1_6()
|
||||
{
|
||||
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_2(ins),
|
||||
new IStore(ins, 1)
|
||||
};
|
||||
|
||||
for (Instruction i : prepareVariables)
|
||||
ins.addInstruction(i);
|
||||
|
||||
LDC_W constant1 = new LDC_W(ins, 575391417),
|
||||
constant2 = new LDC_W(ins, -497786999);
|
||||
|
||||
Instruction body[] = {
|
||||
new ILoad(ins, 0),
|
||||
new ILoad(ins, 1),
|
||||
new Dup_X1(ins),
|
||||
new Pop(ins),
|
||||
new Pop(ins),
|
||||
constant1,
|
||||
new IMul(ins),
|
||||
constant2,
|
||||
new IMul(ins),
|
||||
new Pop(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());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDupX1_7()
|
||||
{
|
||||
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_2(ins),
|
||||
new IStore(ins, 1)
|
||||
};
|
||||
|
||||
for (Instruction i : prepareVariables)
|
||||
ins.addInstruction(i);
|
||||
|
||||
LDC_W constant1 = new LDC_W(ins, 2131037801),
|
||||
constant2 = new LDC_W(ins, -1306959399),
|
||||
constant3 = new LDC_W(ins, -1);
|
||||
|
||||
Instruction body[] = {
|
||||
constant3,
|
||||
constant1,
|
||||
new IMul(ins),
|
||||
constant2,
|
||||
new IMul(ins),
|
||||
new Pop(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());
|
||||
Assert.assertEquals(1, constant3.getConstantAsInt());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user