Search in sources :

Example 1 with Frame

use of net.runelite.asm.execution.Frame in project runelite by runelite.

the class MappingExecutorUtil method map.

public static ParallelExecutorMapping map(Method m1, Method m2) {
    ClassGroup group1 = m1.getClassFile().getGroup();
    ClassGroup group2 = m2.getClassFile().getGroup();
    Execution e = new Execution(group1);
    e.step = true;
    Frame frame = new Frame(e, m1);
    frame.initialize();
    e.frames.add(frame);
    Execution e2 = new Execution(group2);
    e2.step = true;
    Frame frame2 = new Frame(e2, m2);
    frame2.initialize();
    e2.frames.add(frame2);
    frame.other = frame2;
    frame2.other = frame;
    ParallellMappingExecutor parallel = new ParallellMappingExecutor(e, e2);
    ParallelExecutorMapping mappings = new ParallelExecutorMapping(m1.getClassFile().getGroup(), m2.getClassFile().getGroup());
    mappings.m1 = m1;
    mappings.m2 = m2;
    parallel.mappings = mappings;
    int same = 0;
    while (parallel.step()) {
        // get what each frame is paused/exited on
        InstructionContext p1 = parallel.getP1(), p2 = parallel.getP2();
        assert p1.getInstruction() instanceof MappableInstruction;
        assert p2.getInstruction() instanceof MappableInstruction;
        MappableInstruction mi1 = (MappableInstruction) p1.getInstruction(), mi2 = (MappableInstruction) p2.getInstruction();
        boolean isSame = mi1.isSame(p1, p2);
        assert isSame == mi2.isSame(p2, p1) : "isSame fail " + p1.getInstruction() + " <> " + p2.getInstruction();
        if (!isSame) {
            mappings.crashed = true;
            p1.getFrame().stop();
            p2.getFrame().stop();
            continue;
        }
        ++same;
        mi1.map(mappings, p1, p2);
    }
    mappings.same = same;
    return mappings;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) MappableInstruction(net.runelite.asm.attributes.code.instruction.types.MappableInstruction) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) ParallellMappingExecutor(net.runelite.asm.execution.ParallellMappingExecutor)

Example 2 with Frame

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

use of net.runelite.asm.execution.Frame in project runelite by runelite.

the class If method map.

@Override
public void map(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
    assert ctx.getBranches().size() == other.getBranches().size();
    // can be empty for packet handlers
    if (!ctx.getBranches().isEmpty()) {
        Frame branch1 = ctx.getBranches().get(0), branch2 = other.getBranches().get(0);
        assert branch1.other == null;
        assert branch2.other == null;
        branch1.other = branch2;
        branch2.other = branch1;
    }
    this.mapArguments(mapping, ctx, other, false);
}
Also used : Frame(net.runelite.asm.execution.Frame)

Example 4 with Frame

use of net.runelite.asm.execution.Frame in project runelite by runelite.

the class If method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    StackContext one = stack.pop();
    StackContext two = stack.pop();
    ins.pop(one, two);
    Frame other = frame.dup();
    other.jump(ins, to);
    ins.branch(other);
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Frame(net.runelite.asm.execution.Frame) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Example 5 with Frame

use of net.runelite.asm.execution.Frame in project runelite by runelite.

the class If method mapOtherBranch.

protected void mapOtherBranch(ParallelExecutorMapping mapping, InstructionContext ctx, InstructionContext other) {
    Frame f1 = ctx.getFrame(), f2 = other.getFrame(), branch1 = ctx.getBranches().get(0), branch2 = other.getBranches().get(0);
    assert branch1.other == null;
    assert branch2.other == null;
    // currently f1 <-> f2
    assert f1.other == f2;
    assert f2.other == f1;
    // change to f1 <-> branch2, f2 <-> branch1
    f1.other = branch2;
    branch2.other = f1;
    f2.other = branch1;
    branch1.other = f2;
    this.mapArguments(mapping, ctx, other, true);
}
Also used : Frame(net.runelite.asm.execution.Frame)

Aggregations

Frame (net.runelite.asm.execution.Frame)17 InstructionContext (net.runelite.asm.execution.InstructionContext)12 Stack (net.runelite.asm.execution.Stack)8 StackContext (net.runelite.asm.execution.StackContext)7 Instructions (net.runelite.asm.attributes.code.Instructions)5 Label (net.runelite.asm.attributes.code.Label)4 Execution (net.runelite.asm.execution.Execution)4 ClassGroup (net.runelite.asm.ClassGroup)3 Instruction (net.runelite.asm.attributes.code.Instruction)3 Variables (net.runelite.asm.execution.Variables)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 ClassFile (net.runelite.asm.ClassFile)2 Method (net.runelite.asm.Method)2 InstructionType (net.runelite.asm.attributes.code.InstructionType)2 LVTInstruction (net.runelite.asm.attributes.code.instruction.types.LVTInstruction)2 MappableInstruction (net.runelite.asm.attributes.code.instruction.types.MappableInstruction)2