Search in sources :

Example 6 with Execution

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

the class MultiplicationDeobfuscatorTest method test13.

// sipush                512
// ldc                   -688421113
// imul
// ldc                   -585812297
// imul
// putstatic             class134/field2009 I
@Test
public void test13() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    LDC constant1 = new LDC(ins, -688421113);
    LDC constant2 = new LDC(ins, -585812297);
    Instruction[] body = { new SiPush(ins, (short) 512), constant1, new IMul(ins), constant2, new IMul(ins), new VReturn(ins) };
    for (Instruction i : body) {
        ins.addInstruction(i);
    }
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    assert constant1.getConstantAsInt() * constant2.getConstantAsInt() == 1;
    Deobfuscator d = new MultiplicationDeobfuscator();
    d.run(group);
    Assert.assertEquals(1, constant1.getConstantAsInt());
    Assert.assertEquals(1, constant2.getConstantAsInt());
}
Also used : SiPush(net.runelite.asm.attributes.code.instructions.SiPush) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Test(org.junit.Test)

Example 7 with Execution

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

the class MultiplyOneDeobfuscatorTest method test2.

// iconst_1
// iconst_m1
// iload                 5
// if_icmpeq             LABEL0x56d1
// iload                 5
// iconst_1
// if_icmpne             LABEL0x56e8
// goto                  LABEL0x56d1
// LABEL0x56d1:
// getstatic             class139/field2130 I
// ldc_w                 -1440517609
// imul
// goto                  LABEL0x5708
// LABEL0x56e8:
// getstatic             class139/field2130 I
// ldc_w                 -1440517609
// imul
// getstatic             client/field377 I
// iadd
// iconst_2
// idiv
// LABEL0x5708:
// imul
// putstatic             client/field377 I
// 
// client.field377 = 1 * (-1 != var5 && var5 != 1?(class139.field2130 + client.field377) / 2:class139.field2130);
@Test
public void test2() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(2);
    // vars[0] = 3
    Instruction[] prepareVariables = { new LDC(ins, 3), new IStore(ins, 0), new LDC(ins, 2), new IStore(ins, 1) };
    for (Instruction i : prepareVariables) ins.addInstruction(i);
    Label label = new Label(ins), label2 = new Label(ins), label3 = new Label(ins);
    LDC one = new LDC(ins, 1);
    IMul mul = new IMul(ins);
    Instruction[] body = { one, new LDC(ins, -1), new ILoad(ins, 0), new IfICmpEq(ins, label), new Goto(ins, label2), label, new ILoad(ins, 1), new LDC(ins, -1440517609), new IDiv(ins), new Goto(ins, label3), label2, new ILoad(ins, 1), new LDC(ins, -1440517609), new IDiv(ins), label3, mul, new VReturn(ins) };
    for (Instruction i : body) ins.addInstruction(i);
    // check execution runs ok
    Execution e = new Execution(group);
    e.populateInitialMethods();
    e.run();
    Deobfuscator d = new MultiplyOneDeobfuscator(false);
    d.run(group);
    Assert.assertTrue(one.getInstructions() == null);
    Assert.assertTrue(mul.getInstructions() == null);
}
Also used : IfICmpEq(net.runelite.asm.attributes.code.instructions.IfICmpEq) IStore(net.runelite.asm.attributes.code.instructions.IStore) Goto(net.runelite.asm.attributes.code.instructions.Goto) ILoad(net.runelite.asm.attributes.code.instructions.ILoad) Label(net.runelite.asm.attributes.code.Label) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) IDiv(net.runelite.asm.attributes.code.instructions.IDiv) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) VReturn(net.runelite.asm.attributes.code.instructions.VReturn) Deobfuscator(net.runelite.deob.Deobfuscator) Execution(net.runelite.asm.execution.Execution) ClassGroup(net.runelite.asm.ClassGroup) IMul(net.runelite.asm.attributes.code.instructions.IMul) Test(org.junit.Test)

