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.

153 lines
4.0 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. IMPLEMENT_SHIM_BEGIN(ModemWizard)
  16. #include "ShimHookMacro.h"
  17. APIHOOK_ENUM_BEGIN
  18. APIHOOK_ENUM_ENTRY(RegQueryValueExA)
  19. APIHOOK_ENUM_END
  20. LONG
  21. APIHOOK(RegQueryValueExA)(
  22. HKEY hKey,
  23. LPSTR lpValueName,
  24. LPDWORD lpReserved,
  25. LPDWORD lpType,
  26. LPBYTE lpData,
  27. LPDWORD lpcbData
  28. )
  29. {
  30. LONG lRet;
  31. CSTRING_TRY
  32. {
  33. CString csValueName(lpValueName);
  34. int iType = 0;
  35. if (csValueName.Compare(L"Class") == 0)
  36. iType = 1;
  37. else if (csValueName.Compare(L"ClassGUID") == 0)
  38. iType = 2;
  39. else if (csValueName.Compare(L"Driver") == 0)
  40. iType = 3;
  41. const CHAR szGUID[] = "{4D36E96D-E325-11CE-BFC1-08002BE10318}";
  42. DWORD dwRegType = REG_SZ;
  43. //Save the passed in size of buffer
  44. DWORD oldcbData = lpcbData ? *lpcbData : 0;
  45. if (iType) {
  46. //
  47. // Query the registry to see if there is a service name for the subkey
  48. // If there is one then check to see if the value returned is "Modem"
  49. //
  50. lRet = ORIGINAL_API(RegQueryValueExA)(hKey, "Service", lpReserved, &dwRegType, lpData, lpcbData);
  51. if (lRet == ERROR_SUCCESS)
  52. {
  53. CString csData((LPCSTR)lpData);
  54. if (csData.Compare(L"Modem") == 0)
  55. {
  56. switch (iType) {
  57. case 1:
  58. //
  59. // We are being queried for a class
  60. //
  61. return lRet;
  62. break;
  63. case 2:
  64. //
  65. // We are being queried for a ClassGUID
  66. // class GUID for modems is
  67. // {4D36E96D-E325-11CE-BFC1-08002BE10318}
  68. //
  69. if (lpData) {
  70. _tcscpy((LPSTR)lpData, szGUID);
  71. *lpcbData = _tcslenBytes(szGUID);
  72. return lRet;
  73. }
  74. break;
  75. case 3:
  76. //
  77. // we are being queried for a Driver
  78. // Check for DrvInst to append to the modemGUID
  79. // its like {4D36E96D-E325-11CE-BFC1-08002BE10318}\0000
  80. //
  81. dwRegType = REG_DWORD;
  82. if ((lRet = ORIGINAL_API(RegQueryValueExA)(hKey, "DrvInst", lpReserved,&dwRegType,lpData,lpcbData)) == ERROR_SUCCESS) {
  83. CString csDrv;
  84. csDrv.Format(L"%s\\%04d", szGUID, (int)(LOBYTE(LOWORD((DWORD)*lpData))));
  85. LPSTR lpszData = (LPSTR)lpData;
  86. _tcscpy(lpszData, csDrv.GetAnsi());
  87. *lpcbData = _tcslenBytes(lpszData);
  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