Search in sources :

Example 41 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class ConstructorMapper method toOtherSignature.

private Signature toOtherSignature(Signature s) {
    Signature.Builder builder = new Signature.Builder().setReturnType(toOtherType(s.getReturnValue()));
    for (Type t : s.getArguments()) {
        Type other = toOtherType(t);
        if (other == null) {
            return null;
        }
        builder.addArgument(other);
    }
    return builder.build();
}
Also used : Type(net.runelite.asm.Type) Signature(net.runelite.asm.signature.Signature)

Example 42 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class UnusedParameters method findUnusedParameters.

private Set<Integer> findUnusedParameters(Method method) {
    int offset = method.isStatic() ? 0 : 1;
    Signature signature = method.getDescriptor();
    List<Integer> unusedParams = new ArrayList<>();
    for (int variableIndex = 0, lvtIndex = offset; variableIndex < signature.size(); lvtIndex += signature.getTypeOfArg(variableIndex++).getSize()) {
        List<? extends Instruction> lv = method.findLVTInstructionsForVariable(lvtIndex);
        if (lv == null || lv.isEmpty()) {
            unusedParams.add(variableIndex);
        }
    }
    return ImmutableSet.copyOf(unusedParams);
}
Also used : Signature(net.runelite.asm.signature.Signature) ArrayList(java.util.ArrayList)

Example 43 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class UnusedParameters method processUnused.

private int processUnused(Execution execution, ClassGroup group) {
    int count = 0;
    for (List<Method> m : unused.keySet()) {
        Collection<Integer> u = unused.get(m);
        int offset = m.size() == 1 && m.get(0).isStatic() ? 0 : 1;
        for (int unusedParameter : u) {
            if (!shouldRemove(m.get(0), unusedParameter)) {
                continue;
            }
            Signature signature = m.get(0).getDescriptor();
            int lvtIndex = this.getLvtIndex(signature, offset, unusedParameter);
            /* removing the parameter can't cause collisions on other (overloaded) methods because prior to this we rename
				 * all classes/fields/methods to have unique names.
				 */
            logger.debug("Removing parameter {} at index {} from {}", unusedParameter, lvtIndex, m);
            removeParameter(group, m, signature, execution, unusedParameter, lvtIndex);
            break;
        }
        ++count;
    }
    return count;
}
Also used : Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.Method)

Example 44 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class ClassGroupFactory method generateGroup.

public static ClassGroup generateGroup() {
    ClassGroup group = new ClassGroup();
    ClassFile cf = new ClassFile(group);
    cf.setName("test");
    cf.setSuperName("java/lang/Object");
    group.addClass(cf);
    Field field = new Field(cf, "field", Type.INT);
    field.setStatic();
    cf.addField(field);
    Method method = new Method(cf, "func", new Signature("()V"));
    method.setStatic();
    cf.addMethod(method);
    Code code = new Code(method);
    method.setCode(code);
    {
        method = new Method(cf, "func2", new Signature("(III)V"));
        method.setStatic();
        cf.addMethod(method);
        code = new Code(method);
        method.setCode(code);
        Instructions ins = code.getInstructions();
        ins.addInstruction(new VReturn(ins));
    }
    addVoidMethod(cf, "void1");
    addVoidMethod(cf, "void2");
    addVoidMethod(cf, "void3");
    addVoidMethod(cf, "void4");
    return group;
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) 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 45 with Signature

use of net.runelite.asm.signature.Signature in project runelite by runelite.

the class Inject method getMethodSignature.

public Signature getMethodSignature(Method m) {
    Signature signature = m.getDescriptor();
    Annotation obfSignature = m.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE);
    if (obfSignature != null) {
        // Annotation exists. Signature was updated by us during deobfuscation
        signature = DeobAnnotations.getObfuscatedSignature(m);
    }
    return signature;
}
Also used : Signature(net.runelite.asm.signature.Signature) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Aggregations

Signature (net.runelite.asm.signature.Signature)51 Method (net.runelite.asm.Method)29 ClassFile (net.runelite.asm.ClassFile)17 Type (net.runelite.asm.Type)16 Instruction (net.runelite.asm.attributes.code.Instruction)16 InvokeVirtual (net.runelite.asm.attributes.code.instructions.InvokeVirtual)16 Code (net.runelite.asm.attributes.Code)15 Instructions (net.runelite.asm.attributes.code.Instructions)15 InvokeStatic (net.runelite.asm.attributes.code.instructions.InvokeStatic)14 Field (net.runelite.asm.Field)10 ClassGroup (net.runelite.asm.ClassGroup)8 ALoad (net.runelite.asm.attributes.code.instructions.ALoad)8 LDC (net.runelite.asm.attributes.code.instructions.LDC)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)7 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)6 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)6 GetStatic (net.runelite.asm.attributes.code.instructions.GetStatic)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)5