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.

153 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. ModemWizard.cpp
  5. Abstract:
  6. This shim hooks the RegQueryValueEx and passes in the app expected values
  7. if the values are missing in the registry.
  8. Notes:
  9. This is an app specific shim.
  10. History:
  11. 01/18/2001 a-leelat Created
  12. --*/
  13. #include "precomp.h"
  14. #include <stdio.h>
  15. #include "strsafe.h"
  16. IMPLEMENT_SHIM_BEGIN(ModemWizard)
  17. #include "ShimHookMacro.h"
  18. APIHOOK_ENUM_BEGIN
  19. APIHOOK_ENUM_ENTRY(RegQueryValueExA)
  20. APIHOOK_ENUM_END
  21. LONG
  22. APIHOOK(RegQueryValueExA)(
  23. HKEY hKey,
  24. LPSTR lpValueName,
  25. LPDWORD lpReserved,
  26. LPDWORD lpType,
  27. LPBYTE lpData,
  28. LPDWORD lpcbData
  29. )
  30. {
  31. LONG lRet;
  32. CSTRING_TRY
  33. {
  34. CString csValueName(lpValueName);
  35. int iType = 0;
  36. if (csValueName.Compare(L"Class") == 0)
  37. iType = 1;
  38. else if (csValueName.Compare(L"ClassGUID") == 0)
  39. iType = 2;
  40. else if (csValueName.Compare(L"Driver") == 0)
  41. iType = 3;
  42. const CHAR szGUID[] = "{4D36E96D-E325-11CE-BFC1-08002BE10318}";
  43. DWORD dwRegType = REG_SZ;
  44. //Save the passed in size of buffer
  45. DWORD oldcbData = lpcbData ? *lpcbData : 0;
  46. if (iType) {
  47. //
  48. // Query the registry to see if there is a service name for the subkey
  49. // If there is one then check to see if the value returned is "Modem"
  50. //
  51. lRet = ORIGINAL_API(RegQueryValueExA)(hKey, "Service", lpReserved, &dwRegType, lpData, lpcbData);
  52. if (lRet == ERROR_SUCCESS)
  53. {
  54. CString csData((LPCSTR)lpData);
  55. if (csData.Compare(L"Modem") == 0)
  56. {
  57. switch (iType) {
  58. case 1:
  59. //
  60. // We are being queried for a class
  61. //
  62. return lRet;
  63. break;
  64. case 2:
  65. //
  66. // We are being queried for a ClassGUID
  67. // class GUID for modems is
  68. // {4D36E96D-E325-11CE-BFC1-08002BE10318}
  69. //
  70. if (lpData) {
  71. StringCchCopyA((LPSTR)lpData, oldcbData, szGUID);
  72. StringCchLengthA((LPSTR)lpData, oldcbData, (size_t *)lpcbData);
  73. return lRet;
  74. }
  75. break;
  76. case 3:
  77. //
  78. // we are being queried for a Driver
  79. // Check for DrvInst to append to the modemGUID
  80. // its like {4D36E96D-E325-11CE-BFC1-08002BE10318}\0000
  81. //
  82. dwRegType = REG_DWORD;
  83. if ((lRet = ORIGINAL_API(RegQueryValueExA)(hKey, "DrvInst", lpReserved,&dwRegType,lpData,lpcbData)) == ERROR_SUCCESS) {
  84. CString csDrv;
  85. csDrv.Format(L"%s\\%04d", szGUID, (int)(LOBYTE(LOWORD((DWORD)*lpData))));
  86. StringCchCopyA((LPSTR)lpData, oldcbData, csDrv.GetAnsi());
  87. StringCchLengthA((LPSTR)lpData, oldcbData, (size_t *)lpcbData);
  88. return lRet;
  89. }
  90. break;
  91. default:
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. if (lpcbData) {
  98. *lpcbData = oldcbData;
  99. }
  100. }
  101. CSTRING_CATCH
  102. {
  103. // Do nothing
  104. }
  105. lRet = ORIGINAL_API(RegQueryValueExA)(hKey, lpValueName, lpReserved,
  106. lpType, lpData, lpcbData);
  107. return lRet;
  108. }
  109. /*++
  110. Register hooked functions
  111. --*/
  112. HOOK_BEGIN
  113. APIHOOK_ENTRY(ADVAPI32.DLL, RegQueryValueExA);
  114. HOOK_END
  115. IMPLEMENT_SHIM_END