Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 80270 Details for
Bug 168597
[Vista] HTTP Recorder requires work-around on Windows Vista for Internet Explorer
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
This C++ file contains the DLL source code for this defect fix
TPTPRegSet.cpp (text/plain), 15.31 KB, created by
DuWayne Morris
on 2007-10-12 15:06:01 EDT
(
hide
)
Description:
This C++ file contains the DLL source code for this defect fix
Filename:
MIME Type:
Creator:
DuWayne Morris
Created:
2007-10-12 15:06:01 EDT
Size:
15.31 KB
patch
obsolete
>/********************************************************************** > * Copyright (c) 2007 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at > * http://www.eclipse.org/legal/epl-v10.html > * $Id: TPTPRegSet.cpp > * > * Contributors: > * IBM Corporation - initial API and implementation > **********************************************************************/ > >#include "stdafx.h" >#include <windows.h> >#include <stdio.h> >#include <conio.h> >#include <tchar.h> >#include <shellapi.h> >#include <stdlib.h> >#include "jni.h" >#include <iepmapi.h> >#include "Psapi.h" >#include "org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper.h" > >BOOL IsProcessIE( DWORD processID ); >DWORD* GetIEProcessesList(int *); >void KillIEProcess(); >DWORD WINAPI MyThread( LPVOID ); > >#define BUFSIZE 1024 >HKEY hTestKey = NULL; >LONG dwError = 0; >DWORD ieProcessID = 0, ieProcessID2 = 0; >HANDLE hIEProcess, hIEProcess2; > > >#ifdef _MANAGED >#pragma managed(push, off) >#endif > >BOOL APIENTRY DllMain( HMODULE hModule, > DWORD dwReason, > LPVOID lpReserved > ) >{ > switch (dwReason){ > case DLL_PROCESS_ATTACH: > // the workbench has started and the recorder is loading this library > break; > case DLL_PROCESS_DETACH: > // the workbench is shutting down > RegCloseKey(hTestKey); > break; > case DLL_THREAD_ATTACH: > case DLL_THREAD_DETACH: > break; > default: > break; > } > > > > > return TRUE; >} > >#ifdef _MANAGED >#pragma managed(pop) >#endif > > > >// on Vista, there does not seem to be an option to enable or disable the Java Console >// Since the code is aleady written, we will leave this here in case we want to use it in the future >JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_getEnableJavaConsole > (JNIEnv *env, jclass cls) >{ > jstring jniStr = NULL; > HKEY hTempKey; > > dwError = RegOpenKeyEx( HKEY_CURRENT_USER, > TEXT("Software\\Microsoft\\Java VM"), > 0, > KEY_READ, > &hTempKey); > if( dwError == ERROR_SUCCESS){ > BYTE retStr[1024]; > BYTE fmtStr[1024]; > DWORD dw, dwtype; > dwError = RegQueryValueEx(hTempKey, TEXT("EnableJavaConsole"), NULL, &dwtype, retStr, &dw); > if (dwError == ERROR_SUCCESS){ > retStr[dw] = '0'; > size_t ilen = strlen("hex:"); > memcpy(fmtStr, "hex:", ilen); > memcpy(&fmtStr[ilen], retStr, dw); > memset(&fmtStr[dw + ilen], '0', 1); > if (dw > 0) > jniStr = (env)->NewStringUTF((const char *)fmtStr); > }else{ > return NULL; > } > RegCloseKey(hTempKey); > }else{ > return NULL; > } > > return jniStr; >} > > >JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_getIEAppPath > (JNIEnv *env, jclass cls) >{ > jstring jniStr = NULL; > HKEY hTempKey; > BYTE retStr[1024]; > > > dwError = RegOpenKeyEx( HKEY_CLASSES_ROOT, > TEXT("Applications\\iexplore.exe\\shell\\open\\command\\"), > 0, > KEY_READ, > &hTempKey); > > if (dwError == ERROR_SUCCESS){ > > > DWORD dw = 1024, dwtype; > dwError = RegQueryValueEx(hTempKey, NULL, NULL, &dwtype, retStr, &dw); > if (dwError == ERROR_SUCCESS){ > retStr[dw] = '0'; > if (dw > 0) > jniStr = (env)->NewString((const jchar *)retStr, (int)dw/sizeof(WCHAR)); > RegCloseKey(hTempKey); > }else{ > return NULL; > } > }else{ > return NULL; > } > > return jniStr; >} > >JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_getIESetting > (JNIEnv *env, jclass cls, jstring keyname) >{ > > jstring jniStr = NULL; > const jchar *str = (env)->GetStringChars(keyname, JNI_FALSE); > > if (hTestKey == NULL){ > > if (RegOpenKeyEx( HKEY_CURRENT_USER, > TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), > 0, > KEY_ALL_ACCESS, > &hTestKey) != ERROR_SUCCESS){ > return NULL; > } > } > if (hTestKey != NULL) > { > BYTE retStr[1024]; > DWORD dw = 1024, dwtype; > dwError = RegQueryValueEx(hTestKey, (LPCWSTR)str, NULL, &dwtype, retStr, &dw); > if (dwError == ERROR_SUCCESS){ > if (dwtype == REG_DWORD){ > int i; > memcpy(&i, &retStr, sizeof(int)); > sprintf((char *)retStr, "dword:%08x", i); > jniStr = (env)->NewStringUTF((const char *)retStr); > }else if(dwtype == REG_SZ && dw > 0){ > retStr[dw] = '0'; > jniStr = (env)->NewString((const jchar *)retStr, (int)dw/sizeof(WCHAR)); > } > }else{ > return NULL; > } > > } > (env)->ReleaseStringChars(keyname, str); > > return jniStr; >} > >JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_getLastError >(JNIEnv *env, jclass){ > > jstring jniStr = NULL; > LPVOID lpMsgBuf; > DWORD dwChars; > > dwChars = FormatMessage( > FORMAT_MESSAGE_ALLOCATE_BUFFER | > FORMAT_MESSAGE_FROM_SYSTEM | > FORMAT_MESSAGE_IGNORE_INSERTS, > NULL, > dwError, > MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), > (LPTSTR) &lpMsgBuf, > 0, NULL ); > > if (dwChars > 0) > jniStr = (env)->NewString((const jchar *)lpMsgBuf, dwChars); > > LocalFree(lpMsgBuf); > > return jniStr; > >} > >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_setIESetting >(JNIEnv *env, jclass, jstring keyname, jstring jvalue, jint type){ > > long retVal = -1; > > if (hTestKey != NULL) > { > DWORD dw, dwtype = type; > jboolean isCopy; > > const jchar *name = (env)->GetStringChars(keyname, &isCopy); > > if (type == REG_SZ){ > const jchar *value = (env)->GetStringChars(jvalue, &isCopy); > dw = (env)->GetStringLength(jvalue) + 1; > dw *= sizeof(WCHAR); > dwError = RegSetValueEx(hTestKey, (LPCWSTR)name, NULL, dwtype, (BYTE *)value, dw); > (env)->ReleaseStringChars(jvalue, value); > } > if (type == REG_DWORD){ > dw = sizeof(DWORD); > const char *value = (env)->GetStringUTFChars(jvalue, NULL); > DWORD dwvalue = atoi(value); > dwError = RegSetValueEx(hTestKey, (LPCWSTR)name, NULL, dwtype, (BYTE *)&dwvalue, dw); > (env)->ReleaseStringUTFChars(jvalue, value); > } > > } > if (dwError != ERROR_SUCCESS) > retVal = 0; // we will set an int return of false to indicate failure > else > retVal = 1; // set a value of 1 to return success (true) > > > return retVal; > > >} > > >// this function is not currently being used, but may be used at a later date, so leave it in >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_setStartPage >(JNIEnv *env, jclass, jstring jvalue){ > > long retVal = -1; > HKEY hTempKey; > > > if (RegOpenKeyEx( HKEY_CURRENT_USER, > TEXT("Software\\Microsoft\\Internet Explorer\\Main"), > 0, > KEY_ALL_ACCESS, > &hTempKey) != ERROR_SUCCESS){ > return 0; > } > > if (hTempKey != NULL) > { > DWORD dw; > jboolean isCopy; > > const jchar *value = (env)->GetStringChars(jvalue, &isCopy); > dw = (env)->GetStringLength(jvalue) + 1; > dw *= sizeof(WCHAR); > dwError = RegSetValueEx(hTempKey, (LPCWSTR)TEXT("Start Page"), NULL, REG_SZ, (BYTE *)value, dw); > (env)->ReleaseStringChars(jvalue, value); > RegCloseKey(hTempKey); > > } > if (dwError != ERROR_SUCCESS) > retVal = 0; // we will set an int return of false to indicate failure > else > retVal = 1; // set a value of 1 to return success (true) > > > return retVal; > > >} > >// this function is not being used, but may be used at a later date, so leave it in >JNIEXPORT jstring JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_getStartPage > (JNIEnv *env, jclass cls) >{ > > jstring jniStr = NULL; > HKEY hTempKey; > > if (RegOpenKeyEx( HKEY_CURRENT_USER, > TEXT("Software\\Microsoft\\Internet Explorer\\Main"), > 0, > KEY_ALL_ACCESS, > &hTempKey) != ERROR_SUCCESS){ > return NULL; > } > > if (hTempKey != NULL) > { > BYTE retStr[1024]; > DWORD dw = 1024, dwtype; > dwError = RegQueryValueEx(hTempKey, (LPCWSTR)TEXT("Start Page"), NULL, &dwtype, retStr, &dw); > if (dwError == ERROR_SUCCESS){ > if (dwtype == REG_SZ && dw > 0){ > retStr[dw] = '0'; > jniStr = (env)->NewString((const jchar *)retStr, (int)dw/sizeof(WCHAR)); > } > }else{ > return NULL; > } > > } > > return jniStr; >} > >/* > In Vista, the reason this function is being called is due to the > fact that we are not running with elevated privilges. IE seems to be a protected process, that is, > when it is executed via CreateProcess, the PROCESS_INFORMATION returned is not for the IE that is > created. > > IELaunchURL is offered on Vista and documentation says this should be used instead of > CreateProcess. It is further stated that this function will return the proper > process ID. > >*/ >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_launchIE >(JNIEnv *env, jclass, jstring jpath){ > > > PROCESS_INFORMATION pi; > jboolean isCopy; > const jchar *urlPath = NULL; > HRESULT hResult = 0; > ieProcessID = 0; > ieProcessID2 = 0; > hIEProcess = 0; > hIEProcess2 = 0; > > ZeroMemory( &pi, sizeof(pi) ); > > if (jpath != NULL){ > urlPath = (env)->GetStringChars(jpath, &isCopy); > hResult = IELaunchURL((LPCWSTR)urlPath, &pi, NULL); > } > // in case of failure to launch, we will just launch IE > // with NULL as the URL, which results in bringing up IE > // with the user's default page > if (jpath == NULL || hResult != S_OK) > hResult = IELaunchURL(NULL, &pi, NULL); > > if (jpath != NULL) > (env)->ReleaseStringChars(jpath, urlPath); > > > ieProcessID = pi.dwProcessId; > return TRUE; >} > > >//now look for a new instance of IE >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_lookForNewBrowser >(JNIEnv *env, jclass){ > > int i, iCount = 0; > DWORD *dwIEList; > HANDLE hThread; > > dwIEList = GetIEProcessesList(&iCount); > > // find the first IE process ID that we didn't launch with IELaunchURL > // that is the one we want > for (i = 0; i < iCount; i++){ > if (dwIEList[i] != ieProcessID){ > ieProcessID2 = dwIEList[i]; > break; > } > } > if (ieProcessID2 != 0){ > // create a new thread to wait for the process > hThread = CreateThread( > NULL, // default security attributes > 0, // use default stack size > MyThread, // thread function > NULL, // argument to thread function > 0, // use default creation flags > NULL); // returns the thread identifier > > CloseHandle(hThread); > > } > > > return TRUE; >} > > >/* >WARNING: The calling thread will be stopped in a wait state until the kicked off child process exits. > >*/ >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_waitForIEProcess >(JNIEnv *, jclass){ > > if (ieProcessID != 0){ > hIEProcess = OpenProcess( SYNCHRONIZE | PROCESS_TERMINATE, > FALSE, ieProcessID ); > // Wait until child process exits. > WaitForSingleObject( hIEProcess, INFINITE ); > CloseHandle(hIEProcess); > hIEProcess = 0; > ieProcessID = 0; > // majority of the time, there will be a second browser instance > // running with protected mode on, wait for this instance to close as well > // before returning to the calling thread to signify the recording is completed. > // the extra thread running "MyThread" function will cleanup the thread handle, etc. > if (hIEProcess2 != 0) > WaitForSingleObject(hIEProcess2, INFINITE); > > return 1; // return TRUE > } > return 0; // return FALSE; > >} > >/* > >This function is called when the user stops the recording with the stop button instead of >stopping the recording by closing IE. > >*/ > >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_killIEProcess >(JNIEnv *, jclass){ > > KillIEProcess(); > return 0; // return FALSE; >} > >void KillIEProcess(){ > > if (hIEProcess != 0){ > TerminateProcess(hIEProcess, 0); > CloseHandle(hIEProcess); > hIEProcess = 0; > } > if (hIEProcess2 != 0){ > TerminateProcess(hIEProcess2, 0); > CloseHandle(hIEProcess2); > hIEProcess2 = 0; > } >} > > >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_isProcessElevated >(JNIEnv *, jclass){ > > HANDLE hToken; > TOKEN_ELEVATION_TYPE elevationType; > DWORD dwSize; > jint isElevated = 0; > > OpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &hToken); > GetTokenInformation(hToken, TokenElevationType, &elevationType, sizeof(elevationType), &dwSize); > > switch (elevationType) { > case TokenElevationTypeDefault: > isElevated = 0; //User is not using a split token > break; > case TokenElevationTypeFull: > isElevated = 1; //User has a split token, and the process is running elevated > break; > case TokenElevationTypeLimited: > isElevated = 0; // User has a split token, but the process is not running elevated > break; > } > > if (hToken) { > CloseHandle(hToken); > } > > return isElevated; >} > >// we need to know if there is an instance of IE running or not >JNIEXPORT jint JNICALL Java_org_eclipse_hyades_execution_recorder_local_appadapters_JNIWrapper_isIERunning >(JNIEnv *, jclass){ > > jint isRunning = 0; > int iCount = 0; > DWORD *dwIEList; > > dwIEList = GetIEProcessesList(&iCount); > if (iCount > 0){ > isRunning = 1; > delete dwIEList; > } > > return isRunning; >} > >DWORD* GetIEProcessesList(int *numIEProcesses) >{ > // Get the list of process identifiers. > DWORD aProcesses[1024], ieProcesses[1024], cbNeeded, cProcesses; > unsigned int i, ieCount = 0; > > if ( !EnumProcesses( aProcesses, sizeof(aProcesses), &cbNeeded ) ) > return NULL; > // Calculate how many process identifiers were returned. > cProcesses = cbNeeded / sizeof(DWORD); > > > for ( i = 0; i < cProcesses; i++ ){ > if( aProcesses[i] != 0 ){ > if (IsProcessIE(aProcesses[i]) == TRUE){ > ieProcesses[ieCount] = aProcesses[i]; > ieCount++; > } > } > } > if (ieCount > 0){ > *numIEProcesses = (int)ieCount; > DWORD *dwList = new DWORD[ieCount]; > memcpy(dwList, ieProcesses, sizeof(DWORD) * ieCount); > return dwList; > }else{ > return NULL; > } >} > >BOOL IsProcessIE( DWORD processID ){ > > TCHAR szProcessName[MAX_PATH] = TEXT("<unknown>"); > BOOL bReturn = FALSE; > > // Get a handle to the process. > > HANDLE hProcess = OpenProcess( 0x1000 | SYNCHRONIZE, > FALSE, processID ); > > // Get the process name. > if (hProcess != NULL) > { > DWORD dwSize = sizeof(szProcessName)/sizeof(TCHAR); > > > if (GetProcessImageFileName(hProcess, szProcessName, dwSize)!= 0){ > if (_tcsstr(szProcessName, TEXT("iexplore.exe")) != NULL){ > bReturn = TRUE; > } > } > CloseHandle( hProcess ); > } > return bReturn; >} > >// worker thread created to wait for second instance of IE to exit >DWORD WINAPI MyThread( LPVOID ) >{ > if (ieProcessID2 != 0){ > hIEProcess2 = OpenProcess( SYNCHRONIZE | PROCESS_TERMINATE, > FALSE, ieProcessID2 ); > // Wait until child process exits. > WaitForSingleObject( hIEProcess2, INFINITE ); > CloseHandle(hIEProcess2); > hIEProcess2 = 0; > ieProcessID2 = 0; > KillIEProcess(); > } > return 0; >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 168597
:
76930
|
76931
|
80259
|
80260
|
80261
|
80262
| 80270 |
80900
|
80901
|
80902