Search in sources :

Example 1 with Type

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

the class PacketWriteDeobfuscator method translate.

private Instruction translate(Instruction i) {
    if (!(i instanceof InvokeVirtual)) {
        return i;
    }
    InvokeVirtual ii = (InvokeVirtual) i;
    Method invoked = ii.getMethod();
    assert invoked.getType().size() == 1;
    Type argumentType = invoked.getType().getTypeOfArg(0);
    Method invokeMethod;
    if (argumentType.equals(Type.BYTE)) {
        invokeMethod = new Method(ii.getMethod().getClazz(), "runeliteWriteByte", new Signature("(B)V"));
    } else if (argumentType.equals(Type.SHORT)) {
        invokeMethod = new Method(ii.getMethod().getClazz(), "runeliteWriteShort", new Signature("(S)V"));
    } else if (argumentType.equals(Type.INT)) {
        invokeMethod = new Method(ii.getMethod().getClazz(), "runeliteWriteInt", new Signature("(I)V"));
    } else if (argumentType.equals(Type.LONG)) {
        invokeMethod = new Method(ii.getMethod().getClazz(), "runeliteWriteLong", new Signature("(J)V"));
    } else if (argumentType.equals(Type.STRING)) {
        invokeMethod = new Method(ii.getMethod().getClazz(), "runeliteWriteString", new Signature("(Ljava/lang/String;)V"));
    } else {
        throw new IllegalStateException("Unknown type " + argumentType);
    }
    return new InvokeVirtual(i.getInstructions(), invokeMethod);
}
Also used : Type(net.runelite.asm.Type) InvokeVirtual(net.runelite.asm.attributes.code.instructions.InvokeVirtual) Signature(net.runelite.asm.signature.Signature) Method(net.runelite.asm.pool.Method)

Example 2 with Type

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

the class SignatureTest method test.

@Test
public void test() {
    Signature signature = new Signature("f(Ljava/lang/String;II[Lch;[ILce;IIB)V");
    Type type = signature.getTypeOfArg(3);
    Assert.assertTrue(type.isArray());
}
Also used : Type(net.runelite.asm.Type) Test(org.junit.Test)

Example 3 with Type

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

the class CastNullTest method testRun.

@Test
public void testRun() {
    ClassGroup group = ClassGroupFactory.generateGroup();
    Code code = group.findClass("test").findMethod("func").getCode();
    Instructions ins = code.getInstructions();
    code.setMaxStack(3);
    CheckCast checkCast = new CheckCast(ins);
    checkCast.setType(new Type("test"));
    Instruction[] instructions = { new LDC(ins, 2), new AConstNull(ins), checkCast, new LDC(ins, 2), new IAdd(ins), new Return(ins, InstructionType.IRETURN) };
    for (Instruction i : instructions) {
        ins.addInstruction(i);
    }
    Assert.assertEquals(6, ins.getInstructions().size());
    CastNull lvt = new CastNull();
    lvt.run(group);
    Assert.assertEquals(5, ins.getInstructions().size());
    Optional<Instruction> o = ins.getInstructions().stream().filter(i -> i instanceof CheckCast).findAny();
    Assert.assertFalse(o.isPresent());
}
Also used : AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) InstructionType(net.runelite.asm.attributes.code.InstructionType) Code(net.runelite.asm.attributes.Code) Test(org.junit.Test) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) ClassGroupFactory(net.runelite.deob.ClassGroupFactory) LDC(net.runelite.asm.attributes.code.instructions.LDC) Return(net.runelite.asm.attributes.code.instructions.Return) Instructions(net.runelite.asm.attributes.code.Instructions) CheckCast(net.runelite.asm.attributes.code.instructions.CheckCast) Optional(java.util.Optional) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Instruction(net.runelite.asm.attributes.code.Instruction) Assert(org.junit.Assert) Return(net.runelite.asm.attributes.code.instructions.Return) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) AConstNull(net.runelite.asm.attributes.code.instructions.AConstNull) CheckCast(net.runelite.asm.attributes.code.instructions.CheckCast) Instruction(net.runelite.asm.attributes.code.Instruction) Code(net.runelite.asm.attributes.Code) InstructionType(net.runelite.asm.attributes.code.InstructionType) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) Test(org.junit.Test)

Example 4 with Type

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

the class Inject method getFieldType.

public Type getFieldType(Field f) {
    Type type = f.getType();
    Annotation obfSignature = f.getAnnotations().find(DeobAnnotations.OBFUSCATED_SIGNATURE);
    if (obfSignature != null) {
        // Annotation exists. Type was updated by us during deobfuscation
        type = DeobAnnotations.getObfuscatedType(f);
    }
    return type;
}
Also used : Type(net.runelite.asm.Type) Annotation(net.runelite.asm.attributes.annotation.Annotation)

Example 5 with Type

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

the class Inject method toObField.

Field toObField(Field field) {
    String obfuscatedClassName = DeobAnnotations.getObfuscatedName(field.getClassFile().getAnnotations());
    // obfuscated name of field
    String obfuscatedFieldName = DeobAnnotations.getObfuscatedName(field.getAnnotations());
    Type type = getFieldType(field);
    ClassFile obfuscatedClass = vanilla.findClass(obfuscatedClassName);
    assert obfuscatedClass != null;
    Field obfuscatedField = obfuscatedClass.findFieldDeep(obfuscatedFieldName, type);
    assert obfuscatedField != null;
    return obfuscatedField;
}
Also used : Field(net.runelite.asm.Field) Type(net.runelite.asm.Type) ClassFile(net.runelite.asm.ClassFile)

Aggregations

Type (net.runelite.asm.Type)34 Signature (net.runelite.asm.signature.Signature)16 Method (net.runelite.asm.Method)15 ClassFile (net.runelite.asm.ClassFile)13 InstructionType (net.runelite.asm.attributes.code.InstructionType)13 Instruction (net.runelite.asm.attributes.code.Instruction)11 Field (net.runelite.asm.Field)10 Code (net.runelite.asm.attributes.Code)9 Instructions (net.runelite.asm.attributes.code.Instructions)9 ClassGroup (net.runelite.asm.ClassGroup)7 LDC (net.runelite.asm.attributes.code.instructions.LDC)7 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 InvokeInstruction (net.runelite.asm.attributes.code.instruction.types.InvokeInstruction)5 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)5 ALoad (net.runelite.asm.attributes.code.instructions.ALoad)5 InstructionContext (net.runelite.asm.execution.InstructionContext)5 Annotation (net.runelite.asm.attributes.annotation.Annotation)4 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)4