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.

1876 lines
47 KiB

  1. //
  2. // Driver Verifier UI
  3. // Copyright (c) Microsoft Corporation, 1999
  4. //
  5. //
  6. //
  7. // module: VSetting.cpp
  8. // author: DMihai
  9. // created: 11/1/00
  10. //
  11. // Description
  12. //
  13. // Implementation of the CVerifierSettings class.
  14. //
  15. #include "stdafx.h"
  16. #include "verifier.h"
  17. #include "VSetting.h"
  18. #include "VrfUtil.h"
  19. #include "VGlobal.h"
  20. #include "disk.h"
  21. #ifdef _DEBUG
  22. #undef THIS_FILE
  23. static char THIS_FILE[]=__FILE__;
  24. #define new DEBUG_NEW
  25. #endif
  26. //////////////////////////////////////////////////////////////////////
  27. // CDriverData Class
  28. //////////////////////////////////////////////////////////////////////
  29. CDriverData::CDriverData()
  30. {
  31. m_SignedStatus = SignedNotVerifiedYet;
  32. m_VerifyDriverStatus = VerifyDriverNo;
  33. }
  34. CDriverData::CDriverData( const CDriverData &DriverData )
  35. {
  36. m_strName = DriverData.m_strName;
  37. m_SignedStatus = DriverData.m_SignedStatus;
  38. m_VerifyDriverStatus= DriverData.m_VerifyDriverStatus;
  39. }
  40. CDriverData::CDriverData( LPCTSTR szDriverName )
  41. {
  42. m_SignedStatus = SignedNotVerifiedYet;
  43. m_VerifyDriverStatus = VerifyDriverNo;
  44. m_strName = szDriverName;
  45. }
  46. CDriverData::~CDriverData()
  47. {
  48. }
  49. //////////////////////////////////////////////////////////////////////
  50. BOOL CDriverData::LoadDriverHeaderData()
  51. {
  52. //
  53. // N.B.
  54. //
  55. // The imagehlp functions are not multithreading safe
  56. // (see Whistler bug #88373) so if we want to use them from more than
  57. // one thread we will have to aquire some critical section before.
  58. //
  59. // Currently only one thread is using the imagehlp APIs in this app
  60. // (CSlowProgressDlg::LoadDriverDataWorkerThread) so we don't need
  61. // our synchronization.
  62. //
  63. LPTSTR szDriverName;
  64. LPTSTR szDriversDir;
  65. PLOADED_IMAGE pLoadedImage;
  66. BOOL bSuccess;
  67. BOOL bUnloaded;
  68. bSuccess = FALSE;
  69. ASSERT( m_strName.GetLength() > 0 );
  70. //
  71. // ImageLoad doesn't know about const pointers so
  72. // we have to GetBuffer here :-(
  73. //
  74. szDriverName = m_strName.GetBuffer( m_strName.GetLength() + 1 );
  75. if( NULL == szDriverName )
  76. {
  77. goto Done;
  78. }
  79. szDriversDir = g_strDriversDir.GetBuffer( g_strDriversDir.GetLength() + 1 );
  80. if( NULL == szDriversDir )
  81. {
  82. m_strName.ReleaseBuffer();
  83. goto Done;
  84. }
  85. //
  86. // Load the image
  87. //
  88. pLoadedImage = VrfImageLoad( szDriverName,
  89. szDriversDir );
  90. if( NULL == pLoadedImage )
  91. {
  92. //
  93. // Could not load the image from %windir%\system32\drivers
  94. // Try again from the PATH
  95. //
  96. pLoadedImage = VrfImageLoad( szDriverName,
  97. NULL );
  98. }
  99. //
  100. // Give our string buffers back to MFC
  101. //
  102. m_strName.ReleaseBuffer();
  103. g_strDriversDir.ReleaseBuffer();
  104. if( NULL == pLoadedImage )
  105. {
  106. //
  107. // We couldn't load this image - bad luck
  108. //
  109. TRACE( _T( "ImageLoad failed for %s, error %u\n" ),
  110. (LPCTSTR) m_strName,
  111. GetLastError() );
  112. goto Done;
  113. }
  114. //
  115. // Keep the OS and image version information (4 means NT 4 etc.)
  116. //
  117. m_wMajorOperatingSystemVersion =
  118. pLoadedImage->FileHeader->OptionalHeader.MajorOperatingSystemVersion;
  119. m_wMajorImageVersion =
  120. pLoadedImage->FileHeader->OptionalHeader.MajorImageVersion;
  121. //
  122. // Check if the current driver is a miniport
  123. //
  124. VrfIsDriverMiniport( pLoadedImage,
  125. m_strMiniportName );
  126. //
  127. // Clean-up
  128. //
  129. bUnloaded = ImageUnload( pLoadedImage );
  130. //
  131. // If ImageUnload fails we cannot do much about it...
  132. //
  133. ASSERT( bUnloaded );
  134. bSuccess = TRUE;
  135. Done:
  136. return bSuccess;
  137. }
  138. //////////////////////////////////////////////////////////////////////
  139. BOOL CDriverData::LoadDriverVersionData()
  140. {
  141. BOOL bResult;
  142. PVOID pWholeVerBlock;
  143. PVOID pTranslationInfoBuffer;
  144. LPCTSTR szVariableValue;
  145. LPTSTR szDriverPath;
  146. DWORD dwWholeBlockSize;
  147. DWORD dwDummyHandle;
  148. UINT uInfoLengthInTChars;
  149. TCHAR szLocale[ 32 ];
  150. TCHAR szBlockName[ 64 ];
  151. CString strDriverPath;
  152. bResult = FALSE;
  153. //
  154. // Get the size of the file info block
  155. //
  156. // GetFileVersionInfoSize doesn't know about
  157. // const pointers so we need to GetBuffer here :-(
  158. //
  159. strDriverPath = g_strDriversDir + '\\' + m_strName;
  160. szDriverPath = strDriverPath.GetBuffer( strDriverPath.GetLength() + 1 );
  161. if( NULL == szDriverPath )
  162. {
  163. goto InitializeWithDefaults;
  164. }
  165. dwWholeBlockSize = GetFileVersionInfoSize(
  166. szDriverPath,
  167. &dwDummyHandle );
  168. strDriverPath.ReleaseBuffer();
  169. if( dwWholeBlockSize == 0 )
  170. {
  171. //
  172. // Couldn't find the binary in %windir%\system32\drivers
  173. // Try %windir%\system32 too
  174. //
  175. strDriverPath = g_strSystemDir + '\\' + m_strName;
  176. szDriverPath = strDriverPath.GetBuffer( strDriverPath.GetLength() + 1 );
  177. if( NULL == szDriverPath )
  178. {
  179. goto InitializeWithDefaults;
  180. }
  181. dwWholeBlockSize = GetFileVersionInfoSize(
  182. szDriverPath,
  183. &dwDummyHandle );
  184. strDriverPath.ReleaseBuffer();
  185. if( dwWholeBlockSize == 0 )
  186. {
  187. //
  188. // Couldn't read version information
  189. //
  190. goto InitializeWithDefaults;
  191. }
  192. }
  193. //
  194. // Allocate the buffer for the version information
  195. //
  196. pWholeVerBlock = malloc( dwWholeBlockSize );
  197. if( pWholeVerBlock == NULL )
  198. {
  199. goto InitializeWithDefaults;
  200. }
  201. //
  202. // Get the version information
  203. //
  204. // GetFileVersionInfo doesn't know about
  205. // const pointers so we need to GetBuffer here :-(
  206. //
  207. szDriverPath = strDriverPath.GetBuffer( strDriverPath.GetLength() + 1 );
  208. if( NULL == szDriverPath )
  209. {
  210. free( pWholeVerBlock );
  211. goto InitializeWithDefaults;
  212. }
  213. bResult = GetFileVersionInfo(
  214. szDriverPath,
  215. dwDummyHandle,
  216. dwWholeBlockSize,
  217. pWholeVerBlock );
  218. strDriverPath.ReleaseBuffer();
  219. if( bResult != TRUE )
  220. {
  221. free( pWholeVerBlock );
  222. goto InitializeWithDefaults;
  223. }
  224. //
  225. // Get the locale info
  226. //
  227. bResult = VerQueryValue(
  228. pWholeVerBlock,
  229. _T( "\\VarFileInfo\\Translation" ),
  230. &pTranslationInfoBuffer,
  231. &uInfoLengthInTChars );
  232. if( TRUE != bResult || NULL == pTranslationInfoBuffer )
  233. {
  234. free( pWholeVerBlock );
  235. goto InitializeWithDefaults;
  236. }
  237. //
  238. // Locale info comes back as two little endian words.
  239. // Flip 'em, 'cause we need them big endian for our calls.
  240. //
  241. _stprintf(
  242. szLocale,
  243. _T( "%02X%02X%02X%02X" ),
  244. (ULONG) HIBYTE( LOWORD ( * (LPDWORD) pTranslationInfoBuffer) ),
  245. (ULONG) LOBYTE( LOWORD ( * (LPDWORD) pTranslationInfoBuffer) ),
  246. (ULONG) HIBYTE( HIWORD ( * (LPDWORD) pTranslationInfoBuffer) ),
  247. (ULONG) LOBYTE( HIWORD ( * (LPDWORD) pTranslationInfoBuffer) ) );
  248. //
  249. // Get the file version
  250. //
  251. _stprintf(
  252. szBlockName,
  253. _T( "\\StringFileInfo\\%s\\FileVersion" ),
  254. szLocale );
  255. bResult = VerQueryValue(
  256. pWholeVerBlock,
  257. szBlockName,
  258. (PVOID*) &szVariableValue,
  259. &uInfoLengthInTChars );
  260. if( TRUE != bResult || 0 == uInfoLengthInTChars )
  261. {
  262. //
  263. // Couldn't find the version
  264. //
  265. VERIFY( m_strFileVersion.LoadString( IDS_UNKNOWN ) );
  266. }
  267. else
  268. {
  269. //
  270. // Found the version
  271. //
  272. m_strFileVersion = szVariableValue;
  273. }
  274. //
  275. // Get the company name
  276. //
  277. _stprintf(
  278. szBlockName,
  279. _T( "\\StringFileInfo\\%s\\CompanyName" ),
  280. szLocale );
  281. bResult = VerQueryValue(
  282. pWholeVerBlock,
  283. szBlockName,
  284. (PVOID*) &szVariableValue,
  285. &uInfoLengthInTChars );
  286. if( TRUE != bResult || uInfoLengthInTChars == 0 )
  287. {
  288. //
  289. // Coudln't find the company name
  290. //
  291. m_strCompanyName.LoadString( IDS_UNKNOWN );
  292. }
  293. else
  294. {
  295. m_strCompanyName = szVariableValue;
  296. }
  297. //
  298. // Get the FileDescription
  299. //
  300. _stprintf(
  301. szBlockName,
  302. _T( "\\StringFileInfo\\%s\\FileDescription" ),
  303. szLocale );
  304. bResult = VerQueryValue(
  305. pWholeVerBlock,
  306. szBlockName,
  307. (PVOID*) &szVariableValue,
  308. &uInfoLengthInTChars );
  309. if( TRUE != bResult || uInfoLengthInTChars == 0 )
  310. {
  311. //
  312. // Coudln't find the FileDescription
  313. //
  314. m_strFileDescription.LoadString( IDS_UNKNOWN );
  315. }
  316. else
  317. {
  318. m_strFileDescription = szVariableValue;
  319. }
  320. //
  321. // clean-up
  322. //
  323. free( pWholeVerBlock );
  324. goto Done;
  325. InitializeWithDefaults:
  326. m_strCompanyName.LoadString( IDS_UNKNOWN );
  327. m_strFileVersion.LoadString( IDS_UNKNOWN );
  328. m_strFileDescription.LoadString( IDS_UNKNOWN );
  329. Done:
  330. //
  331. // We always return TRUE from this function because
  332. // the app will work fine without the version info -
  333. // it's just something that we would like to be able to display
  334. //
  335. return TRUE;
  336. }
  337. //////////////////////////////////////////////////////////////////////
  338. BOOL CDriverData::LoadDriverImageData()
  339. {
  340. BOOL bResult1;
  341. BOOL bResult2;
  342. bResult1 = LoadDriverHeaderData();
  343. bResult2 = LoadDriverVersionData();
  344. return ( bResult1 && bResult2 );
  345. }
  346. //////////////////////////////////////////////////////////////////////
  347. void CDriverData::AssertValid() const
  348. {
  349. ASSERT( SignedNotVerifiedYet == m_SignedStatus ||
  350. SignedYes == m_SignedStatus ||
  351. SignedNo == m_SignedStatus );
  352. ASSERT( VerifyDriverNo == m_VerifyDriverStatus ||
  353. VerifyDriverYes == m_VerifyDriverStatus );
  354. CObject::AssertValid();
  355. }
  356. //////////////////////////////////////////////////////////////////////
  357. // CDriverDataArray Class
  358. //////////////////////////////////////////////////////////////////////
  359. CDriverDataArray::~CDriverDataArray()
  360. {
  361. DeleteAll();
  362. }
  363. //////////////////////////////////////////////////////////////////////
  364. VOID CDriverDataArray::DeleteAll()
  365. {
  366. INT_PTR nArraySize;
  367. CDriverData *pCrtDriverData;
  368. nArraySize = GetSize();
  369. while( nArraySize > 0 )
  370. {
  371. nArraySize -= 1;
  372. pCrtDriverData = GetAt( nArraySize );
  373. ASSERT_VALID( pCrtDriverData );
  374. delete pCrtDriverData;
  375. }
  376. RemoveAll();
  377. }
  378. //////////////////////////////////////////////////////////////////////
  379. CDriverData *CDriverDataArray::GetAt( INT_PTR nIndex ) const
  380. {
  381. return (CDriverData *)CObArray::GetAt( nIndex );
  382. }
  383. //////////////////////////////////////////////////////////////////////
  384. CDriverDataArray &CDriverDataArray::operator = (const CDriverDataArray &DriversDataArray)
  385. {
  386. INT_PTR nNewArraySize;
  387. INT_PTR nCrtElement;
  388. CDriverData *pCopiedDriverData;
  389. CDriverData *pNewDriverData;
  390. DeleteAll();
  391. nNewArraySize = DriversDataArray.GetSize();
  392. for( nCrtElement = 0; nCrtElement < nNewArraySize; nCrtElement += 1 )
  393. {
  394. pCopiedDriverData = DriversDataArray.GetAt( nCrtElement );
  395. ASSERT_VALID( pCopiedDriverData );
  396. pNewDriverData = new CDriverData( *pCopiedDriverData );
  397. if( NULL != pNewDriverData )
  398. {
  399. ASSERT_VALID( pNewDriverData );
  400. Add( pNewDriverData );
  401. }
  402. else
  403. {
  404. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  405. goto Done;
  406. }
  407. }
  408. Done:
  409. //
  410. // All done, assert that our data is consistent
  411. //
  412. ASSERT_VALID( this );
  413. return *this;
  414. }
  415. //////////////////////////////////////////////////////////////////////
  416. // CDriversSet Class
  417. //////////////////////////////////////////////////////////////////////
  418. //////////////////////////////////////////////////////////////////////
  419. // Construction/Destruction
  420. //////////////////////////////////////////////////////////////////////
  421. CDriversSet::CDriversSet()
  422. {
  423. m_DriverSetType = DriversSetNotSigned;
  424. m_bDriverDataInitialized = FALSE;
  425. m_bUnsignedDriverDataInitialized = FALSE;
  426. }
  427. CDriversSet::~CDriversSet()
  428. {
  429. }
  430. //////////////////////////////////////////////////////////////////////
  431. BOOL CDriversSet::FindUnsignedDrivers( HANDLE hAbortEvent,
  432. CVrfProgressCtrl &ProgressCtl)
  433. {
  434. INT_PTR nAllDriverNames;
  435. INT_PTR nCrtDriverName;
  436. DWORD dwWaitResult;
  437. BOOL bSigned;
  438. BOOL bChangedCurrentDirectory;
  439. CDriverData *pDriverData;
  440. ProgressCtl.SetRange32(0, 100);
  441. ProgressCtl.SetStep( 1 );
  442. ProgressCtl.SetPos( 0 );
  443. bChangedCurrentDirectory = FALSE;
  444. if( TRUE != m_bUnsignedDriverDataInitialized )
  445. {
  446. ASSERT( TRUE == m_bDriverDataInitialized );
  447. //
  448. // We are going to check all drivers' signature
  449. // so change directory to %windir%\system32\drivers first
  450. //
  451. bChangedCurrentDirectory = SetCurrentDirectory( g_strDriversDir );
  452. if( TRUE != bChangedCurrentDirectory )
  453. {
  454. VrfErrorResourceFormat( IDS_CANNOT_SET_CURRENT_DIRECTORY,
  455. (LPCTSTR) g_strDriversDir );
  456. }
  457. //
  458. // The unsigned drivers data is not initialized yet.
  459. // Try to initialize it now.
  460. //
  461. nAllDriverNames = m_aDriverData.GetSize();
  462. ProgressCtl.SetRange32(0, nAllDriverNames );
  463. for( nCrtDriverName = 0; nCrtDriverName < nAllDriverNames; nCrtDriverName+=1 )
  464. {
  465. if( NULL != hAbortEvent )
  466. {
  467. //
  468. // Check if the thread has to die
  469. //
  470. dwWaitResult = WaitForSingleObject( hAbortEvent,
  471. 0 );
  472. if( WAIT_OBJECT_0 == dwWaitResult )
  473. {
  474. //
  475. // We have to die...
  476. //
  477. TRACE( _T( "CDriversSet::FindUnsignedDrivers : aborting at driver %d of %d\n" ),
  478. nCrtDriverName,
  479. nAllDriverNames );
  480. goto Done;
  481. }
  482. }
  483. pDriverData = m_aDriverData.GetAt( nCrtDriverName );
  484. ASSERT_VALID( pDriverData );
  485. //
  486. // If we already checked the signature of this driver before
  487. // don't spend any more time on it - use the cached data
  488. //
  489. if( CDriverData::SignedNotVerifiedYet == pDriverData->m_SignedStatus )
  490. {
  491. bSigned = IsDriverSigned( pDriverData->m_strName );
  492. if( TRUE != bSigned )
  493. {
  494. //
  495. // This driver is not signed
  496. //
  497. pDriverData->m_SignedStatus = CDriverData::SignedNo;
  498. }
  499. else
  500. {
  501. //
  502. // This driver is signed
  503. //
  504. pDriverData->m_SignedStatus = CDriverData::SignedYes;
  505. }
  506. }
  507. ProgressCtl.StepIt();
  508. }
  509. m_bUnsignedDriverDataInitialized = TRUE;
  510. }
  511. Done:
  512. if( TRUE == bChangedCurrentDirectory )
  513. {
  514. SetCurrentDirectory( g_strInitialCurrentDirectory );
  515. }
  516. return m_bUnsignedDriverDataInitialized;
  517. }
  518. //////////////////////////////////////////////////////////////////////
  519. BOOL CDriversSet::LoadAllDriversData( HANDLE hAbortEvent,
  520. CVrfProgressCtrl &ProgressCtl )
  521. {
  522. ULONG uBufferSize;
  523. ULONG uCrtModule;
  524. PVOID pBuffer;
  525. INT nCrtModuleNameLength;
  526. INT nBackSlashIndex;
  527. INT_PTR nDrvDataIndex;
  528. NTSTATUS Status;
  529. LPTSTR szCrtModuleName;
  530. DWORD dwWaitResult;
  531. CString strCrModuleName;
  532. CDriverData *pDriverData;
  533. PRTL_PROCESS_MODULES Modules;
  534. ProgressCtl.SetPos( 0 );
  535. ProgressCtl.SetRange32( 0, 100 );
  536. ProgressCtl.SetStep( 1 );
  537. m_aDriverData.DeleteAll();
  538. if( TRUE != m_bDriverDataInitialized )
  539. {
  540. for( uBufferSize = 0x10000; TRUE; uBufferSize += 0x1000)
  541. {
  542. //
  543. // Allocate a new buffer
  544. //
  545. pBuffer = new BYTE[ uBufferSize ];
  546. if( NULL == pBuffer )
  547. {
  548. goto Done;
  549. }
  550. //
  551. // Query the kernel
  552. //
  553. Status = NtQuerySystemInformation ( SystemModuleInformation,
  554. pBuffer,
  555. uBufferSize,
  556. NULL);
  557. if( ! NT_SUCCESS( Status ) )
  558. {
  559. delete [] pBuffer;
  560. if (Status == STATUS_INFO_LENGTH_MISMATCH)
  561. {
  562. //
  563. // Try with a bigger buffer
  564. //
  565. continue;
  566. }
  567. else
  568. {
  569. //
  570. // Fatal error - we cannot query
  571. //
  572. VrfErrorResourceFormat( IDS_CANT_GET_ACTIVE_DRVLIST,
  573. Status );
  574. goto Done;
  575. }
  576. }
  577. else
  578. {
  579. //
  580. // Got all the information we needed
  581. //
  582. break;
  583. }
  584. }
  585. Modules = (PRTL_PROCESS_MODULES)pBuffer;
  586. ProgressCtl.SetRange32(0, Modules->NumberOfModules );
  587. for( uCrtModule = 0; uCrtModule < Modules->NumberOfModules; uCrtModule += 1 )
  588. {
  589. //
  590. // Check if the user wants to abort this long file processing...
  591. //
  592. if( NULL != hAbortEvent )
  593. {
  594. //
  595. // Check if the thread has to die
  596. //
  597. dwWaitResult = WaitForSingleObject( hAbortEvent,
  598. 0 );
  599. if( WAIT_OBJECT_0 == dwWaitResult )
  600. {
  601. //
  602. // We have to die...
  603. //
  604. TRACE( _T( "CDriversSet::LoadAllDriversData : aborting at driver %u of %u\n" ),
  605. uCrtModule,
  606. (ULONG) Modules->NumberOfModules );
  607. delete [] pBuffer;
  608. goto Done;
  609. }
  610. }
  611. if( Modules->Modules[uCrtModule].ImageBase < g_pHighestUserAddress )
  612. {
  613. //
  614. // This is a user-mode module - we don't care about it
  615. //
  616. ProgressCtl.StepIt();
  617. continue;
  618. }
  619. //
  620. // Add this driver to our list
  621. //
  622. nCrtModuleNameLength = strlen( (const char*)&Modules->Modules[uCrtModule].FullPathName[0] );
  623. szCrtModuleName = strCrModuleName.GetBuffer( nCrtModuleNameLength + 1 );
  624. if( NULL == szCrtModuleName )
  625. {
  626. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  627. goto Done;
  628. }
  629. #ifdef UNICODE
  630. MultiByteToWideChar( CP_ACP,
  631. 0,
  632. (const char*)&Modules->Modules[uCrtModule].FullPathName[0],
  633. -1,
  634. szCrtModuleName,
  635. ( nCrtModuleNameLength + 1 ) * sizeof( TCHAR ) );
  636. #else
  637. strcpy( szCrtModuleName,
  638. (const char*)&Modules->Modules[uCrtModule].FullPathName[0] );
  639. #endif
  640. strCrModuleName.ReleaseBuffer();
  641. //
  642. // Keep only the file name, without the path
  643. //
  644. // It turns out that NtQuerySystemInformation ( SystemModuleInformation )
  645. // can return the path in several different formats
  646. //
  647. // E.g.
  648. //
  649. // \winnt\system32\ntoskrnl.exe
  650. // acpi.sys
  651. // \winnt\system32\drivers\battc.sys
  652. // \systemroot\system32\drivers\videoprt.sys
  653. //
  654. nBackSlashIndex = strCrModuleName.ReverseFind( _T( '\\' ) );
  655. if( nBackSlashIndex > 0 )
  656. {
  657. strCrModuleName = strCrModuleName.Right( nCrtModuleNameLength - nBackSlashIndex - 1 );
  658. }
  659. //
  660. // Add a data entry for this driver
  661. //
  662. strCrModuleName.MakeLower();
  663. nDrvDataIndex = AddNewDriverData( strCrModuleName );
  664. //
  665. // Deal with the kernel and HAL differently
  666. //
  667. if( ( uCrtModule == 0 || uCrtModule == 1 ) && nDrvDataIndex >= 0)
  668. {
  669. pDriverData = m_aDriverData.GetAt( nDrvDataIndex );
  670. ASSERT_VALID( pDriverData );
  671. if( 0 == uCrtModule )
  672. {
  673. //
  674. // This is the kernel
  675. //
  676. pDriverData->m_strReservedName = _T( "ntoskrnl.exe" );
  677. }
  678. else
  679. {
  680. //
  681. // This is the kernel
  682. //
  683. pDriverData->m_strReservedName = _T( "hal.dll" );
  684. }
  685. }
  686. ProgressCtl.StepIt();
  687. }
  688. delete [] pBuffer;
  689. m_bDriverDataInitialized = TRUE;
  690. }
  691. Done:
  692. return m_bDriverDataInitialized;
  693. }
  694. //////////////////////////////////////////////////////////////////////
  695. BOOL CDriversSet::ShouldDriverBeVerified( const CDriverData *pDriverData ) const
  696. {
  697. BOOL bResult;
  698. bResult = FALSE;
  699. switch( m_DriverSetType )
  700. {
  701. case DriversSetNotSigned:
  702. bResult = ( CDriverData::SignedNo == pDriverData->m_SignedStatus );
  703. break;
  704. case DriversSetOldOs:
  705. bResult = ( 0 != pDriverData->m_wMajorOperatingSystemVersion && 5 > pDriverData->m_wMajorOperatingSystemVersion ) ||
  706. ( 0 != pDriverData->m_wMajorImageVersion && 5 > pDriverData->m_wMajorImageVersion );
  707. break;
  708. case DriversSetAllDrivers:
  709. bResult = TRUE;
  710. break;
  711. case DriversSetCustom:
  712. bResult = ( CDriverData::VerifyDriverYes == pDriverData->m_VerifyDriverStatus );
  713. break;
  714. default:
  715. //
  716. // Oops, how did we get here?!?
  717. //
  718. ASSERT( FALSE );
  719. }
  720. return bResult;
  721. }
  722. //////////////////////////////////////////////////////////////////////
  723. BOOL CDriversSet::ShouldVerifySomeDrivers( ) const
  724. {
  725. INT_PTR nDrivers;
  726. INT_PTR nCrtDriver;
  727. CDriverData *pDriverData;
  728. BOOL bShouldVerifySome;
  729. bShouldVerifySome = FALSE;
  730. nDrivers = m_aDriverData.GetSize();
  731. for( nCrtDriver = 0; nCrtDriver < nDrivers; nCrtDriver += 1 )
  732. {
  733. pDriverData = m_aDriverData.GetAt( nCrtDriver );
  734. ASSERT_VALID( pDriverData );
  735. if( ShouldDriverBeVerified( pDriverData ) )
  736. {
  737. bShouldVerifySome = TRUE;
  738. break;
  739. }
  740. }
  741. return bShouldVerifySome;
  742. }
  743. //////////////////////////////////////////////////////////////////////
  744. BOOL CDriversSet::GetDriversToVerify( CString &strDriversToVerify )
  745. {
  746. INT_PTR nDriversNo;
  747. INT_PTR nCrtDriver;
  748. CDriverData *pCrtDrvData;
  749. if( DriversSetAllDrivers == m_DriverSetType )
  750. {
  751. //
  752. // Verify all drivers
  753. //
  754. strDriversToVerify = _T( '*' );
  755. }
  756. else
  757. {
  758. //
  759. // Parse all the drivers list and see which ones should be verified
  760. //
  761. strDriversToVerify = _T( "" );
  762. nDriversNo = m_aDriverData.GetSize();
  763. for( nCrtDriver = 0; nCrtDriver < nDriversNo; nCrtDriver += 1 )
  764. {
  765. pCrtDrvData = m_aDriverData.GetAt( nCrtDriver );
  766. ASSERT_VALID( pCrtDrvData );
  767. if( ShouldDriverBeVerified( pCrtDrvData ) )
  768. {
  769. if( pCrtDrvData->m_strReservedName.GetLength() > 0 )
  770. {
  771. //
  772. // Kernel or HAL
  773. //
  774. VrfAddDriverNameNoDuplicates( pCrtDrvData->m_strReservedName,
  775. strDriversToVerify );
  776. }
  777. else
  778. {
  779. //
  780. // Regular driver
  781. //
  782. VrfAddDriverNameNoDuplicates( pCrtDrvData->m_strName,
  783. strDriversToVerify );
  784. }
  785. if( pCrtDrvData->m_strMiniportName.GetLength() > 0 )
  786. {
  787. //
  788. // This is a miniport - auto-enable the corresponding driver
  789. //
  790. TRACE( _T( "Auto-enabling %s\n" ), (LPCTSTR)pCrtDrvData->m_strMiniportName );
  791. VrfAddDriverNameNoDuplicates( pCrtDrvData->m_strMiniportName,
  792. strDriversToVerify );
  793. }
  794. }
  795. }
  796. }
  797. return TRUE;
  798. }
  799. //////////////////////////////////////////////////////////////////////
  800. INT_PTR CDriversSet::AddNewDriverData( LPCTSTR szDriverName )
  801. {
  802. INT_PTR nIndexInArray;
  803. CDriverData *pNewDriverData;
  804. BOOL bSuccess;
  805. ASSERT( IsDriverNameInList( szDriverName ) == FALSE );
  806. nIndexInArray = -1;
  807. pNewDriverData = new CDriverData( szDriverName );
  808. if( NULL != pNewDriverData )
  809. {
  810. pNewDriverData->LoadDriverImageData();
  811. TRY
  812. {
  813. nIndexInArray = m_aDriverData.Add( pNewDriverData );
  814. }
  815. CATCH( CMemoryException, pMemException )
  816. {
  817. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  818. nIndexInArray = -1;
  819. //
  820. // Clean-up the allocation since we cannot add it to our list
  821. //
  822. delete pNewDriverData;
  823. }
  824. END_CATCH
  825. }
  826. return nIndexInArray;
  827. }
  828. //////////////////////////////////////////////////////////////////////
  829. //
  830. // Is this driver name already in our list?
  831. //
  832. BOOL CDriversSet::IsDriverNameInList( LPCTSTR szDriverName )
  833. {
  834. INT_PTR nDrivers;
  835. INT_PTR nCrtDriver;
  836. CDriverData *pCrtDriverData;
  837. BOOL bIsInList;
  838. bIsInList = FALSE;
  839. nDrivers = m_aDriverData.GetSize();
  840. for( nCrtDriver = 0; nCrtDriver < nDrivers; nCrtDriver += 1 )
  841. {
  842. pCrtDriverData = m_aDriverData.GetAt( nCrtDriver );
  843. ASSERT_VALID( pCrtDriverData );
  844. if( pCrtDriverData->m_strName.CompareNoCase( szDriverName ) == 0 )
  845. {
  846. bIsInList = TRUE;
  847. break;
  848. }
  849. }
  850. return bIsInList;
  851. }
  852. //////////////////////////////////////////////////////////////////////
  853. //
  854. // Operators
  855. //
  856. CDriversSet & CDriversSet::operator = (const CDriversSet &DriversSet)
  857. {
  858. m_DriverSetType = DriversSet.m_DriverSetType;
  859. m_aDriverData = DriversSet.m_aDriverData;
  860. m_bDriverDataInitialized = DriversSet.m_bDriverDataInitialized;
  861. m_bUnsignedDriverDataInitialized = DriversSet.m_bUnsignedDriverDataInitialized;
  862. ::CopyStringArray(
  863. DriversSet.m_astrNotInstalledDriversToVerify,
  864. m_astrNotInstalledDriversToVerify );
  865. //
  866. // All done - assert that our data is consistent
  867. //
  868. ASSERT_VALID( this );
  869. return *this;
  870. }
  871. //////////////////////////////////////////////////////////////////////
  872. //
  873. // Overrides
  874. //
  875. void CDriversSet::AssertValid() const
  876. {
  877. ASSERT( DriversSetCustom == m_DriverSetType ||
  878. DriversSetOldOs == m_DriverSetType ||
  879. DriversSetNotSigned == m_DriverSetType ||
  880. DriversSetAllDrivers== m_DriverSetType );
  881. ASSERT( TRUE == m_bDriverDataInitialized ||
  882. FALSE == m_bDriverDataInitialized );
  883. ASSERT( TRUE == m_bUnsignedDriverDataInitialized ||
  884. FALSE == m_bUnsignedDriverDataInitialized );
  885. m_aDriverData.AssertValid();
  886. m_astrNotInstalledDriversToVerify.AssertValid();
  887. CObject::AssertValid();
  888. }
  889. //////////////////////////////////////////////////////////////////////
  890. //////////////////////////////////////////////////////////////////////
  891. //////////////////////////////////////////////////////////////////////
  892. // CSettingsBits Class
  893. //////////////////////////////////////////////////////////////////////
  894. //////////////////////////////////////////////////////////////////////
  895. // Construction/Destruction
  896. //////////////////////////////////////////////////////////////////////
  897. CSettingsBits::CSettingsBits()
  898. {
  899. m_SettingsType = SettingsTypeTypical;
  900. }
  901. CSettingsBits::~CSettingsBits()
  902. {
  903. }
  904. //////////////////////////////////////////////////////////////////////
  905. //
  906. // Operators
  907. //
  908. CSettingsBits & CSettingsBits::operator = (const CSettingsBits &SettingsBits)
  909. {
  910. m_SettingsType = SettingsBits.m_SettingsType;
  911. m_bSpecialPoolEnabled = SettingsBits.m_bSpecialPoolEnabled;
  912. m_bForceIrqlEnabled = SettingsBits.m_bForceIrqlEnabled;
  913. m_bLowResEnabled = SettingsBits.m_bLowResEnabled;
  914. m_bPoolTrackingEnabled = SettingsBits.m_bPoolTrackingEnabled;
  915. m_bIoEnabled = SettingsBits.m_bIoEnabled;
  916. m_bDeadlockDetectEnabled= SettingsBits.m_bDeadlockDetectEnabled;
  917. m_bDMAVerifEnabled = SettingsBits.m_bDMAVerifEnabled;
  918. m_bEnhIoEnabled = SettingsBits.m_bEnhIoEnabled;
  919. //
  920. // All done, assert that our data is consistent
  921. //
  922. ASSERT_VALID( this );
  923. return *this;
  924. }
  925. //////////////////////////////////////////////////////////////////////
  926. //
  927. // Overrides
  928. //
  929. void CSettingsBits::AssertValid() const
  930. {
  931. CObject::AssertValid();
  932. }
  933. //////////////////////////////////////////////////////////////////////
  934. VOID CSettingsBits::SetTypicalOnly()
  935. {
  936. m_SettingsType = SettingsTypeTypical;
  937. m_bSpecialPoolEnabled = TRUE;
  938. m_bForceIrqlEnabled = TRUE;
  939. m_bPoolTrackingEnabled = TRUE;
  940. m_bIoEnabled = TRUE;
  941. m_bDeadlockDetectEnabled= TRUE;
  942. m_bDMAVerifEnabled = TRUE;
  943. //
  944. // Low resource simulation
  945. //
  946. m_bLowResEnabled = FALSE;
  947. //
  948. // Extreme or spurious tests
  949. //
  950. m_bEnhIoEnabled = FALSE;
  951. }
  952. //////////////////////////////////////////////////////////////////////
  953. VOID CSettingsBits::EnableTypicalTests( BOOL bEnable )
  954. {
  955. ASSERT( SettingsTypeTypical == m_SettingsType ||
  956. SettingsTypeCustom == m_SettingsType );
  957. m_bSpecialPoolEnabled = ( FALSE != bEnable );
  958. m_bForceIrqlEnabled = ( FALSE != bEnable );
  959. m_bPoolTrackingEnabled = ( FALSE != bEnable );
  960. m_bIoEnabled = ( FALSE != bEnable );
  961. m_bDeadlockDetectEnabled= ( FALSE != bEnable );
  962. m_bDMAVerifEnabled = ( FALSE != bEnable );
  963. }
  964. //////////////////////////////////////////////////////////////////////
  965. VOID CSettingsBits::EnableExcessiveTests( BOOL bEnable )
  966. {
  967. m_bEnhIoEnabled = ( FALSE != bEnable );
  968. }
  969. //////////////////////////////////////////////////////////////////////
  970. VOID CSettingsBits::EnableLowResTests( BOOL bEnable )
  971. {
  972. m_bLowResEnabled = ( FALSE != bEnable );
  973. }
  974. //////////////////////////////////////////////////////////////////////
  975. BOOL CSettingsBits::GetVerifierFlags( DWORD &dwVerifyFlags )
  976. {
  977. dwVerifyFlags = 0;
  978. if( FALSE != m_bSpecialPoolEnabled )
  979. {
  980. dwVerifyFlags |= DRIVER_VERIFIER_SPECIAL_POOLING;
  981. }
  982. if( FALSE != m_bForceIrqlEnabled )
  983. {
  984. dwVerifyFlags |= DRIVER_VERIFIER_FORCE_IRQL_CHECKING;
  985. }
  986. if( FALSE != m_bLowResEnabled )
  987. {
  988. dwVerifyFlags |= DRIVER_VERIFIER_INJECT_ALLOCATION_FAILURES;
  989. }
  990. if( FALSE != m_bPoolTrackingEnabled )
  991. {
  992. dwVerifyFlags |= DRIVER_VERIFIER_TRACK_POOL_ALLOCATIONS;
  993. }
  994. if( FALSE != m_bIoEnabled )
  995. {
  996. dwVerifyFlags |= DRIVER_VERIFIER_IO_CHECKING;
  997. }
  998. if( FALSE != m_bDeadlockDetectEnabled )
  999. {
  1000. dwVerifyFlags |= DRIVER_VERIFIER_DEADLOCK_DETECTION;
  1001. }
  1002. if( FALSE != m_bDMAVerifEnabled )
  1003. {
  1004. dwVerifyFlags |= DRIVER_VERIFIER_DMA_VERIFIER;
  1005. }
  1006. if( FALSE != m_bEnhIoEnabled )
  1007. {
  1008. dwVerifyFlags |= DRIVER_VERIFIER_ENHANCED_IO_CHECKING;
  1009. }
  1010. return TRUE;
  1011. }
  1012. //////////////////////////////////////////////////////////////////////
  1013. //////////////////////////////////////////////////////////////////////
  1014. //////////////////////////////////////////////////////////////////////
  1015. // CVerifierSettings Class
  1016. //////////////////////////////////////////////////////////////////////
  1017. //////////////////////////////////////////////////////////////////////
  1018. // Construction/Destruction
  1019. //////////////////////////////////////////////////////////////////////
  1020. CVerifierSettings::CVerifierSettings()
  1021. {
  1022. }
  1023. CVerifierSettings::~CVerifierSettings()
  1024. {
  1025. }
  1026. //////////////////////////////////////////////////////////////////////
  1027. CVerifierSettings &CVerifierSettings::operator = (const CVerifierSettings &VerifSettings)
  1028. {
  1029. m_SettingsBits = VerifSettings.m_SettingsBits;
  1030. m_DriversSet = VerifSettings.m_DriversSet;
  1031. m_aDiskData = VerifSettings.m_aDiskData;
  1032. //
  1033. // All done - assert that our data is consistent
  1034. //
  1035. ASSERT_VALID( this );
  1036. return *this;
  1037. }
  1038. //////////////////////////////////////////////////////////////////////
  1039. BOOL CVerifierSettings::SaveToRegistry()
  1040. {
  1041. DWORD dwVerifyFlags;
  1042. DWORD dwPrevFlags;
  1043. BOOL bSuccess;
  1044. CString strDriversToVerify;
  1045. CString strPrevVerifiedDrivers;
  1046. CString strDisksToVerify;
  1047. dwVerifyFlags = 0;
  1048. //
  1049. // Get the list of drivers to verify
  1050. //
  1051. bSuccess = m_DriversSet.GetDriversToVerify( strDriversToVerify ) &&
  1052. m_SettingsBits.GetVerifierFlags( dwVerifyFlags );
  1053. if( FALSE != bSuccess )
  1054. {
  1055. //
  1056. // Have something to write to the registry
  1057. //
  1058. //
  1059. // Try to get the old settings
  1060. //
  1061. dwPrevFlags = 0;
  1062. VrfReadVerifierSettings( strPrevVerifiedDrivers,
  1063. dwPrevFlags );
  1064. if( strDriversToVerify.CompareNoCase( strPrevVerifiedDrivers ) != 0 ||
  1065. dwVerifyFlags != dwPrevFlags )
  1066. {
  1067. bSuccess = VrfWriteVerifierSettings( TRUE,
  1068. strDriversToVerify,
  1069. TRUE,
  1070. dwVerifyFlags );
  1071. }
  1072. }
  1073. if( FALSE != bSuccess )
  1074. {
  1075. bSuccess = m_aDiskData.SaveNewSettings();
  1076. }
  1077. if( FALSE != bSuccess )
  1078. {
  1079. if( FALSE == g_bSettingsSaved )
  1080. {
  1081. VrfMesssageFromResource( IDS_NO_SETTINGS_WERE_CHANGED );
  1082. }
  1083. else
  1084. {
  1085. VrfMesssageFromResource( IDS_REBOOT );
  1086. }
  1087. }
  1088. return bSuccess;
  1089. }
  1090. //////////////////////////////////////////////////////////////////////
  1091. //
  1092. // Overrides
  1093. //
  1094. void CVerifierSettings::AssertValid() const
  1095. {
  1096. m_SettingsBits.AssertValid();
  1097. m_DriversSet.AssertValid();
  1098. m_aDiskData.AssertValid();
  1099. CObject::AssertValid();
  1100. }
  1101. //////////////////////////////////////////////////////////////////////
  1102. //////////////////////////////////////////////////////////////////////
  1103. //////////////////////////////////////////////////////////////////////
  1104. //
  1105. // Runtime data - queried from the kernel
  1106. //
  1107. //////////////////////////////////////////////////////////////////////
  1108. //////////////////////////////////////////////////////////////////////
  1109. //////////////////////////////////////////////////////////////////////
  1110. //////////////////////////////////////////////////////////////////////
  1111. //
  1112. // class CRuntimeDriverData
  1113. //
  1114. CRuntimeDriverData::CRuntimeDriverData()
  1115. {
  1116. Loads = 0;
  1117. Unloads = 0;
  1118. CurrentPagedPoolAllocations = 0;
  1119. CurrentNonPagedPoolAllocations = 0;
  1120. PeakPagedPoolAllocations = 0;
  1121. PeakNonPagedPoolAllocations = 0;
  1122. PagedPoolUsageInBytes = 0;
  1123. NonPagedPoolUsageInBytes = 0;
  1124. PeakPagedPoolUsageInBytes = 0;
  1125. PeakNonPagedPoolUsageInBytes = 0;
  1126. }
  1127. //////////////////////////////////////////////////////////////////////
  1128. //
  1129. // class CRuntimeDriverDataArray
  1130. //
  1131. CRuntimeDriverDataArray::~CRuntimeDriverDataArray()
  1132. {
  1133. DeleteAll();
  1134. }
  1135. //////////////////////////////////////////////////////////////////////
  1136. CRuntimeDriverData *CRuntimeDriverDataArray::GetAt( INT_PTR nIndex )
  1137. {
  1138. CRuntimeDriverData *pRetVal = (CRuntimeDriverData *)CObArray::GetAt( nIndex );
  1139. ASSERT_VALID( pRetVal );
  1140. return pRetVal;
  1141. }
  1142. //////////////////////////////////////////////////////////////////////
  1143. VOID CRuntimeDriverDataArray::DeleteAll()
  1144. {
  1145. INT_PTR nArraySize;
  1146. CRuntimeDriverData *pCrtDriverData;
  1147. nArraySize = GetSize();
  1148. while( nArraySize > 0 )
  1149. {
  1150. nArraySize -= 1;
  1151. pCrtDriverData = GetAt( nArraySize );
  1152. ASSERT_VALID( pCrtDriverData );
  1153. delete pCrtDriverData;
  1154. }
  1155. RemoveAll();
  1156. }
  1157. //////////////////////////////////////////////////////////////////////
  1158. //////////////////////////////////////////////////////////////////////
  1159. //
  1160. // class CRuntimeVerifierData
  1161. //
  1162. CRuntimeVerifierData::CRuntimeVerifierData()
  1163. {
  1164. FillWithDefaults();
  1165. }
  1166. //////////////////////////////////////////////////////////////////////
  1167. VOID CRuntimeVerifierData::FillWithDefaults()
  1168. {
  1169. m_bSpecialPool = FALSE;
  1170. m_bPoolTracking = FALSE;
  1171. m_bForceIrql = FALSE;
  1172. m_bIo = FALSE;
  1173. m_bEnhIo = FALSE;
  1174. m_bDeadlockDetect = FALSE;
  1175. m_bDMAVerif = FALSE;
  1176. m_bLowRes = FALSE;
  1177. RaiseIrqls = 0;
  1178. AcquireSpinLocks = 0;
  1179. SynchronizeExecutions = 0;
  1180. AllocationsAttempted = 0;
  1181. AllocationsSucceeded = 0;
  1182. AllocationsSucceededSpecialPool = 0;
  1183. AllocationsWithNoTag;
  1184. Trims = 0;
  1185. AllocationsFailed = 0;
  1186. AllocationsFailedDeliberately = 0;
  1187. UnTrackedPool = 0;
  1188. Level = 0;
  1189. m_RuntimeDriverDataArray.DeleteAll();
  1190. }
  1191. //////////////////////////////////////////////////////////////////////
  1192. BOOL CRuntimeVerifierData::IsDriverVerified( LPCTSTR szDriveName )
  1193. {
  1194. CRuntimeDriverData *pCrtDriverData;
  1195. INT_PTR nDrivers;
  1196. BOOL bFound;
  1197. bFound = FALSE;
  1198. nDrivers = m_RuntimeDriverDataArray.GetSize();
  1199. while( nDrivers > 0 )
  1200. {
  1201. nDrivers -= 1;
  1202. pCrtDriverData = m_RuntimeDriverDataArray.GetAt( nDrivers );
  1203. ASSERT_VALID( pCrtDriverData );
  1204. if( 0 == pCrtDriverData->m_strName.CompareNoCase( szDriveName ) )
  1205. {
  1206. bFound = TRUE;
  1207. break;
  1208. }
  1209. }
  1210. return bFound;
  1211. }
  1212. //////////////////////////////////////////////////////////////////////
  1213. // CDiskData Class
  1214. //////////////////////////////////////////////////////////////////////
  1215. CDiskData::CDiskData( LPCTSTR szVerifierEnabled,
  1216. LPCTSTR szDiskDevicesForDisplay,
  1217. LPCTSTR szDiskDevicesPDOName )
  1218. {
  1219. m_bVerifierEnabled = ( 0 != _ttoi( szVerifierEnabled ) );
  1220. m_strDiskDevicesForDisplay = szDiskDevicesForDisplay;
  1221. m_strDiskDevicesPDOName = szDiskDevicesPDOName;
  1222. }
  1223. CDiskData::CDiskData( const CDiskData &DiskData )
  1224. {
  1225. m_bVerifierEnabled = DiskData.m_bVerifierEnabled;
  1226. m_strDiskDevicesForDisplay = DiskData.m_strDiskDevicesForDisplay;
  1227. m_strDiskDevicesPDOName = DiskData.m_strDiskDevicesPDOName;
  1228. }
  1229. CDiskData::~CDiskData()
  1230. {
  1231. }
  1232. //////////////////////////////////////////////////////////////////////
  1233. void CDiskData::AssertValid() const
  1234. {
  1235. ASSERT( m_bVerifierEnabled == FALSE || m_bVerifierEnabled == TRUE );
  1236. ASSERT( m_strDiskDevicesForDisplay.GetLength() > 0 );
  1237. ASSERT( m_strDiskDevicesPDOName.GetLength() > 0 );
  1238. CObject::AssertValid();
  1239. }
  1240. //////////////////////////////////////////////////////////////////////
  1241. // CDiskDataArray Class
  1242. //////////////////////////////////////////////////////////////////////
  1243. CDiskDataArray::CDiskDataArray()
  1244. {
  1245. }
  1246. CDiskDataArray::~CDiskDataArray()
  1247. {
  1248. DeleteAll();
  1249. }
  1250. //////////////////////////////////////////////////////////////////////
  1251. VOID CDiskDataArray::DeleteAll()
  1252. {
  1253. INT_PTR nArraySize;
  1254. CDiskData *pCrtDiskData;
  1255. nArraySize = GetSize();
  1256. while( nArraySize > 0 )
  1257. {
  1258. nArraySize -= 1;
  1259. pCrtDiskData = GetAt( nArraySize );
  1260. ASSERT_VALID( pCrtDiskData );
  1261. delete pCrtDiskData;
  1262. }
  1263. RemoveAll();
  1264. }
  1265. //////////////////////////////////////////////////////////////////////
  1266. CDiskData *CDiskDataArray::GetAt( INT_PTR nIndex ) const
  1267. {
  1268. return (CDiskData *)CObArray::GetAt( nIndex );
  1269. }
  1270. //////////////////////////////////////////////////////////////////////
  1271. CDiskDataArray &CDiskDataArray::operator = (const CDiskDataArray &DiskDataArray)
  1272. {
  1273. INT_PTR nNewArraySize;
  1274. INT_PTR nCrtElement;
  1275. CDiskData *pCopiedDiskData;
  1276. CDiskData *pNewDiskData;
  1277. DeleteAll();
  1278. nNewArraySize = DiskDataArray.GetSize();
  1279. for( nCrtElement = 0; nCrtElement < nNewArraySize; nCrtElement += 1 )
  1280. {
  1281. pCopiedDiskData = DiskDataArray.GetAt( nCrtElement );
  1282. ASSERT_VALID( pCopiedDiskData );
  1283. pNewDiskData = new CDiskData( *pCopiedDiskData );
  1284. if( NULL != pNewDiskData )
  1285. {
  1286. ASSERT_VALID( pNewDiskData );
  1287. Add( pNewDiskData );
  1288. }
  1289. else
  1290. {
  1291. VrfErrorResourceFormat( IDS_NOT_ENOUGH_MEMORY );
  1292. goto Done;
  1293. }
  1294. }
  1295. Done:
  1296. //
  1297. // All done, assert that our data is consistent
  1298. //
  1299. ASSERT_VALID( this );
  1300. return *this;
  1301. }
  1302. //////////////////////////////////////////////////////////////////////
  1303. BOOL CDiskDataArray::InitializeDiskList()
  1304. {
  1305. BOOLEAN bSuccess;
  1306. INT nCrtLength;
  1307. CDiskData *pNewDiskData;
  1308. LPTSTR DiskDevicesForDisplay = NULL;
  1309. LPTSTR DiskDevicesPDOName = NULL;
  1310. LPTSTR VerifierEnabled = NULL;
  1311. LPTSTR DiskDevicesForDisplayCrt;
  1312. LPTSTR DiskDevicesPDONameCrt;
  1313. LPTSTR VerifierEnabledCrt;
  1314. DeleteAll();
  1315. bSuccess = DiskEnumerate( g_szFilter,
  1316. &DiskDevicesForDisplay,
  1317. &DiskDevicesPDOName,
  1318. &VerifierEnabled );
  1319. if( FALSE != bSuccess )
  1320. {
  1321. DiskDevicesForDisplayCrt = DiskDevicesForDisplay;
  1322. DiskDevicesPDONameCrt = DiskDevicesPDOName;
  1323. VerifierEnabledCrt = VerifierEnabled;
  1324. do
  1325. {
  1326. pNewDiskData = new CDiskData( VerifierEnabledCrt,
  1327. DiskDevicesForDisplayCrt,
  1328. DiskDevicesPDONameCrt );
  1329. if( NULL == pNewDiskData )
  1330. {
  1331. bSuccess = FALSE;
  1332. break;
  1333. }
  1334. ASSERT_VALID( pNewDiskData );
  1335. nCrtLength = pNewDiskData->m_strDiskDevicesForDisplay.GetLength();
  1336. if( nCrtLength == 0 )
  1337. {
  1338. delete pNewDiskData;
  1339. break;
  1340. }
  1341. DiskDevicesForDisplayCrt += (nCrtLength + 1);
  1342. nCrtLength = pNewDiskData->m_strDiskDevicesPDOName.GetLength();
  1343. if( nCrtLength == 0 )
  1344. {
  1345. delete pNewDiskData;
  1346. break;
  1347. }
  1348. DiskDevicesPDONameCrt += (nCrtLength + 1);
  1349. VerifierEnabledCrt += ( _tcslen( VerifierEnabledCrt ) + 1 );
  1350. Add( pNewDiskData );
  1351. }
  1352. while( TRUE );
  1353. FreeDiskMultiSz( DiskDevicesForDisplay );
  1354. FreeDiskMultiSz( DiskDevicesPDOName );
  1355. FreeDiskMultiSz( VerifierEnabled );
  1356. }
  1357. return (FALSE != bSuccess);
  1358. }
  1359. //////////////////////////////////////////////////////////////////////
  1360. BOOL CDiskDataArray::VerifyAnyDisk()
  1361. {
  1362. INT_PTR nArraySize;
  1363. CDiskData *pDiskData;
  1364. nArraySize = GetSize();
  1365. while( nArraySize > 0 )
  1366. {
  1367. nArraySize -= 1;
  1368. pDiskData = GetAt( nArraySize );
  1369. ASSERT_VALID( pDiskData );
  1370. if( FALSE != pDiskData->m_bVerifierEnabled )
  1371. {
  1372. return TRUE;
  1373. }
  1374. }
  1375. return FALSE;
  1376. }
  1377. //////////////////////////////////////////////////////////////////////
  1378. BOOL CDiskDataArray::SaveNewSettings()
  1379. {
  1380. BOOL bSuccess;
  1381. INT_PTR nArraySize;
  1382. CDiskData *pNewDiskData;
  1383. CDiskData *pOldDiskData;
  1384. LPTSTR szDiskDevicesPDOName;
  1385. bSuccess = TRUE;
  1386. nArraySize = GetSize();
  1387. while( nArraySize > 0 )
  1388. {
  1389. nArraySize -= 1;
  1390. pNewDiskData = GetAt( nArraySize );
  1391. ASSERT_VALID( pNewDiskData );
  1392. pOldDiskData = g_OldDiskData.GetAt( nArraySize );
  1393. ASSERT_VALID( pOldDiskData );
  1394. if( pNewDiskData->m_bVerifierEnabled != pOldDiskData->m_bVerifierEnabled )
  1395. {
  1396. szDiskDevicesPDOName = pNewDiskData->m_strDiskDevicesPDOName.GetBuffer(
  1397. pNewDiskData->m_strDiskDevicesPDOName.GetLength() + 1 );
  1398. if( NULL == szDiskDevicesPDOName )
  1399. {
  1400. bSuccess = FALSE;
  1401. break;
  1402. }
  1403. if( FALSE != pNewDiskData->m_bVerifierEnabled )
  1404. {
  1405. //
  1406. // Verifier will be enabled for this disk.
  1407. //
  1408. bSuccess = ( AddFilter( g_szFilter,
  1409. szDiskDevicesPDOName) != FALSE);
  1410. }
  1411. else
  1412. {
  1413. //
  1414. // Verifier will be disabled for this disk.
  1415. //
  1416. bSuccess = ( DelFilter( g_szFilter,
  1417. szDiskDevicesPDOName ) != FALSE);
  1418. }
  1419. pNewDiskData->m_strDiskDevicesPDOName.ReleaseBuffer();
  1420. if( FALSE == bSuccess )
  1421. {
  1422. break;
  1423. }
  1424. else
  1425. {
  1426. g_bSettingsSaved = TRUE;
  1427. }
  1428. }
  1429. }
  1430. return bSuccess;
  1431. }
  1432. //////////////////////////////////////////////////////////////////////
  1433. VOID CDiskDataArray::SetVerifyAllDisks( BOOL bEnabled )
  1434. {
  1435. INT_PTR nArraySize;
  1436. CDiskData *pDiskData;
  1437. nArraySize = GetSize();
  1438. while( nArraySize > 0 )
  1439. {
  1440. nArraySize -= 1;
  1441. pDiskData = GetAt( nArraySize );
  1442. ASSERT_VALID( pDiskData );
  1443. pDiskData->m_bVerifierEnabled = bEnabled;
  1444. }
  1445. }