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