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.

161 lines
3.3 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. NFLFever2000.cpp
  5. Abstract:
  6. The app reads past the end of files that it's copied into memory.
  7. The shim allocates additional memory for it
  8. Note we included an in-memory patch for Win2k. On Whistler it's not
  9. required, the rest of the shim does the work.
  10. Notes:
  11. This is an app specific shim.
  12. History:
  13. 01/11/2000 linstev Created
  14. 10/03/2000 maonis Modified (the acm stuff is now in a general purpose shim)
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(NFLFever2000)
  18. #include "ShimHookMacro.h"
  19. APIHOOK_ENUM_BEGIN
  20. APIHOOK_ENUM_ENTRY(GetFileSize)
  21. APIHOOK_ENUM_ENTRY(RtlAllocateHeap)
  22. APIHOOK_ENUM_ENTRY(mmioSetInfo)
  23. APIHOOK_ENUM_END
  24. DWORD g_dwFileSize = -1;
  25. BOOL g_bPatched = FALSE;
  26. /*++
  27. Hook GetFileSize to make sure we get the correct heap allocations.
  28. --*/
  29. DWORD
  30. APIHOOK(GetFileSize)(
  31. HANDLE hFile,
  32. LPDWORD lpFileSizeHigh
  33. )
  34. {
  35. DWORD dwRet = ORIGINAL_API(GetFileSize)(hFile, lpFileSizeHigh);
  36. g_dwFileSize = dwRet;
  37. PBYTE p;
  38. ULONG oldProtect;
  39. if (!g_bPatched) {
  40. p = (PBYTE)0x10995d0;
  41. if (!IsBadReadPtr(p, 1) && (*p == 0x8b)) {
  42. VirtualProtect(p, 3, PAGE_READWRITE, &oldProtect);
  43. *p = 0xc2;
  44. *(p + 1) = 0x8;
  45. *(p + 2) = 0x0;
  46. VirtualProtect(p, 3, oldProtect, &oldProtect);
  47. g_bPatched = TRUE;
  48. }
  49. }
  50. return dwRet;
  51. }
  52. /*++
  53. Increase the heap allocation size.
  54. --*/
  55. PVOID
  56. APIHOOK(RtlAllocateHeap) (
  57. PVOID HeapHandle,
  58. ULONG Flags,
  59. SIZE_T Size
  60. )
  61. {
  62. if (Size == g_dwFileSize) {
  63. DPFN( eDbgLevelError, "Adjusted heap allocation from %d to %d\n", Size, Size+0x1000);
  64. Size += 0x1000;
  65. }
  66. return ORIGINAL_API(RtlAllocateHeap)(HeapHandle, Flags, Size);
  67. }
  68. /*++
  69. Make the buffer read/write.
  70. --*/
  71. MMRESULT
  72. APIHOOK(mmioSetInfo)(
  73. HMMIO hmmio,
  74. LPMMIOINFO lpmmioinfo,
  75. UINT wFlags
  76. )
  77. {
  78. //
  79. // BUGBUG: Not needed on XP, but still required on Win2k
  80. // This fix causes sound to skip, see #304678.
  81. //
  82. // Win2k used to check if the buffer could be written to, instead of just
  83. // read. We fixed this on XP. However, it's not enough to just copy the
  84. // buffer, because it's used later.
  85. // Not clear what the actual fix is though.
  86. //
  87. /*
  88. HPSTR p = NULL;
  89. if (lpmmioinfo && lpmmioinfo->pchBuffer &&
  90. (IsBadWritePtr(lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer) &&
  91. !IsBadReadPtr(lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer))) {
  92. p = (HPSTR) malloc(lpmmioinfo->cchBuffer);
  93. if (p) {
  94. DPFN( eDbgLevelError, "Fixing mmioSetInfo buffer");
  95. MoveMemory(p, lpmmioinfo->pchBuffer, lpmmioinfo->cchBuffer);
  96. lpmmioinfo->pchBuffer = p;
  97. }
  98. }
  99. MMRESULT mRet = ORIGINAL_API(mmioSetInfo)(hmmio, lpmmioinfo, wFlags);
  100. if (p) {
  101. free(p);
  102. }
  103. return mRet;
  104. */
  105. return ORIGINAL_API(mmioSetInfo)(hmmio, lpmmioinfo, wFlags);
  106. }
  107. /*++
  108. Register hooked functions
  109. --*/
  110. HOOK_BEGIN
  111. APIHOOK_ENTRY(KERNEL32.DLL, GetFileSize)
  112. APIHOOK_ENTRY(NTDLL.DLL, RtlAllocateHeap)
  113. APIHOOK_ENTRY(WINMM.DLL, mmioSetInfo)
  114. HOOK_END
  115. IMPLEMENT_SHIM_END