Search in sources :

Example 71 with Method

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

the class Mapper method mapMemberMethods.

private void mapMemberMethods(ParallelExecutorMapping mapping) {
    for (ClassFile cf : source.getClasses()) {
        ClassFile other = (ClassFile) mapping.get(cf);
        if (other == null) {
            continue;
        }
        List<Method> methods1 = cf.getMethods().stream().filter(m -> !m.isStatic()).filter(m -> !m.getName().equals("<init>")).filter(m -> m.getCode() != null).collect(Collectors.toList());
        List<Method> methods2 = other.getMethods().stream().filter(m -> !m.isStatic()).filter(m -> !m.getName().equals("<init>")).filter(m -> m.getCode() != null).collect(Collectors.toList());
        for (Method method : methods1) {
            if (// already mapped
            mapping.get(method) != null) {
                continue;
            }
            List<Method> possible = methods2.stream().filter(m -> MappingExecutorUtil.isMaybeEqual(m.getDescriptor(), method.getDescriptor())).collect(Collectors.toList());
            // Run over execution mapper
            ExecutionMapper em = new ExecutionMapper(method, possible);
            ParallelExecutorMapping map = em.run();
            if (map == null) {
                continue;
            }
            map.map(null, map.m1, map.m2);
            logger.debug("Mapped {} -> {} based on exiting class mapping and method signatures", map.m1, map.m2);
            mapping.merge(map);
        }
    }
}
Also used : List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Logger(org.slf4j.Logger) Method(net.runelite.asm.Method) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ClassGroup(net.runelite.asm.ClassGroup) ClassFile(net.runelite.asm.ClassFile) Method(net.runelite.asm.Method)

Example 72 with Method

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

the class StaticInitializerIndexer method index.

public void index() {
    for (ClassFile cf : group.getClasses()) {
        Method method = cf.findMethod("<clinit>");
        if (method == null) {
            continue;
        }
        Instructions instructions = method.getCode().getInstructions();
        for (Instruction i : instructions.getInstructions()) {
            if (i.getType() != InstructionType.PUTSTATIC) {
                continue;
            }
            PutStatic putstatic = (PutStatic) i;
            if (!putstatic.getField().getClazz().equals(cf.getPoolClass()) || putstatic.getMyField() == null) {
                continue;
            }
            fields.add(putstatic.getMyField());
        }
    }
    logger.debug("Indexed {} statically initialized fields", fields.size());
}
Also used : ClassFile(net.runelite.asm.ClassFile) Instructions(net.runelite.asm.attributes.code.Instructions) Method(net.runelite.asm.Method) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic)

Example 73 with Method

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

the class AnnotationTest method testAnnotation.

@Test
public void testAnnotation() throws IOException {
    InputStream in = this.getClass().getClassLoader().getResourceAsStream("net/runelite/asm/annotations/TestClass.class");
    Assert.assertNotNull(in);
    ClassGroup group = new ClassGroup();
    ClassFile cf = ClassUtil.loadClass(in);
    group.addClass(cf);
    byte[] out = JarUtil.writeClass(group, cf);
    // parse it again
    cf = ClassUtil.loadClass(new ByteArrayInputStream(out));
    Method method = cf.getMethods().get(1);
    Assert.assertEquals("method1", method.getName());
    Annotations annotations = method.getAnnotations();
    Assert.assertNotNull(annotations);
    Optional<Annotation> annotation = annotations.getAnnotations().stream().filter(a -> a.getType().equals(new Type("Lnet/runelite/asm/annotations/MyAnnotation;"))).findFirst();
    Assert.assertTrue(annotation.isPresent());
    Annotation an = annotation.get();
    List<Element> elements = an.getElements();
    Assert.assertEquals(1, elements.size());
    Element element = elements.get(0);
    Assert.assertEquals("value", element.getName());
    Assert.assertEquals("method1", element.getValue());
}
Also used : Annotations(net.runelite.asm.attributes.Annotations) IOException(java.io.IOException) Test(org.junit.Test) Type(net.runelite.asm.Type) ClassGroup(net.runelite.asm.ClassGroup) JarUtil(net.runelite.deob.util.JarUtil) List(java.util.List) ClassFile(net.runelite.asm.ClassFile) Annotation(net.runelite.asm.attributes.annotation.Annotation) ByteArrayInputStream(java.io.ByteArrayInputStream) Method(net.runelite.asm.Method) ClassUtil(net.runelite.asm.ClassUtil) Element(net.runelite.asm.attributes.annotation.Element) Optional(java.util.Optional) Assert(org.junit.Assert) InputStream(java.io.InputStream) ClassFile(net.runelite.asm.ClassFile) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(net.runelite.asm.attributes.annotation.Element) Method(net.runelite.asm.Method) Annotation(net.runelite.asm.attributes.annotation.Annotation) Type(net.runelite.asm.Type) Annotations(net.runelite.asm.attributes.Annotations) ByteArrayInputStream(java.io.ByteArrayInputStream) ClassGroup(net.runelite.asm.ClassGroup) Test(org.junit.Test)

