Search in sources :

Example 1 with ClassFile

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

the class OpcodesTransformer method transform.

@Override
public void transform(ClassGroup group) {
    ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
    if (runeliteOpcodes == null) {
        runeliteOpcodes = new ClassFile(group);
        runeliteOpcodes.setName(RUNELITE_OPCODES);
        runeliteOpcodes.setSuperName(Type.OBJECT.getInternalName());
        runeliteOpcodes.setAccess(Opcodes.ACC_PUBLIC);
        group.addClass(runeliteOpcodes);
    } else {
        runeliteOpcodes.getFields().clear();
    }
    Method clinit = runeliteOpcodes.findMethod("<clinit>");
    if (clinit == null) {
        clinit = new Method(runeliteOpcodes, "<clinit>", new Signature("()V"));
        clinit.setStatic();
        Code code = new Code(clinit);
        code.setMaxStack(1);
        clinit.setCode(code);
        runeliteOpcodes.addMethod(clinit);
        Instructions instructions = code.getInstructions();
        instructions.addInstruction(new VReturn(instructions));
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn)

Example 2 with ClassFile

use of net.runelite.asm.ClassFile 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 3 with ClassFile

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

the class ParallelExecutorMapping method mapClass.

private void mapClass(StaticInitializerIndexer staticIndexer1, StaticInitializerIndexer staticIndexer2, Object one, Object two) {
    ClassFile cf1, cf2;
    if (one instanceof Field || two instanceof Field) {
        assert one instanceof Field;
        assert two instanceof Field;
        Field f1 = (Field) one;
        Field f2 = (Field) two;
        assert f1.isStatic() == f2.isStatic();
        if (staticIndexer1.isStatic(f1) && staticIndexer2.isStatic(f2)) {
            logger.debug("Mapping class of {} -> {} due to static initializer", f1, f2);
        } else if (f1.isStatic() || f2.isStatic()) {
            return;
        }
        cf1 = f1.getClassFile();
        cf2 = f2.getClassFile();
    } else if (one instanceof Method || two instanceof Method) {
        assert one instanceof Method;
        assert two instanceof Method;
        Method m1 = (Method) one;
        Method m2 = (Method) two;
        assert m1.isStatic() == m1.isStatic();
        if (m1.isStatic() || m2.isStatic()) {
            return;
        }
        cf1 = m1.getClassFile();
        cf2 = m2.getClassFile();
    } else {
        assert false;
        return;
    }
    belongs(cf1, group);
    belongs(cf2, group2);
    Mapping m = getMapping(cf1, cf2);
    m.inc();
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 4 with ClassFile

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

the class ParallelExecutorMapping method buildClasses.

public void buildClasses() {
    for (Object o : new HashSet<>(map.keySet())) {
        if (o instanceof ClassFile) {
            map.removeAll(o);
        }
    }
    StaticInitializerIndexer staticIndexer1 = new StaticInitializerIndexer(group);
    staticIndexer1.index();
    StaticInitializerIndexer staticIndexer2 = new StaticInitializerIndexer(group2);
    staticIndexer2.index();
    Map<Object, Object> map = getMap();
    for (Object key : map.keySet()) {
        Object value = map.get(key);
        mapClass(staticIndexer1, staticIndexer2, key, value);
    }
    // rebuild map now we've inserted classes...
    map = getMap();
    reduce();
    /* get leftover classes, they usually contain exclusively static
		 * fields and methods so they're hard to pinpoint
		 */
    ClassGroupMapper m = new ClassGroupMapper(group, group2);
    m.map();
    for (ClassFile cf : group.getClasses()) {
        if (!map.containsKey(cf)) {
            ClassFile other = m.get(cf);
            if (other == null) {
                logger.info("Unable to map class {}", cf);
            } else {
                // these are both probably very small
                long nonStaticFields = cf.getFields().stream().filter(f -> !f.isStatic()).count(), nonStaticMethods = cf.getMethods().stream().filter(m2 -> !m2.isStatic()).count();
                logger.info("Build classes fallback {} -> {}, non static fields: {}, non static methods: {}", cf, other, nonStaticFields, nonStaticMethods);
                Mapping ma = getMapping(cf, other);
                ma.inc();
            }
        }
    }
}
Also used : Logger(org.slf4j.Logger) Collection(java.util.Collection) Field(net.runelite.asm.Field) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) HashSet(java.util.HashSet) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) HashMultimap(com.google.common.collect.HashMultimap) Method(net.runelite.asm.Method) Map(java.util.Map) Entry(java.util.Map.Entry) Instruction(net.runelite.asm.attributes.code.Instruction) Collections(java.util.Collections) ClassFile(net.runelite.asm.ClassFile) HashSet(java.util.HashSet)

Example 5 with ClassFile

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

the class PacketTypeFinder method find.

public void find() {
    for (ClassFile cf : group.getClasses()) {
        for (Method method : cf.getMethods()) {
            run(method.getCode());
        }
    }
    packetType = sets.entrySet().stream().max((entry1, entry2) -> Integer.compare(entry1.getValue(), entry2.getValue())).get().getKey();
    logger.info("Identified {} as packetType", packetType);
}
Also used : Logger(org.slf4j.Logger) InstructionType(net.runelite.asm.attributes.code.InstructionType) 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) HashMap(java.util.HashMap) Code(net.runelite.asm.attributes.Code) ClassGroup(net.runelite.asm.ClassGroup) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Map(java.util.Map) Instructions(net.runelite.asm.attributes.code.Instructions) Objects(com.google.common.base.Objects) Instruction(net.runelite.asm.attributes.code.Instruction) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Aggregations

ClassFile (net.runelite.asm.ClassFile)103 Method (net.runelite.asm.Method)62 Field (net.runelite.asm.Field)39 ClassGroup (net.runelite.asm.ClassGroup)32 Code (net.runelite.asm.attributes.Code)21 Instruction (net.runelite.asm.attributes.code.Instruction)18 Test (org.junit.Test)18 Signature (net.runelite.asm.signature.Signature)17 Type (net.runelite.asm.Type)16 Instructions (net.runelite.asm.attributes.code.Instructions)16 ArrayList (java.util.ArrayList)14 List (java.util.List)13 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 IOException (java.io.IOException)9 InputStream (java.io.InputStream)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)9 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)9 HashMap (java.util.HashMap)8 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)7