Examples of JiapiMethod


Examples of alt.jiapi.reflect.JiapiMethod

    static byte[] jiapiHelloWorld() throws MethodExistsException {
        JiapiClass c = JiapiClass.createClass("HelloWorld");

        // No API to set SourceFile!

        JiapiMethod method = c.addMethod(Modifier.PUBLIC, "<init>", emptySig);
        InstructionList il = method.getInstructionList();
        InstructionFactory iFactory = il.getInstructionFactory();
        il.add(iFactory.aload(0));
        il.add(iFactory.invoke(0, "java/lang/Object", "<init>", emptySig));
        il.add(iFactory.returnMethod(method));

        method = c.addMethod(Modifier.PUBLIC | Modifier.STATIC, "main", mainSig);
        il = method.getInstructionList();
        iFactory = il.getInstructionFactory();
        il.add(iFactory.getField(Modifier.STATIC,
                "java/lang/System",
                "out",
                "Ljava/io/PrintStream;"));
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

            }
        }

        log.info("Creating method " + clazz.getName() + "." + methodName);

        JiapiMethod method = null;
        try {
            Signature signature = new Signature(returnType, parameterNames);
            method = clazz.addMethod((short)modifiers, methodName, signature);
        }
        catch (MethodExistsException mee) {
            log.info("method " + clazz.getName() + "." + methodName +
                     " already exists");

            method = mee.getMethod();
        }

        if (forwardMode == FORWARD_ORIGINAL) {
            forward(il);
        }
        else if (forwardMode == FORWARD_NEW) {
            forward(method.getInstructionList());
        }
        else {
            // Forward both
            forward(il);
            forward(method.getInstructionList());
        }

        if (createReturn) {
            InstructionFactory factory = method.getInstructionFactory();
            method.getInstructionList().add(factory.returnMethod(method));
        }
    }
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

        // Add an empty method for a clazz. The method signature must
        // match the method from HelloWorld interface, the only difference
        // is that we want to implement the method now so it can't be abstract.
        Signature signature = new Signature("void", new String[] {} );
        JiapiMethod method = clazz.addMethod(Modifier.PUBLIC, "helloWorld",
                                             signature);
       
        // Then create the method body. The body will make a call to
        // System.out.println and then just return.
        InstructionList il = method.getInstructionList();
        InstructionFactory iFactory = method.getInstructionFactory();

        JiapiMethod println = clazz.getDeclaredMethod("println", new String[]
                                                      {"java.lang.Object"});

//         il.add(iFactory.getField(loader.loadClass("java.lang.System").getField("out")));
//         JiapiMethod println = loader.loadClass(System.out.getClass().getName()).getMethod("println", new String[] { "java.lang.String" } );
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

        String[] parameterTypeNames = new String[parameterTypes.length];
        for (int i = 0; i < parameterTypes.length; i++) {
            parameterTypeNames[i] = parameterTypes[i].getName();
        }

        JiapiMethod method = clazz.getMethod(sourceMethod.getName(),
                                             parameterTypeNames);
        source = method.getInstructionList();
    }
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

    public void instrument(JiapiMethod jm) {
        InstructionList il = jm.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();
        JiapiClass fep = getEventProducer();
        JiapiMethod fieldGet = null;
        JiapiMethod fieldSet = null;
        JiapiField jiapiField = getEventProducerField();

        try {
            fieldGet =
                fep.getDeclaredMethod("fieldGet",
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

    public void instrument(JiapiMethod jm) {
        InstructionList il = jm.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();
        JiapiClass mep = getEventProducer();
        JiapiMethod methodEntered = null;
        JiapiMethod methodExited = null;
        JiapiField jiapiField = getEventProducerField();

        // a flag, that tells whether or not InstructionList being
        // processed is in a static method.
        boolean isStatic = Modifier.isStatic(il.getDeclaringMethod().getModifiers());
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

        }
       

        // Next, create static initializer, that initializes
        // field created above.
        JiapiMethod clinit = null;
        try {
            clinit = currentClass.getDeclaredMethod("<clinit>",new String[]{});
        }
        catch(NoSuchMethodException nsme) {
            // It did not exists, so create one
            try {
                clinit =
                    currentClass.addMethod(Modifier.STATIC, "<clinit>",
                                           new Signature("void",
                                                         new String[0]));
                // create 'return' from <clinit>
                clinit.getInstructionList().add(clinit.getInstructionList().getInstructionFactory().returnMethod(clinit));
            }
            catch(MethodExistsException mee) {
                mee.printStackTrace();
            }
        }

        InstructionList il = clinit.getInstructionList();
        InstructionFactory factory = il.getInstructionFactory();
        InstructionList initializer = il.createEmptyList();

        try {
            JiapiClass er = currentClass.getLoader().loadClass("alt.jiapi.event.EventRuntime");
            JiapiMethod gfv =
                er.getDeclaredMethod("getFieldValue",
                                     new String[] {"java.lang.String"});

            // Get the field value from runtime
            initializer.add(factory.pushConstant(fieldName));
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

                else if ("getArguments".equals(inv.getMethodName())) {
                    // NOT IMPLEMENTED
                    // This needs some further thinking before implementing
                }
                else if ("getInstrumentedObject".equals(inv.getMethodName())) {
        JiapiMethod jm = il.getDeclaringMethod();
        int modifiers = jm.getModifiers();
        if (Modifier.isStatic(modifiers)) {
      // Static methods do not have reference to 'this'
      //view.add(factory.pushNull());
      view.add(factory.pushConstant(jm.getDeclaringClass().getName()));
      view.add(factory.invoke(Modifier.STATIC, "java.lang.Class", "forName", new Signature("java.lang.Class", new String[] {"java.lang.String"})));
        }
        else {
      view.add(factory.aload(0));
        }
View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

     */
    public void instrument(InstructionList il) {
        log.info("Instrumenting " + getCurrentClass().getName() + "." +
                 il.getDeclaringMethod().getName());

        JiapiMethod jm = il.getDeclaringMethod();
        // Native or abstract methods can't be instrumented.
        int modifiers = jm.getModifiers();
        if (Modifier.isNative(modifiers) || Modifier.isAbstract(modifiers)) {
            log.info("skipping abstract or native method: " +
                     getCurrentClass().getName() + "." + jm.getName());

            forward(il);
            return;
        }

View Full Code Here

Examples of alt.jiapi.reflect.JiapiMethod

           
            for (int i = 0; i < pTypes.length; i++) {
                pTypes[i] = hpTypes[i].getName();
            }
           
            JiapiMethod hMethod =hClass.getDeclaredMethod(hookMethod.getName(),
                                                          pTypes);
            il.add(factory.invoke(hMethod));
        }
        catch(Exception e) {
            log.error("Failed to add invoke instruction: " + e);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.