Example 74 with Method

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

the class ParallellMappingExecutorTest method testStaticStep.

@Test
public void testStaticStep() throws Exception {
    ClassFile cf1 = ClassUtil.loadClass(getClass().getResourceAsStream("mapper/StaticStepTest.class"));
    ClassFile cf2 = ClassUtil.loadClass(getClass().getResourceAsStream("mapper/StaticStepTest.class"));
    ClassGroup group1 = new ClassGroup();
    ClassGroup group2 = new ClassGroup();
    group1.addClass(cf1);
    group2.addClass(cf2);
    group1.buildClassGraph();
    group1.lookup();
    group2.buildClassGraph();
    group2.lookup();
    Method m1 = cf1.findMethod("entry");
    Method m2 = cf2.findMethod("entry");
    Method map1 = cf1.findMethod("map"), map2 = cf2.findMethod("map");
    Assert.assertNotNull(map1);
    Assert.assertNotNull(map2);
    ParallelExecutorMapping map = MappingExecutorUtil.map(m1, m2);
    Assert.assertEquals(map2, map.get(map1));
}
Also used : ClassFile(net.runelite.asm.ClassFile) ClassGroup(net.runelite.asm.ClassGroup) Method(net.runelite.asm.Method) ParallelExecutorMapping(net.runelite.deob.deobfuscators.mapping.ParallelExecutorMapping) Test(org.junit.Test)

Example 75 with Method

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

the class OpcodeReplacer method run.

public void run(ClassGroup group, Collection<PacketWrite> writes) {
    int count = 0;
    ClassFile runeliteOpcodes = group.findClass(RUNELITE_OPCODES);
    assert runeliteOpcodes != null : "Opcodes class must exist";
    for (PacketWrite wp : writes) {
        Instructions ins = wp.getInstructions();
        Instruction param = wp.getOpcodeIns();
        if (!(param instanceof PushConstantInstruction)) {
            continue;
        }
        final String fieldName = "PACKET_CLIENT_" + wp.getOpcode();
        net.runelite.asm.pool.Field field = new net.runelite.asm.pool.Field(new net.runelite.asm.pool.Class(RUNELITE_OPCODES), fieldName, Type.INT);
        ins.replace(param, new GetStatic(ins, field));
        if (runeliteOpcodes.findField(fieldName) == null) {
            Field opField = new Field(runeliteOpcodes, fieldName, Type.INT);
            // ACC_FINAL causes javac to inline the fields, which prevents
            // the mapper from doing field mapping
            opField.setAccessFlags(ACC_PUBLIC | ACC_STATIC);
            // setting a non-final static field value
            // doesn't work with fernflower
            opField.setValue(wp.getOpcode());
            runeliteOpcodes.addField(opField);
            // add initialization
            Method clinit = runeliteOpcodes.findMethod("<clinit>");
            assert clinit != null;
            Instructions instructions = clinit.getCode().getInstructions();
            instructions.addInstruction(0, new LDC(instructions, wp.getOpcode()));
            instructions.addInstruction(1, new PutStatic(instructions, opField));
        }
        ++count;
    }
    logger.info("Injected {} packet writes", count);
}
Also used : ClassFile(net.runelite.asm.ClassFile) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instructions(net.runelite.asm.attributes.code.Instructions) LDC(net.runelite.asm.attributes.code.instructions.LDC) Method(net.runelite.asm.Method) PushConstantInstruction(net.runelite.asm.attributes.code.instruction.types.PushConstantInstruction) Instruction(net.runelite.asm.attributes.code.Instruction) PutStatic(net.runelite.asm.attributes.code.instructions.PutStatic) Field(net.runelite.asm.Field) GetStatic(net.runelite.asm.attributes.code.instructions.GetStatic)

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