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.

101 lines
1.4 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. MathBlaster9_12.cpp
  5. Abstract:
  6. App requires lookaside on VirtualAllocs...
  7. Notes:
  8. This is an appspecific shim.
  9. History:
  10. 10/10/2000 linstev Created
  11. --*/
  12. #include "precomp.h"
  13. IMPLEMENT_SHIM_BEGIN(MathBlaster9_12)
  14. #include "ShimHookMacro.h"
  15. APIHOOK_ENUM_BEGIN
  16. APIHOOK_ENUM_ENTRY(VirtualAlloc)
  17. APIHOOK_ENUM_ENTRY(VirtualFree)
  18. APIHOOK_ENUM_END
  19. LPVOID g_pLast = NULL;
  20. /*++
  21. Use the cached value.
  22. --*/
  23. LPVOID
  24. APIHOOK(VirtualAlloc)(
  25. LPVOID lpAddress,
  26. DWORD dwSize,
  27. DWORD flAllocationType,
  28. DWORD flProtect
  29. )
  30. {
  31. LPVOID pRet = 0;
  32. if (!lpAddress && g_pLast)
  33. {
  34. pRet = ORIGINAL_API(VirtualAlloc)(g_pLast, dwSize, flAllocationType, flProtect);
  35. }
  36. if (!pRet)
  37. {
  38. pRet = ORIGINAL_API(VirtualAlloc)(lpAddress, dwSize, flAllocationType, flProtect);
  39. }
  40. return pRet;
  41. }
  42. /*++
  43. Use the cached value.
  44. --*/
  45. BOOL
  46. APIHOOK(VirtualFree)(
  47. LPVOID lpAddress,
  48. DWORD dwSize,
  49. DWORD dwFreeType )
  50. {
  51. BOOL bRet = ORIGINAL_API(VirtualFree)(lpAddress, dwSize, dwFreeType);
  52. if (bRet)
  53. {
  54. g_pLast = lpAddress;
  55. }
  56. return bRet;
  57. }
  58. /*++
  59. Register hooked functions
  60. --*/
  61. HOOK_BEGIN
  62. APIHOOK_ENTRY(Kernel32.DLL, VirtualAlloc )
  63. APIHOOK_ENTRY(Kernel32.DLL, VirtualFree )
  64. HOOK_END
  65. IMPLEMENT_SHIM_END