2 * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * - Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * - Neither the name of Sun Microsystems nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
20 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
27 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #ifndef JAVA_CRW_DEMO_H
33 #define JAVA_CRW_DEMO_H
41 /* This callback is used to notify the caller of a fatal error. */
43 typedef void (*FatalErrorHandler)(const char*message, const char*file, int line);
45 /* This callback is used to return the method information for a class.
46 * Since the information was already read here, it was useful to
47 * return it here, with no JVMTI phase restrictions.
48 * If the class file does represent a "class" and it has methods, then
49 * this callback will be called with the class number and pointers to
50 * the array of names, array of signatures, and the count of methods.
53 typedef void (*MethodNumberRegister)(unsigned, const char**, const char**, int);
55 /* Class file reader/writer interface. Basic input is a classfile image
56 * and details about what to inject. The output is a new classfile image
57 * that was allocated with malloc(), and should be freed by the caller.
60 /* Names of external symbols to look for. These are the names that we
61 * try and lookup in the shared library. On Windows 2000, the naming
62 * convention is to prefix a "_" and suffix a "@N" where N is 4 times
63 * the number or arguments supplied.It has 19 args, so 76 = 19*4.
64 * On Windows 2003, Linux, and Solaris, the first name will be
65 * found, on Windows 2000 a second try should find the second name.
67 * WARNING: If You change the JavaCrwDemo typedef, you MUST change
68 * multiple things in this file, including this name.
71 #define JAVA_CRW_DEMO_SYMBOLS { "java_crw_demo", "_java_crw_demo@76" }
73 /* Typedef needed for type casting in dynamic access situations. */
75 typedef void (JNICALL *JavaCrwDemo)(
76 unsigned class_number,
78 const unsigned char *file_image,
91 unsigned char **pnew_file_image,
93 FatalErrorHandler fatal_error_handler,
94 MethodNumberRegister mnum_callback
97 /* Function export (should match typedef above) */
99 JNIEXPORT void JNICALL java_crw_demo(
101 unsigned class_number, /* Caller assigned class number for class */
103 const char *name, /* Internal class name, e.g. java/lang/Object */
104 /* (Do not use "java.lang.Object" format) */
107 *file_image, /* Pointer to classfile image for this class */
109 long file_len, /* Length of the classfile in bytes */
111 int system_class, /* Set to 1 if this is a system class */
112 /* (prevents injections into empty */
113 /* <clinit>, finalize, and <init> methods) */
115 char* tclass_name, /* Class that has methods we will call at */
116 /* the injection sites (tclass) */
118 char* tclass_sig, /* Signature of tclass */
119 /* (Must be "L" + tclass_name + ";") */
121 char* call_name, /* Method name in tclass to call at offset 0 */
122 /* for every method */
124 char* call_sig, /* Signature of this call_name method */
125 /* (Must be "(II)V") */
127 char* return_name, /* Method name in tclass to call at all */
128 /* return opcodes in every method */
130 char* return_sig, /* Signature of this return_name method */
131 /* (Must be "(II)V") */
133 char* obj_init_name, /* Method name in tclass to call first thing */
134 /* when injecting java.lang.Object.<init> */
136 char* obj_init_sig, /* Signature of this obj_init_name method */
137 /* (Must be "(Ljava/lang/Object;)V") */
139 char* newarray_name, /* Method name in tclass to call after every */
140 /* newarray opcode in every method */
142 char* newarray_sig, /* Signature of this method */
143 /* (Must be "(Ljava/lang/Object;II)V") */
146 **pnew_file_image, /* Returns a pointer to new classfile image */
148 long *pnew_file_len, /* Returns the length of the new image */
151 fatal_error_handler, /* Pointer to function to call on any */
152 /* fatal error. NULL sends error to stderr */
155 mnum_callback /* Pointer to function that gets called */
156 /* with all details on methods in this */
157 /* class. NULL means skip this call. */
162 /* External to read the class name out of a class file .
164 * WARNING: If You change the typedef, you MUST change
165 * multiple things in this file, including this name.
168 #define JAVA_CRW_DEMO_CLASSNAME_SYMBOLS \
169 { "java_crw_demo_classname", "_java_crw_demo_classname@12" }
171 /* Typedef needed for type casting in dynamic access situations. */
173 typedef char * (JNICALL *JavaCrwDemoClassname)(
174 const unsigned char *file_image,
176 FatalErrorHandler fatal_error_handler);
178 JNIEXPORT char * JNICALL java_crw_demo_classname(
179 const unsigned char *file_image,
181 FatalErrorHandler fatal_error_handler);
185 #endif /* __cplusplus */