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.

181 lines
4.8 KiB

  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include "chkdev.h"
  4. #include <stdlib.h>
  5. #include "resource.h"
  6. #include "WbemCli.h"
  7. extern enum Classes_Provided;
  8. // nonstandard array size
  9. #pragma warning(disable:4200)
  10. #ifdef DLLENTRY
  11. #define DllExport __declspec( dllexport )
  12. #else
  13. #define DllExport
  14. #endif
  15. // define flags
  16. #define FLAGS_RUN_CHKDRV 0x00001
  17. #define FLAGS_IGNORE_STORAGE 0x00002
  18. #define STORAGE_BASE_KEY "STORAGE\\VOLUME\\"
  19. //
  20. // Error return codes
  21. //
  22. #define SUCCESS 0
  23. #define COULD_NOT_OPEN_FILE 1 // get last error still should be valid from CreateFile
  24. #define FILE_TOO_BIG 2 // greater than 4 gig
  25. #define BAD_PARAMITER 3 // paramiter is wrong
  26. #define MEMORY_ALLOCATION_ERROR 4
  27. #define FILE_CHECK_FAILED 5
  28. #define CREATE_HASH_ERROR 6
  29. #define WRONG_VERSION 7
  30. #define SOME_RANDOM_XCPT 8
  31. #define NO_MATCH_FOUND 9
  32. #define BADERROR ((0xE0 << 24) | (FACILITY_ITF << 16))
  33. #define RETURN_COMRESULT(x) _HRESULT_TYPEDEF_(x ? (BADERROR | x) : x)
  34. typedef struct tag_DeviceElement
  35. {
  36. CHAR NAME[_MAX_PATH];
  37. CHAR HWID[_MAX_PATH];
  38. CHAR DeviceID[_MAX_PATH];
  39. ULONG ulProblem;
  40. ULONG ulStatus;
  41. ULONG dwHandle;
  42. CHAR INIFILE[_MAX_FNAME + _MAX_EXT +1];
  43. UINT IsPresent;
  44. } DeviceElement;
  45. typedef struct tag_BIOS_Version
  46. {
  47. CHAR BIOSString [100];
  48. CHAR BIOSDate [100];
  49. } BIOSVERSION;
  50. typedef struct tag_InfoFileHeader
  51. {
  52. char FileVersionName[32];
  53. DWORD FileVersion[4];
  54. DWORD TimeStamp;
  55. } InfoFileHeader;
  56. typedef struct tag_FileHash
  57. {
  58. CHAR FileName[_MAX_PATH];
  59. DWORD ulHashSize;
  60. BYTE Hash[_MAX_PATH];
  61. } FileHash;
  62. typedef struct tag_FileListHeader
  63. {
  64. DWORD TAG;
  65. DWORD CountFiles;
  66. FileHash Files[];
  67. } FileListHeader;
  68. typedef struct tag_FileHeader
  69. {
  70. InfoFileHeader FileInfo;
  71. DWORD ThisFileSize;
  72. DWORD CountStructs;
  73. DWORD CountFiles;
  74. BIOSVERSION BiosVersion ;
  75. FileListHeader *pFileList;
  76. DeviceElement DeviceArray[];
  77. } FileHeader;
  78. #pragma warning(default:4200)
  79. BOOL _cdecl logprintf(TCHAR *lpszFormat, ...);
  80. DWORD WINAPI ScanDeviceList(void *pVoid);
  81. DWORD WINAPI ScanFileList(void *pVoid);
  82. BOOL CompareDevice (InfnodeClass *pDevice, DeviceElement *pElement);
  83. BOOL CompareFiles(char *FileName, ULONG HashSize, PBYTE Hash);
  84. int ScanTreeHelper(DEVNODE hDevnode, DEVNODE hParent);
  85. DWORD WINAPI ScanDeviceList(void *pVoid);
  86. DWORD WINAPI ScanFileList(void *pVoid);
  87. int CreateList(IWbemContext *pCtx , Classes_Provided eClasses);
  88. int WalkTree(void);
  89. int WalkTreeHelper(DEVNODE hDevnode, DEVNODE hParent);
  90. int WriteDeviceToBuffer(DeviceElement *pElement, CheckDevice *pDevice);
  91. int WriteFileListToBuffer(FileHash *pHash, FileNode *pFile);
  92. int ScanList (TCHAR *szFileName, UINT uFlags);
  93. BOOL GetList (TCHAR **pErrorString);
  94. BOOL IsExcludedDriver (TCHAR *DeviceID);
  95. BOOL IsExcludedClass (TCHAR *DeviceID);
  96. BOOL WriteBiosDateAndVersion (BIOSVERSION *BVer);
  97. BOOL GetBiosDateAndVersion(BIOSVERSION *BVer);
  98. // cmplist.cpp
  99. BOOL CryptFile (ULONG key, WORD *buffer, ULONG size /* in bytes */);
  100. BOOL bVerifyVersion(DWORD *pVersion);
  101. BOOL MatchPCI_ID(PCHAR pHwid, DeviceElement *pElement, ULONG count);
  102. BOOL MatchUSB_ID(PCHAR pHwid, DeviceElement *pElement, ULONG count);
  103. BOOL MatchHID_ID(PCHAR pHwid, DeviceElement *pElement, ULONG count);
  104. BOOL MatchACPI_ID(PCHAR pHwid, DeviceElement *pElement, ULONG count);
  105. BOOL MatchXxx_ID(PCHAR pHwid, DeviceElement *pElement, ULONG count);
  106. extern "C" BOOL DllExport WINAPI Chkdrv_IsFileAMatch (ULONG pFileHandle, char *lpszFileName);
  107. extern "C" BOOL DllExport WINAPI Chkdrv_IsHWIDAMatch (ULONG pFileHandle, char *lpszHWIDName);
  108. extern "C" DWORD DllExport WINAPI Chkdrv_CloseListFile (ULONG pFileHandle);
  109. extern "C" DWORD DllExport WINAPI Chkdrv_OpenListFile(char *szFileName);
  110. extern "C" ULONG DllExport WINAPI Chkdrv_CompareListFiles(ULONG handle1, ULONG handle2, TCHAR **LogFile, UINT *cbResult);
  111. extern "C" DWORD DllExport WINAPI CreateEnvCheckFile (PCHAR lpszFileName, HWND hParent);
  112. extern "C" DWORD DllExport WINAPI ScanDevicesForChanges(PCHAR lpszFileName, CHAR **lppszResults, UINT *cbResults, DWORD dwFlags);
  113. extern "C" BOOL bIgnoreStorage;
  114. BOOL ProgBoxStep(char *text);
  115. int WalkTreeDevnode(DEVNODE hDevnode, DEVNODE hParent);
  116. extern "C" INT_PTR WINAPI ProgBoxProcedure(
  117. HWND hwndDlg, // handle to dialog box
  118. UINT uMsg, // message
  119. WPARAM wParam, // first message parameter
  120. LPARAM lParam // second message parameter
  121. );
  122. extern HANDLE hMutex;
  123. #ifdef DEBUG
  124. #ifndef ASSERT
  125. #define ASSERT(x) \
  126. if (!x) _asm int 3;
  127. //void *::operator new(SIZE_T size);
  128. #endif
  129. #else
  130. #ifndef ASSERT
  131. #define ASSERT(x)
  132. #endif
  133. #endif