54 static void JNICALL
55 ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
56 jclass class_being_redefined, jobject loader,
57 const char* name, jobject protection_domain,
58 jint class_data_len, const unsigned char* class_data,
59 jint *new_class_data_len, unsigned char** new_class_data) {
60 int found_1 = NSK_FALSE;
61 int found_2 = NSK_FALSE;
62 jint magicIndex = 0;
63 jint i;
64
65 if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) {
66 ClassFileLoadHookEventFlag = NSK_TRUE;
67 NSK_DISPLAY0("ClassFileLoadHook event\n");
68
69 if (!NSK_VERIFY(class_being_redefined == NULL)) {
70 nsk_jvmti_setFailStatus();
71 return;
72 }
73
74 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB3(Allocate,
75 jvmti_env, class_data_len, &klass_bytes)))
76 nsk_jvmti_setFailStatus();
77
78 else {
79 memcpy(klass_bytes, class_data, class_data_len);
80 klass_byte_count = class_data_len;
81
82 for (i = 0; i < klass_byte_count - 3; i++) {
83 if (((jint)klass_bytes[i+3] |
84 ((jint)klass_bytes[i+2] << 8) |
85 ((jint)klass_bytes[i+1] << 16) |
86 ((jint)klass_bytes[i] << 24)) == magicNumber_1) {
87 NSK_DISPLAY2("index of 0x%x: %d\n", magicNumber_1, i);
88 found_1 = NSK_TRUE;
89 } else if (((jint)klass_bytes[i+3] |
90 ((jint)klass_bytes[i+2] << 8) |
91 ((jint)klass_bytes[i+1] << 16) |
92 ((jint)klass_bytes[i] << 24)) == magicNumber_2) {
93 NSK_DISPLAY2("index of 0x%x: %d\n", magicNumber_2, i);
94 magicIndex = i;
95 found_2 = NSK_TRUE;
158
159 NSK_DISPLAY0("Agent_OnLoad\n");
160
161 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
162 return JNI_ERR;
163
164 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
165
166 if (!NSK_VERIFY((jvmti =
167 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
168 return JNI_ERR;
169
170 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
171 return JNI_ERR;
172
173 memset(&callbacks, 0, sizeof(callbacks));
174 callbacks.ClassFileLoadHook = &ClassFileLoadHook;
175 if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
176 return JNI_ERR;
177
178 if (!NSK_JVMTI_VERIFY(NSK_CPP_STUB4(SetEventNotificationMode,
179 jvmti, JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL)))
180 return JNI_ERR;
181
182 return JNI_OK;
183 }
184
185 /* ========================================================================== */
186
187 }
|
54 static void JNICALL
55 ClassFileLoadHook(jvmtiEnv *jvmti_env, JNIEnv *jni_env,
56 jclass class_being_redefined, jobject loader,
57 const char* name, jobject protection_domain,
58 jint class_data_len, const unsigned char* class_data,
59 jint *new_class_data_len, unsigned char** new_class_data) {
60 int found_1 = NSK_FALSE;
61 int found_2 = NSK_FALSE;
62 jint magicIndex = 0;
63 jint i;
64
65 if (name != NULL && (strcmp(name, CLASS_NAME) == 0)) {
66 ClassFileLoadHookEventFlag = NSK_TRUE;
67 NSK_DISPLAY0("ClassFileLoadHook event\n");
68
69 if (!NSK_VERIFY(class_being_redefined == NULL)) {
70 nsk_jvmti_setFailStatus();
71 return;
72 }
73
74 if (!NSK_JVMTI_VERIFY(jvmti_env->Allocate(class_data_len, &klass_bytes)))
75 nsk_jvmti_setFailStatus();
76
77 else {
78 memcpy(klass_bytes, class_data, class_data_len);
79 klass_byte_count = class_data_len;
80
81 for (i = 0; i < klass_byte_count - 3; i++) {
82 if (((jint)klass_bytes[i+3] |
83 ((jint)klass_bytes[i+2] << 8) |
84 ((jint)klass_bytes[i+1] << 16) |
85 ((jint)klass_bytes[i] << 24)) == magicNumber_1) {
86 NSK_DISPLAY2("index of 0x%x: %d\n", magicNumber_1, i);
87 found_1 = NSK_TRUE;
88 } else if (((jint)klass_bytes[i+3] |
89 ((jint)klass_bytes[i+2] << 8) |
90 ((jint)klass_bytes[i+1] << 16) |
91 ((jint)klass_bytes[i] << 24)) == magicNumber_2) {
92 NSK_DISPLAY2("index of 0x%x: %d\n", magicNumber_2, i);
93 magicIndex = i;
94 found_2 = NSK_TRUE;
157
158 NSK_DISPLAY0("Agent_OnLoad\n");
159
160 if (!NSK_VERIFY(nsk_jvmti_parseOptions(options)))
161 return JNI_ERR;
162
163 timeout = nsk_jvmti_getWaitTime() * 60 * 1000;
164
165 if (!NSK_VERIFY((jvmti =
166 nsk_jvmti_createJVMTIEnv(jvm, reserved)) != NULL))
167 return JNI_ERR;
168
169 if (!NSK_VERIFY(nsk_jvmti_setAgentProc(agentProc, NULL)))
170 return JNI_ERR;
171
172 memset(&callbacks, 0, sizeof(callbacks));
173 callbacks.ClassFileLoadHook = &ClassFileLoadHook;
174 if (!NSK_VERIFY(nsk_jvmti_init_MA(&callbacks)))
175 return JNI_ERR;
176
177 if (!NSK_JVMTI_VERIFY(jvmti->SetEventNotificationMode(JVMTI_ENABLE, JVMTI_EVENT_CLASS_FILE_LOAD_HOOK, NULL)))
178 return JNI_ERR;
179
180 return JNI_OK;
181 }
182
183 /* ========================================================================== */
184
185 }
|