Search in sources :

Example 91 with ClassFile

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

the class InjectMojo method getClassFile.

private File getClassFile(File base, ClassFile cf) {
    File f = base;
    String[] parts = cf.getName().split("/");
    for (int i = 0; i < parts.length - 1; ++i) {
        String part = parts[i];
        f = new File(f, part);
    }
    f.mkdirs();
    f = new File(f, parts[parts.length - 1] + ".class");
    return f;
}
Also used : File(java.io.File) ClassFile(net.runelite.asm.ClassFile)

Example 92 with ClassFile

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

the class DrawAfterWidgets method findStaticMethod.

private Method findStaticMethod(String name) {
    for (ClassFile c : inject.getDeobfuscated().getClasses()) {
        for (Method m : c.getMethods()) {
            if (!m.getName().equals(name)) {
                continue;
            }
            String obfuscatedName = DeobAnnotations.getObfuscatedName(m.getAnnotations());
            Signature obfuscatedSignature = DeobAnnotations.getObfuscatedSignature(m);
            ClassFile c2 = inject.toObClass(c);
            return c2.findMethod(obfuscatedName, (obfuscatedSignature != null) ? obfuscatedSignature : m.getDescriptor());
        }
    }
    return null;
}
Also used : ClassFile(net.runelite.asm.ClassFile) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method)

Example 93 with ClassFile

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

the class InjectConstruct method inject.

public void inject(Map<ClassFile, java.lang.Class> implemented) throws InjectionException {
    for (Entry<ClassFile, java.lang.Class> entry : implemented.entrySet()) {
        Class<?> clazz = entry.getValue();
        ClassFile cf = entry.getKey();
        if (clazz == null) {
            continue;
        }
        for (java.lang.reflect.Method method : clazz.getDeclaredMethods()) {
            if (method.isSynthetic()) {
                continue;
            }
            Construct construct = method.getAnnotation(Construct.class);
            if (construct == null) {
                continue;
            }
            String obfuscatedName = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
            if (obfuscatedName == null) {
                obfuscatedName = cf.getName();
            }
            ClassGroup vanilla = inject.getVanilla();
            ClassFile other = vanilla.findClass(obfuscatedName);
            assert other != null : "unable to find vanilla class from obfuscated name: " + obfuscatedName;
            injectConstruct(other, method);
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Construct(net.runelite.mapping.Construct)

Example 94 with ClassFile

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

the class InjectInvoker method process.

/**
 * Inject an invoker for a method
 *
 * @param m Method in the deobfuscated client to inject an invoker for
 * @param other Class in the vanilla client of the same class m is a
 * member of
 * @param implementingClass Java class for the API interface the class
 * will implement
 */
public void process(Method m, ClassFile other, java.lang.Class<?> implementingClass) {
    Annotations an = m.getAnnotations();
    if (an == null || an.find(EXPORT) == null) {
        // not an exported method
        return;
    }
    String exportedName = DeobAnnotations.getExportedName(an);
    String obfuscatedName = DeobAnnotations.getObfuscatedName(an);
    if (obfuscatedName == null) {
        obfuscatedName = m.getName();
    }
    String garbage = DeobAnnotations.getObfuscatedValue(m);
    Method otherm = other.findMethod(obfuscatedName, inject.getMethodSignature(m));
    assert otherm != null;
    assert m.isStatic() == otherm.isStatic();
    ClassGroup vanilla = inject.getVanilla();
    ClassFile targetClass = m.isStatic() ? vanilla.findClass("client") : other;
    // Place into implementing class, unless the method is static
    java.lang.Class<?> targetClassJava = m.isStatic() ? Inject.CLIENT_CLASS : implementingClass;
    if (targetClassJava == null) {
        assert !m.isStatic();
        // non static exported method on non exported interface, weird.
        logger.debug("Non static exported method {} on non exported interface", exportedName);
        return;
    }
    // api method to invoke 'otherm'
    java.lang.reflect.Method apiMethod = inject.findImportMethodOnApi(targetClassJava, exportedName, null);
    if (apiMethod == null) {
        logger.debug("Unable to find api method on {} with imported name {}, not injecting invoker", targetClassJava, exportedName);
        return;
    }
    injectInvoker(targetClass, apiMethod, m, otherm, garbage);
    ++injectedInvokers;
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) DeobAnnotations(net.runelite.deob.DeobAnnotations) ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Method(net.runelite.asm.Method)

Example 95 with ClassFile

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

the class MixinInjector method findShadowFields.

/**
 * Find fields which are marked @Shadow, and what they shadow
 *
 * @param mixinClasses
 * @throws InjectionException
 */
private void findShadowFields(Map<Class<?>, List<ClassFile>> mixinClasses) throws InjectionException {
    // Injected static fields take precedence when looking up shadowed fields
    for (Class<?> mixinClass : mixinClasses.keySet()) {
        ClassFile mixinCf;
        try {
            mixinCf = loadClass(mixinClass);
        } catch (IOException ex) {
            throw new InjectionException(ex);
        }
        for (Field field : mixinCf.getFields()) {
            Annotation shadow = field.getAnnotations().find(SHADOW);
            if (shadow != null) {
                if (!field.isStatic()) {
                    throw new InjectionException("Can only shadow static fields");
                }
                // shadow this field
                String shadowName = shadow.getElement().getString();
                Field injectedField = injectedFields.get(shadowName);
                if (injectedField != null) {
                    // Shadow a field injected by a mixin
                    shadowFields.put(field.getPoolField(), injectedField);
                } else {
                    // Shadow a field already in the gamepack
                    Field shadowField = findDeobField(shadowName);
                    if (shadowField == null) {
                        throw new InjectionException("Shadow of nonexistent field " + shadowName);
                    }
                    Field obShadow = inject.toObField(shadowField);
                    assert obShadow != null;
                    shadowFields.put(field.getPoolField(), obShadow);
                }
            }
        }
    }
}
Also used : GetField(net.runelite.asm.attributes.code.instructions.GetField) Field(net.runelite.asm.Field) PutField(net.runelite.asm.attributes.code.instructions.PutField) ClassFile(net.runelite.asm.ClassFile) IOException(java.io.IOException) Annotation(net.runelite.asm.attributes.annotation.Annotation)

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