Example 8 with Execution

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

the class InvokeSpecial method execute.

@Override
public InstructionContext execute(Frame frame) {
    InstructionContext ins = new InstructionContext(this, frame);
    Stack stack = frame.getStack();
    int count = method.getType().size();
    for (int i = 0; i < count; ++i) {
        StackContext arg = stack.pop();
        ins.pop(arg);
    }
    StackContext object = stack.pop();
    ins.pop(object);
    if (!method.getType().isVoid()) {
        StackContext ctx = new StackContext(ins, method.getType().getReturnValue(), Value.UNKNOWN);
        stack.push(ctx);
        ins.push(ctx);
    }
    if (myMethod != null) {
        ins.invoke(myMethod);
        assert myMethod.getCode() != null;
        // add possible method call to execution
        Execution execution = frame.getExecution();
        execution.invoke(ins, myMethod);
        frame.getExecution().order(frame, myMethod);
    }
    return ins;
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) Execution(net.runelite.asm.execution.Execution) StackContext(net.runelite.asm.execution.StackContext) Stack(net.runelite.asm.execution.Stack)

Example 9 with Execution

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

the class Deob method run.

private static void run(ClassGroup group, Deobfuscator deob) {
    Stopwatch stopwatch = Stopwatch.createStarted();
    deob.run(group);
    stopwatch.stop();
    logger.info("{} took {}", deob.getClass().getSimpleName(), stopwatch);
    // check code is still correct
    if (CHECK_EXEC) {
        Execution execution = new Execution(group);
        execution.populateInitialMethods();
        execution.run();
    }
}
Also used : Execution(net.runelite.asm.execution.Execution) Stopwatch(com.google.common.base.Stopwatch)

Example 10 with Execution

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

the class ModArith method runOnce.

public int runOnce() {
    group.buildClassGraph();
    pairs.clear();
    fieldInfo.clear();
    execution = new Execution(group);
    execution.addMethodContextVisitor(i -> findUses(i));
    execution.addMethodContextVisitor(i -> findConstants(i));
    execution.populateInitialMethods();
    execution.run();
    guess();
    int i = 0;
    Encryption encr = new Encryption();
    for (Pair pair : pairs) {
        logger.debug("Processing {} getter {} setter {}", pair.field.getName(), pair.getter, pair.setter);
        encr.addPair(pair);
        // sum total
        encryption.addPair(pair);
        ++i;
    }
    logger.info("Done processing {}", i);
    if (i > 0) {
        insertGetterSetterMuls(encr);
    }
    return i;
}
Also used : Execution(net.runelite.asm.execution.Execution)

Aggregations

Execution (net.runelite.asm.execution.Execution)44 Instruction (net.runelite.asm.attributes.code.Instruction)25 ClassGroup (net.runelite.asm.ClassGroup)23 Instructions (net.runelite.asm.attributes.code.Instructions)23 Code (net.runelite.asm.attributes.Code)21 Deobfuscator (net.runelite.deob.Deobfuscator)21 LDC (net.runelite.asm.attributes.code.instructions.LDC)19 VReturn (net.runelite.asm.attributes.code.instructions.VReturn)19 IMul (net.runelite.asm.attributes.code.instructions.IMul)18 Test (org.junit.Test)18 IStore (net.runelite.asm.attributes.code.instructions.IStore)17 ILoad (net.runelite.asm.attributes.code.instructions.ILoad)16 InstructionContext (net.runelite.asm.execution.InstructionContext)12 Label (net.runelite.asm.attributes.code.Label)10 Method (net.runelite.asm.Method)8 ClassFile (net.runelite.asm.ClassFile)7 Pop (net.runelite.asm.attributes.code.instructions.Pop)7 StackContext (net.runelite.asm.execution.StackContext)7 Field (net.runelite.asm.Field)5 Dup_X1 (net.runelite.asm.attributes.code.instructions.Dup_X1)5