Search in sources :

Example 16 with Deobfuscator

use of net.runelite.deob.Deobfuscator in project runelite by runelite.

the class MultiplicationDeobfuscatorTest method test8.

@Test
public void test8() {
    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) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    LDC constant1 = new LDC(ins, -1616202347);
    LDC constant2 = new LDC(ins, 2747837);
    Label label1 = new Label(ins), label2 = new Label(ins), label3 = new Label(ins);
    Instruction[] body = { constant1, constant2, new IMul(ins), new ILoad(ins, 0), new LDC(ins, 42), new IfEq(ins, label1), new Goto(ins, label2), label1, new LDC(ins, -1), new Goto(ins, label3), label2, new LDC(ins, 0), new Goto(ins, label3), label3, new InvokeStatic(ins, group.findClass("test").findMethod("func2").getPoolMethod()), 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());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) Goto(net.runelite.asm.attributes.code.instructions.Goto) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) InvokeStatic(net.runelite.asm.attributes.code.instructions.InvokeStatic) Test(org.junit.Test)

Example 17 with Deobfuscator

use of net.runelite.deob.Deobfuscator in project runelite by runelite.

the class MultiplicationDeobfuscatorTest method test5.

@Test
public void test5() {
    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, -2079217519), constant2 = new LDC(ins, -2079217519), constant3 = new LDC(ins, 561453169);
    Instruction[] body = { new ILoad(ins, 0), constant1, new IMul(ins), new IStore(ins, 2), new ILoad(ins, 2), new ILoad(ins, 1), constant2, new IMul(ins), new IAdd(ins), constant3, 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;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
    Assert.assertEquals(1, constant3.getConstantAsInt());
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 18 with Deobfuscator

use of net.runelite.deob.Deobfuscator in project runelite by runelite.

the class MultiplyOneDeobfuscatorTest 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);
    Label label = new Label(ins), label2 = new Label(ins);
    LDC one = new LDC(ins, 1);
    IMul mul = new IMul(ins);
    Instruction[] body = { new SiPush(ins, (short) 256), new ILoad(ins, 0), new IfEq(ins, label), label, one, label2, mul, new VReturn(ins) };
    for (Instruction i : body) ins.addInstruction(i);
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new MultiplyOneDeobfuscator(false);
    d.run(group);
    Assert.assertTrue(one.getInstructions() == null);
    Assert.assertTrue(mul.getInstructions() == null);
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 19 with Deobfuscator

use of net.runelite.deob.Deobfuscator in project runelite by runelite.

the class MultiplyOneDeobfuscatorTest method testDir.

@Test
public void testDir() {
    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);
    Label label = new Label(ins), label2 = new Label(ins);
    LDC one = new LDC(ins, 1);
    Instruction[] body = { new SiPush(ins, (short) 256), new ILoad(ins, 0), new IfEq(ins, label), new LDC(ins, 2), new Goto(ins, label2), label, one, label2, new IMul(ins), new VReturn(ins) };
    for (Instruction i : body) ins.addInstruction(i);
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new MultiplyOneDeobfuscator(false);
    d.run(group);
    Assert.assertTrue(one.getInstructions() != null);
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) IStore(net.runelite.asm.attributes.code.instructions.IStore) Goto(net.runelite.asm.attributes.code.instructions.Goto) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 20 with Deobfuscator

use of net.runelite.deob.Deobfuscator in project runelite by runelite.

the class SimpleModArithTest method test2.

@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 = ClassUtil.loadClass(in);
    group.addClass(cf);
    ModArith d1 = new ModArith();
    d1.run(group);
    d1.runOnce();
    Deobfuscator d2 = new MultiplicationDeobfuscator();
    d2.run(group);
    Encryption e = d1.getEncryption();
    Pair pair = e.getField(cf.findField("field2863").getPoolField());
    Assert.assertEquals(378529589, (int) pair.getter);
}
Also used : ClassFile(net.runelite.asm.ClassFile) InputStream(java.io.InputStream) ClassGroup(net.runelite.asm.ClassGroup) Deobfuscator(net.runelite.deob.Deobfuscator) Test(org.junit.Test)

Aggregations

ClassGroup (net.runelite.asm.ClassGroup)20 Deobfuscator (net.runelite.deob.Deobfuscator)20 Test (org.junit.Test)20 Code (net.runelite.asm.attributes.Code)18 Instruction (net.runelite.asm.attributes.code.Instruction)18 Instructions (net.runelite.asm.attributes.code.Instructions)18 LDC (net.runelite.asm.attributes.code.instructions.LDC)18 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)18 Execution (net.runelite.asm.execution.Execution)18 IMul (net.runelite.asm.attributes.code.instructions.IMul)17 IStore (net.runelite.asm.attributes.code.instructions.IStore)16 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)15 Pop (net.runelite.asm.attributes.code.instructions.Pop)7 Label (net.runelite.asm.attributes.code.Label)6 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)6 IfEq (net.runelite.asm.attributes.code.instructions.IfEq)5 AConstNull (net.runelite.asm.attributes.code.instructions.AConstNull)4 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)4 Pop2 (net.runelite.asm.attributes.code.instructions.Pop2)4 Goto (net.runelite.asm.attributes.code.instructions.Goto)3