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.

135 lines
2.8 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. NFLBlitz.cpp
  5. Abstract:
  6. NFL Blitz has 2 problems:
  7. 1. It keeps linked lists on it's stack and somehow the stack pointer
  8. is changed to allow altered FindFirstFile to corrupt it. We don't hit
  9. this on win9x because FindFirstFile doesn't use any app stack space.
  10. 2. Autorun and the main executable are synchronized using a mutex that is
  11. freed only on process termination. The sequence of events is:
  12. a. Autorun creates a mutex
  13. b. Autorun creates a new process
  14. c. Autorun terminates thus freeing the mutex in (a).
  15. d. New process checks if it's already running by examining the
  16. mutex created in (a).
  17. This fails when (c) and (d) are exchanged which happens all the time
  18. on NT, but apparently very seldom on win9x.
  19. Notes:
  20. This is an app specific shim.
  21. History:
  22. 02/10/2000 linstev Created
  23. --*/
  24. #include "precomp.h"
  25. IMPLEMENT_SHIM_BEGIN(NFLBlitz)
  26. #include "ShimHookMacro.h"
  27. APIHOOK_ENUM_BEGIN
  28. APIHOOK_ENUM_ENTRY(CreateMutexA)
  29. APIHOOK_ENUM_ENTRY(CreateProcessA)
  30. APIHOOK_ENUM_END
  31. HANDLE g_hMutex = NULL;
  32. /*++
  33. Store the handle to the mutex we're interested in.
  34. --*/
  35. HANDLE
  36. APIHOOK(CreateMutexA)(
  37. LPSECURITY_ATTRIBUTES lpMutexAttributes,
  38. BOOL bInitialOwner,
  39. LPCSTR lpName
  40. )
  41. {
  42. HANDLE hRet = ORIGINAL_API(CreateMutexA)(
  43. lpMutexAttributes,
  44. bInitialOwner,
  45. lpName);
  46. DWORD dwErrCode = GetLastError();
  47. if (lpName && _stricmp(lpName, "NFL BLITZ") == 0)
  48. {
  49. g_hMutex = hRet;
  50. }
  51. SetLastError(dwErrCode);
  52. return hRet;
  53. }
  54. /*++
  55. Close the mutex.
  56. --*/
  57. BOOL
  58. APIHOOK(CreateProcessA)(
  59. LPCSTR lpApplicationName,
  60. LPSTR lpCommandLine,
  61. LPSECURITY_ATTRIBUTES lpProcessAttributes,
  62. LPSECURITY_ATTRIBUTES lpThreadAttributes,
  63. BOOL bInheritHandles,
  64. DWORD dwCreationFlags,
  65. LPVOID lpEnvironment,
  66. LPCSTR lpCurrentDirectory,
  67. LPSTARTUPINFOA lpStartupInfo,
  68. LPPROCESS_INFORMATION lpProcessInformation
  69. )
  70. {
  71. if (g_hMutex)
  72. {
  73. ReleaseMutex(g_hMutex);
  74. CloseHandle(g_hMutex);
  75. g_hMutex = NULL;
  76. }
  77. return ORIGINAL_API(CreateProcessA)(
  78. lpApplicationName,
  79. lpCommandLine,
  80. lpProcessAttributes,
  81. lpThreadAttributes,
  82. bInheritHandles,
  83. dwCreationFlags,
  84. lpEnvironment,
  85. lpCurrentDirectory,
  86. lpStartupInfo,
  87. lpProcessInformation);
  88. }
  89. /*++
  90. Register hooked functions
  91. --*/
  92. HOOK_BEGIN
  93. APIHOOK_ENTRY(KERNEL32.DLL, CreateMutexA)
  94. APIHOOK_ENTRY(KERNEL32.DLL, CreateProcessA)
  95. HOOK_END
  96. IMPLEMENT_SHIM_END