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.

105 lines
2.0 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. AOLSystemInfo.cpp
  5. Abstract:
  6. AOL looks to enumerate the registry key
  7. HKLM\System\CurrentControlSet\Control\Class
  8. but passes a fixed size buffer. The number
  9. of keys under 'Class' have changed in XP
  10. causing unexpected behaviour.
  11. Notes:
  12. This is specific to this app.
  13. History:
  14. 05/17/2001 prashkud Created
  15. --*/
  16. #include "precomp.h"
  17. IMPLEMENT_SHIM_BEGIN(AOLSystemInfo)
  18. #include "ShimHookMacro.h"
  19. #define ALLOC_SIZE 50
  20. APIHOOK_ENUM_BEGIN
  21. APIHOOK_ENUM_ENTRY(RegEnumKeyExA)
  22. APIHOOK_ENUM_END
  23. /*++
  24. The idea here is to check for the buffer sizes and wait till it is
  25. one size close to it and then allocate a buffer and pass it onto the
  26. API.
  27. --*/
  28. LONG
  29. APIHOOK(RegEnumKeyExA)(
  30. HKEY hkey,
  31. DWORD dwIndex,
  32. LPSTR lpName,
  33. LPDWORD lpcName,
  34. LPDWORD lpReserved,
  35. LPSTR lpClass,
  36. LPDWORD lpcClass,
  37. PFILETIME lpftLastWriteTime
  38. )
  39. {
  40. LONG lRet = 0;
  41. static BOOL bSet = FALSE;
  42. DWORD dwNameSize = *(lpcName) ? *(lpcName) : ALLOC_SIZE;
  43. // Get the difference in the passed buffer gap
  44. DWORD dwSize = (DWORD)((LPSTR)lpcName - lpName);
  45. if (!bSet && (dwSize <= dwNameSize))
  46. {
  47. bSet = TRUE;
  48. }
  49. if (bSet)
  50. {
  51. lpName = (LPSTR)HeapAlloc(GetProcessHeap(),
  52. HEAP_NO_SERIALIZE | HEAP_ZERO_MEMORY,
  53. ALLOC_SIZE
  54. );
  55. if (!lpName)
  56. {
  57. return ERROR_NO_MORE_ITEMS;
  58. }
  59. *(lpcName) = dwNameSize;
  60. }
  61. lRet = ORIGINAL_API(RegEnumKeyExA)(hkey, dwIndex, lpName,lpcName,
  62. lpReserved, lpClass, lpcClass, lpftLastWriteTime);
  63. if (lRet == ERROR_NO_MORE_ITEMS)
  64. {
  65. bSet = FALSE;
  66. }
  67. return lRet;
  68. }
  69. /*++
  70. Register hooked functions
  71. --*/
  72. HOOK_BEGIN
  73. APIHOOK_ENTRY(ADVAPI32.DLL, RegEnumKeyExA)
  74. HOOK_END
  75. IMPLEMENT_SHIM_END