Search in sources :

Example 1 with FieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.

the class BufferMethodInjector method inject.

private void inject(ClassFile bufferClass, Method method) {
    assert method.getExceptions().getExceptions().isEmpty();
    Method newMethod = new Method(bufferClass, method.getName(), method.getDescriptor());
    Code code = new Code(newMethod);
    newMethod.setCode(code);
    method.getCode().getInstructions().getInstructions().stream().forEach(i -> {
        if (!(i instanceof Label)) {
            i = i.clone();
        }
        if (i instanceof FieldInstruction) {
            FieldInstruction fi = (FieldInstruction) i;
            if (fi.getField().getName().equals("offset")) {
                fi.setField(bp.getOffset().getPoolField());
            } else if (fi.getField().getName().equals("payload")) {
                fi.setField(bp.getBuffer().getPoolField());
            } else if (fi.getField().getName().equals("runeliteLengthOffset")) {
                fi.setField(bufferClass.findField("runeliteLengthOffset").getPoolField());
            }
        }
        i.setInstructions(code.getInstructions());
        code.getInstructions().addInstruction(i);
    });
    code.getExceptions().getExceptions().addAll(method.getCode().getExceptions().getExceptions());
    bufferClass.addMethod(newMethod);
}
Also used : Label(net.runelite.asm.attributes.code.Label) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) Code(net.runelite.asm.attributes.Code)

Example 2 with FieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.

the class FieldInliner method findFieldIns.

private void findFieldIns() {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null)
                continue;
            for (Instruction i : code.getInstructions().getInstructions()) {
                if (!(i instanceof FieldInstruction))
                    continue;
                FieldInstruction sf = (FieldInstruction) i;
                if (sf.getMyField() == null)
                    continue;
                fieldInstructions.put(sf.getMyField(), sf);
            }
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 3 with FieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.

the class FieldInliner method inlineUse.

public int inlineUse() {
    int count = 0;
    for (Field f : fields) {
        // replace getfield with constant push
        List<FieldInstruction> fins = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof GetFieldInstruction).collect(Collectors.toList());
        Object value = f.getValue();
        for (FieldInstruction fin : fins) {
            // remove fin, add push constant
            Instruction i = (Instruction) fin;
            Instruction pushIns = new LDC(i.getInstructions(), value);
            List<Instruction> instructions = i.getInstructions().getInstructions();
            int idx = instructions.indexOf(i);
            assert idx != -1;
            i.getInstructions().remove(i);
            instructions.add(idx, pushIns);
            ++count;
        }
        f.getClassFile().removeField(f);
    }
    return count;
}
Also used : Logger(org.slf4j.Logger) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Field(net.runelite.asm.Field) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) LoggerFactory(org.slf4j.LoggerFactory) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Code(net.runelite.asm.attributes.Code) Multimap(com.google.common.collect.Multimap) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) HashMultimap(com.google.common.collect.HashMultimap) Method(net.runelite.asm.Method) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) Field(net.runelite.asm.Field) LDC(net.runelite.asm.attributes.code.instructions.LDC) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 4 with FieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.

the class FieldInliner method makeConstantValues.

private void makeConstantValues() {
    for (ClassFile cf : group.getClasses()) {
        for (Field f : cf.getFields()) {
            if (!f.isStatic() || !f.getType().equals(Type.STRING))
                continue;
            Object constantValue = f.getValue();
            if (constantValue != null)
                continue;
            List<FieldInstruction> sfis = fieldInstructions.get(f).stream().filter(f2 -> f2 instanceof SetFieldInstruction).collect(Collectors.toList());
            if (sfis.size() != 1)
                continue;
            SetFieldInstruction sfi = (SetFieldInstruction) sfis.get(0);
            Instruction ins = (Instruction) sfi;
            Method mOfSet = ins.getInstructions().getCode().getMethod();
            if (!mOfSet.getName().equals("<clinit>"))
                continue;
            // get prev instruction and change to a constant value
            Instructions instructions = mOfSet.getCode().getInstructions();
            int idx = instructions.getInstructions().indexOf(ins);
            assert idx != -1;
            Instruction prev = instructions.getInstructions().get(idx - 1);
            if (!(prev instanceof PushConstantInstruction))
                continue;
            PushConstantInstruction pci = (PushConstantInstruction) prev;
            constantValue = pci.getConstant();
            f.setValue(constantValue);
            fields.add(f);
            boolean b = instructions.getInstructions().remove(prev);
            assert b;
            b = instructions.getInstructions().remove(ins);
            assert b;
        }
    }
}
Also used : Logger(org.slf4j.Logger) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Field(net.runelite.asm.Field) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) LoggerFactory(org.slf4j.LoggerFactory) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Code(net.runelite.asm.attributes.Code) Multimap(com.google.common.collect.Multimap) Type(net.runelite.asm.Type) Deobfuscator(net.runelite.deob.Deobfuscator) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) HashMultimap(com.google.common.collect.HashMultimap) Method(net.runelite.asm.Method) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) ClassFile(net.runelite.asm.ClassFile) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Field(net.runelite.asm.Field) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 5 with FieldInstruction

use of net.runelite.asm.attributes.code.instruction.types.FieldInstruction in project runelite by runelite.

the class CodeVisitor method visitFieldInsn.

@Override
public void visitFieldInsn(int opcode, String owner, String name, String desc) {
    FieldInstruction i = (FieldInstruction) createInstructionFromOpcode(opcode);
    Field field = new Field(new net.runelite.asm.pool.Class(owner), name, new Type(desc));
    i.setField(field);
}
Also used : Field(net.runelite.asm.pool.Field) InstructionType(net.runelite.asm.attributes.code.InstructionType) Type(net.runelite.asm.Type) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction)

Aggregations

FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)7 Method (net.runelite.asm.Method)5 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)5 Field (net.runelite.asm.Field)4 Type (net.runelite.asm.Type)4 Code (net.runelite.asm.attributes.Code)4 Instruction (net.runelite.asm.attributes.code.Instruction)4 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)4 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)4 ClassFile (net.runelite.asm.ClassFile)3 LDC (net.runelite.asm.attributes.code.instructions.LDC)3 HashMultimap (com.google.common.collect.HashMultimap)2 Multimap (com.google.common.collect.Multimap)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassGroup (net.runelite.asm.ClassGroup)2 Instructions (net.runelite.asm.attributes.code.Instructions)2 Deobfuscator (net.runelite.deob.Deobfuscator)2 Logger (org.slf4j.Logger)2