Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

105 lines
2.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. WinG32SysToSys32.cpp
  5. Abstract:
  6. During its dllmain WinG32 checks its install location. It does this by parsing the path returned from
  7. GetModuleFileName. If it finds that it was installed in the system directory, it will post a message box
  8. and fail. This is fixed by checking and tweaking the string returned from the API call.
  9. History:
  10. 03/21/2001 alexsm Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(WinG32SysToSys32)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(GetModuleFileNameA)
  17. APIHOOK_ENUM_END
  18. DWORD
  19. APIHOOK(GetModuleFileNameA)(HMODULE hModule, LPSTR lpFileName, DWORD nSize)
  20. {
  21. DWORD nReturn = 0;
  22. int nFound = -1;
  23. char * lpNewFileName = NULL;
  24. WCHAR * lpSystemCheck = L"SYSTEM\\WING32.DLL";
  25. WCHAR * lpWinG32 = L"WING32.dll";
  26. CString csOldFileName;
  27. CString csNewFileName;
  28. nReturn = ORIGINAL_API(GetModuleFileNameA)(hModule, lpFileName, nSize);
  29. // Do nothing on failure.
  30. if( 0 == nReturn || nReturn >= nSize )
  31. {
  32. return nReturn;
  33. }
  34. // Check the string. If the string is not pointing to system32, we need to redirect.
  35. CSTRING_TRY
  36. {
  37. csOldFileName = lpFileName;
  38. csOldFileName.MakeUpper();
  39. nFound = csOldFileName.Find(lpSystemCheck);
  40. }
  41. CSTRING_CATCH
  42. {
  43. // Do Nothing
  44. }
  45. if(nFound >= 0)
  46. {
  47. DPFN(
  48. eDbgLevelInfo,
  49. "[WinG32SysToSys32] Changing system\\wing32.dll to system32\\wing32.dll");
  50. CSTRING_TRY
  51. {
  52. csNewFileName.GetSystemDirectoryW();
  53. csNewFileName.AppendPath(lpWinG32);
  54. lpNewFileName = csNewFileName.GetAnsiNIE();
  55. if(lpNewFileName && nSize > (unsigned int)csNewFileName.GetLength())
  56. {
  57. nReturn = csNewFileName.GetLength();
  58. memcpy(lpFileName, lpNewFileName, sizeof(char) * (nReturn + 1));
  59. }
  60. }
  61. CSTRING_CATCH
  62. {
  63. DPFN(
  64. eDbgLevelInfo,
  65. "[WinG32SysToSys32] Error parsing new string");
  66. }
  67. }
  68. return nReturn;
  69. }
  70. /*++
  71. Register hooked functions
  72. --*/
  73. HOOK_BEGIN
  74. APIHOOK_ENTRY(KERNEL32.DLL, GetModuleFileNameA)
  75. HOOK_END
  76. IMPLEMENT_SHIM_END