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.

286 lines
5.3 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. //
  7. // module: VGlobal.cpp
  8. // author: DMihai
  9. // created: 11/1/00
  10. //
  11. // Description
  12. //
  13. #include "stdafx.h"
  14. #include "verifier.h"
  15. #include "vglobal.h"
  16. #include "VrfUtil.h"
  17. //
  18. // Help file name
  19. //
  20. TCHAR g_szVerifierHelpFile[] = _T( "verifier.hlp" );
  21. //
  22. // Application name ("Driver Verifier Manager")
  23. //
  24. CString g_strAppName;
  25. //
  26. // Exe module handle - used for loading resources
  27. //
  28. HMODULE g_hProgramModule;
  29. //
  30. // GUI mode or command line mode?
  31. //
  32. BOOL g_bCommandLineMode = FALSE;
  33. //
  34. // Brush used to fill out the background of our steps lists
  35. //
  36. HBRUSH g_hDialogColorBrush = NULL;
  37. //
  38. // Path to %windir%\system32
  39. //
  40. CString g_strSystemDir;
  41. //
  42. // Path to %windir%\system32\drivers
  43. //
  44. CString g_strDriversDir;
  45. //
  46. // Initial current directory
  47. //
  48. CString g_strInitialCurrentDirectory;
  49. //
  50. // Filled out by CryptCATAdminAcquireContext
  51. //
  52. HCATADMIN g_hCatAdmin = NULL;
  53. //
  54. // Highest user address - used to filter out user-mode stuff
  55. // returned by NtQuerySystemInformation ( SystemModuleInformation )
  56. //
  57. PVOID g_pHighestUserAddress;
  58. //
  59. // Did we enable the debug privilege already?
  60. //
  61. BOOL g_bPrivilegeEnabled = FALSE;
  62. //
  63. // Need to reboot ?
  64. //
  65. BOOL g_bSettingsSaved = FALSE;
  66. //
  67. // Dummy text used to insert an item in a list control with checkboxes
  68. //
  69. TCHAR g_szVoidText[] = _T( "" );
  70. //
  71. // New registry settings
  72. //
  73. CVerifierSettings g_NewVerifierSettings;
  74. //
  75. // Are all drivers verified? (loaded from the registry)
  76. //
  77. BOOL g_bAllDriversVerified;
  78. //
  79. // Drivers to be verified names (loaded from the registry)
  80. // We have data in this array only if g_bAllDriversVerified == FALSE.
  81. //
  82. CStringArray g_astrVerifyDriverNamesRegistry;
  83. //
  84. // Verifier flags (loaded from the registry)
  85. //
  86. DWORD g_dwVerifierFlagsRegistry;
  87. //
  88. // Old disk integrity verifier settings.
  89. //
  90. CDiskDataArray g_OldDiskData;
  91. //
  92. // Disk verifier filter name.
  93. //
  94. TCHAR g_szFilter[] = _T( "crcdisk" );
  95. //
  96. // Show the disk selection page or not.
  97. // Used to force displaying this property page even when
  98. // no disk in g_NewVerifierSettings.m_aDiskData has the
  99. // verifier flag turned on.
  100. //
  101. BOOL g_bShowDiskPropertyPage = FALSE;
  102. ////////////////////////////////////////////////////////////////
  103. BOOL VerifInitalizeGlobalData( VOID )
  104. {
  105. BOOL bSuccess;
  106. LPTSTR szDirectory;
  107. ULONG uCharacters;
  108. MEMORYSTATUSEX MemoryStatusEx;
  109. //
  110. // Exe module handle - used for loading resources
  111. //
  112. g_hProgramModule = GetModuleHandle( NULL );
  113. bSuccess = FALSE;
  114. //
  115. // Load the app name from the resources
  116. //
  117. TRY
  118. {
  119. bSuccess = VrfLoadString( IDS_APPTITLE,
  120. g_strAppName );
  121. if( FALSE == bSuccess )
  122. {
  123. VrfErrorResourceFormat( IDS_CANNOT_LOAD_APP_TITLE );
  124. }
  125. }
  126. CATCH( CMemoryException, pMemException )
  127. {
  128. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  129. }
  130. END_CATCH
  131. if( FALSE == bSuccess )
  132. {
  133. goto Done;
  134. }
  135. //
  136. // Save the %windir%\system32 and %windir%\system32\drivers
  137. // paths in some global variables
  138. //
  139. szDirectory = g_strSystemDir.GetBuffer( MAX_PATH );
  140. if( NULL == szDirectory )
  141. {
  142. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  143. goto Done;
  144. }
  145. uCharacters = GetSystemDirectory( szDirectory,
  146. MAX_PATH );
  147. g_strSystemDir.ReleaseBuffer();
  148. if( uCharacters == 0 || uCharacters >= MAX_PATH )
  149. {
  150. VrfErrorResourceFormat( IDS_CANNOT_GET_SYSTEM_DIRECTORY );
  151. bSuccess = FALSE;
  152. goto Done;
  153. }
  154. g_strDriversDir = g_strSystemDir + "\\drivers" ;
  155. //
  156. // Save the initial current directory
  157. //
  158. szDirectory = g_strInitialCurrentDirectory.GetBuffer( MAX_PATH );
  159. if( NULL == szDirectory )
  160. {
  161. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  162. goto Done;
  163. }
  164. uCharacters = GetCurrentDirectory( MAX_PATH,
  165. szDirectory );
  166. g_strInitialCurrentDirectory.ReleaseBuffer();
  167. if( uCharacters == 0 || uCharacters >= MAX_PATH )
  168. {
  169. VrfErrorResourceFormat( IDS_CANNOT_GET_CURRENT_DIRECTORY );
  170. bSuccess = FALSE;
  171. goto Done;
  172. }
  173. //
  174. // We need the highest user-mode address to filter out user-mode stuff
  175. // returned by NtQuerySystemInformation ( SystemModuleInformation )
  176. //
  177. ZeroMemory( &MemoryStatusEx,
  178. sizeof( MemoryStatusEx ) );
  179. MemoryStatusEx.dwLength = sizeof( MemoryStatusEx );
  180. bSuccess = GlobalMemoryStatusEx( &MemoryStatusEx );
  181. if( FALSE == bSuccess )
  182. {
  183. goto Done;
  184. }
  185. g_pHighestUserAddress = (PVOID) MemoryStatusEx.ullTotalVirtual;
  186. //
  187. // Initialize the list of physical disks.
  188. //
  189. bSuccess = g_OldDiskData.InitializeDiskList();
  190. if( FALSE == bSuccess )
  191. {
  192. goto Done;
  193. }
  194. g_NewVerifierSettings.m_aDiskData = g_OldDiskData;
  195. //
  196. // Always start with fresh data (don't verify any disks).
  197. //
  198. g_NewVerifierSettings.m_aDiskData.SetVerifyAllDisks( FALSE );
  199. Done:
  200. return bSuccess;
  201. }