Search in sources :

Example 1 with LStore

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

the class MultiplicationDeobfuscatorTest method test9.

// aload                 0
// aload                 0
// aload                 1
// invokevirtual         class226/method4078()J
// ldc2_w                -81013729583719545
// lmul
// dup2_x1
// ldc2_w                -6236978337732675017
// lmul
// putfield              class227/field3204 J
// ldc2_w                -6236978337732675017
// lmul
// putfield              class227/field3196 J
@Test
public void test9() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(3);
    Instruction[] prepareVariables = { new LDC(ins, 1L), new LStore(ins, 0) };
    for (Instruction i : prepareVariables) {
        ins.addInstruction(i);
    }
    LDC constant1 = new LDC(ins, -81013729583719545L), constant2 = new LDC(ins, -6236978337732675017L), constant3 = new LDC(ins, -6236978337732675017L);
    Instruction[] body = { new LDC(ins, 0), new LLoad(ins, 0), constant1, new LMul(ins), // lmul, 0, lmul
    new Dup2_X1(ins), constant2, new LMul(ins), new Pop(ins), new Pop(ins), constant3, new LMul(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.getConstantAsLong() * constant2.getConstantAsLong() == 1L;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1L, constant1.getConstantAsLong());
    Assert.assertEquals(1L, constant2.getConstantAsLong());
    Assert.assertEquals(1L, constant3.getConstantAsLong());
}
Also used : LLoad(net.runelite.asm.attributes.code.instructions.LLoad) 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) LStore(net.runelite.asm.attributes.code.instructions.LStore) 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) Dup2_X1(net.runelite.asm.attributes.code.instructions.Dup2_X1) ClassGroup(net.runelite.asm.ClassGroup) LMul(net.runelite.asm.attributes.code.instructions.LMul) Test(org.junit.Test)

Example 2 with LStore

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

the class LvtTest method testReuseIndex.

@Test
public void testReuseIndex() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    Instruction[] body = { // var0 = null
    new AConstNull(ins), new AStore(ins, 0), // this forces a reindex to varn
    new LDC(ins, 0), new IStore(ins, 0), // var2 = null
    new AConstNull(ins), new AStore(ins, 2), // this forces a reindex to varn+1
    new LDC(ins, 0), new IStore(ins, 2), // var0 = 0L
    new LDC(ins, 0L), new LStore(ins, 0), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Lvt lvt = new Lvt();
    lvt.run(group);
    AStore astore1 = (AStore) body[1];
    IStore istore1 = (IStore) body[3];
    AStore astore2 = (AStore) body[5];
    IStore istore2 = (IStore) body[7];
    LStore lstore1 = (LStore) body[9];
    int astore1Idx = astore1.getVariableIndex();
    int istore1Idx = istore1.getVariableIndex();
    int astore2Idx = astore2.getVariableIndex();
    int istore2Idx = istore2.getVariableIndex();
    int lstore1Idx = lstore1.getVariableIndex();
    logger.debug("{} -> {}", astore1, astore1.getVariableIndex());
    logger.debug("{} -> {}", istore1, istore1.getVariableIndex());
    logger.debug("{} -> {}", astore2, astore2.getVariableIndex());
    logger.debug("{} -> {}", istore2, istore2.getVariableIndex());
    logger.debug("{} -> {}", lstore1, lstore1.getVariableIndex());
    Assert.assertNotEquals(astore1Idx, istore1Idx);
    Assert.assertNotEquals(astore2Idx, istore2Idx);
    // assert that the lstore doesn't overwrite an existing index
    Assert.assertNotEquals(lstore1Idx + 1, astore1Idx);
    Assert.assertNotEquals(lstore1Idx + 1, istore1Idx);
    Assert.assertNotEquals(lstore1Idx + 1, astore2Idx);
    Assert.assertNotEquals(lstore1Idx + 1, istore2Idx);
}
Also used : IStore(net.runelite.asm.attributes.code.instructions.IStore) 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) LStore(net.runelite.asm.attributes.code.instructions.LStore) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) AStore(net.runelite.asm.attributes.code.instructions.AStore) ClassGroup(net.runelite.asm.ClassGroup) Test(org.junit.Test)

Aggregations

ClassGroup (net.runelite.asm.ClassGroup)2 Code (net.runelite.asm.attributes.Code)2 Instruction (net.runelite.asm.attributes.code.Instruction)2 Instructions (net.runelite.asm.attributes.code.Instructions)2 LDC (net.runelite.asm.attributes.code.instructions.LDC)2 LStore (net.runelite.asm.attributes.code.instructions.LStore)2 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)2 Test (org.junit.Test)2 AConstNull (net.runelite.asm.attributes.code.instructions.AConstNull)1 AStore (net.runelite.asm.attributes.code.instructions.AStore)1 Dup2_X1 (net.runelite.asm.attributes.code.instructions.Dup2_X1)1 IStore (net.runelite.asm.attributes.code.instructions.IStore)1 LLoad (net.runelite.asm.attributes.code.instructions.LLoad)1 LMul (net.runelite.asm.attributes.code.instructions.LMul)1 Pop (net.runelite.asm.attributes.code.instructions.Pop)1 Execution (net.runelite.asm.execution.Execution)1 Deobfuscator (net.runelite.deob.Deobfuscator)1