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.

113 lines
2.5 KiB

  1. //
  2. // Modified by RogerJ, 03/08/00
  3. // Original Creator Unknown
  4. // Modification --- UNICODE and Win64 ready
  5. //
  6. //////////////////////////////////////////////////////////////////////////////
  7. typedef enum _PARSE_TOKEN_TYPE
  8. {
  9. TOKEN_LEFTPAREN,
  10. TOKEN_RIGHTPAREN,
  11. TOKEN_AND,
  12. TOKEN_OR,
  13. TOKEN_NOT,
  14. TOKEN_VARIABLE,
  15. TOKEN_DONE
  16. } PARSE_TOKEN_TYPE;
  17. typedef struct _TOKEN_IDENTIFIER
  18. {
  19. TCHAR *pszTok;
  20. PARSE_TOKEN_TYPE tok;
  21. } TOKEN_IDENTIFIER;
  22. const bool FAILURE_RESULT = false;
  23. class CExpressionParser
  24. {
  25. public:
  26. typedef enum _enumToken
  27. {
  28. // comparison tokens
  29. COMP_EQUALS,
  30. COMP_NOT_EQUALS,
  31. COMP_LESS_THAN,
  32. COMP_LESS_THAN_EQUALS,
  33. COMP_GREATER_THAN,
  34. COMP_GREATER_THAN_EQUALS,
  35. // directory tokens
  36. DIR_SYSTEM,
  37. DIR_WINDOWS
  38. } enumToken;
  39. typedef struct _TokenMapping
  40. {
  41. const TCHAR * /*const*/ pszToken;
  42. enumToken enToken;
  43. } TokenMapping;
  44. CExpressionParser(DETECTION_STRUCT *pDetection)
  45. : m_pDetection(pDetection),
  46. m_pch(NULL)
  47. {}
  48. //
  49. // Expression parsing methods
  50. //
  51. void vSkipWS(void);
  52. bool fGetCurToken( PARSE_TOKEN_TYPE & tok,
  53. TOKEN_IDENTIFIER *grTokens,
  54. int nSize);
  55. bool fGetCurTermToken(PARSE_TOKEN_TYPE & tok);
  56. bool fGetCurExprToken(PARSE_TOKEN_TYPE & tok);
  57. bool fGetVariable(TCHAR *pszVariable);
  58. bool fPerformDetection(TCHAR * pszVariable, bool & fResult);
  59. bool fEvalTerm(bool & fResult, bool fSkip);
  60. HRESULT fEvalExpression(TCHAR * pszExpr, bool * pfResult);
  61. bool fEvalExpr(bool & fResult);
  62. bool fGetCifEntry( TCHAR *pszParamName,
  63. TCHAR *pszParamValue,
  64. DWORD cbParamValue);
  65. //
  66. // Detection methods
  67. //
  68. bool fKeyType(TCHAR *szRootType, HKEY *phKey);
  69. bool fDetectRegSubStr(TCHAR * pszBuf);
  70. bool fDetectRegBinary(TCHAR * pszBuf);
  71. bool fDetectFileVer(TCHAR * pszBuf);
  72. bool fDetectRegKeyExists(TCHAR * pszBuf);
  73. bool fDetectRegKeyVersion(TCHAR * pszBuf);
  74. bool fDetect40BitSecurity(TCHAR * pszBuf);
  75. bool fMapToken(TCHAR *pszToken,
  76. int nSize,
  77. TokenMapping grTokenMap[],
  78. enumToken *penToken);
  79. bool fMapRootDirToken(TCHAR *pszRootDirToken, enumToken *penToken);
  80. bool fMapComparisonToken(TCHAR *pszComparisonToken,
  81. enumToken *penToken);
  82. bool fCompareVersion(IN DWORD dwVer1,
  83. IN DWORD dwBuild1,
  84. IN enumToken enComparisonToken,
  85. IN DWORD dwVer2,
  86. IN DWORD dwBuild2);
  87. DWORD dwParseValue(DWORD iToken, TCHAR * szBuf, TargetRegValue & targetValue);
  88. private:
  89. TCHAR *m_pch;
  90. DETECTION_STRUCT *m_pDetection;
  91. };