java_crw_demo.h revision 0
4169N/A/*
1178N/A * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
1178N/A *
1178N/A * Redistribution and use in source and binary forms, with or without
1178N/A * modification, are permitted provided that the following conditions
1178N/A * are met:
1178N/A *
1178N/A * - Redistributions of source code must retain the above copyright
1178N/A * notice, this list of conditions and the following disclaimer.
1178N/A *
1178N/A * - Redistributions in binary form must reproduce the above copyright
1178N/A * notice, this list of conditions and the following disclaimer in the
1178N/A * documentation and/or other materials provided with the distribution.
1178N/A *
1178N/A * - Neither the name of Sun Microsystems nor the names of its
1178N/A * contributors may be used to endorse or promote products derived
1178N/A * from this software without specific prior written permission.
2362N/A *
2362N/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
2362N/A * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
1178N/A * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
4169N/A * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
1178N/A * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
1178N/A * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
4033N/A * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
4033N/A * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
1178N/A * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
1178N/A * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
4033N/A * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1178N/A */
4033N/A
0N/A#ifndef JAVA_CRW_DEMO_H
1178N/A#define JAVA_CRW_DEMO_H
1178N/A
1178N/A#include <jni.h>
1178N/A
1178N/A#ifdef __cplusplus
1178N/Aextern "C" {
1178N/A#endif
1178N/A
1178N/A/* This callback is used to notify the caller of a fatal error. */
4033N/A
1178N/Atypedef void (*FatalErrorHandler)(const char*message, const char*file, int line);
1178N/A
4033N/A/* This callback is used to return the method information for a class.
1178N/A * Since the information was already read here, it was useful to
1178N/A * return it here, with no JVMTI phase restrictions.
1178N/A * If the class file does represent a "class" and it has methods, then
1178N/A * this callback will be called with the class number and pointers to
0N/A * the array of names, array of signatures, and the count of methods.
1178N/A */
1178N/A
1178N/Atypedef void (*MethodNumberRegister)(unsigned, const char**, const char**, int);
1178N/A
1178N/A/* Class file reader/writer interface. Basic input is a classfile image
1178N/A * and details about what to inject. The output is a new classfile image
4033N/A * that was allocated with malloc(), and should be freed by the caller.
1178N/A */
1178N/A
4033N/A/* Names of external symbols to look for. These are the names that we
1178N/A * try and lookup in the shared library. On Windows 2000, the naming
1178N/A * convention is to prefix a "_" and suffix a "@N" where N is 4 times
4033N/A * the number or arguments supplied.It has 19 args, so 76 = 19*4.
1178N/A * On Windows 2003, Linux, and Solaris, the first name will be
1178N/A * found, on Windows 2000 a second try should find the second name.
4033N/A *
1178N/A * WARNING: If You change the JavaCrwDemo typedef, you MUST change
0N/A * multiple things in this file, including this name.
4033N/A */
4033N/A
0N/A#define JAVA_CRW_DEMO_SYMBOLS { "java_crw_demo", "_java_crw_demo@76" }
4033N/A
0N/A/* Typedef needed for type casting in dynamic access situations. */
4033N/A
0N/Atypedef void (JNICALL *JavaCrwDemo)(
1178N/A unsigned class_number,
1178N/A const char *name,
1178N/A const unsigned char *file_image,
4033N/A long file_len,
1178N/A int system_class,
1178N/A char* tclass_name,
4033N/A char* tclass_sig,
1178N/A char* call_name,
1178N/A char* call_sig,
1178N/A char* return_name,
1178N/A char* return_sig,
1178N/A char* obj_init_name,
1178N/A char* obj_init_sig,
1178N/A char* newarray_name,
4033N/A char* newarray_sig,
1178N/A unsigned char **pnew_file_image,
1178N/A long *pnew_file_len,
1178N/A FatalErrorHandler fatal_error_handler,
1178N/A MethodNumberRegister mnum_callback
1178N/A);
1178N/A
1178N/A/* Function export (should match typedef above) */
1178N/A
1178N/AJNIEXPORT void JNICALL java_crw_demo(
4033N/A
1178N/A unsigned class_number, /* Caller assigned class number for class */
1178N/A
1178N/A const char *name, /* Internal class name, e.g. java/lang/Object */
1178N/A /* (Do not use "java.lang.Object" format) */
1178N/A
1178N/A const unsigned char
1178N/A *file_image, /* Pointer to classfile image for this class */
4033N/A
1178N/A long file_len, /* Length of the classfile in bytes */
1178N/A
1178N/A int system_class, /* Set to 1 if this is a system class */
1178N/A /* (prevents injections into empty */
4033N/A /* <clinit>, finalize, and <init> methods) */
1178N/A
1178N/A char* tclass_name, /* Class that has methods we will call at */
4033N/A /* the injection sites (tclass) */
1178N/A
1178N/A char* tclass_sig, /* Signature of tclass */
4033N/A /* (Must be "L" + tclass_name + ";") */
1178N/A
1178N/A char* call_name, /* Method name in tclass to call at offset 0 */
1178N/A /* for every method */
4033N/A
1178N/A char* call_sig, /* Signature of this call_name method */
4033N/A /* (Must be "(II)V") */
1178N/A
1178N/A char* return_name, /* Method name in tclass to call at all */
4033N/A /* return opcodes in every method */
4033N/A
1178N/A char* return_sig, /* Signature of this return_name method */
1178N/A /* (Must be "(II)V") */
4033N/A
1178N/A char* obj_init_name, /* Method name in tclass to call first thing */
1178N/A /* when injecting java.lang.Object.<init> */
4033N/A
1178N/A char* obj_init_sig, /* Signature of this obj_init_name method */
1178N/A /* (Must be "(Ljava/lang/Object;)V") */
4033N/A
0N/A char* newarray_name, /* Method name in tclass to call after every */
1178N/A /* newarray opcode in every method */
1178N/A
4033N/A char* newarray_sig, /* Signature of this method */
1178N/A /* (Must be "(Ljava/lang/Object;II)V") */
4033N/A
0N/A unsigned char
1178N/A **pnew_file_image, /* Returns a pointer to new classfile image */
1178N/A
1178N/A long *pnew_file_len, /* Returns the length of the new image */
1178N/A
1178N/A FatalErrorHandler
1178N/A fatal_error_handler, /* Pointer to function to call on any */
1178N/A /* fatal error. NULL sends error to stderr */
1178N/A
1178N/A MethodNumberRegister
1178N/A mnum_callback /* Pointer to function that gets called */
1178N/A /* with all details on methods in this */
0N/A /* class. NULL means skip this call. */
1178N/A
4033N/A );
1178N/A
1178N/A
4033N/A/* External to read the class name out of a class file .
4033N/A *
1178N/A * WARNING: If You change the typedef, you MUST change
1178N/A * multiple things in this file, including this name.
4033N/A */
1178N/A
1178N/A#define JAVA_CRW_DEMO_CLASSNAME_SYMBOLS \
4033N/A { "java_crw_demo_classname", "_java_crw_demo_classname@12" }
1178N/A
1178N/A/* Typedef needed for type casting in dynamic access situations. */
4033N/A
1178N/Atypedef char * (JNICALL *JavaCrwDemoClassname)(
1178N/A const unsigned char *file_image,
1178N/A long file_len,
0N/A FatalErrorHandler fatal_error_handler);
4033N/A
1178N/AJNIEXPORT char * JNICALL java_crw_demo_classname(
1178N/A const unsigned char *file_image,
1178N/A long file_len,
4033N/A FatalErrorHandler fatal_error_handler);
1178N/A
4033N/A#ifdef __cplusplus
4033N/A} /* extern "C" */
1178N/A#endif /* __cplusplus */
1178N/A
4033N/A#endif
4033N/A