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.

2718 lines
72 KiB

  1. // *********************************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // Module Name:
  6. //
  7. // DriverQuery.cpp
  8. //
  9. // Abstract:
  10. //
  11. // This modules Queries the information of the various drivers present in the
  12. // system .
  13. //
  14. // Syntax:
  15. // ------
  16. // DriverQuery [-s server ] [-u [domain\]username [-p password]]
  17. // [-fo format ] [-n|noheader ] [-v]
  18. //
  19. // Author:
  20. //
  21. // J.S.Vasu ([email protected])
  22. //
  23. // Revision History:
  24. //
  25. // Created on 31-0ct-2000 by J.S.Vasu
  26. // Modified on 9-Dec-2000 by Santhosh Brahmappa Added a new function IsWin64()
  27. //
  28. //
  29. // *********************************************************************************
  30. //
  31. #include "pch.h"
  32. #include "Resource.h"
  33. #include "DriverQuery.h"
  34. #include "LOCALE.H"
  35. #include "shlwapi.h"
  36. #ifndef _WIN64
  37. BOOL IsWin64(void);
  38. #define countof(x) (sizeof(x) / sizeof((x)[0]))
  39. #endif
  40. // function prototypes
  41. LCID GetSupportedUserLocale( BOOL& bLocaleChanged );
  42. // ***************************************************************************
  43. // Routine Description:
  44. // This the entry point to this utility.
  45. //
  46. // Arguments:
  47. // [ in ] argc : argument(s) count specified at the command prompt
  48. // [ in ] argv : argument(s) specified at the command prompt
  49. //
  50. // Return Value:
  51. // 0 : If the utility successfully displayed the driver information.
  52. // 1 : If the utility completely failed to display the driver information
  53. //
  54. // ***************************************************************************
  55. DWORD _cdecl _tmain(DWORD argc,LPCTSTR argv[])
  56. {
  57. BOOL bResult = FALSE ;
  58. BOOL bNeedPassword = FALSE ;
  59. BOOL bUsage = FALSE ;
  60. BOOL bHeader= FALSE ;
  61. LPTSTR szUserName = NULL ;
  62. LPTSTR szPassword = NULL ;
  63. LPTSTR szServer = NULL ;
  64. LPTSTR szTmpUserName = NULL ;
  65. LPTSTR szTmpPassword = NULL ;
  66. LPTSTR szTmpServer = NULL ;
  67. __MAX_SIZE_STRING szFormat = NULL_STRING ;
  68. DWORD dwSystemType = 0;
  69. HRESULT hQueryResult = S_OK ;
  70. DWORD dwExitCode = 0;
  71. DWORD dwErrCode = 0;
  72. BOOL bLocalFlag = TRUE ;
  73. BOOL bLocalSystem = TRUE;
  74. BOOL bVerbose = FALSE ;
  75. BOOL bComInitFlag = FALSE ;
  76. IWbemLocator* pIWbemLocator = NULL ;
  77. IWbemServices* pIWbemServReg = NULL ;
  78. LPCTSTR szToken = NULL ;
  79. COAUTHIDENTITY *pAuthIdentity = NULL;
  80. BOOL bFlag = FALSE ;
  81. BOOL bSigned = FALSE ;
  82. _tsetlocale( LC_ALL, _T(""));
  83. szServer = (LPTSTR) malloc ((MAX_STRING_LENGTH) * sizeof(TCHAR));
  84. szUserName = (LPTSTR) malloc ((MAX_STRING_LENGTH) * sizeof(TCHAR));
  85. szPassword = (LPTSTR) malloc ((MAX_STRING_LENGTH) * sizeof(TCHAR));
  86. szTmpUserName = szUserName ;
  87. szTmpPassword = szPassword ;
  88. szTmpServer = szServer ;
  89. if ((szServer == NULL)||(szUserName == NULL)||(szPassword == NULL))
  90. {
  91. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  92. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  93. ShowLastError(stderr);
  94. dwExitCode = 1;
  95. SAFEFREE(szTmpServer);
  96. SAFEFREE(szTmpUserName);
  97. SAFEFREE(szTmpPassword);
  98. ReleaseGlobals();
  99. return(dwExitCode);
  100. }
  101. memset(szServer,0,MAX_STRING_LENGTH*sizeof(TCHAR));
  102. memset(szUserName,0,MAX_STRING_LENGTH*sizeof(TCHAR));
  103. memset(szPassword,0,MAX_STRING_LENGTH*sizeof(TCHAR));
  104. bResult = ProcessOptions(argc,argv,&bUsage,&szServer,&szUserName,&szPassword,szFormat,
  105. &bHeader,&bNeedPassword,&bVerbose,&bSigned);
  106. if(bResult == FALSE)
  107. {
  108. ShowMessage(stderr,GetReason());
  109. dwExitCode = 1;
  110. SAFEFREE(szTmpServer);
  111. SAFEFREE(szTmpUserName);
  112. SAFEFREE(szTmpPassword);
  113. ReleaseGlobals();
  114. return(dwExitCode);
  115. }
  116. // check if the help option has been specified.
  117. if(bUsage==TRUE)
  118. {
  119. ShowUsage() ;
  120. ReleaseGlobals();
  121. SAFEFREE(szTmpServer);
  122. SAFEFREE(szTmpUserName);
  123. SAFEFREE(szTmpPassword);
  124. return(dwExitCode);
  125. }
  126. if( ( IsLocalSystem( szServer ) == TRUE )&&(lstrlen(szUserName)!=0) )
  127. {
  128. DISPLAY_MESSAGE(stdout,GetResString(IDS_IGNORE_LOCAL_CRED));
  129. }
  130. bComInitFlag = InitialiseCom(&pIWbemLocator);
  131. if(bComInitFlag == FALSE )
  132. {
  133. dwExitCode = 1;
  134. CloseConnection(szServer);
  135. ReleaseGlobals();
  136. SAFEFREE(szTmpServer);
  137. SAFEFREE(szTmpUserName);
  138. SAFEFREE(szTmpPassword);
  139. return(dwExitCode);
  140. }
  141. CHString strUserName = NULL_STRING;
  142. CHString strPassword = NULL_STRING;
  143. CHString strMachineName = NULL_STRING;
  144. try
  145. {
  146. strUserName = szUserName ;
  147. strPassword = szPassword ;
  148. strMachineName = szServer ;
  149. bFlag = ConnectWmiEx( pIWbemLocator, &pIWbemServReg, strMachineName,
  150. strUserName, strPassword, &pAuthIdentity, bNeedPassword, DEFAULT_NAMESPACE, &bLocalSystem );
  151. //if unable to connect to wmi exit failure
  152. if( bFlag == FALSE )
  153. {
  154. SAFEIRELEASE( pIWbemLocator);
  155. SAFEIRELEASE( pIWbemServReg );
  156. CoUninitialize();
  157. ReleaseGlobals();
  158. SAFEFREE(szTmpServer);
  159. SAFEFREE(szTmpUserName);
  160. SAFEFREE(szTmpPassword);
  161. return( EXIT_FAILURE );
  162. }
  163. szUserName = strUserName.GetBuffer(strUserName.GetLength());
  164. szPassword = strPassword.GetBuffer(strPassword.GetLength()) ;
  165. szServer = strMachineName.GetBuffer(strPassword.GetLength());
  166. }
  167. catch(CHeap_Exception)
  168. {
  169. DISPLAY_MESSAGE( stderr, ERROR_TAG );
  170. SetLastError( E_OUTOFMEMORY );
  171. ShowLastError( stderr );
  172. SAFEIRELEASE( pIWbemLocator);
  173. SAFEIRELEASE( pIWbemServReg );
  174. CoUninitialize();
  175. ReleaseGlobals();
  176. SAFEFREE(szTmpServer);
  177. SAFEFREE(szTmpUserName);
  178. SAFEFREE(szTmpPassword);
  179. return( EXIT_FAILURE );
  180. }
  181. // establish connection to remote system by using win32api function
  182. if ( bLocalSystem == FALSE )
  183. {
  184. LPCWSTR pwszUser = NULL;
  185. LPCWSTR pwszPassword = NULL;
  186. // identify the password to connect to the remote system
  187. if ( pAuthIdentity != NULL )
  188. {
  189. pwszPassword = pAuthIdentity->Password;
  190. if ( strUserName.GetLength() != 0 )
  191. pwszUser = strUserName;
  192. }
  193. DWORD dwConnect = 0 ;
  194. dwConnect = ConnectServer( strMachineName, pwszUser, pwszPassword );
  195. if(dwConnect !=NO_ERROR )
  196. {
  197. dwErrCode = GetLastError();
  198. if(dwErrCode == ERROR_SESSION_CREDENTIAL_CONFLICT)
  199. {
  200. DISPLAY_MESSAGE(stdout,GetResString(IDS_WARNING_TAG));
  201. ShowLastError(stdout);
  202. }
  203. else if( dwConnect == ERROR_EXTENDED_ERROR )
  204. {
  205. DISPLAY_MESSAGE( stderr, ERROR_TAG );
  206. DISPLAY_MESSAGE( stderr, GetReason() );
  207. SAFEIRELEASE( pIWbemLocator );
  208. SAFEIRELEASE( pIWbemServReg );
  209. CoUninitialize();
  210. ReleaseGlobals();
  211. SAFEFREE(szTmpServer);
  212. SAFEFREE(szTmpUserName);
  213. SAFEFREE(szTmpPassword);
  214. return( EXIT_FAILURE );
  215. }
  216. else
  217. {
  218. SetLastError( dwConnect );
  219. DISPLAY_MESSAGE( stderr, ERROR_TAG );
  220. ShowLastError( stderr );
  221. SAFEIRELEASE( pIWbemLocator );
  222. SAFEIRELEASE( pIWbemServReg );
  223. CoUninitialize();
  224. ReleaseGlobals();
  225. SAFEFREE(szTmpServer);
  226. SAFEFREE(szTmpUserName);
  227. SAFEFREE(szTmpPassword);
  228. return( EXIT_FAILURE );
  229. }
  230. }
  231. else
  232. {
  233. bLocalFlag = FALSE ;
  234. }
  235. }
  236. else
  237. {
  238. lstrcpy( szServer, _T( "" ) );
  239. }
  240. hQueryResult = QueryDriverInfo(szServer, szUserName,szPassword,szFormat,bHeader,bVerbose,pIWbemLocator,pAuthIdentity,pIWbemServReg,bSigned);
  241. if(hQueryResult == FAILURE)
  242. {
  243. // close connection to the specified system and exit with failure.
  244. if (bLocalFlag == FALSE )
  245. {
  246. CloseConnection(szServer);
  247. }
  248. dwExitCode = 1;
  249. ReleaseGlobals();
  250. SAFEFREE(szTmpServer);
  251. SAFEFREE(szTmpUserName);
  252. SAFEFREE(szTmpPassword);
  253. return(dwExitCode);
  254. }
  255. // close connection to the specified system and exit
  256. if (bLocalFlag == FALSE )
  257. {
  258. CloseConnection(szServer);
  259. }
  260. SAFEFREE(szTmpServer);
  261. SAFEFREE(szTmpUserName);
  262. SAFEFREE(szTmpPassword);
  263. ReleaseGlobals();
  264. return (dwExitCode);
  265. }
  266. // ***************************************************************************
  267. // Routine Description:
  268. // This function fetches usage information from resource file and displays it
  269. //
  270. // Arguments:
  271. // None
  272. //
  273. // Return Value:
  274. // None
  275. // ***************************************************************************
  276. void ShowUsage()
  277. {
  278. DWORD dwIndex = ID_USAGE_BEGIN;
  279. for(;dwIndex<=ID_USAGE_ENDING; dwIndex++)
  280. {
  281. DISPLAY_MESSAGE(stdout,GetResString( dwIndex ));
  282. }
  283. }
  284. // ***************************************************************************
  285. // Routine Description:
  286. // This function queries the driverinfo of the specified system by connecting to WMI
  287. //
  288. // Arguments:
  289. // [ in ] szServer : server name on which DriverInformation has to be queried.
  290. // [ in ] szUserName : User name for whom DriverInformation has to be queried.
  291. // [ in ] szPassword : Password for the user
  292. // [ in ] szFormat : Format in which the results are to be displayed.
  293. // [ in ] bHeader : Boolean indicating if the header is required.
  294. //
  295. // Return Value:
  296. // SUCCESS : if the function is successful in querying
  297. // FAILURE : if the function is unsuccessful in querying.
  298. // ***************************************************************************
  299. DWORD QueryDriverInfo(LPTSTR szServer,LPTSTR szUserName,LPTSTR szPassword,LPTSTR szFormat,BOOL bHeader,BOOL bVerbose,IWbemLocator* pIWbemLocator,COAUTHIDENTITY* pAuthIdentity,IWbemServices* pIWbemServReg,BOOL bSigned )
  300. {
  301. HRESULT hRes = S_OK ;
  302. HRESULT hConnect = S_OK;
  303. _bstr_t bstrUserName ;
  304. _bstr_t bstrPassword ;
  305. _bstr_t bstrNamespace ;
  306. _bstr_t bstrServer ;
  307. try
  308. {
  309. bstrNamespace = CIMV2_NAMESPACE ;
  310. bstrServer = szServer ;
  311. }
  312. catch(...)
  313. {
  314. DISPLAY_MESSAGE( stderr,ERROR_RETREIVE_INFO);
  315. CoUninitialize();
  316. return FAILURE;
  317. }
  318. DWORD dwProcessResult = 0;
  319. DWORD dwSystemType = 0 ;
  320. LPTSTR lpMsgBuf = NULL;
  321. //Create a pointer to IWbemServices,IWbemLocator interfaces
  322. IWbemServices *pIWbemServices = NULL;
  323. IEnumWbemClassObject *pSystemSet = NULL;
  324. HRESULT hISecurity = S_FALSE;
  325. if ( IsLocalSystem( szServer ) == FALSE )
  326. {
  327. try
  328. {
  329. //appending UNC paths to form the complete path.
  330. bstrNamespace = TOKEN_BACKSLASH2 + _bstr_t( szServer ) + TOKEN_BACKSLASH + CIMV2_NAMESPACE;
  331. // if user name is specified then only take user name and password
  332. if ( lstrlen( szUserName ) != 0 )
  333. {
  334. bstrUserName = szUserName;
  335. if (lstrlen(szPassword)==0)
  336. {
  337. bstrPassword = L"";
  338. }
  339. else
  340. {
  341. bstrPassword = szPassword ;
  342. }
  343. }
  344. }
  345. catch(...)
  346. {
  347. DISPLAY_MESSAGE( stderr,ERROR_RETREIVE_INFO);
  348. CoUninitialize();
  349. return FAILURE;
  350. }
  351. }
  352. /* TCHAR szHost[256] = _T("");
  353. _tcscpy(szHost,szServer);
  354. if( IsValidIPAddress( szHost ) == TRUE )
  355. {
  356. //if( GetHostByIPAddr( szHost, szServer, FALSE ) == FALSE )
  357. GetHostByIPAddr( szHost, szServer, FALSE );
  358. //return FAILURE;
  359. } */
  360. dwSystemType = GetSystemType(pAuthIdentity,pIWbemServReg);
  361. if (dwSystemType == ERROR_WMI_VALUES)
  362. {
  363. DISPLAY_MESSAGE( stderr,ERROR_RETREIVE_INFO);
  364. CoUninitialize();
  365. return FAILURE;
  366. }
  367. // Connect to the Root\Cimv2 namespace of the specified system with the current user.
  368. // If no system is specified then connect to the local system.
  369. // To pass the appropriate Username to connectserver
  370. // depending upon whether the user has entered domain\user or only username at the command prompt.
  371. // connect to the server with the credentials supplied.
  372. hConnect = pIWbemLocator->ConnectServer(bstrNamespace,
  373. bstrUserName,
  374. bstrPassword,
  375. 0L,
  376. 0L,
  377. NULL,
  378. NULL,
  379. &pIWbemServices );
  380. if((lstrlen(szUserName)!=0) && FAILED(hConnect) && (hConnect == E_ACCESSDENIED))
  381. {
  382. hConnect = pIWbemLocator->ConnectServer(bstrNamespace,
  383. bstrUserName,
  384. NULL,
  385. 0L,
  386. 0L,
  387. NULL,
  388. NULL,
  389. &pIWbemServices );
  390. }
  391. if(hConnect == WBEM_S_NO_ERROR)
  392. {
  393. // Set the proxy so that impersonation of the client occurs.
  394. hISecurity = SetInterfaceSecurity(pIWbemServices,pAuthIdentity);
  395. if(FAILED(hISecurity))
  396. {
  397. GetWbemErrorText(hISecurity);
  398. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  399. DISPLAY_MESSAGE(stderr,GetReason());
  400. SAFEIRELEASE(pIWbemServices);
  401. CoUninitialize();
  402. return FAILURE ;
  403. }
  404. // Use the IWbemServices pointer to make requests of WMI.
  405. // Create enumeration of Win32_ComputerSystem class
  406. if(bSigned == FALSE)
  407. {
  408. hRes = pIWbemServices->CreateInstanceEnum(_bstr_t(CLASS_SYSTEMDRIVER),
  409. WBEM_FLAG_RETURN_IMMEDIATELY | WBEM_FLAG_FORWARD_ONLY,
  410. NULL,
  411. &pSystemSet);
  412. }
  413. else
  414. {
  415. hRes = pIWbemServices->ExecQuery(_bstr_t(LANGUAGE_WQL),_bstr_t(WQL_QUERY),WBEM_FLAG_RETURN_IMMEDIATELY| WBEM_FLAG_FORWARD_ONLY,NULL,&pSystemSet);
  416. }
  417. //if ( hRes == S_OK)
  418. if ( SUCCEEDED(hRes ))
  419. {
  420. hISecurity = SetInterfaceSecurity(pSystemSet,pAuthIdentity);
  421. if(FAILED(hISecurity))
  422. {
  423. GetWbemErrorText(hISecurity);
  424. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  425. DISPLAY_MESSAGE(stderr,GetReason());
  426. SAFEIRELEASE(pSystemSet);
  427. CoUninitialize();
  428. return FAILURE ;
  429. }
  430. if(bSigned == FALSE)
  431. {
  432. dwProcessResult = ProcessCompSysEnum(szServer,pSystemSet,szFormat,bHeader,dwSystemType,bVerbose);
  433. }
  434. else
  435. {
  436. dwProcessResult = ProcessSignedDriverInfo(szServer,pSystemSet,szFormat,bHeader,dwSystemType,bVerbose);
  437. }
  438. switch(dwProcessResult)
  439. {
  440. case FAILURE:
  441. SAFEIRELEASE(pSystemSet);
  442. SAFEIRELEASE(pIWbemServices);
  443. SAFEIRELEASE(pIWbemLocator);
  444. CoUninitialize();
  445. return FAILURE ;
  446. case EXIT_FAILURE_MALLOC :
  447. SetLastError(ERROR_NOT_ENOUGH_MEMORY);
  448. DISPLAY_MESSAGE( stderr, ERROR_TAG);
  449. ShowLastError(stderr);
  450. SAFEIRELEASE(pSystemSet);
  451. SAFEIRELEASE(pIWbemServices);
  452. SAFEIRELEASE(pIWbemLocator);
  453. CoUninitialize();
  454. return FAILURE ;
  455. case EXIT_FAILURE_FORMAT:
  456. DISPLAY_MESSAGE(stderr, ERROR_ENUMERATE_INSTANCE);
  457. SAFEIRELEASE(pSystemSet);
  458. SAFEIRELEASE(pIWbemServices);
  459. SAFEIRELEASE(pIWbemLocator);
  460. CoUninitialize();
  461. return FAILURE ;
  462. case EXIT_SUCCESSFUL:
  463. SAFEIRELEASE(pSystemSet);
  464. SAFEIRELEASE(pIWbemServices);
  465. SAFEIRELEASE(pIWbemLocator);
  466. CoUninitialize();
  467. return SUCCESS ;
  468. break ;
  469. case EXIT_FAILURE_RESULTS:
  470. DISPLAY_MESSAGE(stdout,GetResString(IDS_NO_DRIVERS_FOUND));
  471. SAFEIRELEASE(pSystemSet);
  472. SAFEIRELEASE(pIWbemServices);
  473. SAFEIRELEASE(pIWbemLocator);
  474. CoUninitialize();
  475. return SUCCESS ;
  476. break ;
  477. }
  478. }
  479. else
  480. {
  481. DISPLAY_MESSAGE( stderr, ERROR_ENUMERATE_INSTANCE);
  482. SAFEIRELEASE(pIWbemServices);
  483. SAFEIRELEASE(pIWbemLocator);
  484. CoUninitialize();
  485. return FAILURE;
  486. }
  487. }
  488. else
  489. {
  490. //display the error if connect server fails
  491. //unauthorized user
  492. if(hRes == WBEM_E_ACCESS_DENIED)
  493. {
  494. DISPLAY_MESSAGE( stderr, ERROR_AUTHENTICATION_FAILURE);
  495. }
  496. //local system credentials
  497. else if(hRes == WBEM_E_LOCAL_CREDENTIALS)
  498. {
  499. DISPLAY_MESSAGE( stderr, ERROR_LOCAL_CREDENTIALS);
  500. }
  501. //some error
  502. else
  503. {
  504. DISPLAY_MESSAGE( stderr, ERROR_WMI_FAILURE );
  505. }
  506. SAFEIRELEASE(pIWbemLocator);
  507. CoUninitialize();
  508. return (FAILURE);
  509. }
  510. // Release pIWbemLocator object
  511. SAFEIRELEASE(pIWbemLocator);
  512. // Close COM library, unload DLLs and free all resources held by
  513. // current thread
  514. CoUninitialize();
  515. return (hRes);
  516. }
  517. // ***************************************************************************
  518. // Routine Description:
  519. // Processes enumeration of Win32_ComputerSystem instances
  520. //
  521. // Arguments:
  522. // [ in ] szHost : HostName to connect to
  523. // [ in ] pSystemSet : pointer to the structure containing system properties.
  524. // [ in ] szFormat : specifies the format
  525. // [ in ] bHeader : specifies if the header is required or not.
  526. //
  527. // Return Value:
  528. // 0 no error
  529. // 1 error occured while allocating memory.
  530. //
  531. // ***************************************************************************
  532. DWORD ProcessCompSysEnum(CHString szHost, IEnumWbemClassObject *pSystemSet,LPTSTR szFormat,BOOL bHeader,DWORD dwSystemType,BOOL bVerbose)
  533. {
  534. HRESULT hRes = S_OK;
  535. ULONG ulReturned = 1;
  536. // declare variant type variables
  537. VARIANT vtPathName;
  538. //declaration of normal variables
  539. CHString szPathName ;
  540. DWORD dwLength = 0;
  541. LPCTSTR szPath = NULL;
  542. LPTSTR szHostName = NULL ;
  543. CHString szAcceptPauseVal ;
  544. CHString szAcceptStopVal ;
  545. LPTSTR szSysManfact = NULL;
  546. TARRAY arrResults = NULL ;
  547. TCHAR szPrintPath[MAX_STRING_LENGTH+1] =TOKEN_EMPTYSTRING ;
  548. DWORD dwRow = 0 ;
  549. BOOL bValue = FALSE ;
  550. DWORD dwValue = 0 ;
  551. TCHAR szDelimiter[MAX_RES_STRING+1] = NULL_STRING ;
  552. DWORD dwPosn1 = 0;
  553. DWORD dwStrlen = 0;
  554. DWORD dwFormatType = SR_FORMAT_TABLE ;
  555. MODULE_DATA Current ;
  556. BOOL bResult = FALSE ;
  557. NUMBERFMT *pNumberFmt = NULL;
  558. TCOLUMNS ResultHeader[ MAX_COLUMNS ];
  559. IWbemClassObject *pSystem = NULL;
  560. LPTSTR szCodeSize = NULL;
  561. LPTSTR szInitSize = NULL;
  562. LPTSTR szBssSize = NULL ;
  563. LPTSTR szAcceptStop = NULL ;
  564. int iLen = 0;
  565. LPTSTR szAcceptPause = NULL;
  566. LPTSTR szPagedSize = NULL ;
  567. TCHAR szDriverTypeVal[MAX_RES_STRING+1] = NULL_STRING;
  568. DWORD dwLocale = 0 ;
  569. WCHAR wszStrVal[MAX_RES_STRING+1] = NULL_STRING;
  570. CHString szValue ;
  571. CHString szSysName ;
  572. CHString szStartMode ;
  573. CHString szDispName ;
  574. CHString szDescription ;
  575. CHString szStatus ;
  576. CHString szState ;
  577. CHString szDriverType ;
  578. BOOL bBlankLine = FALSE;
  579. BOOL bFirstTime = TRUE;
  580. //get the paged pool acc to the Locale
  581. BOOL bFValue = FALSE ;
  582. // Fill up the NUMBERFMT structure acc to the locale specific information
  583. LPTSTR szGroupSep = NULL;
  584. LPTSTR szDecimalSep = NULL ;
  585. LPTSTR szGroupThousSep = NULL ;
  586. pNumberFmt = (NUMBERFMT *) malloc(sizeof(NUMBERFMT));
  587. if(pNumberFmt == NULL)
  588. {
  589. return EXIT_FAILURE_MALLOC ;
  590. }
  591. // Initialise the structure to Zero.
  592. ZeroMemory(&Current,sizeof(Current));
  593. // assign the appropriate format type to the dwFormattype flag
  594. if( StringCompare(szFormat,TABLE_FORMAT, TRUE,sizeof(TABLE_FORMAT)) == 0 )
  595. {
  596. dwFormatType = SR_FORMAT_TABLE;
  597. }
  598. else if( StringCompare(szFormat,LIST_FORMAT, TRUE,sizeof(LIST_FORMAT)) == 0 )
  599. {
  600. dwFormatType = SR_FORMAT_LIST;
  601. }
  602. else if( StringCompare(szFormat,CSV_FORMAT, TRUE,sizeof(CSV_FORMAT)) == 0 )
  603. {
  604. dwFormatType = SR_FORMAT_CSV;
  605. }
  606. // formulate the Column headers and show results appropriately
  607. FormHeader(dwFormatType,bHeader,ResultHeader,bVerbose);
  608. // loop till there are results.
  609. bFirstTime = TRUE;
  610. while ( ulReturned == 1 )
  611. {
  612. // Create new Dynamic Array to hold the result
  613. arrResults = CreateDynamicArray();
  614. if(arrResults == NULL)
  615. {
  616. SAFEFREE(pNumberFmt);
  617. return EXIT_FAILURE_MALLOC ;
  618. }
  619. // Enumerate through the resultset.
  620. hRes = pSystemSet->Next(WBEM_INFINITE,
  621. 1, // return just one system
  622. &pSystem, // pointer to system
  623. &ulReturned ); // number obtained: one or zero
  624. if ( SUCCEEDED( hRes ) && (ulReturned == 1) )
  625. {
  626. // initialise the variant variables to empty
  627. VariantInit(&vtPathName);
  628. szValue = NO_DATA_AVAILABLE;
  629. szSysName = NO_DATA_AVAILABLE ;
  630. szStartMode = NO_DATA_AVAILABLE ;
  631. szDispName = NO_DATA_AVAILABLE ;
  632. szDescription = NO_DATA_AVAILABLE ;
  633. szStatus = NO_DATA_AVAILABLE ;
  634. szState = NO_DATA_AVAILABLE ;
  635. szDriverType = NO_DATA_AVAILABLE ;
  636. try
  637. {
  638. hRes = PropertyGet(pSystem,PROPERTY_NAME,szValue);
  639. ONFAILTHROWERROR(hRes);
  640. hRes = PropertyGet(pSystem,PROPERTY_SYSTEMNAME,szSysName);
  641. ONFAILTHROWERROR(hRes);
  642. hRes = PropertyGet(pSystem,PROPERTY_STARTMODE,szStartMode);
  643. ONFAILTHROWERROR(hRes);
  644. hRes = PropertyGet(pSystem,PROPERTY_DISPLAYNAME,szDispName);
  645. ONFAILTHROWERROR(hRes);
  646. hRes = PropertyGet(pSystem,PROPERTY_DESCRIPTION,szDescription);
  647. ONFAILTHROWERROR(hRes);
  648. hRes = PropertyGet(pSystem,PROPERTY_STATUS,szStatus);
  649. ONFAILTHROWERROR(hRes);
  650. hRes = PropertyGet(pSystem,PROPERTY_STATE,szState);
  651. ONFAILTHROWERROR(hRes);
  652. hRes = PropertyGet(pSystem,PROPERTY_ACCEPTPAUSE,szAcceptPauseVal);
  653. ONFAILTHROWERROR(hRes);
  654. hRes = PropertyGet(pSystem,PROPERTY_ACCEPTSTOP,szAcceptStopVal);
  655. ONFAILTHROWERROR(hRes);
  656. hRes = PropertyGet(pSystem,PROPERTY_SERVICETYPE,szDriverType);
  657. ONFAILTHROWERROR(hRes);
  658. }
  659. catch(_com_error)
  660. {
  661. DISPLAY_MESSAGE(stderr,ERROR_GET_VALUE);
  662. SAFEIRELEASE(pSystem);
  663. DestroyDynamicArray(&arrResults);
  664. SAFEFREE(pNumberFmt);
  665. return FAILURE;
  666. }
  667. // retreive the PathName property
  668. szPath = NULL;
  669. try
  670. {
  671. hRes = pSystem->Get( PROPERTY_PATHNAME, 0,&vtPathName,0,NULL );
  672. if (( hRes == WBEM_S_NO_ERROR) && (vtPathName.vt != VT_NULL) && (vtPathName.vt != VT_EMPTY))
  673. {
  674. szPathName = ( LPWSTR ) _bstr_t(vtPathName);
  675. szSysManfact = (LPTSTR) malloc ((MAX_RES_STRING) * sizeof(TCHAR));
  676. if (szSysManfact == NULL)
  677. {
  678. SAFEIRELEASE(pSystem);
  679. DestroyDynamicArray(&arrResults);
  680. SAFEFREE(pNumberFmt);
  681. return EXIT_FAILURE_MALLOC;
  682. }
  683. dwLength = wcslen(szPathName);
  684. GetCompatibleStringFromUnicode( szPathName, szSysManfact, dwLength+2 );
  685. szPath = szSysManfact ;
  686. // Initialise the structure to Zero.
  687. ZeroMemory(&Current,sizeof(Current));
  688. // convert the szHost variable (containing hostname) into LPCTSTR and pass it to the GETAPI function
  689. szHostName = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR)));
  690. if (szHostName == NULL)
  691. {
  692. SAFEIRELEASE(pSystem);
  693. DestroyDynamicArray(&arrResults);
  694. SAFEFREE(pNumberFmt);
  695. SAFEFREE(szSysManfact);
  696. return EXIT_FAILURE_MALLOC;
  697. }
  698. GetCompatibleStringFromUnicode( szHost, szHostName,dwLength+2 );
  699. _tcscpy(szPrintPath,szPath);
  700. BOOL bApiInfo = GetApiInfo(szHostName,szPath,&Current, dwSystemType);
  701. if(bApiInfo == FAILURE)
  702. {
  703. DestroyDynamicArray(&arrResults);
  704. SAFEFREE(pNumberFmt);
  705. SAFEFREE(szHostName);
  706. SAFEFREE(szSysManfact);
  707. continue ;
  708. }
  709. }
  710. else
  711. {
  712. DestroyDynamicArray(&arrResults);
  713. SAFEFREE(pNumberFmt);
  714. SAFEFREE(szHostName);
  715. SAFEFREE(szSysManfact);
  716. continue ; // ignore exception
  717. }
  718. }
  719. catch(...)
  720. {
  721. // If the path is empty then ignore the present continue with next iteration
  722. DestroyDynamicArray(&arrResults);
  723. SAFEFREE(pNumberFmt);
  724. SAFEFREE(szHostName);
  725. SAFEFREE(szSysManfact);
  726. continue ; // ignore exception
  727. }
  728. //create a new empty row with required no of columns
  729. dwRow = DynArrayAppendRow(arrResults,MAX_COLUMNS) ;
  730. // Insert the results into the Dynamic Array
  731. DynArraySetString2( arrResults,dwRow,COL0,szSysName,0 );
  732. DynArraySetString2( arrResults,dwRow,COL1,szValue,0 );
  733. DynArraySetString2( arrResults,dwRow,COL2,szDispName,0 );
  734. DynArraySetString2( arrResults,dwRow,COL3,szDescription,0 );
  735. // strip off the word Driver from the display.
  736. dwLength = wcslen(szDriverType) ;
  737. GetCompatibleStringFromUnicode( szDriverType, szDriverTypeVal,dwLength+2 );
  738. _tcscpy(szDelimiter,DRIVER_TAG);
  739. dwPosn1 = _tcslen(szDelimiter);
  740. dwStrlen = _tcslen(szDriverTypeVal);
  741. szDriverTypeVal[dwStrlen-dwPosn1] = _T('\0');
  742. DynArraySetString2( arrResults,dwRow,COL4,szDriverTypeVal,0 );
  743. DynArraySetString2( arrResults,dwRow,COL5,szStartMode,0 );
  744. DynArraySetString2( arrResults,dwRow,COL6,szState,0 );
  745. DynArraySetString2( arrResults,dwRow,COL7,szStatus,0 );
  746. iLen = wcslen(szAcceptStopVal);
  747. szAcceptStop = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR )));
  748. if (szAcceptStop == NULL)
  749. {
  750. SAFEIRELEASE(pSystem);
  751. SAFEFREE(pNumberFmt);
  752. SAFEFREE(szHostName);
  753. SAFEFREE(szSysManfact);
  754. DestroyDynamicArray(&arrResults);
  755. return EXIT_FAILURE_MALLOC;
  756. }
  757. GetCompatibleStringFromUnicode(szAcceptStopVal,szAcceptStop,iLen + 2 );
  758. szAcceptStop[iLen] = '\0';
  759. if (lstrcmp(szAcceptStop,_T("0"))==0)
  760. {
  761. lstrcpy(szAcceptStop,FALSE_VALUE);
  762. }
  763. else
  764. {
  765. lstrcpy(szAcceptStop,TRUE_VALUE);
  766. }
  767. DynArraySetString2( arrResults,dwRow,COL8,szAcceptStop,0 );
  768. iLen = wcslen(szAcceptPauseVal);
  769. szAcceptPause = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR )));
  770. if (szAcceptPause == NULL)
  771. {
  772. SAFEIRELEASE(pSystem);
  773. SAFEFREE(pNumberFmt);
  774. SAFEFREE(szHostName);
  775. SAFEFREE(szSysManfact);
  776. SAFEFREE(szAcceptStop);
  777. DestroyDynamicArray(&arrResults);
  778. return EXIT_FAILURE_MALLOC;
  779. }
  780. GetCompatibleStringFromUnicode(szAcceptPauseVal,szAcceptPause,iLen + 2 );
  781. szAcceptPause[iLen] = '\0';
  782. if (lstrcmp(szAcceptPause,_T("0"))==0)
  783. {
  784. lstrcpy(szAcceptPause,FALSE_VALUE);
  785. }
  786. else
  787. {
  788. lstrcpy(szAcceptPause,TRUE_VALUE);
  789. }
  790. DynArraySetString2( arrResults,dwRow,COL9,szAcceptPause,0 );
  791. bFValue = FormatAccToLocale(pNumberFmt, &szGroupSep,&szDecimalSep,&szGroupThousSep);
  792. if (bFValue == FALSE)
  793. {
  794. SAFEIRELEASE(pSystem);
  795. SAFEFREE(pNumberFmt);
  796. SAFEFREE(szHostName);
  797. SAFEFREE(szSysManfact);
  798. SAFEFREE(szAcceptStop);
  799. SAFEFREE(szAcceptPause);
  800. SAFEFREE(szGroupThousSep);
  801. SAFEFREE(szDecimalSep);
  802. SAFEFREE(szGroupSep);
  803. DestroyDynamicArray(&arrResults);
  804. return EXIT_FAILURE_FORMAT ;
  805. }
  806. szPagedSize = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR )));
  807. if (szPagedSize == NULL)
  808. {
  809. SAFEIRELEASE(pSystem);
  810. SAFEFREE(pNumberFmt);
  811. SAFEFREE(szHostName);
  812. SAFEFREE(szSysManfact);
  813. SAFEFREE(szAcceptStop);
  814. SAFEFREE(szAcceptPause);
  815. SAFEFREE(szGroupThousSep);
  816. SAFEFREE(szDecimalSep);
  817. SAFEFREE(szGroupSep);
  818. DestroyDynamicArray(&arrResults);
  819. return EXIT_FAILURE_MALLOC;
  820. }
  821. _ltow(Current.ulPagedSize, wszStrVal,10);
  822. dwLocale = GetNumberFormat(LOCALE_USER_DEFAULT,0,wszStrVal,pNumberFmt,
  823. szPagedSize,(MAX_RES_STRING + 1));
  824. if(dwLocale == 0)
  825. {
  826. SAFEFREE(pNumberFmt);
  827. SAFEFREE(szHostName);
  828. SAFEFREE(szSysManfact);
  829. SAFEFREE(szAcceptStop);
  830. SAFEFREE(szAcceptPause);
  831. SAFEFREE(szPagedSize);
  832. SAFEFREE(szGroupThousSep);
  833. SAFEFREE(szDecimalSep);
  834. SAFEFREE(szGroupSep);
  835. DestroyDynamicArray(&arrResults);
  836. return EXIT_FAILURE_FORMAT;
  837. }
  838. DynArraySetString2( arrResults,dwRow,COL10, szPagedSize,0 );
  839. // get the CodeSize info acc to the locale
  840. szCodeSize = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR )));
  841. if (szCodeSize == NULL)
  842. {
  843. SAFEIRELEASE(pSystem);
  844. SAFEFREE(pNumberFmt);
  845. SAFEFREE(szHostName);
  846. SAFEFREE(szSysManfact);
  847. SAFEFREE(szAcceptStop);
  848. SAFEFREE(szAcceptPause);
  849. SAFEFREE(szPagedSize);
  850. SAFEFREE(szGroupThousSep);
  851. SAFEFREE(szDecimalSep);
  852. SAFEFREE(szGroupSep);
  853. DestroyDynamicArray(&arrResults);
  854. return EXIT_FAILURE_MALLOC;
  855. }
  856. _ltow(Current.ulCodeSize, wszStrVal,10);
  857. dwLocale = GetNumberFormat(LOCALE_USER_DEFAULT,0,wszStrVal,pNumberFmt,szCodeSize,(MAX_RES_STRING + 1));
  858. if(dwLocale == 0)
  859. {
  860. SAFEIRELEASE(pSystem);
  861. SAFEFREE(pNumberFmt);
  862. SAFEFREE(szHostName);
  863. SAFEFREE(szSysManfact);
  864. SAFEFREE(szAcceptStop);
  865. SAFEFREE(szAcceptPause);
  866. SAFEFREE(szCodeSize);
  867. SAFEFREE(szGroupThousSep);
  868. SAFEFREE(szDecimalSep);
  869. SAFEFREE(szGroupSep);
  870. DestroyDynamicArray(&arrResults);
  871. return EXIT_FAILURE_FORMAT ;
  872. }
  873. DynArraySetString2( arrResults,dwRow,COL11, szCodeSize,0 );
  874. // retreive the bss info acc to the locale
  875. szBssSize = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR )));
  876. if (szBssSize == NULL)
  877. {
  878. SAFEIRELEASE(pSystem);
  879. SAFEFREE(pNumberFmt);
  880. SAFEFREE(szHostName);
  881. SAFEFREE(szSysManfact);
  882. SAFEFREE(szAcceptStop);
  883. SAFEFREE(szAcceptPause);
  884. SAFEFREE(szCodeSize);
  885. SAFEFREE(szGroupThousSep);
  886. SAFEFREE(szDecimalSep);
  887. SAFEFREE(szGroupSep);
  888. DestroyDynamicArray(&arrResults);
  889. return EXIT_FAILURE_MALLOC ;
  890. }
  891. _ltow(Current.ulBssSize, wszStrVal,10);
  892. dwLocale = GetNumberFormat(LOCALE_USER_DEFAULT,0,wszStrVal,pNumberFmt,
  893. szBssSize,(MAX_RES_STRING + 1));
  894. if(dwLocale == 0)
  895. {
  896. SAFEIRELEASE(pSystem);
  897. SAFEFREE(pNumberFmt);
  898. SAFEFREE(szHostName);
  899. SAFEFREE(szSysManfact);
  900. SAFEFREE(szAcceptStop);
  901. SAFEFREE(szAcceptPause);
  902. SAFEFREE(szCodeSize);
  903. SAFEFREE(szBssSize);
  904. SAFEFREE(szGroupThousSep);
  905. SAFEFREE(szDecimalSep);
  906. SAFEFREE(szGroupSep);
  907. DestroyDynamicArray(&arrResults);
  908. return EXIT_FAILURE_FORMAT ;
  909. }
  910. DynArraySetString2( arrResults,dwRow,COL12, szBssSize,0 );
  911. //link date
  912. DynArraySetString2(arrResults,dwRow,COL13,(LPTSTR)(Current.szTimeDateStamp),0);
  913. //Path of the File
  914. if(szPath != NULL)
  915. {
  916. DynArraySetString2(arrResults,dwRow,COL14,(LPTSTR)szPrintPath,0); //
  917. }
  918. else
  919. {
  920. szPath= NO_DATA_AVAILABLE;
  921. DynArraySetString2(arrResults,dwRow,COL14,(LPTSTR)szPath,0); //
  922. }
  923. // get the initsize info acc to the locale
  924. szInitSize = (LPTSTR) malloc ((MAX_RES_STRING) * (sizeof(TCHAR )));
  925. if (szInitSize == NULL)
  926. {
  927. SAFEIRELEASE(pSystem);
  928. SAFEFREE(pNumberFmt);
  929. SAFEFREE(szHostName);
  930. SAFEFREE(szSysManfact);
  931. SAFEFREE(szAcceptStop);
  932. SAFEFREE(szAcceptPause);
  933. SAFEFREE(szCodeSize);
  934. SAFEFREE(szBssSize);
  935. SAFEFREE(szGroupThousSep);
  936. SAFEFREE(szDecimalSep);
  937. SAFEFREE(szGroupSep);
  938. DestroyDynamicArray(&arrResults);
  939. return EXIT_FAILURE_MALLOC ;
  940. }
  941. _ltow(Current.ulInitSize, wszStrVal,10);
  942. dwLocale = GetNumberFormat(LOCALE_USER_DEFAULT,0,wszStrVal,pNumberFmt,
  943. szInitSize,(MAX_RES_STRING + 1));
  944. if(dwLocale == 0)
  945. {
  946. SAFEIRELEASE(pSystem);
  947. SAFEFREE(pNumberFmt);
  948. SAFEFREE(szHostName);
  949. SAFEFREE(szSysManfact);
  950. SAFEFREE(szAcceptStop);
  951. SAFEFREE(szAcceptPause);
  952. SAFEFREE(szCodeSize);
  953. SAFEFREE(szBssSize);;
  954. SAFEFREE(szInitSize);
  955. SAFEFREE(szGroupThousSep);
  956. SAFEFREE(szDecimalSep);
  957. SAFEFREE(szGroupSep);
  958. DestroyDynamicArray(&arrResults);
  959. return EXIT_FAILURE_FORMAT ;
  960. }
  961. DynArraySetString2( arrResults,dwRow,COL15, szInitSize,0 );
  962. if ( bBlankLine == TRUE && (dwFormatType & SR_FORMAT_MASK) == SR_FORMAT_LIST )
  963. ShowMessage( stdout, _T( "\n" ) );
  964. if ( bFirstTime == TRUE )
  965. {
  966. ShowMessage( stdout, _T( "\n" ) );
  967. bFirstTime = FALSE;
  968. }
  969. if(bHeader)
  970. {
  971. ShowResults(MAX_COLUMNS, ResultHeader, dwFormatType|SR_NOHEADER,arrResults ) ;
  972. }
  973. else
  974. {
  975. ShowResults(MAX_COLUMNS, ResultHeader, dwFormatType,arrResults ) ;
  976. }
  977. //set the header flag to true
  978. bHeader = TRUE ;
  979. bBlankLine = TRUE;
  980. //set the bResult to true indicating that driver information has been displyed.
  981. bResult = TRUE ;
  982. // free the allocated memory
  983. SAFEFREE(szSysManfact);
  984. SAFEFREE(pNumberFmt);
  985. SAFEFREE(szHostName);
  986. SAFEFREE(szAcceptStop);
  987. SAFEFREE(szAcceptPause);
  988. SAFEFREE(szPagedSize);
  989. SAFEFREE(szBssSize);
  990. SAFEFREE(szInitSize);
  991. SAFEFREE(szCodeSize);
  992. SAFEFREE(szGroupThousSep);
  993. SAFEFREE(szDecimalSep);
  994. SAFEFREE(szGroupSep);
  995. SAFEIRELEASE(pSystem);
  996. } // If System Succeeded
  997. // Destroy the Dynamic arrays
  998. DestroyDynamicArray(&arrResults);
  999. }// While SystemSet returning objects
  1000. // return the error value or success value
  1001. if (bResult == TRUE)
  1002. {
  1003. return SUCCESS ;
  1004. }
  1005. else
  1006. {
  1007. return EXIT_FAILURE_RESULTS ;
  1008. }
  1009. }
  1010. // ***************************************************************************
  1011. // Routine Description:
  1012. // This function queries the system properties using API's .
  1013. //
  1014. // Arguments:
  1015. // [ in ] szHostName : HostName to connect to
  1016. // [ in ] pszPath : pointer to the string containing the Path of the file.
  1017. // [ out] Mod : pointer to the structure containing system properties.
  1018. //
  1019. // Return Value:
  1020. // SUCCESS : If successful in getting the information using API's.
  1021. // FAILURE : If unable to get the information using API's.
  1022. // ***************************************************************************
  1023. BOOL GetApiInfo(LPTSTR szHostName,LPCTSTR pszPath,PMODULE_DATA Mod,DWORD dwSystemType)
  1024. {
  1025. HANDLE hMappedFile = NULL;
  1026. PIMAGE_DOS_HEADER DosHeader;
  1027. LOADED_IMAGE LoadedImage;
  1028. ULONG ulSectionAlignment = 0;
  1029. PIMAGE_SECTION_HEADER Section;
  1030. DWORD dwI = 0;
  1031. ULONG ulSize = 0;
  1032. TCHAR szTmpServer[ MAX_STRING_LENGTH + 1 ] = NULL_STRING;
  1033. HANDLE hFile = NULL ;
  1034. PTCHAR pszToken = NULL;
  1035. lstrcpy(szTmpServer,TOKEN_BACKSLASH2);
  1036. TCHAR szFinalPath[MAX_STRING_LENGTH+1] =TOKEN_EMPTYSTRING ;
  1037. PTCHAR pdest = NULL ;
  1038. #ifndef _WIN64
  1039. BOOL bIsWin64;
  1040. #endif
  1041. //copy the path into a variable
  1042. _tcscpy(szFinalPath,pszPath);
  1043. //get the token upto the delimiter ":"
  1044. pszToken = _tcstok(szFinalPath, COLON_SYMBOL );
  1045. //form the string for getting the absolute path in the required format if it is a remote system.
  1046. if(_tcslen(szHostName) != 0)
  1047. {
  1048. pdest = _tcsstr(pszPath,COLON_SYMBOL);
  1049. if(pdest== NULL)
  1050. {
  1051. return FAILURE ;
  1052. }
  1053. _tcsnset(pdest,TOKEN_DOLLAR,1);
  1054. _tcscat(szTmpServer,szHostName);
  1055. _tcscat(szTmpServer,TOKEN_BACKSLASH);
  1056. _tcscat(szTmpServer,pszToken);
  1057. _tcscat(szTmpServer,pdest);
  1058. }
  1059. else
  1060. {
  1061. _tcscpy(szTmpServer,pszPath) ;
  1062. }
  1063. #ifndef _WIN64
  1064. bIsWin64 = IsWin64();
  1065. if(bIsWin64)
  1066. Wow64DisableFilesystemRedirector((LPCTSTR)szTmpServer);
  1067. #endif
  1068. // create a file on the specified system and return a handle to it.
  1069. hFile = CreateFile(szTmpServer,
  1070. GENERIC_READ,
  1071. FILE_SHARE_READ,
  1072. NULL,
  1073. OPEN_EXISTING,
  1074. 0,
  1075. NULL);
  1076. //if the filehandle is invalid then return a error
  1077. if(hFile == INVALID_HANDLE_VALUE)
  1078. {
  1079. return FAILURE ;
  1080. }
  1081. #ifndef _WIN64
  1082. if(bIsWin64)
  1083. Wow64EnableFilesystemRedirector();
  1084. #endif
  1085. // create a mapping to the specified file
  1086. hMappedFile = CreateFileMapping(hFile,
  1087. NULL,
  1088. PAGE_READONLY,
  1089. 0,
  1090. 0,
  1091. NULL);
  1092. if (hMappedFile == NULL)
  1093. {
  1094. CloseHandle(hFile);
  1095. return FAILURE ;
  1096. }
  1097. LoadedImage.MappedAddress = (PUCHAR)MapViewOfFile(hMappedFile,
  1098. FILE_MAP_READ,
  1099. 0,
  1100. 0,
  1101. 0);
  1102. // close the opened file handles
  1103. CloseHandle(hMappedFile);
  1104. CloseHandle(hFile);
  1105. if ( !LoadedImage.MappedAddress )
  1106. {
  1107. return FAILURE ;
  1108. }
  1109. // check the image and find nt image headers
  1110. DosHeader = (PIMAGE_DOS_HEADER)LoadedImage.MappedAddress;
  1111. //exit if the DOS header does not match
  1112. if ( DosHeader->e_magic != IMAGE_DOS_SIGNATURE )
  1113. {
  1114. UnmapViewOfFile(LoadedImage.MappedAddress);
  1115. return FAILURE ;
  1116. }
  1117. LoadedImage.FileHeader = (PIMAGE_NT_HEADERS)((ULONG_PTR)DosHeader + DosHeader->e_lfanew);
  1118. if ( LoadedImage.FileHeader->Signature != IMAGE_NT_SIGNATURE )
  1119. {
  1120. UnmapViewOfFile(LoadedImage.MappedAddress);
  1121. return FAILURE ;
  1122. }
  1123. //get the number of sections present
  1124. LoadedImage.NumberOfSections = LoadedImage.FileHeader->FileHeader.NumberOfSections;
  1125. if(dwSystemType == SYSTEM_64_BIT )
  1126. {
  1127. LoadedImage.Sections = (PIMAGE_SECTION_HEADER)((ULONG_PTR)LoadedImage.FileHeader + sizeof(IMAGE_NT_HEADERS64));
  1128. }
  1129. else
  1130. {
  1131. LoadedImage.Sections = (PIMAGE_SECTION_HEADER)((ULONG_PTR)LoadedImage.FileHeader + sizeof(IMAGE_NT_HEADERS32));
  1132. }
  1133. LoadedImage.LastRvaSection = LoadedImage.Sections;
  1134. // Walk through the sections and tally the dater
  1135. ulSectionAlignment = LoadedImage.FileHeader->OptionalHeader.SectionAlignment;
  1136. for(Section = LoadedImage.Sections,dwI=0;dwI < LoadedImage.NumberOfSections; dwI++,Section++)
  1137. {
  1138. ulSize = Section->Misc.VirtualSize;
  1139. if (ulSize == 0)
  1140. {
  1141. ulSize = Section->SizeOfRawData;
  1142. }
  1143. ulSize = (ulSize + ulSectionAlignment - 1) & ~(ulSectionAlignment - 1);
  1144. if (!_strnicmp((char *)(Section->Name),EXTN_PAGE, 4 ))
  1145. {
  1146. Mod->ulPagedSize += ulSize;
  1147. }
  1148. else if (!_stricmp((char *)(Section->Name),EXTN_INIT ))
  1149. {
  1150. Mod->ulInitSize += ulSize;
  1151. }
  1152. else if(!_stricmp((char *)(Section->Name),EXTN_BSS))
  1153. {
  1154. Mod->ulBssSize = ulSize;
  1155. }
  1156. else if (!_stricmp((char *)(Section->Name),EXTN_EDATA))
  1157. {
  1158. Mod->ulExportDataSize = ulSize ;
  1159. }
  1160. else if (!_stricmp((char *)(Section->Name),EXTN_IDATA ))
  1161. {
  1162. Mod->ulImportDataSize = ulSize;
  1163. }
  1164. else if (!_stricmp((char *)(Section->Name),EXTN_RSRC))
  1165. {
  1166. Mod->ulResourceDataSize = ulSize;
  1167. }
  1168. else if (Section->Characteristics & IMAGE_SCN_MEM_EXECUTE)
  1169. {
  1170. Mod->ulCodeSize += ulSize;
  1171. }
  1172. else if (Section->Characteristics & IMAGE_SCN_MEM_WRITE)
  1173. {
  1174. Mod->ulDataSize += ulSize;
  1175. }
  1176. else
  1177. {
  1178. Mod->ulDataSize += ulSize;
  1179. }
  1180. }
  1181. #ifndef _WIN64
  1182. LONG lTimeVal ;
  1183. #else
  1184. LONG64 lTimeVal;
  1185. #endif
  1186. lTimeVal = LoadedImage.FileHeader->FileHeader.TimeDateStamp ;
  1187. struct tm *tmVal = NULL;
  1188. tmVal = localtime(&lTimeVal);
  1189. // proceed furthur only if we successfully got the localtime
  1190. if ( tmVal != NULL )
  1191. {
  1192. LCID lcid;
  1193. SYSTEMTIME systime;
  1194. __STRING_64 szBuffer;
  1195. BOOL bLocaleChanged = FALSE;
  1196. systime.wYear = (WORD) (DWORD_PTR)( tmVal->tm_year + 1900 ); // tm -> Year - 1900 SYSTEMTIME -> Year = Year
  1197. systime.wMonth = (WORD) (DWORD_PTR) tmVal->tm_mon + 1; // tm -> Jan = 0 SYSTEMTIME -> Jan = 1
  1198. systime.wDayOfWeek = (WORD) (DWORD_PTR) tmVal->tm_wday;
  1199. systime.wDay = (WORD) (DWORD_PTR) tmVal->tm_mday;
  1200. systime.wHour = (WORD) (DWORD_PTR) tmVal->tm_hour;
  1201. systime.wMinute = (WORD) (DWORD_PTR) tmVal->tm_min;
  1202. systime.wSecond = (WORD) (DWORD_PTR) tmVal->tm_sec;
  1203. systime.wMilliseconds = 0;
  1204. // verify whether console supports the current locale 100% or not
  1205. lcid = GetSupportedUserLocale( bLocaleChanged );
  1206. // get the formatted date
  1207. GetDateFormat( lcid, 0, &systime,
  1208. ((bLocaleChanged == TRUE) ? L"MM/dd/yyyy" : NULL), szBuffer, SIZE_OF_ARRAY( szBuffer ) );
  1209. // copy the date info
  1210. lstrcpy( Mod->szTimeDateStamp, szBuffer );
  1211. // now format the date
  1212. GetTimeFormat( LOCALE_USER_DEFAULT, 0, &systime,
  1213. ((bLocaleChanged == TRUE) ? L"HH:mm:ss" : NULL), szBuffer, SIZE_OF_ARRAY( szBuffer ) );
  1214. // now copy time info
  1215. lstrcat( Mod->szTimeDateStamp, _T( " " ) );
  1216. lstrcat( Mod->szTimeDateStamp, szBuffer );
  1217. }
  1218. UnmapViewOfFile(LoadedImage.MappedAddress);
  1219. return SUCCESS;
  1220. }
  1221. // ***************************************************************************
  1222. // Routine Description:
  1223. // This function parses the options specified at the command prompt
  1224. //
  1225. // Arguments:
  1226. // [ in ] argc : count of elements in argv
  1227. // [ in ] argv : command-line parameterd specified by the user
  1228. // [ out ] pbShowUsage : set to TRUE if -? exists in 'argv'
  1229. // [ out ] pszServer : value(s) specified with -s ( server ) option in 'argv'
  1230. // [ out ] pszUserName : value of -u ( username ) option in 'argv'
  1231. // [ out ] pszPassword : value of -p ( password ) option in 'argv'
  1232. // [ out ] pszFormat : Display format
  1233. // [ out ] bHeader : specifies whether to display a header or not.
  1234. // [ in ] bNeedPassword : specifies if the password is required or not.
  1235. //
  1236. // Return Value:
  1237. // TRUE : if the parsing is successful
  1238. // FALSE : if errors occured in parsing
  1239. // ***************************************************************************
  1240. BOOL ProcessOptions(LONG argc,LPCTSTR argv[],PBOOL pbShowUsage,LPTSTR *pszServer,LPTSTR *pszUserName,LPTSTR *pszPassword,LPTSTR pszFormat,PBOOL pbHeader, PBOOL bNeedPassword,PBOOL pbVerbose,PBOOL pbSigned)
  1241. {
  1242. PTCMDPARSER pcmdOption = NULL; //pointer to the structure
  1243. TCMDPARSER cmdOptions[MAX_OPTIONS] ;
  1244. BOOL bval = TRUE ;
  1245. LPCTSTR szToken = NULL ;
  1246. // init the password
  1247. if ( pszPassword != NULL && *pszPassword != NULL )
  1248. {
  1249. lstrcpy( *pszPassword, _T( "*" ) );
  1250. }
  1251. // help option
  1252. pcmdOption = &cmdOptions[OI_HELP] ;
  1253. pcmdOption->dwCount = 1 ;
  1254. pcmdOption->dwActuals = 0;
  1255. pcmdOption->dwFlags = CP_USAGE ;
  1256. pcmdOption->pValue = pbShowUsage ;
  1257. pcmdOption->pFunction = NULL ;
  1258. pcmdOption->pFunctionData = NULL ;
  1259. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1260. lstrcpy(pcmdOption->szOption,OPTION_HELP); // _T("?")
  1261. //server name option
  1262. pcmdOption = &cmdOptions[OI_SERVER] ;
  1263. pcmdOption->dwCount = 1 ;
  1264. pcmdOption->dwActuals = 0;
  1265. pcmdOption->dwFlags = CP_TYPE_TEXT|CP_VALUE_MANDATORY ;
  1266. pcmdOption->pValue = *pszServer ;
  1267. pcmdOption->pFunction = NULL ;
  1268. pcmdOption->pFunctionData = NULL ;
  1269. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1270. lstrcpy(pcmdOption->szOption,OPTION_SERVER); // _T("s")
  1271. //domain\user option
  1272. pcmdOption = &cmdOptions[OI_USERNAME] ;
  1273. pcmdOption->dwCount = 1 ;
  1274. pcmdOption->dwActuals = 0;
  1275. pcmdOption->dwFlags = CP_TYPE_TEXT|CP_VALUE_MANDATORY ;
  1276. pcmdOption->pValue = *pszUserName ;
  1277. pcmdOption->pFunction = NULL ;
  1278. pcmdOption->pFunctionData = NULL ;
  1279. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1280. lstrcpy(pcmdOption->szOption,OPTION_USERNAME); // _T("u")
  1281. //password option
  1282. pcmdOption = &cmdOptions[OI_PASSWORD] ;
  1283. pcmdOption->dwCount = 1 ;
  1284. pcmdOption->dwActuals = 0;
  1285. pcmdOption->dwFlags = CP_TYPE_TEXT|CP_VALUE_OPTIONAL;
  1286. pcmdOption->pValue = *pszPassword ;
  1287. pcmdOption->pFunction = NULL ;
  1288. pcmdOption->pFunctionData = NULL ;
  1289. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1290. lstrcpy(pcmdOption->szOption,OPTION_PASSWORD); // _T("p")
  1291. //format option.
  1292. pcmdOption = &cmdOptions[OI_FORMAT] ;
  1293. pcmdOption->dwCount = 1 ;
  1294. pcmdOption->dwActuals = 0;
  1295. pcmdOption->dwFlags = CP_TYPE_TEXT|CP_VALUE_MANDATORY|CP_MODE_VALUES ;
  1296. pcmdOption->pValue = pszFormat ;
  1297. pcmdOption->pFunction = NULL ;
  1298. pcmdOption->pFunctionData = NULL ;
  1299. lstrcpy(pcmdOption->szValues,FORMAT_VALUES);
  1300. lstrcpy(pcmdOption->szOption,OPTION_FORMAT); // _T("fo")
  1301. //no header option
  1302. pcmdOption = &cmdOptions[OI_HEADER] ;
  1303. pcmdOption->dwCount = 1 ;
  1304. pcmdOption->dwActuals = 0;
  1305. pcmdOption->dwFlags = 0;
  1306. pcmdOption->pValue = pbHeader;
  1307. pcmdOption->pFunction = NULL ;
  1308. pcmdOption->pFunctionData = NULL ;
  1309. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1310. lstrcpy(pcmdOption->szOption,OPTION_HEADER); // _T("nh")
  1311. //verbose option..
  1312. pcmdOption = &cmdOptions[OI_VERBOSE] ;
  1313. pcmdOption->dwCount = 1 ;
  1314. pcmdOption->dwActuals = 0;
  1315. pcmdOption->dwFlags = 0 ;
  1316. pcmdOption->pValue = pbVerbose;
  1317. pcmdOption->pFunction = NULL ;
  1318. pcmdOption->pFunctionData = NULL ;
  1319. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1320. lstrcpy(pcmdOption->szOption,OPTION_VERBOSE); // _T("v")
  1321. pcmdOption = &cmdOptions[OI_SIGNED] ;
  1322. pcmdOption->dwCount = 1 ;
  1323. pcmdOption->dwActuals = 0;
  1324. pcmdOption->dwFlags = 0 ;
  1325. pcmdOption->pValue = pbSigned;
  1326. pcmdOption->pFunction = NULL ;
  1327. pcmdOption->pFunctionData = NULL ;
  1328. lstrcpy(pcmdOption->szValues,NULL_STRING);
  1329. lstrcpy(pcmdOption->szOption,OPTION_SIGNED); // _T("di")
  1330. bval = DoParseParam(argc,argv,MAX_OPTIONS,cmdOptions) ;
  1331. if( bval== FALSE)
  1332. {
  1333. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  1334. return FALSE ;
  1335. }
  1336. if((*pbShowUsage == TRUE)&&(argc > 2))
  1337. {
  1338. SetReason(ERROR_SYNTAX);
  1339. return FALSE ;
  1340. }
  1341. // checking if -u is specified when -s options is not specified and display error msg .
  1342. if ((cmdOptions[OI_SERVER].dwActuals == 0) && (cmdOptions[OI_USERNAME].dwActuals !=0 ))
  1343. {
  1344. SetReason(ERROR_USERNAME_BUT_NOMACHINE);
  1345. return FALSE ;
  1346. }
  1347. // checking if -u is specified when -p options is not specified and display error msg .
  1348. if ((cmdOptions[OI_USERNAME].dwActuals == 0) && (cmdOptions[OI_PASSWORD].dwActuals !=0 ))
  1349. {
  1350. SetReason(ERROR_PASSWORD_BUT_NOUSERNAME);
  1351. return FALSE ;
  1352. }
  1353. // checking if -p is specified when -u options is not specified and display error msg .
  1354. if ((cmdOptions[OI_SERVER].dwActuals != 0) && (lstrlen(*pszServer)==0 ))
  1355. {
  1356. SetReason(ERROR_INVALID_SERVER);
  1357. return FALSE ;
  1358. }
  1359. // checking if -p is specified when -u options is not specified and display error msg .
  1360. if ((cmdOptions[OI_USERNAME].dwActuals != 0) && (lstrlen(*pszUserName)==0 ))
  1361. {
  1362. SetReason(ERROR_INVALID_USER);
  1363. return FALSE ;
  1364. }
  1365. if((cmdOptions[OI_FORMAT].dwActuals != 0)&&(lstrcmpi((LPCTSTR)cmdOptions[OI_FORMAT].pValue,LIST_FORMAT) == 0)&&(cmdOptions[OI_HEADER].dwActuals != 0))
  1366. {
  1367. SetReason(ERROR_NO_HEADERS);
  1368. return FALSE ;
  1369. }
  1370. if((cmdOptions[OI_SIGNED].dwActuals != 0)&&(cmdOptions[OI_VERBOSE].dwActuals != 0))
  1371. {
  1372. SetReason(INVALID_SIGNED_SYNTAX);
  1373. return FALSE ;
  1374. }
  1375. if(StrCmpN(*pszServer,TOKEN_BACKSLASH2,2)==0)
  1376. {
  1377. if(!StrCmpN(*pszServer,TOKEN_BACKSLASH3,3)==0)
  1378. {
  1379. szToken = _tcstok(*pszServer,TOKEN_BACKSLASH2);
  1380. lstrcpy(*pszServer,szToken);
  1381. }
  1382. }
  1383. if(IsLocalSystem( *pszServer ) == FALSE )
  1384. {
  1385. // set the bNeedPassword to True or False .
  1386. if ( cmdOptions[ OI_PASSWORD ].dwActuals != 0 &&
  1387. pszPassword != NULL && *pszPassword != NULL && lstrcmp( *pszPassword, _T( "*" ) ) == 0 )
  1388. {
  1389. // user wants the utility to prompt for the password before trying to connect
  1390. *bNeedPassword = TRUE;
  1391. }
  1392. else if ( cmdOptions[ OI_PASSWORD ].dwActuals == 0 &&
  1393. ( cmdOptions[ OI_SERVER ].dwActuals != 0 || cmdOptions[ OI_USERNAME ].dwActuals != 0 ) )
  1394. {
  1395. // -s, -u is specified without password ...
  1396. // utility needs to try to connect first and if it fails then prompt for the password
  1397. *bNeedPassword = TRUE;
  1398. if ( pszPassword != NULL && *pszPassword != NULL )
  1399. {
  1400. lstrcpy( *pszPassword, _T( "" ) );
  1401. }
  1402. }
  1403. }
  1404. return TRUE ;
  1405. }
  1406. // ***************************************************************************
  1407. // Routine Description:
  1408. // This function is used to build the header and also display the
  1409. // result in the required format as specified by the user.
  1410. //
  1411. // Arguments:
  1412. // [ in ] arrResults : argument(s) count specified at the command prompt
  1413. // [ in ] dwFormatType : format flags
  1414. // [ in ] bHeader : Boolean for specifying if the header is required or not.
  1415. //
  1416. // Return Value:
  1417. // none
  1418. //
  1419. // ***************************************************************************
  1420. VOID FormHeader(DWORD dwFormatType,BOOL bHeader,TCOLUMNS *ResultHeader,BOOL bVerbose)
  1421. {
  1422. // host name
  1423. ResultHeader[COL0].dwWidth = COL_HOSTNAME_WIDTH;
  1424. ResultHeader[COL0].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1425. ResultHeader[COL0].pFunction = NULL;
  1426. ResultHeader[COL0].pFunctionData = NULL;
  1427. lstrcpy( ResultHeader[COL0].szFormat, NULL_STRING );
  1428. lstrcpy( ResultHeader[COL0].szColumn,COL_HOSTNAME );
  1429. //File Name header
  1430. ResultHeader[COL1].dwWidth = COL_FILENAME_WIDTH ;
  1431. ResultHeader[COL1].dwFlags = SR_TYPE_STRING;
  1432. ResultHeader[COL1].pFunction = NULL;
  1433. ResultHeader[COL1].pFunctionData = NULL;
  1434. lstrcpy( ResultHeader[COL1].szFormat, NULL_STRING );
  1435. lstrcpy( ResultHeader[COL1].szColumn,COL_FILENAME );
  1436. // Forming the DisplayName header Column
  1437. ResultHeader[COL2].dwWidth = COL_DISPLAYNAME_WIDTH ;
  1438. ResultHeader[COL2].dwFlags = SR_TYPE_STRING;
  1439. ResultHeader[COL2].pFunction = NULL;
  1440. ResultHeader[COL2].pFunctionData = NULL;
  1441. lstrcpy( ResultHeader[COL2].szFormat, NULL_STRING );
  1442. lstrcpy( ResultHeader[COL2].szColumn,COL_DISPLAYNAME );
  1443. // Forming the Description header Column
  1444. ResultHeader[COL3].dwWidth = COL_DESCRIPTION_WIDTH;
  1445. if(!bVerbose)
  1446. {
  1447. ResultHeader[COL3].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1448. }
  1449. else
  1450. {
  1451. ResultHeader[COL3].dwFlags = SR_TYPE_STRING;
  1452. }
  1453. ResultHeader[COL3].pFunction = NULL;
  1454. ResultHeader[COL3].pFunctionData = NULL;
  1455. lstrcpy( ResultHeader[COL3].szFormat, NULL_STRING );
  1456. lstrcpy( ResultHeader[COL3].szColumn,COL_DESCRIPTION );
  1457. // Forming the Drivertype header Column
  1458. ResultHeader[COL4].dwWidth = COL_DRIVERTYPE_WIDTH ;
  1459. ResultHeader[COL4].dwFlags = SR_TYPE_STRING;
  1460. ResultHeader[COL4].pFunction = NULL;
  1461. ResultHeader[COL4].pFunctionData = NULL;
  1462. lstrcpy( ResultHeader[COL4].szFormat, NULL_STRING );
  1463. lstrcpy( ResultHeader[COL4].szColumn,COL_DRIVERTYPE );
  1464. // Forming the StartMode header Column
  1465. ResultHeader[COL5].dwWidth = COL_STARTMODE_WIDTH;
  1466. if(!bVerbose)
  1467. {
  1468. ResultHeader[COL5].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1469. }
  1470. else
  1471. {
  1472. ResultHeader[COL5].dwFlags = SR_TYPE_STRING;
  1473. }
  1474. ResultHeader[COL5].pFunction = NULL;
  1475. ResultHeader[COL5].pFunctionData = NULL;
  1476. lstrcpy( ResultHeader[COL5].szFormat, NULL_STRING );
  1477. lstrcpy( ResultHeader[COL5].szColumn,COL_STARTMODE );
  1478. // Forming the State header Column
  1479. ResultHeader[COL6].dwWidth = COL_STATE_WIDTH ;
  1480. if(!bVerbose)
  1481. {
  1482. ResultHeader[COL6].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1483. }
  1484. else
  1485. {
  1486. ResultHeader[COL6].dwFlags = SR_TYPE_STRING;
  1487. }
  1488. ResultHeader[COL6].pFunction = NULL;
  1489. ResultHeader[COL6].pFunctionData = NULL;
  1490. lstrcpy( ResultHeader[COL6].szFormat, NULL_STRING );
  1491. lstrcpy( ResultHeader[COL6].szColumn,COL_STATE );
  1492. // Forming the Status header Column
  1493. ResultHeader[COL7].dwWidth = COL_STATUS_WIDTH;
  1494. if(!bVerbose)
  1495. {
  1496. ResultHeader[COL7].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1497. }
  1498. else
  1499. {
  1500. ResultHeader[COL7].dwFlags = SR_TYPE_STRING;
  1501. }
  1502. ResultHeader[COL7].pFunction = NULL;
  1503. ResultHeader[COL7].pFunctionData = NULL;
  1504. lstrcpy( ResultHeader[COL7].szFormat, NULL_STRING );
  1505. lstrcpy( ResultHeader[COL7].szColumn,COL_STATUS );
  1506. // Forming the AcceptStop header Column
  1507. ResultHeader[COL8].dwWidth = COL_ACCEPTSTOP_WIDTH ;
  1508. if(!bVerbose)
  1509. {
  1510. ResultHeader[COL8].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1511. }
  1512. else
  1513. {
  1514. ResultHeader[COL8].dwFlags = SR_TYPE_STRING;
  1515. }
  1516. ResultHeader[COL8].pFunction = NULL;
  1517. ResultHeader[COL8].pFunctionData = NULL;
  1518. lstrcpy( ResultHeader[COL8].szFormat, NULL_STRING );
  1519. lstrcpy( ResultHeader[COL8].szColumn,COL_ACCEPTSTOP );
  1520. // Forming the AcceptPause header Column
  1521. ResultHeader[COL9].dwWidth = COL_ACCEPTPAUSE_WIDTH;
  1522. if(!bVerbose)
  1523. {
  1524. ResultHeader[COL9].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1525. }
  1526. else
  1527. {
  1528. ResultHeader[COL9].dwFlags = SR_TYPE_STRING;
  1529. }
  1530. ResultHeader[COL9].pFunction = NULL;
  1531. ResultHeader[COL9].pFunctionData = NULL;
  1532. lstrcpy( ResultHeader[COL9].szFormat, NULL_STRING );
  1533. lstrcpy( ResultHeader[COL9].szColumn,COL_ACCEPTPAUSE );
  1534. // Forming the PagedPool header Column
  1535. ResultHeader[COL10].dwWidth = COL_PAGEDPOOL_WIDTH ;
  1536. if(!bVerbose)
  1537. {
  1538. ResultHeader[COL10].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN ;
  1539. }
  1540. else
  1541. {
  1542. ResultHeader[COL10].dwFlags = SR_TYPE_STRING;
  1543. }
  1544. ResultHeader[COL10].pFunction = NULL;
  1545. ResultHeader[COL10].pFunctionData = NULL;
  1546. lstrcpy( ResultHeader[COL10].szFormat, NULL_STRING );
  1547. lstrcpy(ResultHeader[COL10].szColumn,COL_PAGEDPOOL) ;
  1548. // Forming the Executable Code header Column
  1549. ResultHeader[COL11].dwWidth = COL_EXECCODE_WIDTH ;
  1550. if(!bVerbose)
  1551. {
  1552. ResultHeader[COL11].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN ;
  1553. }
  1554. else
  1555. {
  1556. ResultHeader[COL11].dwFlags = SR_TYPE_STRING;
  1557. }
  1558. ResultHeader[COL11].pFunction = NULL;
  1559. ResultHeader[COL11].pFunctionData = NULL;
  1560. lstrcpy( ResultHeader[COL11].szFormat, NULL_STRING );
  1561. lstrcpy(ResultHeader[COL11].szColumn ,COL_EXECCODE) ;
  1562. // Forming the BlockStorage Segment header Column
  1563. ResultHeader[COL12].dwWidth = COL_BSS_WIDTH ;
  1564. if(!bVerbose)
  1565. {
  1566. ResultHeader[COL12].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1567. }
  1568. else
  1569. {
  1570. ResultHeader[COL12].dwFlags = SR_TYPE_STRING ;
  1571. }
  1572. ResultHeader[COL12].pFunction = NULL;
  1573. ResultHeader[COL12].pFunctionData = NULL;
  1574. lstrcpy( ResultHeader[COL12].szFormat, NULL_STRING );
  1575. lstrcpy(ResultHeader[COL12].szColumn ,COL_BSS );
  1576. // Forming the LinkDate header Column
  1577. ResultHeader[COL13].dwWidth = COL_LINKDATE_WIDTH;
  1578. ResultHeader[COL13].dwFlags = SR_TYPE_STRING;
  1579. ResultHeader[COL13].pFunction = NULL;
  1580. ResultHeader[COL13].pFunctionData = NULL;
  1581. lstrcpy( ResultHeader[COL13].szFormat, NULL_STRING );
  1582. lstrcpy( ResultHeader[COL13].szColumn,COL_LINKDATE );
  1583. // Forming the Location header Column
  1584. ResultHeader[COL14].dwWidth = COL_LOCATION_WIDTH ;
  1585. if(!bVerbose)
  1586. {
  1587. ResultHeader[COL14].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1588. }
  1589. else
  1590. {
  1591. ResultHeader[COL14].dwFlags = SR_TYPE_STRING;
  1592. }
  1593. ResultHeader[COL14].pFunction = NULL;
  1594. ResultHeader[COL14].pFunctionData = NULL;
  1595. _tcscpy( ResultHeader[COL14].szFormat, NULL_STRING );
  1596. _tcscpy(ResultHeader[COL14].szColumn,COL_LOCATION);
  1597. // Forming the Init Code header Column
  1598. ResultHeader[COL15].dwWidth = COL_INITSIZE_WIDTH ;
  1599. if(!bVerbose)
  1600. {
  1601. ResultHeader[COL15].dwFlags = SR_TYPE_STRING|SR_HIDECOLUMN;
  1602. }
  1603. else
  1604. {
  1605. ResultHeader[COL15].dwFlags = SR_TYPE_STRING;
  1606. }
  1607. ResultHeader[COL15].pFunction = NULL;
  1608. ResultHeader[COL15].pFunctionData = NULL;
  1609. _tcscpy( ResultHeader[COL15].szFormat, NULL_STRING );
  1610. _tcscpy(ResultHeader[COL15].szColumn,COL_INITSIZE);
  1611. }
  1612. #ifndef _WIN64
  1613. /*-------------------------------------------------------------------------*
  1614. // IsWin64
  1615. //
  1616. // Arguments :
  1617. // none
  1618. // Returns true if we're running on Win64, false otherwise.
  1619. *--------------------------------------------------------------------------*/
  1620. BOOL IsWin64(void)
  1621. {
  1622. #ifdef UNICODE
  1623. // get a pointer to kernel32!GetSystemWow64Directory
  1624. HMODULE hmod = GetModuleHandle (_T("kernel32.dll"));
  1625. if (hmod == NULL)
  1626. return (FALSE);
  1627. UINT (WINAPI* pfnGetSystemWow64Directory)(LPTSTR, UINT);
  1628. (FARPROC&)pfnGetSystemWow64Directory = GetProcAddress (hmod, "GetSystemWow64DirectoryW");
  1629. if (pfnGetSystemWow64Directory == NULL)
  1630. return (FALSE);
  1631. /*
  1632. * if GetSystemWow64Directory fails and sets the last error to
  1633. * ERROR_CALL_NOT_IMPLEMENTED, we're on a 32-bit OS
  1634. */
  1635. TCHAR szWow64Dir[MAX_PATH];
  1636. if (((pfnGetSystemWow64Directory)(szWow64Dir, countof(szWow64Dir)) == 0) &&
  1637. (GetLastError() == ERROR_CALL_NOT_IMPLEMENTED))
  1638. {
  1639. return (FALSE);
  1640. }
  1641. // we're on Win64
  1642. return (TRUE);
  1643. #else
  1644. // non-Unicode platforms cannot be Win64
  1645. return (FALSE);
  1646. #endif // UNICODE
  1647. }
  1648. #endif // _WIN64
  1649. /*-------------------------------------------------------------------
  1650. Routine Description:
  1651. Formats the Number to the locale with thousands position
  1652. Arguments:
  1653. NUMBERFMT *pNumberFmt[in] - NUMBERFMT Structure to be filled with .
  1654. Return Value:
  1655. VOID
  1656. --------------------------------------------------------------------*/
  1657. BOOL FormatAccToLocale( NUMBERFMT *pNumberFmt,LPTSTR* pszGroupSep,LPTSTR* pszDecimalSep,LPTSTR* pszGroupThousSep)
  1658. {
  1659. TCHAR szFormatedString[MAX_RES_STRING + 1] = NULL_STRING;
  1660. HRESULT hResult = 0;
  1661. DWORD dwLocale = 0;
  1662. if( GetInfo( LOCALE_SGROUPING, pszGroupSep ) == FALSE)
  1663. {
  1664. pNumberFmt = NULL;
  1665. return FALSE ;
  1666. }
  1667. if( GetInfo( LOCALE_SDECIMAL, pszDecimalSep ) == FALSE)
  1668. {
  1669. pNumberFmt = NULL;
  1670. return FALSE ;
  1671. }
  1672. if( GetInfo( LOCALE_STHOUSAND, pszGroupThousSep ) == FALSE)
  1673. {
  1674. pNumberFmt = NULL;
  1675. return FALSE ;
  1676. }
  1677. if(pNumberFmt != NULL)
  1678. {
  1679. pNumberFmt->LeadingZero = 0;
  1680. pNumberFmt->NegativeOrder = 0;
  1681. pNumberFmt->NumDigits = 0;
  1682. if(lstrcmp(*pszGroupSep, GROUP_FORMAT_32) == 0)
  1683. {
  1684. pNumberFmt->Grouping = GROUP_32_VALUE;
  1685. }
  1686. else
  1687. {
  1688. pNumberFmt->Grouping = UINT( _ttoi( *pszGroupSep ) );
  1689. }
  1690. pNumberFmt->lpDecimalSep = *pszDecimalSep;
  1691. pNumberFmt->lpThousandSep = *pszGroupThousSep;
  1692. }
  1693. return TRUE ;
  1694. }
  1695. /*-------------------------------------------------------------------
  1696. //
  1697. //Routine Description:
  1698. //
  1699. //Gets the Locale information
  1700. //
  1701. //Arguments:
  1702. //
  1703. // LCTYPE lctype [in] -- Locale Information to get
  1704. // LPTSTR* pszData [out] -- Locale value corresponding to the given
  1705. // information
  1706. //
  1707. // Return Value:
  1708. // BOOL
  1709. //--------------------------------------------------------------------*/
  1710. BOOL GetInfo( LCTYPE lctype, LPTSTR* pszData )
  1711. {
  1712. LONG lSize = 0;
  1713. // get the locale specific info
  1714. lSize = GetLocaleInfo( LOCALE_USER_DEFAULT, lctype, NULL, 0 );
  1715. if ( lSize != 0 )
  1716. {
  1717. *pszData = (LPTSTR)malloc((lSize + 1)*sizeof(TCHAR));
  1718. if ( *pszData != NULL )
  1719. {
  1720. // get the locale specific time seperator
  1721. GetLocaleInfo( LOCALE_USER_DEFAULT, lctype, *pszData, lSize );
  1722. return TRUE;
  1723. }
  1724. }
  1725. return FALSE;
  1726. }//end of GetInfo
  1727. /*-------------------------------------------------------------------
  1728. //
  1729. //Routine Description:
  1730. //
  1731. //Gets the type os the specified System ( 32 bit or 64 bit)
  1732. //
  1733. //Arguments:
  1734. //
  1735. // IWbemLocator *pLocator[in] -- Pointer to the locator interface.
  1736. // _bstr_t bstrServer[in] -- Server Name
  1737. // _bstr_t bstrUserName[in] -- User Name
  1738. // _bstr_t bstrPassword [in] -- Password
  1739. // information
  1740. //
  1741. // Return Value:
  1742. // DWORD : SYSTEM_32_BIT -- If the system is 32 bit system.
  1743. // SYSTEM_64_BIT -- If the system is 32 bit system.
  1744. // ERROR_WMI_VALUES -- If error occured while retreiving values from WMI.
  1745. //--------------------------------------------------------------------*/
  1746. DWORD GetSystemType(COAUTHIDENTITY* pAuthIdentity,IWbemServices* pIWbemServReg)
  1747. {
  1748. IWbemClassObject * pInClass = NULL;
  1749. IWbemClassObject * pClass = NULL;
  1750. IWbemClassObject * pOutInst = NULL;
  1751. IWbemClassObject * pInInst = NULL;
  1752. VARIANT varConnectName;
  1753. VARIANT varSvalue ;
  1754. VARIANT varHkey;
  1755. VARIANT varVaue ;
  1756. VARIANT varRetVal ;
  1757. HRESULT hRes = S_OK;
  1758. LPTSTR szSysName = NULL ;
  1759. CHString szSystemName ;
  1760. DWORD dwSysType = 0 ;
  1761. VariantInit(&varConnectName) ;
  1762. VariantInit(&varSvalue) ;
  1763. VariantInit(&varHkey) ;
  1764. VariantInit(&varVaue) ;
  1765. VariantInit(&varRetVal) ;
  1766. try
  1767. {
  1768. hRes = pIWbemServReg->GetObject(bstr_t(STD_REG_CLASS), 0, NULL, &pClass, NULL);
  1769. ONFAILTHROWERROR(hRes);
  1770. if(hRes != WBEM_S_NO_ERROR)
  1771. {
  1772. hRes = FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1773. return (ERROR_WMI_VALUES);
  1774. }
  1775. // Get the input argument and set the property
  1776. hRes = pClass->GetMethod(_bstr_t(PROPERTY_GETSTRINGVAL), 0, &pInClass, NULL);
  1777. ONFAILTHROWERROR(hRes);
  1778. if(hRes != WBEM_S_NO_ERROR)
  1779. {
  1780. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1781. return (ERROR_WMI_VALUES);
  1782. }
  1783. hRes = pInClass->SpawnInstance(0, &pInInst);
  1784. ONFAILTHROWERROR(hRes);
  1785. if(hRes != WBEM_S_NO_ERROR)
  1786. {
  1787. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1788. return (ERROR_WMI_VALUES);
  1789. }
  1790. //the registry path to get the connection name
  1791. varConnectName.vt = VT_BSTR;
  1792. varConnectName.bstrVal= SysAllocString(REG_PATH);
  1793. hRes = pInInst->Put(REG_SUB_KEY_VALUE, 0, &varConnectName, 0);
  1794. ONFAILTHROWERROR(hRes);
  1795. //set the svalue name
  1796. varSvalue.vt = VT_BSTR;
  1797. varSvalue.bstrVal= SysAllocString(REG_SVALUE);
  1798. hRes = pInInst->Put(REG_VALUE_NAME, 0, &varSvalue, 0);
  1799. ONFAILTHROWERROR(hRes);
  1800. varHkey.vt = VT_I4 ;
  1801. varHkey.lVal = HEF_KEY_VALUE;
  1802. hRes = pInInst->Put(HKEY_VALUE, 0, &varHkey, 0);
  1803. ONFAILTHROWERROR(hRes);
  1804. // Call the method
  1805. hRes = pIWbemServReg->ExecMethod(_bstr_t(STD_REG_CLASS), _bstr_t(REG_METHOD), 0, NULL, pInInst, &pOutInst, NULL);
  1806. ONFAILTHROWERROR(hRes);
  1807. if(pOutInst == NULL)
  1808. {
  1809. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1810. return (ERROR_WMI_VALUES);
  1811. }
  1812. hRes = pOutInst->Get(PROPERTY_RETURNVAL,0,&varRetVal,NULL,NULL);
  1813. ONFAILTHROWERROR(hRes);
  1814. if(varRetVal.lVal != 0)
  1815. {
  1816. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1817. return (ERROR_WMI_VALUES);
  1818. }
  1819. hRes = pOutInst->Get(REG_RETURN_VALUE,0,&varVaue,NULL,NULL);
  1820. ONFAILTHROWERROR(hRes);
  1821. if(hRes != WBEM_S_NO_ERROR)
  1822. {
  1823. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1824. return (ERROR_WMI_VALUES);
  1825. }
  1826. }
  1827. catch(_com_error)
  1828. {
  1829. DISPLAY_MESSAGE(stderr,ERROR_GET_VALUE);
  1830. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1831. return (ERROR_WMI_VALUES);
  1832. }
  1833. szSystemName = V_BSTR(&varVaue);
  1834. szSysName = (LPTSTR)malloc((MAX_RES_STRING)*sizeof(TCHAR));
  1835. if(szSysName == NULL)
  1836. {
  1837. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1838. return (ERROR_WMI_VALUES);
  1839. }
  1840. GetCompatibleStringFromUnicode( szSystemName, szSysName, wcslen( szSystemName )+2 );
  1841. dwSysType = _tcsstr(szSysName,X86_MACHINE) ? SYSTEM_32_BIT:SYSTEM_64_BIT ;
  1842. FreeMemory(pInClass,pClass,pOutInst,pInInst,pIWbemServReg,varConnectName,varSvalue,varHkey,varRetVal,varVaue,szSysName );
  1843. return (dwSysType);
  1844. }
  1845. /*-------------------------------------------------------------------
  1846. //
  1847. //Routine Description:
  1848. //
  1849. //Gets the type os the specified System ( 32 bit or 64 bit)
  1850. //
  1851. //Arguments:
  1852. //
  1853. // IWbemLocator** pLocator[in] -- Pointer to the locator interface.
  1854. //
  1855. //
  1856. //
  1857. // information
  1858. //
  1859. // Return Value:
  1860. // BOOL : TRUE on Successfully initialising COM.
  1861. // FALSE on Failure to initialise COM.
  1862. //
  1863. //
  1864. //
  1865. //--------------------------------------------------------------------*/
  1866. BOOL InitialiseCom(IWbemLocator** ppIWbemLocator)
  1867. {
  1868. HRESULT hRes = S_OK ;
  1869. try
  1870. {
  1871. // To initialize the COM library.
  1872. hRes = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED );
  1873. ONFAILTHROWERROR(hRes);
  1874. // Initialize COM security for DCOM services, Adjust security to
  1875. // allow client impersonation
  1876. hRes = CoInitializeSecurity( NULL, -1, NULL, NULL,
  1877. RPC_C_AUTHN_LEVEL_NONE,
  1878. RPC_C_IMP_LEVEL_IMPERSONATE,
  1879. NULL,
  1880. EOAC_NONE, 0 );
  1881. ONFAILTHROWERROR(hRes);
  1882. // get a pointer to the Interface IWbemLocator
  1883. hRes = CoCreateInstance(CLSID_WbemLocator, NULL,
  1884. CLSCTX_INPROC_SERVER, IID_IWbemLocator, (LPVOID *) ppIWbemLocator);
  1885. ONFAILTHROWERROR(hRes);
  1886. }
  1887. catch(_com_error& e )
  1888. {
  1889. GetWbemErrorText( e.Error() );
  1890. DISPLAY_MESSAGE( stderr, ERROR_TAG );
  1891. DISPLAY_MESSAGE( stderr, GetReason() );
  1892. return( FALSE );
  1893. }
  1894. // if successfully initialised COM then return true
  1895. return TRUE ;
  1896. }
  1897. /*-------------------------------------------------------------------
  1898. //
  1899. //Routine Description:
  1900. //
  1901. // To perform the Get .
  1902. //
  1903. //Arguments:
  1904. //
  1905. // IWbemClassObject** pWmiObject[in] -- Pointer to the locator interface.
  1906. // LPCTSTR pszInputVal[in] -- Input string containing the desired value.
  1907. // CHString szOutPutVal[out]-- String containing the retreived value.
  1908. //
  1909. // information
  1910. //
  1911. // Return Value:
  1912. // BOOL : TRUE on Successfully initialising COM.
  1913. // FALSE on Failure to initialise COM.
  1914. //
  1915. //
  1916. //
  1917. //--------------------------------------------------------------------*/
  1918. HRESULT PropertyGet(IWbemClassObject* pWmiObject,LPCTSTR pszInputVal,CHString &szOutPutVal)
  1919. {
  1920. HRESULT hRes = S_FALSE ;
  1921. VARIANT vtValue ;
  1922. VariantInit(&vtValue);
  1923. hRes = pWmiObject->Get(pszInputVal,0,&vtValue,NULL,NULL);
  1924. if (hRes != WBEM_S_NO_ERROR)
  1925. {
  1926. hRes = VariantClear(&vtValue);
  1927. return (hRes);
  1928. }
  1929. if ((hRes == WBEM_S_NO_ERROR)&&(vtValue.vt != VT_NULL) && (vtValue.vt != VT_EMPTY))
  1930. {
  1931. szOutPutVal = (LPCWSTR)_bstr_t(vtValue);
  1932. }
  1933. hRes = VariantClear(&vtValue);
  1934. if(hRes != S_OK)
  1935. {
  1936. return hRes ;
  1937. }
  1938. return TRUE ;
  1939. }
  1940. // ***************************************************************************
  1941. // Routine Description:
  1942. // This function frees the memory allocated in the function.
  1943. //
  1944. // Arguments:
  1945. // IWbemClassObject *pInClass - Interface ptr pointing to the IWbemClassObject interface
  1946. // IWbemClassObject * pClass - Interface ptr pointing to the IWbemClassObject interface
  1947. // IWbemClassObject * pOutInst - Interface ptr pointing to the IWbemClassObject interface
  1948. // IWbemClassObject * pInInst - Interface ptr pointing to the IWbemClassObject interface
  1949. // IWbemServices *pIWbemServReg - Interface ptr pointing to the IWbemServices interface
  1950. // VARIANT varConnectName - variant
  1951. // VARIANT varSvalue - variant
  1952. // VARIANT varHkey - variant
  1953. // VARIANT varRetVal - variant
  1954. // VARIANT varVaue - variant
  1955. // LPTSTR szSysName - LPTSTR varaible containing the system name.
  1956. // Return Value:
  1957. // None
  1958. // ***************************************************************************
  1959. HRESULT FreeMemory(IWbemClassObject *pInClass,IWbemClassObject * pClass,IWbemClassObject * pOutInst ,
  1960. IWbemClassObject * pInInst,IWbemServices *pIWbemServReg,VARIANT varConnectName,VARIANT varSvalue,VARIANT varHkey,VARIANT varRetVal,VARIANT varVaue,LPTSTR szSysName )
  1961. {
  1962. HRESULT hRes = S_OK ;
  1963. SAFEIRELEASE(pInInst);
  1964. SAFEIRELEASE(pInClass);
  1965. SAFEIRELEASE(pClass);
  1966. SAFEIRELEASE(pIWbemServReg);
  1967. SAFEFREE(szSysName);
  1968. hRes = VariantClear(&varConnectName);
  1969. if(hRes != S_OK)
  1970. {
  1971. return hRes ;
  1972. }
  1973. hRes = VariantClear(&varSvalue);
  1974. if(hRes != S_OK)
  1975. {
  1976. return hRes ;
  1977. }
  1978. hRes = VariantClear(&varHkey);
  1979. if(hRes != S_OK)
  1980. {
  1981. return hRes ;
  1982. }
  1983. hRes = VariantClear(&varVaue);
  1984. if(hRes != S_OK)
  1985. {
  1986. return hRes ;
  1987. }
  1988. hRes = VariantClear(&varRetVal);
  1989. if(hRes != S_OK)
  1990. {
  1991. return hRes ;
  1992. }
  1993. return S_OK ;
  1994. }
  1995. // ***************************************************************************
  1996. // Routine Description:
  1997. // Processes enumeration of Win32_PnpSignedDriver instances
  1998. //
  1999. // Arguments:
  2000. // [ in ] szHost : HostName to connect to
  2001. // [ in ] pSystemSet : pointer to the structure containing system properties.
  2002. // [ in ] szFormat : specifies the format
  2003. // [ in ] bHeader : specifies if the header is required or not.
  2004. //
  2005. // Return Value:
  2006. // 0 no error
  2007. // 1 error occured while allocating memory.
  2008. //
  2009. // ***************************************************************************
  2010. DWORD ProcessSignedDriverInfo(CHString szHost, IEnumWbemClassObject *pSystemSet,LPTSTR szFormat,BOOL bHeader,DWORD dwSystemType,BOOL bVerbose)
  2011. {
  2012. HRESULT hRes = S_OK;
  2013. ULONG ulReturned = 1;
  2014. //declaration of normal variables
  2015. IWbemClassObject *pSystem = NULL;
  2016. CHString szPnpDeviceName ;
  2017. CHString szPnpInfName ;
  2018. CHString szPnpMfg ;
  2019. CHString szSigned ;
  2020. BOOL bIsSigned = FALSE;
  2021. TCOLUMNS ResultHeader[ MAX_COLUMNS ];
  2022. TARRAY arrResults = NULL;
  2023. DWORD dwRow = 0;
  2024. DWORD dwFormatType = SR_FORMAT_TABLE ;
  2025. BOOL bVersion = FALSE ;
  2026. // Create new Dynamic Array to hold the result
  2027. arrResults = CreateDynamicArray();
  2028. if(arrResults == NULL)
  2029. {
  2030. return EXIT_FAILURE_MALLOC ;
  2031. }
  2032. if( StringCompare(szFormat,TABLE_FORMAT, TRUE,sizeof(TABLE_FORMAT)) == 0 )
  2033. {
  2034. dwFormatType = SR_FORMAT_TABLE;
  2035. }
  2036. else if( StringCompare(szFormat,LIST_FORMAT, TRUE,sizeof(LIST_FORMAT)) == 0 )
  2037. {
  2038. dwFormatType = SR_FORMAT_LIST;
  2039. }
  2040. else if( StringCompare(szFormat,CSV_FORMAT, TRUE,sizeof(CSV_FORMAT)) == 0 )
  2041. {
  2042. dwFormatType = SR_FORMAT_CSV;
  2043. }
  2044. FormSignedHeader(dwFormatType,bHeader,ResultHeader);
  2045. // loop till there are results.
  2046. while ( ulReturned == 1 )
  2047. {
  2048. szPnpDeviceName = NO_DATA_AVAILABLE;
  2049. szPnpInfName = NO_DATA_AVAILABLE;
  2050. szSigned = NO_DATA_AVAILABLE ;
  2051. szPnpMfg = NO_DATA_AVAILABLE ;
  2052. // Enumerate through the resultset.
  2053. hRes = pSystemSet->Next(WBEM_INFINITE,
  2054. 1, // return just one system
  2055. &pSystem, // pointer to system
  2056. &ulReturned ); // number obtained: one or zero
  2057. if ( SUCCEEDED( hRes ) && (ulReturned == 1) )
  2058. {
  2059. // initialise the variant variables to empty
  2060. //create a new empty row with required no of columns
  2061. dwRow = DynArrayAppendRow(arrResults,MAX_COLUMNS) ;
  2062. try
  2063. {
  2064. hRes = PropertyGet(pSystem,PROPERTY_PNP_DEVICENAME,szPnpDeviceName);
  2065. ONFAILTHROWERROR(hRes);
  2066. hRes = PropertyGet(pSystem,PROPERTY_PNP_INFNAME,szPnpInfName);
  2067. ONFAILTHROWERROR(hRes);
  2068. hRes = PropertyGet_Bool(pSystem,PROPERTY_PNP_ISSIGNED,&bIsSigned);
  2069. ONFAILTHROWERROR(hRes);
  2070. hRes = PropertyGet(pSystem,PROPERTY_PNP_MFG,szPnpMfg);
  2071. ONFAILTHROWERROR(hRes);
  2072. }
  2073. catch(_com_error)
  2074. {
  2075. DISPLAY_MESSAGE(stderr,ERROR_GET_VALUE);
  2076. SAFEIRELEASE(pSystem);
  2077. return FAILURE;
  2078. }
  2079. // free the allocated memory
  2080. SAFEIRELEASE(pSystem);
  2081. if(bIsSigned)
  2082. szSigned = TRUE_VALUE;
  2083. else
  2084. szSigned = FALSE_VALUE;
  2085. DynArraySetString2( arrResults,dwRow,COL0,szPnpDeviceName,0 );
  2086. DynArraySetString2( arrResults,dwRow,COL1,szPnpInfName,0 );
  2087. DynArraySetString2( arrResults,dwRow,COL2,szSigned,0 );
  2088. DynArraySetString2( arrResults,dwRow,COL3,szPnpMfg,0 );
  2089. //this flag is to check if there are any results
  2090. //else display an error message.
  2091. bVersion = TRUE ;
  2092. } // If System Succeeded
  2093. }// While SystemSet returning objects
  2094. if (bVersion == FALSE)
  2095. {
  2096. //
  2097. // To display custom message in case the remote system is Win2k
  2098. // System.
  2099. if( hRes == -2147217392)
  2100. {
  2101. DISPLAY_MESSAGE(stderr,GetResString(IDS_VERSION_MISMATCH_ERROR));
  2102. DestroyDynamicArray(&arrResults);
  2103. // free the allocated memory
  2104. SAFEIRELEASE(pSystem);
  2105. return FAILURE ;
  2106. }
  2107. //display a error message
  2108. GetWbemErrorText(hRes);
  2109. DISPLAY_MESSAGE(stderr,ERROR_TAG);
  2110. DISPLAY_MESSAGE(stderr,GetReason());
  2111. SAFEIRELEASE(pSystem);
  2112. return FAILURE;
  2113. }
  2114. ShowMessage( stdout, _T( "\n" ) );
  2115. if(bHeader)
  2116. {
  2117. ShowResults(MAX_SIGNED_COLUMNS, ResultHeader, dwFormatType|SR_NOHEADER,arrResults ) ;
  2118. }
  2119. else
  2120. {
  2121. ShowResults(MAX_SIGNED_COLUMNS, ResultHeader, dwFormatType,arrResults ) ;
  2122. }
  2123. DestroyDynamicArray(&arrResults);
  2124. // free the allocated memory
  2125. SAFEIRELEASE(pSystem);
  2126. return SUCCESS ;
  2127. }
  2128. /*-------------------------------------------------------------------
  2129. //
  2130. //Routine Description:
  2131. //
  2132. // To perform the Get .
  2133. //
  2134. //Arguments:
  2135. //
  2136. // IWbemClassObject** pWmiObject[in] -- Pointer to the locator interface.
  2137. // LPCTSTR pszInputVal[in] -- Input string containing the desired value.
  2138. // PBOOL pIsSigned[out]-- String containing the retreived value.
  2139. //
  2140. // information
  2141. //
  2142. // Return Value:
  2143. // HRESULT : hRes on Successfully retreiving the value.
  2144. // S_FALSE on Failure in retreiving the value.
  2145. //
  2146. //
  2147. //
  2148. //--------------------------------------------------------------------*/
  2149. HRESULT PropertyGet_Bool(IWbemClassObject* pWmiObject, LPCTSTR pszInputVal, PBOOL pIsSigned)
  2150. {
  2151. HRESULT hRes = S_FALSE ;
  2152. VARIANT vtValue ;
  2153. VariantInit(&vtValue);
  2154. hRes = pWmiObject->Get(pszInputVal,0,&vtValue,NULL,NULL);
  2155. if (hRes != WBEM_S_NO_ERROR)
  2156. {
  2157. hRes = VariantClear(&vtValue);
  2158. return (hRes);
  2159. }
  2160. if ((hRes == WBEM_S_NO_ERROR)&&(vtValue.vt != VT_NULL) && (vtValue.vt != VT_EMPTY))
  2161. {
  2162. if(vtValue.vt == VT_BOOL)
  2163. if(vtValue.boolVal == -1)
  2164. *pIsSigned = 1;
  2165. else
  2166. *pIsSigned = 0;
  2167. hRes = VariantClear(&vtValue);
  2168. if(hRes != S_OK)
  2169. {
  2170. return hRes ;
  2171. }
  2172. return TRUE ;
  2173. }
  2174. hRes = VariantClear(&vtValue);
  2175. return S_FALSE ;
  2176. }
  2177. // ***************************************************************************
  2178. // Routine Description:
  2179. // This function is used to build the header and also display the
  2180. // result in the required format as specified by the user.
  2181. //
  2182. // Arguments:
  2183. // [ in ] arrResults : argument(s) count specified at the command prompt
  2184. // [ in ] dwFormatType : format flags
  2185. // [ in ] bHeader : Boolean for specifying if the header is required or not.
  2186. //
  2187. // Return Value:
  2188. // none
  2189. //
  2190. // ***************************************************************************
  2191. VOID FormSignedHeader(DWORD dwFormatType,BOOL bHeader,TCOLUMNS *ResultHeader)
  2192. {
  2193. // Device name
  2194. ResultHeader[COL0].dwWidth = COL_DEVICE_WIDTH ;
  2195. ResultHeader[COL0].dwFlags = SR_TYPE_STRING;
  2196. ResultHeader[COL0].pFunction = NULL;
  2197. ResultHeader[COL0].pFunctionData = NULL;
  2198. lstrcpy( ResultHeader[COL0].szFormat, NULL_STRING );
  2199. lstrcpy( ResultHeader[COL0].szColumn,COL_DEVICENAME );
  2200. //Inf header
  2201. ResultHeader[COL1].dwWidth = COL_INF_WIDTH ;
  2202. ResultHeader[COL1].dwFlags = SR_TYPE_STRING;
  2203. ResultHeader[COL1].pFunction = NULL;
  2204. ResultHeader[COL1].pFunctionData = NULL;
  2205. lstrcpy( ResultHeader[COL1].szFormat, NULL_STRING );
  2206. lstrcpy( ResultHeader[COL1].szColumn,COL_INF_NAME );
  2207. // Forming the IsSigned header Column
  2208. ResultHeader[COL2].dwWidth = COL_ISSIGNED_WIDTH ;
  2209. ResultHeader[COL2].dwFlags = SR_TYPE_STRING;
  2210. ResultHeader[COL2].pFunction = NULL;
  2211. ResultHeader[COL2].pFunctionData = NULL;
  2212. lstrcpy( ResultHeader[COL2].szFormat, NULL_STRING );
  2213. lstrcpy( ResultHeader[COL2].szColumn,COL_ISSIGNED );
  2214. // Forming the Manufacturer header Column
  2215. ResultHeader[COL3].dwWidth = COL_MANUFACTURER_WIDTH ;
  2216. ResultHeader[COL3].dwFlags = SR_TYPE_STRING;
  2217. ResultHeader[COL3].pFunction = NULL;
  2218. ResultHeader[COL3].pFunctionData = NULL;
  2219. lstrcpy( ResultHeader[COL3].szFormat, NULL_STRING );
  2220. lstrcpy( ResultHeader[COL3].szColumn,COL_MANUFACTURER);
  2221. }
  2222. // ***************************************************************************
  2223. // Routine Description: This function checks if the current locale is supported or not.
  2224. //
  2225. // Arguments: [input] bLocaleChanged
  2226. //
  2227. // Return Value: LCID of the current locale.
  2228. //
  2229. // ***************************************************************************
  2230. LCID GetSupportedUserLocale( BOOL& bLocaleChanged )
  2231. {
  2232. // local variables
  2233. LCID lcid;
  2234. // get the current locale
  2235. lcid = GetUserDefaultLCID();
  2236. // check whether the current locale is supported by our tool or not
  2237. // if not change the locale to the english which is our default locale
  2238. bLocaleChanged = FALSE;
  2239. if ( PRIMARYLANGID( lcid ) == LANG_ARABIC || PRIMARYLANGID( lcid ) == LANG_HEBREW ||
  2240. PRIMARYLANGID( lcid ) == LANG_THAI || PRIMARYLANGID( lcid ) == LANG_HINDI ||
  2241. PRIMARYLANGID( lcid ) == LANG_TAMIL || PRIMARYLANGID( lcid ) == LANG_FARSI )
  2242. {
  2243. bLocaleChanged = TRUE;
  2244. lcid = MAKELCID( MAKELANGID( LANG_ENGLISH, SUBLANG_DEFAULT ), SORT_DEFAULT ); // 0x409;
  2245. }
  2246. // return the locale
  2247. return lcid;
  2248. }