Search in sources :

Example 26 with Method

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

the class ModArith method insertGetterSetterMuls.

private void insertGetterSetterMuls(Encryption encr) {
    // before setfield insert imul * getter
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null) {
                continue;
            }
            Instructions ins = code.getInstructions();
            List<Instruction> ilist = ins.getInstructions();
            for (int i = 0; i < ilist.size(); ++i) {
                Instruction in = ilist.get(i);
                if (in instanceof SetFieldInstruction) {
                    SetFieldInstruction sfi = (SetFieldInstruction) in;
                    Field f = sfi.getMyField();
                    if (f == null) {
                        continue;
                    }
                    Pair p = encr.getField(f.getPoolField());
                    if (p == null) {
                        continue;
                    }
                    // insert imul
                    if (p.getType() == Integer.class) {
                        ilist.add(i++, new LDC(ins, (int) p.getter));
                        ilist.add(i++, new IMul(ins));
                    } else if (p.getType() == Long.class) {
                        ilist.add(i++, new LDC(ins, (long) p.getter));
                        ilist.add(i++, new LMul(ins));
                    } else {
                        throw new IllegalStateException();
                    }
                } else if (in instanceof GetFieldInstruction) {
                    GetFieldInstruction sfi = (GetFieldInstruction) in;
                    Field f = sfi.getMyField();
                    if (f == null) {
                        continue;
                    }
                    Pair p = encr.getField(f.getPoolField());
                    if (p == null) {
                        continue;
                    }
                    // imul
                    if (p.getType() == Integer.class) {
                        ilist.add(++i, new LDC(ins, (int) p.setter));
                        ilist.add(++i, new IMul(ins));
                    } else if (p.getType() == Long.class) {
                        ilist.add(++i, new LDC(ins, (long) p.setter));
                        ilist.add(++i, new LMul(ins));
                    } else {
                        throw new IllegalStateException();
                    }
                }
            }
        }
    }
}
Also used : SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) ClassFile(net.runelite.asm.ClassFile) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) DivisionInstruction(net.runelite.asm.attributes.code.instruction.types.DivisionInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) ArrayStoreInstruction(net.runelite.asm.attributes.code.instruction.types.ArrayStoreInstruction) InvokeInstruction(net.runelite.asm.attributes.code.instruction.types.InvokeInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) Field(net.runelite.asm.Field) IMul(net.runelite.asm.attributes.code.instructions.IMul) LMul(net.runelite.asm.attributes.code.instructions.LMul) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)

Example 27 with Method

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

the class ControlFlowDeobfuscator method run.

@Override
public void run(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null || !code.getExceptions().getExceptions().isEmpty()) {
                continue;
            }
            split(code);
            run(code);
            runJumpLabel(code);
        }
    }
    logger.info("Inserted {} jumps, reordered {} blocks, and removed {} jumps. jump delta {}", insertedJump, placedBlocks, removedJumps, insertedJump - removedJumps);
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

Example 28 with Method

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

the class FieldInliner method findFieldIns.

private void findFieldIns() {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code code = m.getCode();
            if (code == null)
                continue;
            for (Instruction i : code.getInstructions().getInstructions()) {
                if (!(i instanceof FieldInstruction))
                    continue;
                FieldInstruction sf = (FieldInstruction) i;
                if (sf.getMyField() == null)
                    continue;
                fieldInstructions.put(sf.getMyField(), sf);
            }
        }
    }
}
Also used : ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) FieldInstruction(net.runelite.asm.attributes.code.instruction.types.FieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 29 with Method

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

the class IllegalStateExceptions method findInteresting.

/* find if, new, ..., athrow, replace with goto */
private void findInteresting(ClassGroup group) {
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null)
                continue;
            Instructions instructions = c.getInstructions();
            List<Instruction> ilist = instructions.getInstructions();
            for (int i = 0; i < ilist.size(); ++i) {
                Instruction ins = ilist.get(i);
                if (// the if
                !(ins instanceof ComparisonInstruction))
                    continue;
                Instruction ins2 = ilist.get(i + 1);
                if (!(ins2 instanceof New))
                    continue;
                New new2 = (New) ins2;
                net.runelite.asm.pool.Class clazz = new2.getNewClass();
                if (!clazz.getName().contains("java/lang/IllegalStateException"))
                    continue;
                interesting.add(ins);
            }
        }
    }
}
Also used : New(net.runelite.asm.attributes.code.instructions.New) ClassFile(net.runelite.asm.ClassFile) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) ComparisonInstruction(net.runelite.asm.attributes.code.instruction.types.ComparisonInstruction) JumpingInstruction(net.runelite.asm.attributes.code.instruction.types.JumpingInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code)

Example 30 with Method

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

the class RuntimeExceptions method run.

@Override
public void run(ClassGroup group) {
    boolean foundInit = false;
    int i = 0;
    for (ClassFile cf : group.getClasses()) {
        for (Method m : cf.getMethods()) {
            Code c = m.getCode();
            if (c == null)
                continue;
            // keeps the client error handling related methods
            if (cf.getName().equals("client") && m.getName().equals("init")) {
                foundInit = true;
                continue;
            }
            for (net.runelite.asm.attributes.code.Exception e : new ArrayList<>(c.getExceptions().getExceptions())) {
                if (e.getCatchType() != null && e.getCatchType().getName().equals("java/lang/RuntimeException")) {
                    c.getExceptions().remove(e);
                    ++i;
                }
            }
        }
    }
    if (!foundInit) {
        throw new IllegalStateException("client.init(...) method seems to be missing!");
    }
    logger.info("Remove {} exception handlers", i);
}
Also used : ClassFile(net.runelite.asm.ClassFile) ArrayList(java.util.ArrayList) Method(net.runelite.asm.Method) Code(net.runelite.asm.attributes.Code)

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