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.

142 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 2000 Microsoft Corporation
  3. Module Name:
  4. Worker.cpp
  5. Abstract:
  6. These are the worker functions for virtual registry. They are called
  7. whenever a non-static value is queried.
  8. Notes:
  9. History:
  10. 07/18/2000 linstev Created
  11. 10/11/2001 mikrause Added protectors.
  12. --*/
  13. #include "precomp.h"
  14. IMPLEMENT_SHIM_BEGIN(VirtualRegistry)
  15. #include "ShimHookMacro.h"
  16. #include "VRegistry.h"
  17. #include "VRegistry_Worker.h"
  18. /*++
  19. Expand REG_EXPAND_SZ for this value
  20. --*/
  21. LONG
  22. WINAPI
  23. VR_Expand(
  24. OPENKEY *key,
  25. VIRTUALKEY*,
  26. VIRTUALVAL *vvalue
  27. )
  28. {
  29. DWORD dwType;
  30. WCHAR wSrc[MAX_PATH];
  31. DWORD dwSize = sizeof(wSrc);
  32. //
  33. // Query the original value
  34. //
  35. LONG lRet = ORIGINAL_API(RegQueryValueExW)(
  36. key->hkOpen,
  37. vvalue->wName,
  38. NULL,
  39. &dwType,
  40. (LPBYTE)wSrc,
  41. &dwSize);
  42. //
  43. // Query failed - this should never happen
  44. //
  45. if (FAILURE(lRet))
  46. {
  47. DPFN( eDbgLevelError, "Failed to query %S for expansion", vvalue->wName);
  48. goto Exit;
  49. }
  50. //
  51. // Not a string type!
  52. //
  53. if (!((dwType == REG_EXPAND_SZ) || (dwType == REG_SZ)) &&
  54. (dwSize > sizeof(wSrc)))
  55. {
  56. DPFN( eDbgLevelError, "Expander: Not a string type");
  57. lRet = ERROR_BAD_ARGUMENTS;
  58. goto Exit;
  59. }
  60. //
  61. // Expand the string and store it in the value
  62. //
  63. vvalue->cbData = ExpandEnvironmentStringsW(wSrc, NULL, 0) * 2;
  64. if (vvalue->cbData == 0)
  65. {
  66. lRet = ERROR_BAD_ARGUMENTS;
  67. goto Exit;
  68. }
  69. vvalue->lpData = (LPBYTE) malloc(vvalue->cbData);
  70. if (!vvalue->lpData)
  71. {
  72. DPFN( eDbgLevelError, szOutOfMemory);
  73. lRet = ERROR_NOT_ENOUGH_MEMORY;
  74. goto Exit;
  75. }
  76. if (ExpandEnvironmentStringsW(wSrc, (PWSTR)vvalue->lpData, vvalue->cbData / 2) != vvalue->cbData / sizeof(WCHAR))
  77. {
  78. lRet = ERROR_NOT_ENOUGH_MEMORY;
  79. goto Exit;
  80. }
  81. //
  82. // Value is now cached, so we don't need to get called again
  83. //
  84. vvalue->pfnQueryValue = NULL;
  85. lRet = ERROR_SUCCESS;
  86. DPFN( eDbgLevelInfo, "Expanded Value=%S\n", vvalue->lpData);
  87. Exit:
  88. return lRet;
  89. }
  90. /*++
  91. Do nothing, the SetValue is ignored.
  92. --*/
  93. LONG
  94. WINAPI
  95. VR_Protect(
  96. OPENKEY*,
  97. VIRTUALKEY*,
  98. VIRTUALVAL*,
  99. DWORD,
  100. const BYTE*,
  101. DWORD)
  102. {
  103. return ERROR_SUCCESS;
  104. }
  105. IMPLEMENT_SHIM_END