![]() |
|
|
00001 /* 00002 * @(#)java_crw_demo.h 1.16 05/01/04 00003 * 00004 * Copyright (c) 2005 Sun Microsystems, Inc. All Rights Reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * 00009 * -Redistribution of source code must retain the above copyright notice, this 00010 * list of conditions and the following disclaimer. 00011 * 00012 * -Redistribution in binary form must reproduce the above copyright notice, 00013 * this list of conditions and the following disclaimer in the documentation 00014 * and/or other materials provided with the distribution. 00015 * 00016 * Neither the name of Sun Microsystems, Inc. or the names of contributors may 00017 * be used to endorse or promote products derived from this software without 00018 * specific prior written permission. 00019 * 00020 * This software is provided "AS IS," without a warranty of any kind. ALL 00021 * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING 00022 * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE 00023 * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MIDROSYSTEMS, INC. ("SUN") 00024 * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE 00025 * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS 00026 * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST 00027 * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, 00028 * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY 00029 * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, 00030 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 00031 * 00032 * You acknowledge that this software is not designed, licensed or intended 00033 * for use in the design, construction, operation or maintenance of any 00034 * nuclear facility. 00035 */ 00036 00037 #ifndef JAVA_CRW_DEMO_H 00038 #define JAVA_CRW_DEMO_H 00039 00040 #include <jni.h> 00041 00042 /* This callback is used to notify the caller of a fatal error. */ 00043 00044 typedef void (*FatalErrorHandler)(const char*message, const char*file, int line); 00045 00046 /* This callback is used to return the method information for a class. 00047 * Since the information was already read here, it was useful to 00048 * return it here, with no JVMTI phase restrictions. 00049 * If the class file does represent a "class" and it has methods, then 00050 * this callback will be called with the class number and pointers to 00051 * the array of names, array of signatures, and the count of methods. 00052 */ 00053 00054 typedef void (*MethodNumberRegister)(unsigned, const char**, const char**, int); 00055 00056 /* Class file reader/writer interface. Basic input is a classfile image 00057 * and details about what to inject. The output is a new classfile image 00058 * that was allocated with malloc(), and should be freed by the caller. 00059 */ 00060 00061 /* Names of external symbols to look for. These are the names that we 00062 * try and lookup in the shared library. On Windows 2000, the naming 00063 * convention is to prefix a "_" and suffix a "@N" where N is 4 times 00064 * the number or arguments supplied.It has 19 args, so 76 = 19*4. 00065 * On Windows 2003, Linux, and Solaris, the first name will be 00066 * found, on Windows 2000 a second try should find the second name. 00067 * 00068 * WARNING: If You change the JavaCrwDemo typedef, you MUST change 00069 * multiple things in this file, including this name. 00070 */ 00071 00072 #define JAVA_CRW_DEMO_SYMBOLS { "java_crw_demo", "_java_crw_demo@76" } 00073 00074 /* Typedef needed for type casting in dynamic access situations. */ 00075 00076 typedef void (JNICALL *JavaCrwDemo)( 00077 unsigned class_number, 00078 const char *name, 00079 const unsigned char *file_image, 00080 long file_len, 00081 int system_class, 00082 char* tclass_name, 00083 char* tclass_sig, 00084 char* call_name, 00085 char* call_sig, 00086 char* return_name, 00087 char* return_sig, 00088 char* obj_init_name, 00089 char* obj_init_sig, 00090 char* newarray_name, 00091 char* newarray_sig, 00092 unsigned char **pnew_file_image, 00093 long *pnew_file_len, 00094 FatalErrorHandler fatal_error_handler, 00095 MethodNumberRegister mnum_callback 00096 ); 00097 00098 /* Function export (should match typedef above) */ 00099 00100 JNIEXPORT void JNICALL java_crw_demo( 00101 00102 unsigned class_number, /* Caller assigned class number for class */ 00103 00104 const char *name, /* Internal class name, e.g. java/lang/Object */ 00105 /* (Do not use "java.lang.Object" format) */ 00106 00107 const unsigned char 00108 *file_image, /* Pointer to classfile image for this class */ 00109 00110 long file_len, /* Length of the classfile in bytes */ 00111 00112 int system_class, /* Set to 1 if this is a system class */ 00113 /* (prevents injections into empty */ 00114 /* <clinit>, finalize, and <init> methods) */ 00115 00116 char* tclass_name, /* Class that has methods we will call at */ 00117 /* the injection sites (tclass) */ 00118 00119 char* tclass_sig, /* Signature of tclass */ 00120 /* (Must be "L" + tclass_name + ";") */ 00121 00122 char* call_name, /* Method name in tclass to call at offset 0 */ 00123 /* for every method */ 00124 00125 char* call_sig, /* Signature of this call_name method */ 00126 /* (Must be "(II)V") */ 00127 00128 char* return_name, /* Method name in tclass to call at all */ 00129 /* return opcodes in every method */ 00130 00131 char* return_sig, /* Signature of this return_name method */ 00132 /* (Must be "(II)V") */ 00133 00134 char* obj_init_name, /* Method name in tclass to call first thing */ 00135 /* when injecting java.lang.Object.<init> */ 00136 00137 char* obj_init_sig, /* Signature of this obj_init_name method */ 00138 /* (Must be "(Ljava/lang/Object;)V") */ 00139 00140 char* newarray_name, /* Method name in tclass to call after every */ 00141 /* newarray opcode in every method */ 00142 00143 char* newarray_sig, /* Signature of this method */ 00144 /* (Must be "(Ljava/lang/Object;II)V") */ 00145 00146 unsigned char 00147 **pnew_file_image, /* Returns a pointer to new classfile image */ 00148 00149 long *pnew_file_len, /* Returns the length of the new image */ 00150 00151 FatalErrorHandler 00152 fatal_error_handler, /* Pointer to function to call on any */ 00153 /* fatal error. NULL sends error to stderr */ 00154 00155 MethodNumberRegister 00156 mnum_callback /* Pointer to function that gets called */ 00157 /* with all details on methods in this */ 00158 /* class. NULL means skip this call. */ 00159 00160 ); 00161 00162 00163 /* External to read the class name out of a class file . 00164 * 00165 * WARNING: If You change the typedef, you MUST change 00166 * multiple things in this file, including this name. 00167 */ 00168 00169 #define JAVA_CRW_DEMO_CLASSNAME_SYMBOLS \ 00170 { "java_crw_demo_classname", "_java_crw_demo_classname@12" } 00171 00172 /* Typedef needed for type casting in dynamic access situations. */ 00173 00174 typedef char * (JNICALL *JavaCrwDemoClassname)( 00175 const unsigned char *file_image, 00176 long file_len, 00177 FatalErrorHandler fatal_error_handler); 00178 00179 JNIEXPORT char * JNICALL java_crw_demo_classname( 00180 const unsigned char *file_image, 00181 long file_len, 00182 FatalErrorHandler fatal_error_handler); 00183 00184 #endif 00185