Search in sources :

Example 6 with IfEq

use of net.runelite.asm.attributes.code.instructions.IfEq 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 7 with IfEq

use of net.runelite.asm.attributes.code.instructions.IfEq 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 8 with IfEq

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

the class PacketWriteDeobfuscator method insert.

private void insert(ClassGroup group, PacketWrite write) {
    Instructions instructions = write.putOpcode.getInstruction().getInstructions();
    List<Instruction> ins = instructions.getInstructions();
    InstructionContext firstWrite = write.writes.get(0);
    InstructionContext lastWrite = write.writes.get(write.writes.size() - 1);
    int idx = ins.indexOf(lastWrite.getInstruction());
    assert idx != -1;
    // past write
    ++idx;
    Label afterWrites = instructions.createLabelFor(ins.get(idx));
    // pops arg, getfield
    InstructionContext beforeFirstWrite = firstWrite.getPops().get(1).getPushed();
    Label putOpcode = instructions.createLabelFor(beforeFirstWrite.getInstruction(), true);
    idx = ins.indexOf(beforeFirstWrite.getInstruction());
    assert idx != -1;
    --idx;
    net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(findClient(group).getName()), RUNELITE_PACKET, Type.BOOLEAN);
    instructions.addInstruction(idx++, new GetStatic(instructions, field));
    instructions.addInstruction(idx++, new IfEq(instructions, putOpcode));
    Instruction before = ins.get(idx);
    for (InstructionContext ctx : write.writes) {
        insert(instructions, ctx, before);
    }
    idx = ins.indexOf(before);
    instructions.addInstruction(idx++, new Goto(instructions, afterWrites));
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Goto(net.runelite.asm.attributes.code.instructions.Goto) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) IfEq(net.runelite.asm.attributes.code.instructions.IfEq) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) ReturnInstruction(net.runelite.asm.attributes.code.instruction.types.ReturnInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

Aggregations

Instruction (net.runelite.asm.attributes.code.Instruction)8 Instructions (net.runelite.asm.attributes.code.Instructions)8 Label (net.runelite.asm.attributes.code.Label)8 IfEq (net.runelite.asm.attributes.code.instructions.IfEq)8 Code (net.runelite.asm.attributes.Code)6 LDC (net.runelite.asm.attributes.code.instructions.LDC)6 ClassGroup (net.runelite.asm.ClassGroup)5 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)5 IMul (net.runelite.asm.attributes.code.instructions.IMul)5 IStore (net.runelite.asm.attributes.code.instructions.IStore)5 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)5 Execution (net.runelite.asm.execution.Execution)5 Deobfuscator (net.runelite.deob.Deobfuscator)5 Test (org.junit.Test)5 Goto (net.runelite.asm.attributes.code.instructions.Goto)4 GetStatic (net.runelite.asm.attributes.code.instructions.GetStatic)3 Field (net.runelite.asm.Field)2 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)2 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)2 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)2