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.

83 lines
2.1 KiB

  1. #include "wudetect.h"
  2. /////////////////////////////////////////////////////////////////////////////
  3. // CExpressionParser::fDetectRegSubStr
  4. // Detect a substring in registry datum.
  5. //
  6. // Form: E=RegSubstr,<SubStr>,<RootKey>,<KeyPath>,<RegValue>,<RegData>
  7. //
  8. // Comments :
  9. /////////////////////////////////////////////////////////////////////////////
  10. bool CExpressionParser::fDetectRegSubStr(TCHAR * pszBuf)
  11. {
  12. bool fSuccess = false;
  13. HKEY hKeyRoot;
  14. HKEY hKey;
  15. DWORD type;
  16. TCHAR szTargetKeyName[MAX_PATH];
  17. TCHAR szTargetKeyValue[MAX_PATH];
  18. TCHAR szKeyMissingStatus[MAX_PATH];
  19. TCHAR szData[MAX_PATH];
  20. TCHAR szSubStr[MAX_PATH];
  21. DWORD iToken = 0;
  22. // Get reg root type (HKLM, etc)
  23. if ( fMapRegRoot(pszBuf, ++iToken, &hKeyRoot) &&
  24. (GetStringField2(pszBuf, ++iToken, szTargetKeyName, sizeof(szTargetKeyName)/sizeof(TCHAR)) != 0) )
  25. {
  26. if ( RegOpenKeyEx( hKeyRoot,
  27. szTargetKeyName,
  28. 0,
  29. KEY_QUERY_VALUE,
  30. &hKey) == ERROR_SUCCESS )
  31. {
  32. if ( (GetStringField2(pszBuf, ++iToken, szTargetKeyValue, sizeof(szTargetKeyValue)/sizeof(TCHAR)) != 0) &&
  33. (GetStringField2(pszBuf, ++iToken, szKeyMissingStatus, sizeof(szKeyMissingStatus)/sizeof(TCHAR)) != 0) )
  34. {
  35. DWORD size = sizeof(szData);
  36. if ( RegQueryValueEx(hKey,
  37. szTargetKeyValue,
  38. 0,
  39. &type,
  40. (BYTE *)szData,
  41. &size) == ERROR_SUCCESS )
  42. {
  43. if ( type == REG_SZ )
  44. {
  45. _tcslwr(szData);
  46. // iterate thru the substrings looking for a match.
  47. while ( GetStringField2(pszBuf, ++iToken, szSubStr, sizeof(szSubStr)) != 0 )
  48. {
  49. _tcslwr(szSubStr);
  50. if ( _tcsstr(szData, szSubStr) != NULL )
  51. {
  52. fSuccess = true;
  53. goto quit_while;
  54. }
  55. }
  56. quit_while:;
  57. }
  58. }
  59. else
  60. {
  61. // if we get an error, assume the key does not exist. Note that if
  62. // the status is DETFIELD_NOT_INSTALLED then we don't have to do
  63. // anything since that is the default status.
  64. if ( lstrcmpi(DETFIELD_INSTALLED, szKeyMissingStatus) == 0 )
  65. {
  66. fSuccess = true;
  67. }
  68. }
  69. }
  70. RegCloseKey(hKey);
  71. }
  72. }
  73. return fSuccess;
  74. }