Search in sources :

Example 36 with Field

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

the class HookImporter method importHooks.

@Test
@Ignore
public void importHooks() {
    int classes = 0, fields = 0, methods = 0;
    NameMappings mappings = new NameMappings();
    for (HookClass hc : hooks) {
        ClassFile cf = findClassWithObfuscatedName(hc.name);
        assert cf != null;
        String implementsName = getAnnotation(cf.getAnnotations(), IMPLEMENTS);
        if (implementsName.isEmpty()) {
            String deobfuscatedClassName = hc.clazz;
            cf.getAnnotations().addAnnotation(IMPLEMENTS, "value", deobfuscatedClassName);
            mappings.map(cf.getPoolClass(), deobfuscatedClassName);
            ++classes;
        }
        for (HookField fh : hc.fields) {
            ClassFile cf2 = findClassWithObfuscatedName(fh.owner);
            assert cf2 != null;
            Field f = findFieldWithObfuscatedName(cf2, fh.name);
            if (f == null) {
                // inlined constant maybe?
                logger.warn("Missing field {}", fh);
                continue;
            }
            String exportedName = getAnnotation(f.getAnnotations(), EXPORT);
            if (exportedName.isEmpty()) {
                String deobfuscatedFieldName = fh.field;
                Field other = cf2.findField(deobfuscatedFieldName);
                if (other != null) {
                    logger.warn("Name collision for field {}", deobfuscatedFieldName);
                    continue;
                }
                f.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedFieldName);
                mappings.map(f.getPoolField(), deobfuscatedFieldName);
                ++fields;
            }
        }
        outer: for (HookMethod hm : hc.methods) {
            ClassFile cf2 = findClassWithObfuscatedName(hm.owner);
            assert cf2 != null;
            Method m = findMethodWithObfuscatedName(cf2, hm.name, hm.descriptor);
            assert m != null;
            // maybe only the base class method is exported
            List<Method> virtualMethods = VirtualMethods.getVirtualMethods(m);
            for (Method method : virtualMethods) {
                String exportedName = getAnnotation(method.getAnnotations(), EXPORT);
                if (!exportedName.isEmpty()) {
                    continue outer;
                }
            }
            String deobfuscatedMethodName = hm.method;
            m.getAnnotations().addAnnotation(EXPORT, "value", deobfuscatedMethodName);
            mappings.map(m.getPoolMethod(), deobfuscatedMethodName);
            ++methods;
        }
    }
    Renamer renamer = new Renamer(mappings);
    renamer.run(group);
    logger.info("Imported {} classes, {} fields, {} methods", classes, fields, methods);
}
Also used : Renamer(net.runelite.deob.deobfuscators.Renamer) Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) List(java.util.List) Method(net.runelite.asm.Method) NameMappings(net.runelite.deob.util.NameMappings) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with Field

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

the class UpdateMappingsTest method summary.

public static void summary(ParallelExecutorMapping finalm, ClassGroup in) {
    int fields = 0, staticMethod = 0, method = 0, total = 0, classes = 0;
    for (Map.Entry<Object, Object> e : finalm.getMap().entrySet()) {
        Object o = e.getKey();
        if (o instanceof Field) {
            ++fields;
            Field f = (Field) o;
            assert f.getClassFile().getGroup() == in;
        } else if (o instanceof Method) {
            Method m = (Method) o;
            assert m.getClassFile().getGroup() == in;
            if (m.isStatic()) {
                ++staticMethod;
            } else {
                ++method;
            }
        } else if (o instanceof ClassFile) {
            ++classes;
        }
        ++total;
    }
    logger.info("Total mapped: {}. {} fields, {} static methods, {} member methods, {} classes", total, fields, staticMethod, method, classes);
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method) Map(java.util.Map)

Example 38 with Field

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

the class BufferMethodInjector method inject.

