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.

79 lines
2.3 KiB

  1. #include "wudetect.h"
  2. /////////////////////////////////////////////////////////////////////////////
  3. // CExpressionParser::fDetectRegKeyVersion
  4. // Detect a substring in registry datum.
  5. //
  6. // Form: E=RegKeyVersion,<root registry key>,<relative registry path>,<value name>,<comparison type>,[version]
  7. /////////////////////////////////////////////////////////////////////////////
  8. bool CExpressionParser::fDetectRegKeyVersion(TCHAR * pszBuf)
  9. {
  10. bool fSuccess = false;
  11. HKEY hKeyRoot;
  12. HKEY hKey;
  13. DWORD type;
  14. TCHAR szTargetKeyName[MAX_PATH];
  15. TCHAR szTargetKeyValue[MAX_PATH];
  16. //TCHAR szVersion[MAX_VERSION_STRING_LEN];
  17. TCHAR szBuf[MAX_PATH];
  18. //TCHAR szCompToken[MAX_PATH];
  19. //DWORD dwStatus;
  20. //DWORD dwLen;
  21. DWORD dwVer;
  22. DWORD dwBuild;
  23. DWORD iToken = 0;
  24. // Get reg root type (HKLM, etc)
  25. if ( fMapRegRoot(pszBuf, ++iToken, &hKeyRoot) &&
  26. (GetStringField2(pszBuf, ++iToken, szTargetKeyName, sizeof(szTargetKeyName)/sizeof(TCHAR)) != 0) )
  27. {
  28. if ( RegOpenKeyEx( hKeyRoot,
  29. szTargetKeyName,
  30. 0,
  31. KEY_QUERY_VALUE,
  32. &hKey) == ERROR_SUCCESS )
  33. {
  34. if ( GetStringField2(pszBuf, ++iToken, szTargetKeyValue, sizeof(szTargetKeyValue)/sizeof(TCHAR)) != 0 )
  35. {
  36. DWORD size = sizeof(szBuf);
  37. if ( RegQueryValueEx(hKey,
  38. szTargetKeyValue,
  39. 0,
  40. &type,
  41. (BYTE *)szBuf,
  42. &size) == ERROR_SUCCESS )
  43. {
  44. enumToken enComparisonToken;
  45. if ( (type == REG_SZ) &&
  46. fConvertDotVersionStrToDwords(szBuf, &dwVer, &dwBuild) &&
  47. (GetStringField2(pszBuf, ++iToken, szBuf, sizeof(szBuf)/sizeof(TCHAR)) != 0) &&
  48. // look at the type of the comparison
  49. fMapComparisonToken(szBuf, &enComparisonToken) )
  50. {
  51. DWORD dwAskVer = m_pDetection->dwAskVer;
  52. DWORD dwAskBuild = m_pDetection->dwAskBuild;
  53. // now, the version can be either stated explicitely or come from
  54. // the version key in the cif file.
  55. if ( GetStringField2(pszBuf, ++iToken, szBuf, sizeof(szBuf)/sizeof(TCHAR)) != 0 )
  56. {
  57. fConvertDotVersionStrToDwords(szBuf, &dwAskVer, &dwAskBuild);
  58. }
  59. if ( fCompareVersion(dwVer, dwBuild, enComparisonToken, dwAskVer, dwAskBuild) )
  60. {
  61. fSuccess = true;
  62. }
  63. }
  64. }
  65. }
  66. RegCloseKey(hKey);
  67. }
  68. }
  69. //cleanup:
  70. return fSuccess;
  71. }