Search in sources :

Example 1 with LDC

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

the class GetPathTransformer method removeInvoke.

private void removeInvoke(Instruction i) {
    Instructions ins = i.getInstructions();
    int idx = ins.getInstructions().indexOf(i);
    ins.remove(i);
    // pop File
    ins.getInstructions().add(idx, new Pop(ins));
    ins.getInstructions().add(idx + 1, new LDC(ins, ""));
}
Also used : Pop(net.runelite.asm.attributes.code.instructions.Pop) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC)

Example 2 with LDC

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

the class MaxMemoryTransformer method insert.

private void insert(Instructions ins, int idx) {
    Class randomClass = new net.runelite.asm.pool.Class("java/util/Random");
    ins.getInstructions().remove(idx);
    // pop runtime
    ins.getInstructions().add(idx++, new Pop(ins));
    ins.getInstructions().add(idx++, new New(ins, randomClass));
    ins.getInstructions().add(idx++, new Dup(ins));
    // new Random
    ins.getInstructions().add(idx++, new InvokeSpecial(ins, new net.runelite.asm.pool.Method(randomClass, "<init>", new Signature("()V"))));
    ins.getInstructions().add(idx++, new LDC(ins, 31457280));
    // nextInt(31457280)
    ins.getInstructions().add(idx++, new InvokeVirtual(ins, new net.runelite.asm.pool.Method(randomClass, "nextInt", new Signature("(I)I"))));
    ins.getInstructions().add(idx++, new LDC(ins, 230686720));
    // 230686720 + nextInt(31457280)
    ins.getInstructions().add(idx++, new IAdd(ins));
    ins.getInstructions().add(idx++, new I2L(ins));
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) I2L(net.runelite.asm.attributes.code.instructions.I2L) InvokeSpecial(net.runelite.asm.attributes.code.instructions.InvokeSpecial) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) Pop(net.runelite.asm.attributes.code.instructions.Pop) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) Class(net.runelite.asm.pool.Class) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Dup(net.runelite.asm.attributes.code.instructions.Dup)

Example 3 with LDC

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

the class CastNullTest method testRun.

@Test
public void testRun() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(3);
    CheckCast checkCast = new CheckCast(ins);
    checkCast.setType(new Type("test"));
    Instruction[] instructions = { new LDC(ins, 2), new AConstNull(ins), checkCast, new LDC(ins, 2), new IAdd(ins), new Return(ins, InstructionType.IRETURN) };
    for (Instruction i : instructions) {
        ins.addInstruction(i);
    }
    Assert.assertEquals(6, ins.getInstructions().size());
    CastNull lvt = new CastNull();
    lvt.run(group);
    Assert.assertEquals(5, ins.getInstructions().size());
    Optional<Instruction> o = ins.getInstructions().stream().filter(i -> i instanceof CheckCast).findAny();
    Assert.assertFalse(o.isPresent());
}
Also used : AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) InstructionType(net.runelite.asm.attributes.code.InstructionType) Code(net.runelite.asm.attributes.Code) Test(org.junit.Test) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) ClassGroupFactory(net.runelite.deob.ClassGroupFactory) LDC(net.runelite.asm.attributes.code.instructions.LDC) Return(net.runelite.asm.attributes.code.instructions.Return) Instructions(net.runelite.asm.attributes.code.Instructions) CheckCast(net.runelite.asm.attributes.code.instructions.CheckCast) Optional(java.util.Optional) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) Assert(org.junit.Assert) Return(net.runelite.asm.attributes.code.instructions.Return) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) CheckCast(net.runelite.asm.attributes.code.instructions.CheckCast) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) InstructionType(net.runelite.asm.attributes.code.InstructionType) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 4 with LDC

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

the class SimpleModArithTest method checkConstants.

private void checkConstants(ClassFile cf) {
    for (Method m : cf.getMethods()) {
        Code code = m.getCode();
        Instructions instructions = code.getInstructions();
        for (Instruction i : instructions.getInstructions()) {
            if (i instanceof LDC) {
                LDC ldc = (LDC) i;
                Integer value = (Integer) ldc.getConstantAsInt();
                assertFalse(isBig(value));
            }
        }
    }
}
Also used : Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 5 with LDC

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

the class ExprArgOrderTest method test2.

@Test
public void test2() {
    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 ILoad(ins, 0), new LDC(ins, 3), new IAdd(ins), new Pop(ins), // 6
    new LDC(ins, 3), new ILoad(ins, 0), new IAdd(ins), new SiPush(ins, (short) 512), 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();
    // ensure this stays the same
    assertEquals(ILOAD, instructions.get(2).getType());
    assertEquals(LDC, instructions.get(3).getType());
    assertEquals(IADD, instructions.get(4).getType());
    // 
    assertEquals(ILOAD, instructions.get(6).getType());
    assertEquals(SIPUSH, instructions.get(7).getType());
    assertEquals(IADD, instructions.get(8).getType());
    assertEquals(LDC, instructions.get(9).getType());
    assertEquals(IADD, instructions.get(10).getType());
}
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) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.InstructionType.LDC) 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) Pop(net.runelite.asm.attributes.code.instructions.Pop) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Aggregations

LDC (net.runelite.asm.attributes.code.instructions.LDC)46 Instruction (net.runelite.asm.attributes.code.Instruction)39 Instructions (net.runelite.asm.attributes.code.Instructions)38 Code (net.runelite.asm.attributes.Code)32 ClassGroup (net.runelite.asm.ClassGroup)29 Test (org.junit.Test)27 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)26 IMul (net.runelite.asm.attributes.code.instructions.IMul)23 IStore (net.runelite.asm.attributes.code.instructions.IStore)23 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)22 Deobfuscator (net.runelite.deob.Deobfuscator)20 Execution (net.runelite.asm.execution.Execution)19 IAdd (net.runelite.asm.attributes.code.instructions.IAdd)14 Pop (net.runelite.asm.attributes.code.instructions.Pop)13 Method (net.runelite.asm.Method)11 Type (net.runelite.asm.Type)10 Label (net.runelite.asm.attributes.code.Label)10 Field (net.runelite.asm.Field)9 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)9 Signature (net.runelite.asm.signature.Signature)8