public void inject() throws IOException {
    Field buffer = bp.getBuffer();
    Field offset = bp.getOffset();
    assert buffer.getClassFile() == offset.getClassFile();
    InputStream in = getClass().getResourceAsStream("RuneliteBuffer.class");
    assert in != null : "no RuneliteBuffer";
    ClassFile runeliteBuffer = loadClass(in);
    ClassFile bufferClass = buffer.getClassFile();
    for (Field f : runeliteBuffer.getFields()) {
        if (!f.getName().startsWith("runelite")) {
            continue;
        }
        inject(bufferClass, f);
    }
    for (Method m : runeliteBuffer.getMethods()) {
        if (!m.getName().startsWith("runelite")) {
            continue;
        }
        inject(bufferClass, m);
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile) InputStream(java.io.InputStream) Method(net.runelite.asm.Method)

Example 39 with Field

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

the class ModArith method annotateEncryption.

public void annotateEncryption() {
    for (ClassFile cf : group.getClasses()) {
        for (Field f : cf.getFields()) {
            Pair pair = encryption.getField(f.getPoolField());
            if (pair == null) {
                continue;
            }
            if (pair.getter.longValue() == 1L) {
                continue;
            }
            String ename = pair.getType() == Long.class ? "longValue" : "intValue";
            f.getAnnotations().addAnnotation(DeobAnnotations.OBFUSCATED_GETTER, ename, pair.getter);
        }
    }
}
Also used : Field(net.runelite.asm.Field) ClassFile(net.runelite.asm.ClassFile)

Example 40 with Field

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

the class ModArith method findUses.

// find potential getters/setters for each field
private void findUses(MethodContext mctx) {
    for (InstructionContext ctx : mctx.getInstructionContexts()) {
        if (ctx.getInstruction() instanceof IMul || ctx.getInstruction() instanceof LMul) {
            Instruction one = ctx.getPops().get(0).getPushed().getInstruction();
            Instruction two = ctx.getPops().get(1).getPushed().getInstruction();
            PushConstantInstruction pc = null;
            GetFieldInstruction gf = null;
            if (one instanceof PushConstantInstruction && two instanceof GetFieldInstruction) {
                pc = (PushConstantInstruction) one;
                gf = (GetFieldInstruction) two;
            } else if (two instanceof PushConstantInstruction && one instanceof GetFieldInstruction) {
                pc = (PushConstantInstruction) two;
                gf = (GetFieldInstruction) one;
            }
            if (pc == null) {
                continue;
            }
            Field field = gf.getMyField();
            if (field == null) {
                continue;
            }
            FieldInfo fieldInfo = getFieldInfo(field);
            // parse the full multiplication expression to
            // get all associated constants
            List<InstructionContext> insInExpr = getInsInExpr(ctx, new HashSet(), true);
            for (InstructionContext ctx2 : insInExpr) {
                if (!(ctx2.getInstruction() instanceof PushConstantInstruction)) {
                    continue;
                }
                PushConstantInstruction pci3 = (PushConstantInstruction) ctx2.getInstruction();
                Number value = (Number) pci3.getConstant();
                // field * constant
                if (value instanceof Integer || value instanceof Long) {
                    fieldInfo.getters.add(value);
                }
            }
        } else if (ctx.getInstruction() instanceof SetFieldInstruction) {
            SetFieldInstruction sf = (SetFieldInstruction) ctx.getInstruction();
            Field field = sf.getMyField();
            if (field == null) {
                continue;
            }
            FieldInfo fieldInfo = getFieldInfo(field);
            // value being set
            InstructionContext pushedsfi = ctx.getPops().get(0).getPushed();
            pushedsfi = pushedsfi.resolve(ctx.getPops().get(0));
            if (!(pushedsfi.getInstruction() instanceof IMul) && !(pushedsfi.getInstruction() instanceof LMul) && !(pushedsfi.getInstruction() instanceof IAdd) && !(pushedsfi.getInstruction() instanceof LAdd) && !(pushedsfi.getInstruction() instanceof ISub) && !(pushedsfi.getInstruction() instanceof LSub)) {
                if (pushedsfi.getInstruction() instanceof LDC) {
                    PushConstantInstruction ldc = (PushConstantInstruction) pushedsfi.getInstruction();
                    if (ldc.getConstant() instanceof Integer || ldc.getConstant() instanceof Long) {
                        Number i = (Number) ldc.getConstant();
                        // field = constant
                        fieldInfo.setters.add(i);
                    }
                }
                continue;
            }
            Instruction one = pushedsfi.getPops().get(0).getPushed().getInstruction();
            Instruction two = pushedsfi.getPops().get(1).getPushed().getInstruction();
            // field = field + imul
            if (pushedsfi.getInstruction() instanceof IAdd) {
                if (one instanceof IMul && two instanceof GetFieldInstruction) {
                    one = pushedsfi.getPops().get(0).getPushed().getPops().get(0).getPushed().getInstruction();
                    two = pushedsfi.getPops().get(0).getPushed().getPops().get(1).getPushed().getInstruction();
                }
            }
            // if both one and two are constants then one of them must not be a setter
            PushConstantInstruction pc = null;
            if (one instanceof PushConstantInstruction && !(two instanceof PushConstantInstruction)) {
                pc = (PushConstantInstruction) one;
            } else if (two instanceof PushConstantInstruction && !(one instanceof PushConstantInstruction)) {
                pc = (PushConstantInstruction) two;
            }
            if (pc == null) {
                continue;
            }
            Number value2 = (Number) pc.getConstant();
            // field = something * constant
            if (value2 instanceof Integer || value2 instanceof Long) {
                fieldInfo.setters.add(value2);
            }
        }
    }
}
Also used : InstructionContext(net.runelite.asm.execution.InstructionContext) SetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) LDC(net.runelite.asm.attributes.code.instructions.LDC) 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) Field(net.runelite.asm.Field) ISub(net.runelite.asm.attributes.code.instructions.ISub) LAdd(net.runelite.asm.attributes.code.instructions.LAdd) LSub(net.runelite.asm.attributes.code.instructions.LSub) IMul(net.runelite.asm.attributes.code.instructions.IMul) IAdd(net.runelite.asm.attributes.code.instructions.IAdd) LMul(net.runelite.asm.attributes.code.instructions.LMul) GetFieldInstruction(net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction) HashSet(java.util.HashSet)

Aggregations

Field (net.runelite.asm.Field)65 ClassFile (net.runelite.asm.ClassFile)39 Method (net.runelite.asm.Method)33 Instruction (net.runelite.asm.attributes.code.Instruction)19 InstructionContext (net.runelite.asm.execution.InstructionContext)19 GetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.GetFieldInstruction)17 Instructions (net.runelite.asm.attributes.code.Instructions)16 StackContext (net.runelite.asm.execution.StackContext)16 Type (net.runelite.asm.Type)15 PushConstantInstruction (net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction)12 LDC (net.runelite.asm.attributes.code.instructions.LDC)11 Code (net.runelite.asm.attributes.Code)10 SetFieldInstruction (net.runelite.asm.attributes.code.instruction.types.SetFieldInstruction)10 Signature (net.runelite.asm.signature.Signature)9 ClassGroup (net.runelite.asm.ClassGroup)8 FieldInstruction (net.runelite.asm.attributes.code.instruction.types.FieldInstruction)8 PutField (net.runelite.asm.attributes.code.instructions.PutField)8 Test (org.junit.Test)8 List (java.util.List)7 Annotation (net.runelite.asm.attributes.annotation.Annotation)7