Search in sources :

Example 1 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class ArrayStore method map.

@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
    assert ctx.getInstruction().getClass() == other.getInstruction().getClass();
    Field myField = this.getMyField(ctx), otherField = ((ArrayStore) other.getInstruction()).getMyField(other);
    mapping.map(this, myField, otherField);
    // map value
    StackContext // value set to.
    object1 = ctx.getPops().get(0), object2 = other.getPops().get(0);
    InstructionContext base1 = MappingExecutorUtil.resolve(object1.getPushed(), object1);
    InstructionContext base2 = MappingExecutorUtil.resolve(object2.getPushed(), object2);
    if (base1.getInstruction() instanceof GetFieldInstruction && base2.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction gf1 = (GetFieldInstruction) base1.getInstruction(), gf2 = (GetFieldInstruction) base2.getInstruction();
        Field f1 = gf1.getMyField(), f2 = gf2.getMyField();
        assert MappingExecutorUtil.isMaybeEqual(f1, f2);
        if (f1 != null && f2 != null) {
            mapping.map(this, f1, f2);
        }
    }
}
Also used : Field(net.runelite.asm.Field) InstructionContext(net.runelite.asm.execution.InstructionContext) StackContext(net.runelite.asm.execution.StackContext) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 2 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class SubtractionInstruction method map.

@Override
default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) {
    StackContext s1 = ctx.getPops().get(0), s2 = ctx.getPops().get(1);
    StackContext o1 = other.getPops().get(0), o2 = other.getPops().get(1);
    InstructionContext i1 = MappingExecutorUtil.resolve(s1.getPushed(), s1);
    InstructionContext i2 = MappingExecutorUtil.resolve(s2.getPushed(), s2);
    InstructionContext io1 = MappingExecutorUtil.resolve(o1.getPushed(), o1);
    InstructionContext io2 = MappingExecutorUtil.resolve(o2.getPushed(), o2);
    if (i1.getInstruction() instanceof GetFieldInstruction && io1.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction f1 = (GetFieldInstruction) i1.getInstruction();
        GetFieldInstruction f2 = (GetFieldInstruction) io1.getInstruction();
        Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
        assert MappingExecutorUtil.isMaybeEqual(fi1, fi2);
        if (fi1 != null && fi2 != null) {
            mappings.map((Instruction) this, fi1, fi2);
        }
    }
    if (i2.getInstruction() instanceof GetFieldInstruction && io2.getInstruction() instanceof GetFieldInstruction) {
        GetFieldInstruction f1 = (GetFieldInstruction) i2.getInstruction();
        GetFieldInstruction f2 = (GetFieldInstruction) io2.getInstruction();
        Field fi1 = f1.getMyField(), fi2 = f2.getMyField();
        assert MappingExecutorUtil.isMaybeEqual(fi1, fi2);
        if (fi1 != null && fi2 != null) {
            mappings.map((Instruction) this, fi1, fi2);
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext)

Example 3 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class AdditionInstruction method map.

@Override
default void map(ParallelExecutorMapping mappings, InstructionContext ctx, InstructionContext other) {
    /* lhs/rhs of addition instructions are randomally swapped, but
		 * we still map if each side is recognizable
		 *
		 * N.B. since the lhs/rhs of nested iadds can be swapped, and
		 * the mapper maps the first that it encounters, this can certainly
		 * attempt to map the wrong instructions even when mapping the correct
		 * method, so be careful.
		 */
    StackContext ctx1 = ctx.getPops().get(0);
    StackContext ctx2 = ctx.getPops().get(1);
    StackContext other1 = other.getPops().get(0);
    StackContext other2 = other.getPops().get(1);
    InstructionContext rc1 = ctx1.getPushed().resolve(ctx1);
    // iaload
    InstructionContext rc2 = ctx2.getPushed().resolve(ctx2);
    InstructionContext ro1 = other1.getPushed().resolve(other1);
    // iaload
    InstructionContext ro2 = other2.getPushed().resolve(other2);
    // There are a couple static final arrays that are only ever read from 1 or 2 places.. and never written
    InstructionContext al1 = findArrayLoad(rc1, rc2);
    InstructionContext al2 = findArrayLoad(ro1, ro2);
    if (al1 == null || al2 == null) {
        return;
    }
    StackContext array1 = al1.getPops().get(1);
    StackContext array2 = al2.getPops().get(1);
    InstructionContext field1 = array1.getPushed().resolve(array1);
    InstructionContext field2 = array2.getPushed().resolve(array2);
    if (!(field1.getInstruction() instanceof GetFieldInstruction) || !(field2.getInstruction() instanceof GetFieldInstruction)) {
        return;
    }
    GetFieldInstruction gf1 = (GetFieldInstruction) field1.getInstruction();
    GetFieldInstruction gf2 = (GetFieldInstruction) field2.getInstruction();
    Field f1 = gf1.getMyField();
    Field f2 = gf2.getMyField();
    if (f1 == null || f2 == null || !MappingExecutorUtil.isMaybeEqual(f1, f2)) {
        return;
    }
    mappings.map((Instruction) this, f1, f2);
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Field(net.runelite.asm.Field) StackContext(net.runelite.asm.execution.StackContext)

Example 4 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class RuneliteBufferTransformer method injectRunelitePacket.

/**
 * inject RUNELITE_PACKET field
 *
 * @param group
 */
private void injectRunelitePacket(ClassGroup group) {
    ClassFile client = findClient(group);
    assert client != null : "no client class";
    if (client.findField(RUNELITE_PACKET) != null) {
        return;
    }
    Field field = new Field(client, RUNELITE_PACKET, Type.BOOLEAN);
    field.setAccessFlags(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC);
    client.addField(field);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile)

Example 5 with Field

use of net.runelite.asm.Field in project runelite by runelite.

the class BufferMethodInjector method inject.

private void inject(ClassFile bufferClass, Field field) {
    Field newField = new Field(bufferClass, field.getName(), field.getType());
    newField.setAccessFlags(field.getAccessFlags());
    newField.setValue(field.getValue());
    bufferClass.addField(newField);
}
Also used : Field(net.runelite.asm.Field)

Aggregations

Field (net.runelite.asm.Field)65 ClassFile (net.runelite.asm.ClassFile)39 Method (net.runelite.asm.Method)33 Instruction (net.runelite.asm.attributes.code.Instruction)19 InstructionContext (net.runelite.asm.execution.InstructionContext)19 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)17 Instructions (net.runelite.asm.attributes.code.Instructions)16 StackContext (net.runelite.asm.execution.StackContext)16 Type (net.runelite.asm.Type)15 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)11 Code (net.runelite.asm.attributes.Code)10 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)10 Signature (net.runelite.asm.signature.Signature)9 ClassGroup (net.runelite.asm.ClassGroup)8 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)8 PutField (net.runelite.asm.attributes.code.instructions.PutField)8 Test (org.junit.Test)8 List (java.util.List)7 Annotation (net.runelite.asm.attributes.annotation.Annotation)7