Source code of Windows XP (NT5)
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.

99 lines
2.1 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. // Check the string. If the string is not pointing to system32, we need to redirect.
  30. CSTRING_TRY
  31. {
  32. csOldFileName = lpFileName;
  33. csOldFileName.MakeUpper();
  34. nFound = csOldFileName.Find(lpSystemCheck);
  35. }
  36. CSTRING_CATCH
  37. {
  38. // Do Nothing
  39. }
  40. if(nFound >= 0)
  41. {
  42. DPFN(
  43. eDbgLevelInfo,
  44. "[WinG32SysToSys32] Changing system\\wing32.dll to system32\\wing32.dll");
  45. CSTRING_TRY
  46. {
  47. csNewFileName.GetSystemDirectoryW();
  48. csNewFileName.AppendPath(lpWinG32);
  49. lpNewFileName = csNewFileName.GetAnsiNIE();
  50. if(lpNewFileName)
  51. {
  52. nReturn = csNewFileName.GetLength();
  53. memcpy(lpFileName, lpNewFileName, sizeof(char) * (nReturn + 1));
  54. }
  55. }
  56. CSTRING_CATCH
  57. {
  58. DPFN(
  59. eDbgLevelInfo,
  60. "[WinG32SysToSys32] Error parsing new string");
  61. }
  62. }
  63. return nReturn;
  64. }
  65. /*++
  66. Register hooked functions
  67. --*/
  68. HOOK_BEGIN
  69. APIHOOK_ENTRY(KERNEL32.DLL, GetModuleFileNameA)
  70. HOOK_END
  71. IMPLEMENT_SHIM_END