Search in sources :

Example 1 with Dup_X1

use of net.runelite.asm.attributes.code.instructions.Dup_X1 in project runelite by runelite.

the class MultiplicationDeobfuscatorTest method test1.

// aload                 2
// ldc_w                 1587543155
// iload                 4
// imul
// dup_x1
// ldc_w                 -2130376517
// imul
// putfield              class2/field279 I
// ldc_w                 -67313687
// imul
// putstatic             class29/field949 I
@Test
public void test1() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(5);
    // 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, 1587543155), constant2 = new LDC(ins, -2130376517), constant3 = new LDC(ins, -67313687);
    Instruction[] body = { // for dup_x1 to place before this
    new LDC(ins, 0), constant1, new ILoad(ins, 0), new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), new Pop(ins), new Pop(ins), constant3, new IMul(ins), new Pop(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
    assert constant1.getConstantAsInt() * constant3.getConstantAsInt() == -1_095_175_765;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
    Assert.assertEquals(-1_095_175_765, 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) Pop(net.runelite.asm.attributes.code.instructions.Pop) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 2 with Dup_X1

use of net.runelite.asm.attributes.code.instructions.Dup_X1 in project runelite by runelite.

the class DupDeobfuscator method undup_x1.

private void undup_x1(InstructionContext ictx) {
    assert ictx.getInstruction() instanceof Dup_X1;
    Instructions instructions = ictx.getInstruction().getInstructions();
    StackContext duplicated = ictx.getPops().get(0);
    // replace dup_x1 with swap
    int idx = instructions.replace(ictx.getInstruction(), new Swap(instructions));
    // copy imul and insert after idx
    copy(duplicated, instructions, idx + 1);
}
Also used : Swap(net.runelite.asm.attributes.code.instructions.Swap) StackContext(net.runelite.asm.execution.StackContext) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) Instructions(net.runelite.asm.attributes.code.Instructions)

Example 3 with Dup_X1

use of net.runelite.asm.attributes.code.instructions.Dup_X1 in project runelite by runelite.

the class DupDeobfuscatorTest method test.

@Test
public void test() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(5);
    Instruction[] prepareVariables = { new LDC(ins, 1), new IStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    LDC constant1 = new LDC(ins, 1129258489), constant2 = new LDC(ins, -1692330935), constant3 = new LDC(ins, 1641298955), constant4 = new LDC(ins, 1043501435);
    Instruction[] body = { // this
    new AConstNull(ins), // this
    new AConstNull(ins), new ILoad(ins, 0), constant1, new IMul(ins), new Dup_X1(ins), constant2, new IMul(ins), // putfield
    new Pop2(ins), constant3, new IMul(ins), constant4, new IMul(ins), // putfield
    new Pop2(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;
    assert constant3.getConstantAsInt() * constant4.getConstantAsInt() * constant1.getConstantAsInt() == 1;
    Deobfuscator d = new DupDeobfuscator();
    d.run(group);
    // assert the dup_x1 was removed
    long dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup_X1).count();
    Assert.assertEquals(0, dupCount);
}
Also used : Pop2(net.runelite.asm.attributes.code.instructions.Pop2) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) GetField(net.runelite.asm.attributes.code.instructions.GetField) IMul(net.runelite.asm.attributes.code.instructions.IMul) Dup(net.runelite.asm.attributes.code.instructions.Dup) Code(net.runelite.asm.attributes.Code) Test(org.junit.Test) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Class(net.runelite.asm.pool.Class) ClassGroupFactory(net.runelite.deob.ClassGroupFactory) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) LDC(net.runelite.asm.attributes.code.instructions.LDC) IStore(net.runelite.asm.attributes.code.instructions.IStore) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Instructions(net.runelite.asm.attributes.code.Instructions) Field(net.runelite.asm.pool.Field) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) Assert(org.junit.Assert) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IStore(net.runelite.asm.attributes.code.instructions.IStore) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Pop2(net.runelite.asm.attributes.code.instructions.Pop2) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) 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) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 4 with Dup_X1

use of net.runelite.asm.attributes.code.instructions.Dup_X1 in project runelite by runelite.

the class DupDeobfuscatorTest method test2.

// 035   aload_0               // this
// 036   dup                   // this this
// 037   getfield              class153/field2097 I // this I
// 038   ldc                   830083863
// 039   imul                                      // this I
// 040   ldc                   830083863
// 041   iadd                                      // this I
// 042   dup_x1                                    // I this I
@Test
public void test2() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(3);
    Instruction[] body = { // this
    new AConstNull(ins), // this this
    new Dup(ins), new GetField(ins, new Field(new Class("test"), "field", Type.INT)), // this this I I
    new LDC(ins, 830083863), // this this I
    new IMul(ins), new LDC(ins, 830083863), new IAdd(ins), new Dup_X1(ins), new LDC(ins, 636900519), // pops dup
    new IMul(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new DupDeobfuscator();
    d.run(group);
    // assert the dup wasn't duplicated
    long dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup).count();
    Assert.assertEquals(1, dupCount);
    // assert the dup_x1 was removed
    dupCount = ins.getInstructions().stream().filter(i -> i instanceof Dup_X1).count();
    Assert.assertEquals(0, dupCount);
}
Also used : Pop2(net.runelite.asm.attributes.code.instructions.Pop2) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) GetField(net.runelite.asm.attributes.code.instructions.GetField) IMul(net.runelite.asm.attributes.code.instructions.IMul) Dup(net.runelite.asm.attributes.code.instructions.Dup) Code(net.runelite.asm.attributes.Code) Test(org.junit.Test) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Class(net.runelite.asm.pool.Class) ClassGroupFactory(net.runelite.deob.ClassGroupFactory) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) LDC(net.runelite.asm.attributes.code.instructions.LDC) IStore(net.runelite.asm.attributes.code.instructions.IStore) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Instructions(net.runelite.asm.attributes.code.Instructions) Field(net.runelite.asm.pool.Field) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) Assert(org.junit.Assert) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) GetField(net.runelite.asm.attributes.code.instructions.GetField) Instructions(net.runelite.asm.attributes.code.Instructions) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) 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) GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.pool.Field) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Class(net.runelite.asm.pool.Class) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Dup(net.runelite.asm.attributes.code.instructions.Dup) Test(org.junit.Test)

Example 5 with Dup_X1

use of net.runelite.asm.attributes.code.instructions.Dup_X1 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());
}
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) Pop(net.runelite.asm.attributes.code.instructions.Pop) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) Dup_X1(net.runelite.asm.attributes.code.instructions.Dup_X1) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Aggregations

Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)8 Instructions (net.runelite.asm.attributes.code.Instructions)7 IMul (net.runelite.asm.attributes.code.instructions.IMul)7 ClassGroup (net.runelite.asm.ClassGroup)6 Code (net.runelite.asm.attributes.Code)6 Instruction (net.runelite.asm.attributes.code.Instruction)6 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)6 IStore (net.runelite.asm.attributes.code.instructions.IStore)6 LDC (net.runelite.asm.attributes.code.instructions.LDC)6 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)6 Execution (net.runelite.asm.execution.Execution)6 Deobfuscator (net.runelite.deob.Deobfuscator)6 Test (org.junit.Test)6 AConstNull (net.runelite.asm.attributes.code.instructions.AConstNull)3 Dup (net.runelite.asm.attributes.code.instructions.Dup)3 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)3 Pop (net.runelite.asm.attributes.code.instructions.Pop)3 Pop2 (net.runelite.asm.attributes.code.instructions.Pop2)3 Type (net.runelite.asm.Type)2 GetField (net.runelite.asm.attributes.code.instructions.GetField)2