Search in sources :

Example 1 with Annotations

use of net.runelite.asm.attributes.Annotations in project runelite by runelite.

the class HookImporter method findMethodWithObfuscatedName.

private Method findMethodWithObfuscatedName(ClassFile c, String name, String signature) {
    Signature sig = new Signature(signature);
    for (Method m : c.getMethods()) {
        Annotations an = m.getAnnotations();
        if (getAnnotation(an, OBFUSCATED_NAME).equals(name)) {
            Signature methodSig = getObfuscatedMethodSignature(m);
            if (methodSig.equals(sig)) {
                return m;
            } else {
                methodSig.equals(sig);
                getObfuscatedMethodSignature(m);
            }
        }
    }
    return null;
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method)

Example 2 with Annotations

use of net.runelite.asm.attributes.Annotations in project runelite by runelite.

the class MappingImporter method makeMappings.

@Test
@Ignore
public void makeMappings() throws IOException {
    InjectionModscript mod = Injection.load(MappingImporter.class.getResourceAsStream(RL_INJECTION));
    int fields = 0, classes = 0;
    for (int i = 0; i < mod.getGetterInjects().size(); ++i) {
        GetterInjectInstruction gii = (GetterInjectInstruction) mod.getGetterInjects().get(i);
        ClassFile cf = this.findClassWithObfuscatedName(gii.getGetterClassName());
        Assert.assertNotNull(cf);
        Field f = this.findFieldWithObfuscatedName(cf, gii.getGetterFieldName());
        if (f == null) {
            // so they don't all exist
            continue;
        }
        String attrName = gii.getGetterName();
        attrName = Utils.toExportedName(attrName);
        Annotations an = f.getAnnotations();
        Annotation a = an.find(EXPORT);
        if (a != null) {
            String exportedName = a.getElement().getString();
            if (!attrName.equals(exportedName)) {
                logger.info("Exported field " + f + " with mismatched name. Theirs: " + attrName + ", mine: " + exportedName);
            }
        } else {
            an.addAnnotation(EXPORT, "value", attrName);
            logger.info("Exporting field " + f + " with name " + attrName);
            ++fields;
        }
    }
    for (AddInterfaceInstruction aii : mod.getAddInterfaceInjects()) {
        ClassFile cf = this.findClassWithObfuscatedName(aii.getClientClass());
        Assert.assertNotNull(cf);
        String iface = aii.getInterfaceClass();
        iface = iface.replace("com/runeloader/api/bridge/os/accessor/", "");
        Annotations an = cf.getAnnotations();
        Annotation a = an.find(IMPLEMENTS);
        if (a != null) {
            String implementsName = a.getElement().getString();
            if (!iface.equals(implementsName)) {
                logger.info("Implements class " + cf + " with mismatched name. Theirs: " + iface + ", mine: " + implementsName);
            }
        } else {
            an.addAnnotation(IMPLEMENTS, "value", iface);
            logger.info("Exporting class " + cf.getName() + " with name " + iface);
            ++classes;
        }
    }
    logger.info("Added {} fields, {} classes", fields, classes);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Annotations(net.runelite.asm.attributes.Annotations) InjectionModscript(net.runelite.runeloader.inject.InjectionModscript) AddInterfaceInstruction(net.runelite.runeloader.inject.AddInterfaceInstruction) GetterInjectInstruction(net.runelite.runeloader.inject.GetterInjectInstruction) Annotation(net.runelite.asm.attributes.annotation.Annotation) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with Annotations

use of net.runelite.asm.attributes.Annotations in project runelite by runelite.

the class InjectHookMethod method process.

public void process(Method method) throws InjectionException {
    Annotations an = method.getAnnotations();
    if (an == null) {
        return;
    }
    Annotation a = an.find(DeobAnnotations.HOOK);
    if (a == null) {
        return;
    }
    // Method is hooked
    // String hookName = DeobAnnotations.getHookName(an); // hook name
    // Find equivalent method in vanilla, and insert callback at the beginning
    ClassFile cf = method.getClassFile();
    String obfuscatedMethodName = DeobAnnotations.getObfuscatedName(an), obfuscatedClassName = DeobAnnotations.getObfuscatedName(cf.getAnnotations());
    // might be a constructor
    if (obfuscatedMethodName == null && method.getName().equals("<init>")) {
        obfuscatedMethodName = "<init>";
    }
    assert obfuscatedClassName != null : "hook on method in class with no obfuscated name";
    assert obfuscatedMethodName != null : "hook on method with no obfuscated name";
    Signature obfuscatedSignature = inject.getMethodSignature(method);
    ClassGroup vanilla = inject.getVanilla();
    ClassFile vanillaClass = vanilla.findClass(obfuscatedClassName);
    Method vanillaMethod = vanillaClass.findMethod(obfuscatedMethodName, obfuscatedSignature);
    // Insert instructions at beginning of method
    injectHookMethod(a, method, vanillaMethod);
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) DeobAnnotations(net.runelite.deob.DeobAnnotations) ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 4 with Annotations

use of net.runelite.asm.attributes.Annotations in project runelite by runelite.

the class HookImporter method toObType.

private Type toObType(Type t) {
    if (t.isPrimitive()) {
        return t;
    }
    if (!t.getInternalName().startsWith("class") && !t.getInternalName().equals("client")) {
        return t;
    }
    ClassFile cf = group.findClass(t.getInternalName());
    assert cf != null;
    Annotations an = cf.getAnnotations();
    String obfuscatedName = an.find(OBFUSCATED_NAME).getElement().getString();
    return Type.getType("L" + obfuscatedName + ";", t.getDimensions());
}
Also used : ClassFile(net.runelite.asm.ClassFile) Annotations(net.runelite.asm.attributes.Annotations)

Example 5 with Annotations

use of net.runelite.asm.attributes.Annotations in project runelite by runelite.

the class ConstantParameter method annotateObfuscatedSignature.

private void annotateObfuscatedSignature(ConstantMethodParameter parameter) {
    for (Method m : parameter.methods) {
        Object value = parameter.values.get(0);
        Annotations annotations = m.getAnnotations();
        Annotation obfuscatedSignature = annotations.find(DeobAnnotations.OBFUSCATED_SIGNATURE);
        if (obfuscatedSignature != null && obfuscatedSignature.getElements().size() == 2) {
            // already annotated
            continue;
        }
        if (obfuscatedSignature == null) {
            obfuscatedSignature = annotations.addAnnotation(DeobAnnotations.OBFUSCATED_SIGNATURE, "signature", m.getDescriptor().toString());
        }
        // Add garbage value
        Element element = new Element(obfuscatedSignature);
        element.setName("garbageValue");
        element.setValue(value.toString());
        obfuscatedSignature.addElement(element);
    }
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) DeobAnnotations(net.runelite.deob.DeobAnnotations) Element(net.runelite.asm.attributes.annotation.Element) Method(net.runelite.asm.Method) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Aggregations

Annotations (net.runelite.asm.attributes.Annotations)9 ClassFile (net.runelite.asm.ClassFile)6 Method (net.runelite.asm.Method)6 Annotation (net.runelite.asm.attributes.annotation.Annotation)6 DeobAnnotations (net.runelite.deob.DeobAnnotations)5 ClassGroup (net.runelite.asm.ClassGroup)3 Field (net.runelite.asm.Field)2 Type (net.runelite.asm.Type)2 Element (net.runelite.asm.attributes.annotation.Element)2 Class (net.runelite.asm.pool.Class)2 Signature (net.runelite.asm.signature.Signature)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1 ClassUtil (net.runelite.asm.ClassUtil)1 Interfaces (net.runelite.asm.Interfaces)1