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.

97 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. HeapClearAllocation.cpp
  5. ModAbstract:
  6. This shim fills all heap allocations with 0
  7. Notes:
  8. This is a general purpose shim.
  9. History:
  10. 05/16/2000 dmunsil Created (based on HeapPadAllocation, by linstev)
  11. 10/10/2000 rparsons Added additional hooks for GlobalAlloc & LocalAlloc
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(HeapClearAllocation)
  15. #include "ShimHookMacro.h"
  16. APIHOOK_ENUM_BEGIN
  17. APIHOOK_ENUM_ENTRY(RtlAllocateHeap)
  18. APIHOOK_ENUM_ENTRY(LocalAlloc)
  19. APIHOOK_ENUM_ENTRY(GlobalAlloc)
  20. APIHOOK_ENUM_END
  21. /*++
  22. Clear the allocation with the requested DWORD.
  23. --*/
  24. PVOID
  25. APIHOOK(RtlAllocateHeap)(
  26. PVOID HeapHandle,
  27. ULONG Flags,
  28. SIZE_T Size
  29. )
  30. {
  31. return ORIGINAL_API(RtlAllocateHeap)(HeapHandle, Flags | HEAP_ZERO_MEMORY, Size);
  32. }
  33. /*++
  34. Clear the allocation with the requested DWORD.
  35. --*/
  36. HLOCAL
  37. APIHOOK(LocalAlloc)(
  38. UINT uFlags,
  39. SIZE_T uBytes
  40. )
  41. {
  42. return ORIGINAL_API(LocalAlloc)(uFlags | LMEM_ZEROINIT, uBytes);
  43. }
  44. /*++
  45. Clear the allocation with the requested DWORD.
  46. --*/
  47. HGLOBAL
  48. APIHOOK(GlobalAlloc)(
  49. UINT uFlags,
  50. DWORD dwBytes
  51. )
  52. {
  53. return ORIGINAL_API(GlobalAlloc)(uFlags | GMEM_ZEROINIT, dwBytes);
  54. }
  55. /*++
  56. Register hooked functions
  57. --*/
  58. HOOK_BEGIN
  59. APIHOOK_ENTRY(NTDLL.DLL, RtlAllocateHeap)
  60. APIHOOK_ENTRY(KERNEL32.DLL, LocalAlloc)
  61. APIHOOK_ENTRY(KERNEL32.DLL, GlobalAlloc)
  62. HOOK_END
  63. IMPLEMENT_SHIM_END