Search in sources :

Example 6 with Method

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

the class MenuActionDeobfuscator method run.

private void run(Method method) {
    if (method.getCode() == null) {
        return;
    }
    Execution execution = new Execution(method.getClassFile().getGroup());
    execution.addMethod(method);
    execution.noInvoke = true;
    Multimap<Integer, Comparison> comps = HashMultimap.create();
    execution.addExecutionVisitor((InstructionContext ictx) -> {
        Instruction i = ictx.getInstruction();
        Frame frame = ictx.getFrame();
        if (i instanceof If) {
            // constant
            InstructionContext ctx1 = ictx.getPops().get(0).getPushed();
            // lvt
            InstructionContext ctx2 = ictx.getPops().get(1).getPushed();
            if (ctx1.getInstruction() instanceof PushConstantInstruction && ctx2.getInstruction() instanceof LVTInstruction) {
                Comparison comparison = new Comparison();
                comparison.cmp = i;
                comparison.ldc = ctx1.getInstruction();
                comparison.lvt = (LVTInstruction) ctx2.getInstruction();
                comps.put(comparison.lvt.getVariableIndex(), comparison);
            }
        }
    });
    execution.run();
    for (int i : comps.keySet()) {
        Collection<Comparison> get = comps.get(i);
        long l = get.stream().filter(c -> c.cmp.getType() == IF_ICMPGE || c.cmp.getType() == IF_ICMPGT || c.cmp.getType() == IF_ICMPLE || c.cmp.getType() == IF_ICMPLT).count();
        List<Comparison> eqcmp = get.stream().filter(c -> c.cmp.getType() == IF_ICMPEQ || c.cmp.getType() == IF_ICMPNE).collect(Collectors.toList());
        if (get.size() > THRESHOLD_EQ && l <= THRESHOLD_LT) {
            logger.info("Sorting {} comparisons in {}", eqcmp.size(), method);
            insert(method, eqcmp);
        }
    }
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LoggerFactory(org.slf4j.LoggerFactory) Multimap(com.google.common.collect.Multimap) IF_ICMPGE(net.runelite.asm.attributes.code.InstructionType.IF_ICMPGE) Goto(net.runelite.asm.attributes.code.instructions.Goto) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) HashMultimap(com.google.common.collect.HashMultimap) Method(net.runelite.asm.Method) IF_ICMPNE(net.runelite.asm.attributes.code.InstructionType.IF_ICMPNE) If(net.runelite.asm.attributes.code.instructions.If) IF_ICMPEQ(net.runelite.asm.attributes.code.InstructionType.IF_ICMPEQ) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) IF_ICMPGT(net.runelite.asm.attributes.code.InstructionType.IF_ICMPGT) Frame(net.runelite.asm.execution.Frame) Logger(org.slf4j.Logger) InstructionType(net.runelite.asm.attributes.code.InstructionType) IF_ICMPLT(net.runelite.asm.attributes.code.InstructionType.IF_ICMPLT) Collection(java.util.Collection) IF_ICMPLE(net.runelite.asm.attributes.code.InstructionType.IF_ICMPLE) Deobfuscator(net.runelite.deob.Deobfuscator) Collectors(java.util.stream.Collectors) InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Label(net.runelite.asm.attributes.code.Label) IfICmpNe(net.runelite.asm.attributes.code.instructions.IfICmpNe) Instructions(net.runelite.asm.attributes.code.Instructions) Instruction(net.runelite.asm.attributes.code.Instruction) Collections(java.util.Collections) InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) LVTInstruction(net.runelite.asm.attributes.code.instruction.types.LVTInstruction) Execution(net.runelite.asm.execution.Execution) If(net.runelite.asm.attributes.code.instructions.If)

Example 7 with Method

use of net.runelite.asm.Method 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)

Example 8 with Method

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

the class AnnotationCopier method copy.

public void copy() {
    for (ClassFile cf1 : group1.getClasses()) {
        ClassFile cf2 = group2.findClass(cf1.getName());
        assert cf2 != null;
        copy(cf1.getAnnotations(), cf2.getAnnotations());
        for (Field f : cf1.getFields()) {
            Field f2 = cf2.findField(f.getName(), f.getType());
            assert f2 != null || f.getAnnotations() == null;
            if (f2 == null)
                continue;
            copy(f.getAnnotations(), f2.getAnnotations());
        }
        for (Method m : cf1.getMethods()) {
            Method m2 = cf2.findMethod(m.getName(), m.getDescriptor());
            assert m2 != null || m.getAnnotations() == null;
            if (m2 == null)
                continue;
            copy(m.getAnnotations(), m2.getAnnotations());
        }
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 9 with Method

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

the class HandlerFinder method prepareFrame.

private void prepareFrame(Execution e, PacketHandlers handlers) {
    List<Method> methods = handlers.getHandlers().stream().map(handler -> handler.getMethod()).distinct().collect(Collectors.toList());
    for (Method method : methods) {
        List<PacketHandler> phandlers = handlers.getHandlers().stream().filter(handler -> handler.getMethod() == method).collect(Collectors.toList());
        prepareFrame(e, method, phandlers);
    }
}
Also used : Frame(net.runelite.asm.execution.Frame) 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) LoggerFactory(org.slf4j.LoggerFactory) Multimap(com.google.common.collect.Multimap) Collectors(java.util.stream.Collectors) InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Label(net.runelite.asm.attributes.code.Label) HashMultimap(com.google.common.collect.HashMultimap) Method(net.runelite.asm.Method) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Instructions(net.runelite.asm.attributes.code.Instructions) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) If(net.runelite.asm.attributes.code.instructions.If) Instruction(net.runelite.asm.attributes.code.Instruction) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic) Collections(java.util.Collections) Method(net.runelite.asm.Method)

Example 10 with Method

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

the class HandlerFinder method findHandlers.

public PacketHandlers findHandlers() {
    // Some of the packet handlers are if (type == 1 || type == 2) func()
    // and func() checks the type... so search all functions for packet handlers
    List<PacketHandler> handlers = new ArrayList<>();
    for (ClassFile cf : group.getClasses()) {
        for (Method method : cf.getMethods()) {
            if (method.getCode() == null) {
                continue;
            }
            List<PacketHandler> h = findHandlers(method, packetType);
            handlers.addAll(h);
        }
    }
    PacketHandlers packetHandlers = new PacketHandlers(group, packetType, handlers);
    removeDuplicates(packetHandlers);
    prepareFrame(execution, packetHandlers);
    return packetHandlers;
}
Also used : ClassFile(net.runelite.asm.ClassFile) ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method)

Aggregations

Method (net.runelite.asm.Method)90 ClassFile (net.runelite.asm.ClassFile)64 Field (net.runelite.asm.Field)34 Instruction (net.runelite.asm.attributes.code.Instruction)29 Code (net.runelite.asm.attributes.Code)28 Instructions (net.runelite.asm.attributes.code.Instructions)28 Signature (net.runelite.asm.signature.Signature)28 ClassGroup (net.runelite.asm.ClassGroup)20 ArrayList (java.util.ArrayList)18 Type (net.runelite.asm.Type)18 List (java.util.List)13 Test (org.junit.Test)13 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 Logger (org.slf4j.Logger)12 LoggerFactory (org.slf4j.LoggerFactory)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)10 DeobAnnotations (net.runelite.deob.DeobAnnotations)9 Annotation (net.runelite.asm.attributes.annotation.Annotation)8 InstructionType (net.runelite.asm.attributes.code.InstructionType)8 Label (net.runelite.asm.attributes.code.Label)8