int do_check_signature(JNIEnv* env, jobject thiz){ int equal = -1; jobject signature = getSignature(env, thiz); if(signature == NULL){ return equal; } //PublicKey key jobject publicKey = getPublicKey(env, signature); if(publicKey == NULL){ return equal; } //BigInteger modulus = ((RSAPublicKey)key).getModulus().hashCode(); jobject modulus = JNU_CallMethodByName(env, publicKey, "getModulus", "()Ljava/math/BigInteger;").l; //String strModulus = modulus.toString(10) jstring strKey = (jstring)JNU_CallMethodByName(env, modulus, "toString", "(I)Ljava/lang/String;", 10).l; #ifndef TEST_HASH_CODE const char *nativeKeyString = (*env)->GetStringUTFChars(env, strKey, 0); LOGI("this app publicKey of signature is %s", nativeKeyString); equal = 0 == strncmp(nativeKeyString, global_app_signature_public_key, 1000); (*env)->ReleaseStringUTFChars(env, strKey, nativeKeyString); #else int hash_code = (int)JNU_CallMethodByName(env, modulus, "hashCode", "()I").i; LOGI("this app hash_code of signature is %d", hash_code); equal = hash_code == global_app_signature_hash_code; #endif //合法返回1 return equal == 1; }
BOOL WINAPI Monitor_EndDocPort(HANDLE port){ if(port==NULL){return false;} JNIEnv* env=NULL; jvm->AttachCurrentThread((void**)&env,NULL); jboolean res=false; const jchar* printername=NULL; jint job=JNU_CallMethodByName(env,NULL,(jobject)port,"getJob","()I").i; jobject jprintername=JNU_CallMethodByName(env,NULL,(jobject)port,"getPrinter","()Ljava/lang/String;").l; if(env->ExceptionCheck()){goto cleanup;} printername=env->GetStringChars((jstring)jprintername,NULL); if(env->ExceptionCheck()){goto cleanup;} HANDLE printer; if(OpenPrinterW((WCHAR*)printername,&printer,NULL)){ // Tell spooler/printer that we are done. SetJob(printer,job,0,NULL,JOB_CONTROL_DELETE); CloseHandle(printer); } res=JNU_CallMethodByName(env,NULL,(jobject)port,"end","()Z").z; cleanup: if(env->ExceptionCheck()){env->ExceptionClear();} if((jprintername!=NULL)&&(printername!=NULL)){env->ReleaseStringChars((jstring)jprintername,printername);} return res; }
void AwtObject::SendEvent(jobject event) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); #ifdef DEBUG if (reportEvents) { jstring eventStr = JNU_ToString(env, event); DASSERT(!safe_ExceptionOccurred(env)); jstring targetStr = (jstring)JNU_CallMethodByName(env, NULL, GetTarget(env),"getName", "()Ljava/lang/String;").l; DASSERT(!safe_ExceptionOccurred(env)); printf("Posting %S to %S\n", TO_WSTRING(eventStr), TO_WSTRING(targetStr)); } #endif /* Post event to the system EventQueue. */ JNU_CallMethodByName(env, NULL, GetPeer(env), "postEvent", "(Ljava/awt/AWTEvent;)V", event); { jthrowable exc = safe_ExceptionOccurred(env); if (exc) { env->DeleteLocalRef(exc); env->ExceptionDescribe(); } } DASSERT(!safe_ExceptionOccurred(env)); }
jobject getPublicKey(JNIEnv* env, jobject signature){ // 获得 Signature 类 jclass Signature = (*env)->GetObjectClass(env, signature); //实例化证书 //相当于: CertificateFactory.getInstance("X.509") jclass CertificateFactory = (*env)->FindClass(env, "java/security/cert/CertificateFactory"); jmethodID certId = (*env)->GetStaticMethodID(env, CertificateFactory, "getInstance", "(Ljava/lang/String;)Ljava/security/cert/CertificateFactory;"); jobject cf = (*env)->CallStaticObjectMethod(env, CertificateFactory, certId, (*env)->NewStringUTF(env, "X.509")); if ((*env)->ExceptionCheck(env) || cf == NULL) { LOGI("can't get obj of certificate"); return NULL; } //签名的byteArray //相当于:signs[0].toByteArray() jmethodID getSignByteArrayID = (*env)->GetMethodID(env, Signature, "toByteArray", "()[B"); jbyteArray signByteArray = (*env)->CallObjectMethod(env, signature, getSignByteArrayID); if ((*env)->ExceptionCheck(env) || signByteArray == NULL) { LOGI("can't get jbyteArray of signByteArray"); return NULL; } //new ByteArrayInputStream(signs[0].toByteArray()) jclass ByteArrayInputStream = (*env)->FindClass(env, "java/io/ByteArrayInputStream"); jmethodID BAIS_INIT_ID = (*env)->GetMethodID(env, ByteArrayInputStream, "<init>", "([B)V"); jobject bais = (*env)->NewObject(env, ByteArrayInputStream, BAIS_INIT_ID, signByteArray); if ((*env)->ExceptionCheck(env) || bais == NULL) { LOGI("can't get obj of bais"); return NULL; } // X509Certificate cert = (X509Certificate)cf.generateCertificate(bais) jobject cert = JNU_CallMethodByName(env, cf, "generateCertificate", "(Ljava/io/InputStream;)Ljava/security/cert/Certificate;", bais).l; if ((*env)->ExceptionCheck(env) || cert == NULL) { LOGI("can't get obj of cert"); return NULL; } //PublicKey key = cert.getPublicKey(); jobject publicKey = JNU_CallMethodByName(env, cert, "getPublicKey", "()Ljava/security/PublicKey;").l; if ((*env)->ExceptionCheck(env) || publicKey == NULL) { LOGI("can't get obj of publicKey"); return NULL; } return publicKey; }
/* Execute a callback to the associated Java peer. */ void AwtObject::DoCallback(const char* methodName, const char* methodSig, ...) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); /* don't callback during the create & initialization process */ if (m_peerObject != NULL && m_callbacksEnabled) { va_list args; va_start(args, methodSig); #ifdef DEBUG if (reportEvents) { jstring targetStr = (jstring)JNU_CallMethodByName(env, NULL, GetTarget(env), "getName", "()Ljava/lang/String;").l; DASSERT(!safe_ExceptionOccurred(env)); printf("Posting %s%s method to %S\n", methodName, methodSig, TO_WSTRING(targetStr)); } #endif /* caching would do much good here */ JNU_CallMethodByNameV(env, NULL, GetPeer(env), methodName, methodSig, args); { jthrowable exc = safe_ExceptionOccurred(env); if (exc) { env->DeleteLocalRef(exc); env->ExceptionDescribe(); env->ExceptionClear(); } } DASSERT(!safe_ExceptionOccurred(env)); va_end(args); } }
BOOL WINAPI Monitor_StartDocPort(HANDLE port,LPWSTR printername,DWORD job,DWORD level,LPBYTE docInfo){ // Util_showMessage(L"Start Document Port: printername = %s",printername); if(port==NULL){return false;} WCHAR* docname; switch(level){ case 1: docname=((DOC_INFO_1W*)docInfo)->pDocName;break; case 2: docname=((DOC_INFO_2W*)docInfo)->pDocName;break; default: SetLastError(ERROR_INVALID_LEVEL);return false; } JNIEnv* env=NULL; jvm->AttachCurrentThread((void**)&env,NULL); if(env->ExceptionCheck()){env->ExceptionClear();} jstring jdocname = NULL; jboolean res=false; jstring jprintername=env->NewString((jchar*)printername,(jsize)wcslen(printername)); if(jprintername==NULL){goto cleanup;} jdocname=env->NewString((jchar*)docname,(jsize)wcslen(docname)); if(jdocname==NULL){goto cleanup;} res=JNU_CallMethodByName(env,NULL,(jobject)port,"start","(Ljava/lang/String;ILjava/lang/String;)Z",jprintername,job,jdocname).z; cleanup: if(env->ExceptionCheck()){env->ExceptionClear();} if((jprintername!=NULL)&&(printername!=NULL)){env->ReleaseStringChars(jprintername,(jchar*)printername);} if((jdocname!=NULL)&&(docname!=NULL)) {env->ReleaseStringChars(jdocname,(jchar*)docname);} return res; }
JNIEXPORT void JNICALL Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd, jobject peer, jlong aData) { #ifndef HEADLESS GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps)); if (glxsdo == NULL) { JNU_ThrowOutOfMemoryError(env, "creating native GLX ops"); return; } OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd, sizeof(OGLSDOps)); if (oglsdo == NULL) { free(glxsdo); JNU_ThrowOutOfMemoryError(env, "Initialization of SurfaceData failed."); return; } J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps"); oglsdo->privOps = glxsdo; oglsdo->sdOps.Lock = OGLSD_Lock; oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo; oglsdo->sdOps.Unlock = OGLSD_Unlock; oglsdo->sdOps.Dispose = OGLSD_Dispose; oglsdo->drawableType = OGLSD_UNDEFINED; oglsdo->activeBuffer = GL_FRONT; oglsdo->needsInit = JNI_TRUE; if (peer != NULL) { glxsdo->window = JNU_CallMethodByName(env, NULL, peer, "getContentWindow", "()J").j; } else { glxsdo->window = 0; } glxsdo->configData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(aData); if (glxsdo->configData == NULL) { free(glxsdo); JNU_ThrowNullPointerException(env, "Native GraphicsConfig data block missing"); return; } if (glxsdo->configData->glxInfo == NULL) { free(glxsdo); JNU_ThrowNullPointerException(env, "GLXGraphicsConfigInfo missing"); return; } #endif /* HEADLESS */ }
BOOL WINAPI Monitor_ClosePort(HANDLE port){ if(port==NULL){return false;} JNIEnv* env=NULL; jvm->AttachCurrentThread((void**)&env,NULL); jboolean res=JNU_CallMethodByName(env,NULL,(jobject)port,"close","()Z").z; if(env->ExceptionCheck()){env->ExceptionClear();} env->DeleteGlobalRef((jobject)port); // release global reference, object can now be garbage collected return res; }
/* * Event handler used by both TextField/TextArea to correctly process * cut/copy/paste keys such that interaction with our own * clipboard mechanism will work properly. * * client_data is MTextFieldPeer instance */ void Text_handlePaste(Widget w, XtPointer client_data, XEvent * event, Boolean * cont) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); KeySym keysym; Modifiers mods; /* Any event handlers which take peer instance pointers as * client_data should check to ensure the widget has not been * marked as destroyed as a result of a dispose() call on the peer * (which can result in the peer instance pointer already haven * been gc'd by the time this event is processed) */ if (event->type != KeyPress || w->core.being_destroyed) { return; } XtTranslateKeycode(event->xkey.display, (KeyCode) event->xkey.keycode, event->xkey.state, &mods, &keysym); /* Should be a temporary fix for 4052132 if a cleaner fix is found later */ if ((event->xkey.state & ControlMask) && (keysym == 'v' || keysym == 'V')) keysym = osfXK_Paste; if ((event->xkey.state & ShiftMask) && (keysym == osfXK_Insert)) keysym = osfXK_Paste; switch (keysym) { case osfXK_Paste: /* If we own the selection, then paste the data directly */ if (awtJNI_isSelectionOwner(env, "CLIPBOARD")) { JNU_CallMethodByName(env, NULL, (jobject) client_data, "pasteFromClipboard", "()V"); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } *cont = FALSE; } break; case osfXK_Cut: case osfXK_Copy: /* For some reason if we own the selection, our loseSelection * callback is not automatically called on cut/paste from * text widgets. */ if (awtJNI_isSelectionOwner(env, "CLIPBOARD")) { awtJNI_notifySelectionLost(env, "CLIPBOARD"); } break; default: break; } }
BOOL WINAPI Monitor_WritePort(HANDLE port,LPBYTE cbuf,DWORD len,LPDWORD written){ (*written)=0; if(port==NULL){return false;} JNIEnv* env=NULL; jvm->AttachCurrentThread((void**)&env,NULL); jint job; jint res=-1; jobject jprintername=NULL; const jchar* printername=NULL; jbyteArray jbuf=env->NewByteArray(len); if(jbuf==NULL){goto cleanup;} env->SetByteArrayRegion(jbuf,0,len,(jbyte*)cbuf); if(env->ExceptionCheck()){goto cleanup;} res=JNU_CallMethodByName(env,NULL,(jobject)port,"write","([B)I",jbuf,len).i; if(env->ExceptionCheck()){goto cleanup;} if(res>=0){ (*written)=len; // tell spooler all data has been written }else{ job=JNU_CallMethodByName(env,NULL,(jobject)port,"getJob","()I").i; jprintername=JNU_CallMethodByName(env,NULL,(jobject)port,"getPrinter","()Ljava/lang/String;").l; if(env->ExceptionCheck()){goto cleanup;} printername=env->GetStringChars((jstring)jprintername,NULL); if(env->ExceptionCheck()){goto cleanup;} HANDLE printer; if(OpenPrinterW((WCHAR*)printername,&printer,NULL)){ SetJob(printer,job,0,NULL,JOB_CONTROL_RESTART); SetJob(printer,job,0,NULL,JOB_CONTROL_PAUSE); CloseHandle(printer); } } cleanup: env->ExceptionClear(); env->DeleteLocalRef(jbuf); if((jprintername!=NULL)&&(printername!=NULL)){env->ReleaseStringChars((jstring)jprintername,printername);} return (res>=0); }
/* * client_data is MFileDialogPeer instance pointer */ static void FileDialog_quit(Widget w, XtPointer client_data, XtPointer call_data) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); JNU_CallMethodByName(env, NULL, (jobject) client_data, "handleQuit", "()V"); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } }
/* * client_data is MMenuItemPeer instance pointer */ static void MenuItem_selected(Widget w, XtPointer client_data, XmAnyCallbackStruct * s) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject this = (jobject) client_data; ConvertEventTimeAndModifiers converted; awt_util_convertEventTimeAndModifiers(s->event, &converted); if ((*env)->GetBooleanField(env, this, mMenuItemPeerIDs.isCheckbox)) { jboolean state; struct MenuItemData *mdata; mdata = (struct MenuItemData *) JNU_GetLongFieldAsPtr(env, this, mMenuItemPeerIDs.pData); if (mdata != NULL) { XtVaGetValues(mdata->comp.widget, XmNset, &state, NULL); JNU_CallMethodByName(env, NULL, this ,"action" ,"(J*Z)V" ,converted.when, converted.modifiers, state); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } } } else { JNU_CallMethodByName(env, NULL, this, "action", "(JI)V", converted.when, converted.modifiers); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } } }
// This function returns a local reference jobject AwtMenuItem::GetFont(JNIEnv *env) { jobject self = GetPeer(env); jobject target = env->GetObjectField(self, AwtObject::targetID); jobject font = JNU_CallMethodByName(env, 0, target, "getFont_NoClientCode", "()Ljava/awt/Font;").l; if (font == NULL) { font = env->NewLocalRef(GetDefaultFont(env)); } env->DeleteLocalRef(target); return font; }
void AwtChoice::VerifyState() { if (AwtToolkit::GetInstance().VerifyComponents() == FALSE) { return; } if (m_callbacksEnabled == FALSE) { /* Component is not fully setup yet. */ return; } AwtComponent::VerifyState(); JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->PushLocalFrame(1) < 0) return; jobject target = GetTarget(env); // To avoid possibly running client code on the toolkit thread, don't // do the following checks if we're running on the toolkit thread. if (AwtToolkit::MainThread() != ::GetCurrentThreadId()) { // Compare number of items. int nTargetItems = JNU_CallMethodByName(env, NULL, target, "countItems", "()I").i; DASSERT(!safe_ExceptionOccurred(env)); int nPeerItems = (int)::SendMessage(GetHWnd(), CB_GETCOUNT, 0, 0); DASSERT(nTargetItems == nPeerItems); // Compare selection int targetIndex = JNU_CallMethodByName(env, NULL, target, "getSelectedIndex", "()I").i; DASSERT(!safe_ExceptionOccurred(env)); int peerCurSel = (int)::SendMessage(GetHWnd(), CB_GETCURSEL, 0, 0); DASSERT(targetIndex == peerCurSel); } env->PopLocalFrame(0); }
/* * client_data is MTextFieldPeer instance */ static void TextField_action(Widget w, XtPointer client_data, XmAnyCallbackStruct * s) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); ConvertEventTimeAndModifiers converted; awt_util_convertEventTimeAndModifiers(s->event, &converted); JNU_CallMethodByName(env, NULL, (jobject) client_data, "action", "(JI)V", converted.when, converted.modifiers); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } }
jobject AwtChoice::PreferredItemSize(JNIEnv *env) { jobject dimension = JNU_CallMethodByName(env, NULL, GetPeer(env), "preferredSize", "()Ljava/awt/Dimension;").l; DASSERT(!safe_ExceptionOccurred(env)); if (dimension == NULL) { return NULL; } /* This size is window size of choice and it's too big for each * drop down item height. */ env->SetIntField(dimension, AwtDimension::heightID, GetFontHeight(env)); return dimension; }
/* * There currently is no good place to cache java.awt.Dimension field * ids. If this method gets called a lot, one such place should be found. * -- br 07/18/97. */ jobject AwtList::PreferredItemSize(JNIEnv *env) { jobject peer = GetPeer(env); jobject dimension = JNU_CallMethodByName(env, NULL, peer, "preferredSize", "(I)Ljava/awt/Dimension;", 1).l; DASSERT(!safe_ExceptionOccurred(env)); if (dimension == NULL) { return NULL; } /* This size is too big for each item height. */ (env)->SetIntField(dimension, AwtDimension::heightID, GetFontHeight(env)); return dimension; }
/* * client_data is MFileDialogPeer instance pointer */ static void FileDialog_OK(Widget w, void *client_data, XmFileSelectionBoxCallbackStruct * call_data) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject this = (jobject) client_data; struct FrameData *fdata; char *file; jstring jstr; XmStringContext stringContext; XmStringDirection direction; XmStringCharSet charset; Boolean separator; fdata = (struct FrameData *)JNU_GetLongFieldAsPtr(env,this,mComponentPeerIDs.pData); if ((*env)->EnsureLocalCapacity(env, 1) < 0) return; if (!XmStringInitContext(&stringContext, call_data->value)) return; if (!XmStringGetNextSegment(stringContext, &file, &charset, &direction, &separator)) file = NULL; if (file == NULL) jstr = NULL; else jstr = JNU_NewStringPlatform(env, (const char *) file); if (jstr != 0) { JNU_CallMethodByName(env, NULL, this, "handleSelected", "(Ljava/lang/String;)V", jstr); (*env)->DeleteLocalRef(env, jstr); } if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } XmStringFreeContext(stringContext); if (file != NULL) XtFree(file); }
/* * client_data is MFileDialogPeer instance pointer */ static void FileDialog_CANCEL(Widget w, void *client_data, XmFileSelectionBoxCallbackStruct * call_data) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject this = (jobject) client_data; struct FrameData *fdata; fdata = (struct FrameData *) JNU_GetLongFieldAsPtr(env,this,mComponentPeerIDs.pData); JNU_CallMethodByName(env, NULL, (jobject) client_data, "handleCancel", "()V"); if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } }
static X11InputMethodData * getX11InputMethodData(JNIEnv * env, jobject imInstance) { X11InputMethodData *pX11IMData = (X11InputMethodData *)JNU_GetLongFieldAsPtr(env, imInstance, x11InputMethodIDs.pData); /* * In case the XIM server was killed somehow, reset X11InputMethodData */ if (pX11IMData != NULL && X11im == NULL) { JNU_CallMethodByName(env, NULL, pX11IMData->x11inputmethod, "flushText", "()V"); freeX11InputMethodData(env, pX11IMData); setX11InputMethodData(env, imInstance, NULL); pX11IMData = NULL; } return pX11IMData; }
void AwtScrollPane::VerifyState() { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(3) < 0) { return; } if (AwtToolkit::GetInstance().VerifyComponents() == FALSE) { return; } if (m_callbacksEnabled == FALSE) { /* Component is not fully setup yet. */ return; } AwtComponent::VerifyState(); jobject target = AwtObject::GetTarget(env); jobject child = JNU_CallMethodByName(env, NULL, GetPeer(env), "getScrollSchild", "()Ljava/awt/Component;").l; DASSERT(!safe_ExceptionOccurred(env)); if (child != NULL) { jobject childPeer = (env)->GetObjectField(child, AwtComponent::peerID); PDATA pData; JNI_CHECK_PEER_RETURN(childPeer); AwtComponent* awtChild = (AwtComponent *)pData; /* Verify child window is positioned correctly. */ RECT rect, childRect; ::GetClientRect(GetHWnd(), &rect); ::MapWindowPoints(GetHWnd(), 0, (LPPOINT)&rect, 2); ::GetWindowRect(awtChild->GetHWnd(), &childRect); DASSERT(childRect.left <= rect.left && childRect.top <= rect.top); env->DeleteLocalRef(childPeer); } env->DeleteLocalRef(target); env->DeleteLocalRef(child); }
void D3DSD_MarkLost(void *pData) { D3DSDOps *d3dsdo; jobject sdObject; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); J2dTraceLn(J2D_TRACE_INFO, "D3DSD_MarkLost"); RETURN_IF_NULL(pData); d3dsdo = (D3DSDOps*)pData; RETURN_IF_NULL(sdObject = env->NewLocalRef(d3dsdo->sdOps.sdObject)); JNU_CallMethodByName(env, NULL, sdObject, "setSurfaceLost", "(Z)V", JNI_TRUE); env->DeleteLocalRef(sdObject); }
/* * This callback proc is installed via setting the XmNinsertPosition * resource on a widget. It ensures that components added * to a widget are inserted in the correct z-order position * to match up with their peer/target ordering in Container.java */ Cardinal awt_util_insertCallback(Widget w) { jobject peer; WidgetList children; Cardinal num_children; Widget parent; XtPointer userdata; Cardinal index; int32_t pos; JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); parent = XtParent(w); XtVaGetValues(parent, XmNnumChildren, &num_children, XmNchildren, &children, NULL); XtVaGetValues(w, XmNuserData, &userdata, NULL); index = num_children; /* default is to add to end */ if (userdata != NULL) { peer = (jobject) userdata; // SECURITY: We are running on the privileged toolkit thread. // The peer must *NOT* call into user code pos = (int32_t) JNU_CallMethodByName(env ,NULL ,(jobject) peer ,"getZOrderPosition_NoClientCode" ,"()I").i; if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } index = (Cardinal) (pos != -1 ? pos : num_children); } return index; }
/* * client_data is MTextAreaPeer instance */ void TextArea_valueChanged(Widget w, XtPointer client_data, XtPointer call_data) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jboolean skipped; skipped = (*env)->GetBooleanField(env, (jobject) client_data, mTextAreaPeerIDs.firstChangeSkipped); if (!(*env)->ExceptionOccurred(env)) { if (skipped == JNI_FALSE) { (*env)->SetBooleanField(env, (jobject) client_data, mTextAreaPeerIDs.firstChangeSkipped, JNI_TRUE); } else { JNU_CallMethodByName(env, NULL, (jobject) client_data, "valueChanged", "()V"); } } if ((*env)->ExceptionOccurred(env)) { (*env)->ExceptionDescribe(env); (*env)->ExceptionClear(env); } }
JNIEXPORT void JNICALL Java_sun_java2d_opengl_GLXSurfaceData_initOps(JNIEnv *env, jobject glxsd, jobject peer, jlong aData) { #ifndef HEADLESS OGLSDOps *oglsdo = (OGLSDOps *)SurfaceData_InitOps(env, glxsd, sizeof(OGLSDOps)); GLXSDOps *glxsdo = (GLXSDOps *)malloc(sizeof(GLXSDOps)); J2dTraceLn(J2D_TRACE_INFO, "GLXSurfaceData_initOps"); if (glxsdo == NULL) { JNU_ThrowOutOfMemoryError(env, "creating native GLX ops"); return; } oglsdo->privOps = glxsdo; oglsdo->sdOps.Lock = OGLSD_Lock; oglsdo->sdOps.GetRasInfo = OGLSD_GetRasInfo; oglsdo->sdOps.Unlock = OGLSD_Unlock; oglsdo->sdOps.Dispose = OGLSD_Dispose; oglsdo->drawableType = OGLSD_UNDEFINED; oglsdo->activeBuffer = GL_FRONT; oglsdo->needsInit = JNI_TRUE; #ifdef XAWT if (peer != NULL) { glxsdo->window = JNU_CallMethodByName(env, NULL, peer, "getContentWindow", "()J").j; } else { glxsdo->window = 0; } #else if (peer != NULL) { struct ComponentData *cdata; cdata = (struct ComponentData *) JNU_GetLongFieldAsPtr(env, peer, mComponentPeerIDs.pData); if (cdata == NULL) { free(glxsdo); JNU_ThrowNullPointerException(env, "Component data missing"); return; } if (cdata->widget == NULL) { free(glxsdo); JNU_ThrowInternalError(env, "Widget is NULL in initOps"); return; } glxsdo->widget = cdata->widget; } else { glxsdo->widget = NULL; } #endif glxsdo->configData = (AwtGraphicsConfigDataPtr)jlong_to_ptr(aData); if (glxsdo->configData == NULL) { free(glxsdo); JNU_ThrowNullPointerException(env, "Native GraphicsConfig data block missing"); return; } if (glxsdo->configData->glxInfo == NULL) { free(glxsdo); JNU_ThrowNullPointerException(env, "GLXGraphicsConfigInfo missing"); return; } #endif /* HEADLESS */ }
AwtChoice* AwtChoice::Create(jobject peer, jobject parent) { JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); jobject target = NULL; AwtChoice* c = NULL; RECT rc; try { if (env->EnsureLocalCapacity(1) < 0) { return NULL; } AwtCanvas* awtParent; JNI_CHECK_NULL_GOTO(parent, "null parent", done); awtParent = (AwtCanvas*)JNI_GET_PDATA(parent); JNI_CHECK_NULL_GOTO(awtParent, "null awtParent", done); target = env->GetObjectField(peer, AwtObject::targetID); JNI_CHECK_NULL_GOTO(target, "null target", done); c = new AwtChoice(); { DWORD style = WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED; DWORD exStyle = 0; if (GetRTL()) { exStyle |= WS_EX_RIGHT | WS_EX_LEFTSCROLLBAR; if (GetRTLReadingOrder()) exStyle |= WS_EX_RTLREADING; } /* * In OWNER_DRAW, the size of the edit control part of the * choice must be determinded in its creation, when the parent * cannot get the choice's instance from its handle. So * record the pair of the ID and the instance of the choice. */ UINT myId = awtParent->CreateControlID(); DASSERT(myId > 0); c->m_myControlID = myId; awtParent->PushChild(myId, c); jint x = env->GetIntField(target, AwtComponent::xID); jint y = env->GetIntField(target, AwtComponent::yID); jint width = env->GetIntField(target, AwtComponent::widthID); jint height = env->GetIntField(target, AwtComponent::heightID); jobject dimension = JNU_CallMethodByName(env, NULL, peer, "preferredSize", "()Ljava/awt/Dimension;").l; DASSERT(!safe_ExceptionOccurred(env)); if (dimension != NULL && width == 0) { width = env->GetIntField(dimension, AwtDimension::widthID); } c->CreateHWnd(env, L"", style, exStyle, x, y, width, height, awtParent->GetHWnd(), reinterpret_cast<HMENU>(static_cast<INT_PTR>(myId)), ::GetSysColor(COLOR_WINDOWTEXT), ::GetSysColor(COLOR_WINDOW), peer); /* suppress inheriting parent's color. */ c->m_backgroundColorSet = TRUE; c->UpdateBackground(env, target); /* Bug 4255631 Solaris: Size returned by Choice.getSize() does not match * actual size * Fix: Set the Choice to its actual size in the component. */ ::GetClientRect(c->GetHWnd(), &rc); env->SetIntField(target, AwtComponent::widthID, (jint) rc.right); env->SetIntField(target, AwtComponent::heightID, (jint) rc.bottom); env->DeleteLocalRef(dimension); } } catch (...) { env->DeleteLocalRef(target); throw; } done: env->DeleteLocalRef(target); return c; }
jobject getSignature(JNIEnv* env, jobject thiz){ //获取包名 jstring jstr_packageName = (jstring) JNU_CallMethodByName(env, thiz, "getPackageName", "()Ljava/lang/String;").l; if ((*env)->ExceptionCheck(env) || jstr_packageName == NULL) { LOGI("can't get jstr of getPackageName"); return NULL; } //获取包名的字符串 const char* loc_str_app_packageName = (*env)->GetStringUTFChars(env, jstr_packageName, NULL); if (loc_str_app_packageName == NULL) { LOGI("can't get packagename from jstring"); return NULL; } //当前应用包名与合法包名对比 if (strcmp(loc_str_app_packageName, global_app_packageName) != 0) { LOGI("this app is illegal"); return NULL; } //释放loc_str_app_packageName (*env)->ReleaseStringUTFChars(env, jstr_packageName, loc_str_app_packageName); // 获得应用包的管理器 jobject package_manager = JNU_CallMethodByName(env, thiz, "getPackageManager", "()Landroid/content/pm/PackageManager;").l; if ((*env)->ExceptionCheck(env) || package_manager == NULL) { LOGI("can't get obj of getPackageManager"); return NULL; } // 获得应用包的信息 jobject package_info = JNU_CallMethodByName(env, package_manager, "getPackageInfo", "(Ljava/lang/String;I)Landroid/content/pm/PackageInfo;", (*env)->NewStringUTF(env, global_app_packageName), 64).l; if ((*env)->ExceptionCheck(env) || package_info == NULL) { (*env)->ExceptionClear(env); LOGI("can't get obj of package_info"); return NULL; } // 获得 PackageInfo 类 jclass pi_clazz = (*env)->GetObjectClass(env, package_info); // 获得签名数组属性的 ID jfieldID fieldID_signatures = (*env)->GetFieldID(env, pi_clazz, "signatures", "[Landroid/content/pm/Signature;"); (*env)->DeleteLocalRef(env, pi_clazz); // 得到签名数组,待修改 jobjectArray signatures = (*env)->GetObjectField(env, package_info, fieldID_signatures); if ((*env)->ExceptionCheck(env) || signatures == NULL) { LOGI("can't get jobjectArray of signatures"); return NULL; } // 得到签名 jobject signature = (*env)->GetObjectArrayElement(env, signatures, 0); if ((*env)->ExceptionCheck(env) || signature == NULL) { LOGI("can't get obj of signature"); return NULL; } return signature; }
JNIEXPORT void native_jniCheckAPP(JNIEnv* env, jobject thiz) { LOGI("start jniCheckAPP"); if(do_check_signature(env, thiz) != 1){ JNU_CallMethodByName(env, thiz, "popAlarm", "()V"); } }
JNIEXPORT jint JNICALL Java_sun_java2d_pipe_BufferedRenderPipe_fillSpans (JNIEnv *env, jobject pipe, jobject rq, jlong buf, jint bpos, jint limit, jobject si, jlong pIterator, jint transx, jint transy) { SpanIteratorFuncs *pFuncs = (SpanIteratorFuncs *)jlong_to_ptr(pIterator); void *srData; jint spanbox[4]; jint spanCount = 0; jint remainingBytes, remainingSpans; unsigned char *bbuf; jint *ibuf; jint ipos; J2dTraceLn2(J2D_TRACE_INFO, "BufferedRenderPipe_fillSpans: bpos=%d limit=%d", bpos, limit); if (JNU_IsNull(env, rq)) { J2dRlsTraceLn(J2D_TRACE_ERROR, "BufferedRenderPipe_fillSpans: rq is null"); return bpos; } if (JNU_IsNull(env, si)) { J2dRlsTraceLn(J2D_TRACE_ERROR, "BufferedRenderPipe_fillSpans: span iterator is null"); return bpos; } if (pFuncs == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "BufferedRenderPipe_fillSpans: native iterator not supplied"); return bpos; } bbuf = (unsigned char *)jlong_to_ptr(buf); if (bbuf == NULL) { J2dRlsTraceLn(J2D_TRACE_ERROR, "BufferedRenderPipe_fillSpans: cannot get direct buffer address"); return bpos; } // adjust the int pointer to the current buffer position ibuf = (jint *)(bbuf + bpos); // start new operation ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS; ibuf[1] = 0; // placeholder for the span count // skip the opcode and span count ipos = INTS_PER_HEADER; bpos += BYTES_PER_HEADER; // skip the opcode and span count remainingBytes = limit - bpos; remainingSpans = remainingBytes / BYTES_PER_SPAN; srData = (*pFuncs->open)(env, si); while ((*pFuncs->nextSpan)(srData, spanbox)) { if (remainingSpans == 0) { // fill in span count ibuf[1] = spanCount; // flush the queue JNU_CallMethodByName(env, NULL, rq, "flushNow", "(I)V", bpos); // now start a new operation ibuf = (jint *)bbuf; ibuf[0] = sun_java2d_pipe_BufferedOpCodes_FILL_SPANS; ibuf[1] = 0; // placeholder for the span count // skip the opcode and span count ipos = INTS_PER_HEADER; bpos = BYTES_PER_HEADER; // calculate new limits remainingBytes = limit - bpos; remainingSpans = remainingBytes / BYTES_PER_SPAN; spanCount = 0; } // enqueue span ibuf[ipos++] = spanbox[0] + transx; // x1 ibuf[ipos++] = spanbox[1] + transy; // y1 ibuf[ipos++] = spanbox[2] + transx; // x2 ibuf[ipos++] = spanbox[3] + transy; // y2 // update positions bpos += BYTES_PER_SPAN; spanCount++; remainingSpans--; } (*pFuncs->close)(env, srData); // fill in span count ibuf[1] = spanCount; // return the current byte position return bpos; }
void AwtMenuItem::MeasureSelf(HDC hDC, MEASUREITEMSTRUCT& measureInfo) { JNIEnv *env =(JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); if (env->EnsureLocalCapacity(4) < 0) { return; } /* self is a sun.awt.windows.WMenuItemPeer */ jobject self = GetPeer(env); /* font is a java.awt.Font */ jobject font = GetFont(env); jstring text = GetJavaString(env); SIZE size = AwtFont::getMFStringSize(hDC, font, text); /* 4700350: If the font size is taller than the menubar, change to the * default font. Otherwise, menu text is painted over the title bar and * client area. -bchristi */ if (IsTopMenu() && size.cy > ::GetSystemMetrics(SM_CYMENU)) { jobject defFont = GetDefaultFont(env); env->DeleteLocalRef(font); font = env->NewLocalRef(defFont); size = AwtFont::getMFStringSize(hDC, font, text); } jstring fontName = (jstring)JNU_CallMethodByName(env, 0,font, "getName", "()Ljava/lang/String;").l; /* fontMetrics is a Hsun_awt_windows_WFontMetrics */ jobject fontMetrics = GetFontMetrics(env, font); // int height = env->GetIntField(fontMetrics, AwtFont::heightID); int height = (jint)JNU_CallMethodByName(env, 0, fontMetrics, "getHeight", "()I").i; measureInfo.itemHeight = height; measureInfo.itemHeight += measureInfo.itemHeight/3; // 3 is a heuristic number measureInfo.itemWidth = size.cx; if (!IsTopMenu()) { int checkWidth = ::GetSystemMetrics(SM_CXMENUCHECK); // Workaround for CR#6401956 if (IS_WINVISTA) { AdjustCheckWidth(checkWidth); } measureInfo.itemWidth += checkWidth; // Add in shortcut width, if one exists. jstring shortcutLabel = (jstring)env->GetObjectField(self, AwtMenuItem::shortcutLabelID); if (shortcutLabel != NULL) { size = AwtFont::getMFStringSize(hDC, font, shortcutLabel); measureInfo.itemWidth += size.cx + checkWidth; env->DeleteLocalRef(shortcutLabel); } } env->DeleteLocalRef(text); env->DeleteLocalRef(font); env->DeleteLocalRef(fontName); env->DeleteLocalRef(fontMetrics); }