use of net.runelite.asm.attributes.code.instructions.Pop in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test6.
@Test
public void test6() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0), new LDC(ins, 2), new IStore(ins, 1) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 575391417);
LDC constant2 = new LDC(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());
}
use of net.runelite.asm.attributes.code.instructions.Pop in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test7.
@Test
public void test7() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0), new LDC(ins, 2), new IStore(ins, 1) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, 2131037801), constant2 = new LDC(ins, -1306959399), constant3 = new LDC(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());
}
use of net.runelite.asm.attributes.code.instructions.Pop in project runelite by runelite.
the class MultiplicationDeobfuscatorTest method test2.
// aload_0
// dup
// getfield class118/field2201 I
// ldc_w -2079217519
// imul
// ldc -2079217519
// iadd
// dup_x1
// ldc_w 561453169
// imul
// putfield class118/field2201 I
// ldc 561453169
// imul
@Test
public void test2() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(4);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
LDC constant1 = new LDC(ins, -2079217519), constant2 = new LDC(ins, -2079217519), constant3 = new LDC(ins, 561453169), constant4 = new LDC(ins, 561453169);
Instruction[] body = { // for dup_x1 to place before this
new LDC(ins, 0), new ILoad(ins, 0), constant1, new IMul(ins), constant2, new IAdd(ins), // result, 0, result
new Dup_X1(ins), constant3, new IMul(ins), new Pop(ins), new Pop(ins), constant4, 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() * constant3.getConstantAsInt() == 1;
assert constant2.getConstantAsInt() * constant4.getConstantAsInt() == 1;
Deobfuscator d = new MultiplicationDeobfuscator();
d.run(group);
Assert.assertEquals(1, constant1.getConstantAsInt());
Assert.assertEquals(1, constant2.getConstantAsInt());
Assert.assertEquals(1, constant3.getConstantAsInt());
Assert.assertEquals(1, constant4.getConstantAsInt());
}
use of net.runelite.asm.attributes.code.instructions.Pop in project runelite by runelite.
the class ExprArgOrderTest method test3.
@Test
public void test3() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
Instruction[] body = { // 512 + (3 + var1) -> var1 + 3 + 512
new LDC(ins, 512), new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new IAdd(ins), new Pop(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
ExprArgOrder exprArgOrder = new ExprArgOrder();
exprArgOrder.run(group);
List<Instruction> instructions = ins.getInstructions();
// 2: iload
// 3: iconst 3
// 4: iadd
// 5: ldc
// 6: add
assertEquals(IADD, instructions.get(4).getType());
assertEquals(IADD, instructions.get(6).getType());
}
use of net.runelite.asm.attributes.code.instructions.Pop in project runelite by runelite.
the class ExprArgOrderTest method test.
@Test
public void test() {
ClassGroup group = ClassGroupFactory.generateGroup();
Code code = group.findClass("test").findMethod("func").getCode();
Instructions ins = code.getInstructions();
code.setMaxStack(2);
// vars[0] = 3
Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0) };
for (Instruction i : prepareVariables) {
ins.addInstruction(i);
}
Instruction[] body = { // 2
new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new Pop(ins), new VReturn(ins) };
for (Instruction i : body) {
ins.addInstruction(i);
}
ExprArgOrder exprArgOrder = new ExprArgOrder();
exprArgOrder.run(group);
List<Instruction> instructions = ins.getInstructions();
assertEquals(ILOAD, instructions.get(2).getType());
assertEquals(LDC, instructions.get(3).getType());
assertEquals(IADD, instructions.get(4).getType());
}
Aggregations