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.

792 lines
23 KiB

  1. //
  2. // LOGFILE.C
  3. //
  4. #include "sigverif.h"
  5. //
  6. // We need to remember the previous logging state when we do toggling.
  7. //
  8. BOOL g_bPrevLoggingEnabled = FALSE;
  9. BOOL LogFile_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
  10. {
  11. TCHAR szBuffer[MAX_PATH];
  12. if (g_App.hIcon) {
  13. SetWindowLongPtr(hwnd, GCLP_HICON, (LONG_PTR) g_App.hIcon);
  14. }
  15. g_App.hLogging = hwnd;
  16. g_bPrevLoggingEnabled = g_App.bLoggingEnabled;
  17. if (GetWindowsDirectory(szBuffer, MAX_PATH)) {
  18. SetCurrentDirectory(szBuffer);
  19. }
  20. SetDlgItemText(hwnd, IDC_LOGNAME, g_App.szLogFile);
  21. CheckDlgButton(hwnd, IDC_ENABLELOG, g_App.bLoggingEnabled ? BST_CHECKED : BST_UNCHECKED);
  22. EnableWindow(GetDlgItem(hwnd, IDC_VIEWLOG), g_App.bLoggingEnabled && EXIST(g_App.szLogFile));
  23. CheckRadioButton(hwnd, IDC_OVERWRITE, IDC_APPEND, g_App.bOverwrite ? IDC_OVERWRITE : IDC_APPEND);
  24. EnableWindow(GetDlgItem(hwnd, IDC_APPEND), g_App.bLoggingEnabled);
  25. EnableWindow(GetDlgItem(hwnd, IDC_OVERWRITE), g_App.bLoggingEnabled);
  26. EnableWindow(GetDlgItem(hwnd, IDC_LOGNAME), g_App.bLoggingEnabled);
  27. SetForegroundWindow(g_App.hDlg);
  28. SetForegroundWindow(hwnd);
  29. return TRUE;
  30. }
  31. void LogFile_UpdateDialog(HWND hwnd)
  32. {
  33. TCHAR szBuffer[MAX_PATH];
  34. if (GetDlgItemText(hwnd, IDC_LOGNAME, szBuffer, MAX_PATH)) {
  35. EnableWindow(GetDlgItem(hwnd, IDC_VIEWLOG), g_App.bLoggingEnabled && EXIST(szBuffer));
  36. } else {
  37. EnableWindow(GetDlgItem(hwnd, IDC_VIEWLOG), FALSE);
  38. }
  39. EnableWindow(GetDlgItem(hwnd, IDC_APPEND), g_App.bLoggingEnabled);
  40. EnableWindow(GetDlgItem(hwnd, IDC_OVERWRITE), g_App.bLoggingEnabled);
  41. EnableWindow(GetDlgItem(hwnd, IDC_LOGNAME), g_App.bLoggingEnabled);
  42. }
  43. void LogFile_OnViewLog(HWND hwnd)
  44. {
  45. TCHAR szDirName[MAX_PATH];
  46. TCHAR szFileName[MAX_PATH];
  47. if (!GetWindowsDirectory(szDirName, MAX_PATH)) {
  48. szDirName[0] = TEXT('\0');
  49. }
  50. if (!GetDlgItemText(hwnd, IDC_LOGNAME, szFileName, MAX_PATH)) {
  51. MyErrorBoxId(IDS_BADLOGNAME);
  52. return;
  53. }
  54. ShellExecute(hwnd, NULL, szFileName, NULL, szDirName, SW_SHOW);
  55. }
  56. BOOL LogFile_VerifyLogFile(HWND hwnd, LPTSTR lpFileName, BOOL bNoisy)
  57. {
  58. TCHAR szFileName[MAX_PATH];
  59. HANDLE hFile;
  60. BOOL bRet;
  61. HWND hTemp;
  62. ZeroMemory(szFileName, sizeof(szFileName));
  63. bRet = GetDlgItemText(hwnd, IDC_LOGNAME, szFileName, MAX_PATH);
  64. if (bRet) {
  65. hFile = CreateFile( szFileName,
  66. GENERIC_READ | GENERIC_WRITE,
  67. FILE_SHARE_READ,
  68. NULL,
  69. OPEN_EXISTING,
  70. FILE_ATTRIBUTE_NORMAL,
  71. NULL);
  72. if (hFile != INVALID_HANDLE_VALUE) {
  73. CloseHandle(hFile);
  74. } else {
  75. hFile = CreateFile( szFileName,
  76. GENERIC_READ | GENERIC_WRITE,
  77. FILE_SHARE_READ,
  78. NULL,
  79. CREATE_NEW,
  80. FILE_ATTRIBUTE_NORMAL,
  81. NULL);
  82. if (hFile != INVALID_HANDLE_VALUE) {
  83. CloseHandle(hFile);
  84. DeleteFile(szFileName);
  85. } else {
  86. //
  87. // If we couldn't open an existing file and we couldn't create a new one, then we fail.
  88. //
  89. bRet = FALSE;
  90. }
  91. }
  92. }
  93. if (!bRet && bNoisy) {
  94. //
  95. // Since we don't want to lose focus, we are going to temporarily change g_App.hDlg. JasKey, I apologize.
  96. //
  97. hTemp = g_App.hDlg;
  98. g_App.hDlg = hwnd;
  99. MyErrorBoxId(IDS_BADLOGNAME);
  100. g_App.hDlg = hTemp;
  101. }
  102. //
  103. // If everything worked and the user wants the file name, copy it into lpFileName
  104. //
  105. if (bRet && lpFileName && *szFileName) {
  106. lstrcpy(lpFileName, szFileName);
  107. }
  108. return bRet;
  109. }
  110. BOOL LogFile_OnOK(HWND hwnd)
  111. {
  112. HKEY hKey;
  113. LONG lRes;
  114. DWORD dwDisp, dwType, dwFlags, cbData;
  115. TCHAR szFileName[MAX_PATH];
  116. ZeroMemory(szFileName, sizeof(szFileName));
  117. if (LogFile_VerifyLogFile(hwnd, szFileName, FALSE)) {
  118. //
  119. // The file is OK to append or overwrite.
  120. //
  121. lstrcpy(g_App.szLogFile, szFileName);
  122. } else {
  123. return FALSE;
  124. }
  125. g_App.bOverwrite = IsDlgButtonChecked(hwnd, IDC_OVERWRITE);
  126. //
  127. // Look in the registry for any settings from the last SigVerif session
  128. //
  129. lRes = RegCreateKeyEx( SIGVERIF_HKEY,
  130. SIGVERIF_KEY,
  131. 0,
  132. NULL,
  133. 0,
  134. KEY_ALL_ACCESS,
  135. NULL,
  136. &hKey,
  137. &dwDisp);
  138. if (lRes == ERROR_SUCCESS) {
  139. cbData = sizeof(DWORD);
  140. dwFlags = 0;
  141. if (g_App.bLoggingEnabled) {
  142. dwFlags = 0x1;
  143. }
  144. if (g_App.bOverwrite) {
  145. dwFlags |= 0x2;
  146. }
  147. dwType = REG_DWORD;
  148. lRes = RegSetValueEx( hKey,
  149. SIGVERIF_FLAGS,
  150. 0,
  151. dwType,
  152. (LPBYTE) &dwFlags,
  153. cbData);
  154. dwType = REG_SZ;
  155. cbData = MAX_PATH;
  156. lRes = RegSetValueEx( hKey,
  157. SIGVERIF_LOGNAME,
  158. 0,
  159. dwType,
  160. (LPBYTE) g_App.szLogFile,
  161. cbData);
  162. RegCloseKey(hKey);
  163. }
  164. return TRUE;
  165. }
  166. void LogFile_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
  167. {
  168. switch (id) {
  169. case IDC_VIEWLOG:
  170. LogFile_OnViewLog(hwnd);
  171. break;
  172. case IDC_ENABLELOG:
  173. g_App.bLoggingEnabled = !g_App.bLoggingEnabled;
  174. //
  175. // Fall through to update...
  176. //
  177. default:
  178. LogFile_UpdateDialog(hwnd);
  179. }
  180. }
  181. //
  182. // This function handles any notification messages for the Search page.
  183. //
  184. LRESULT LogFile_NotifyHandler(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  185. {
  186. NMHDR *lpnmhdr = (NMHDR *) lParam;
  187. LRESULT lResult;
  188. BOOL bRet;
  189. switch (lpnmhdr->code) {
  190. case PSN_APPLY:
  191. if (LogFile_OnOK(hwnd)) {
  192. lResult = PSNRET_NOERROR;
  193. } else {
  194. lResult = PSNRET_INVALID_NOCHANGEPAGE;
  195. }
  196. SetWindowLongPtr(hwnd,
  197. DWLP_MSGRESULT,
  198. (LONG_PTR) lResult);
  199. return lResult;
  200. case PSN_KILLACTIVE:
  201. bRet = !LogFile_VerifyLogFile(hwnd, NULL, TRUE);
  202. if (bRet) {
  203. SetForegroundWindow(g_App.hLogging);
  204. SetFocus(GetDlgItem(g_App.hLogging, IDC_LOGNAME));
  205. }
  206. SetWindowLongPtr(hwnd,
  207. DWLP_MSGRESULT,
  208. (LONG_PTR) bRet);
  209. return bRet;
  210. }
  211. return 0;
  212. }
  213. INT_PTR CALLBACK LogFile_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  214. {
  215. BOOL fProcessed = TRUE;
  216. switch (uMsg) {
  217. HANDLE_MSG(hwnd, WM_INITDIALOG, LogFile_OnInitDialog);
  218. HANDLE_MSG(hwnd, WM_COMMAND, LogFile_OnCommand);
  219. case WM_NOTIFY:
  220. return LogFile_NotifyHandler(hwnd, uMsg, wParam, lParam);
  221. case WM_HELP:
  222. SigVerif_Help(hwnd, uMsg, wParam, lParam, FALSE);
  223. break;
  224. case WM_CONTEXTMENU:
  225. SigVerif_Help(hwnd, uMsg, wParam, lParam, TRUE);
  226. break;
  227. default: fProcessed = FALSE;
  228. }
  229. return fProcessed;
  230. }
  231. void PrintUnscannedFileListItems(HANDLE hFile)
  232. {
  233. LPFILENODE lpFileNode;
  234. TCHAR szDirectory[MAX_PATH];
  235. TCHAR szBuffer[MAX_PATH * 2];
  236. TCHAR szBuffer2[MAX_PATH];
  237. DWORD dwBytesWritten;
  238. *szDirectory = 0;
  239. for (lpFileNode = g_App.lpFileList;lpFileNode;lpFileNode = lpFileNode->next) {
  240. //
  241. // Make sure we only log files that have NOT been scanned.
  242. //
  243. if (!lpFileNode->bScanned) {
  244. if (lstrcmp(szDirectory, lpFileNode->lpDirName)) {
  245. SetCurrentDirectory(lpFileNode->lpDirName);
  246. lstrcpy(szDirectory, lpFileNode->lpDirName);
  247. MyLoadString(szBuffer2, IDS_DIR);
  248. wsprintf(szBuffer, szBuffer2, szDirectory);
  249. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  250. }
  251. MyLoadString(szBuffer2, IDS_STRING);
  252. wsprintf(szBuffer, szBuffer2, lpFileNode->lpFileName);
  253. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  254. //
  255. // Print out the reason that the file was not scanned.
  256. //
  257. if (lpFileNode->LastError != ERROR_SUCCESS) {
  258. //
  259. // We will special case the error ERROR_FILE_NOT_FOUND and display
  260. // the text "The file is not installed." in the log file instead of
  261. // the default ERROR_FILE_NOT_FOUND text "The system cannot find the
  262. // file specified."
  263. //
  264. if (lpFileNode->LastError == ERROR_FILE_NOT_FOUND) {
  265. MyLoadString(szBuffer, IDS_FILENOTINSTALLED);
  266. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  267. } else {
  268. LPVOID lpLastError = NULL;
  269. if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
  270. FORMAT_MESSAGE_FROM_SYSTEM |
  271. FORMAT_MESSAGE_IGNORE_INSERTS,
  272. NULL,
  273. lpFileNode->LastError,
  274. MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  275. (LPTSTR)&lpLastError,
  276. 0,
  277. NULL) != 0) {
  278. if (lpLastError) {
  279. WriteFile(hFile, (LPTSTR)lpLastError, lstrlen((LPTSTR)lpLastError) * sizeof(TCHAR), &dwBytesWritten, NULL);
  280. LocalFree(lpLastError);
  281. }
  282. }
  283. }
  284. }
  285. }
  286. }
  287. MyLoadString(szBuffer, IDS_LINEFEED);
  288. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  289. }
  290. void PrintFileListItems(HANDLE hFile)
  291. {
  292. LPFILENODE lpFileNode;
  293. TCHAR szDirectory[MAX_PATH];
  294. TCHAR szBuffer[MAX_PATH * 2];
  295. TCHAR szBuffer2[MAX_PATH];
  296. TCHAR szBuffer3[MAX_PATH];
  297. DWORD dwBytesWritten;
  298. LPTSTR lpString;
  299. int iRet;
  300. BOOL bMirroredApp;
  301. bMirroredApp = (GetWindowLong(g_App.hDlg, GWL_EXSTYLE) & WS_EX_LAYOUTRTL);
  302. *szDirectory = 0;
  303. for (lpFileNode = g_App.lpFileList;lpFileNode;lpFileNode = lpFileNode->next) {
  304. //
  305. // Make sure we only log files that have actually been scanned.
  306. //
  307. if (lpFileNode->bScanned) {
  308. if (lstrcmp(szDirectory, lpFileNode->lpDirName)) {
  309. SetCurrentDirectory(lpFileNode->lpDirName);
  310. lstrcpy(szDirectory, lpFileNode->lpDirName);
  311. MyLoadString(szBuffer2, IDS_DIR);
  312. wsprintf(szBuffer, szBuffer2, szDirectory);
  313. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  314. }
  315. MyLoadString(szBuffer2, IDS_STRING);
  316. wsprintf(szBuffer, szBuffer2, lpFileNode->lpFileName);
  317. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  318. MyLoadString(szBuffer, IDS_SPACES);
  319. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  320. //
  321. // Get the date format, so we are localizable...
  322. //
  323. MyLoadString(szBuffer2, IDS_UNKNOWN);
  324. iRet = GetDateFormat(LOCALE_SYSTEM_DEFAULT,
  325. bMirroredApp ?
  326. DATE_RTLREADING | DATE_SHORTDATE :
  327. DATE_SHORTDATE,
  328. &lpFileNode->LastModified,
  329. NULL,
  330. NULL,
  331. 0);
  332. if (iRet) {
  333. lpString = MALLOC((iRet + 1) * sizeof(TCHAR));
  334. if (lpString) {
  335. iRet = GetDateFormat(LOCALE_SYSTEM_DEFAULT,
  336. bMirroredApp ?
  337. DATE_RTLREADING | DATE_SHORTDATE :
  338. DATE_SHORTDATE,
  339. &lpFileNode->LastModified,
  340. NULL,
  341. lpString,
  342. iRet);
  343. if (iRet) {
  344. lstrcpy(szBuffer2, lpString);
  345. }
  346. FREE(lpString);
  347. }
  348. }
  349. MyLoadString(szBuffer3, IDS_STRING2);
  350. wsprintf(szBuffer, szBuffer3, szBuffer2);
  351. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  352. MyLoadString(szBuffer, IDS_SPACES);
  353. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  354. if (lpFileNode->lpVersion && *lpFileNode->lpVersion) {
  355. lstrcpy(szBuffer3, lpFileNode->lpVersion);
  356. } else {
  357. MyLoadString(szBuffer3, IDS_NOVERSION);
  358. }
  359. MyLoadString(szBuffer2, IDS_STRING);
  360. wsprintf(szBuffer, szBuffer2, szBuffer3);
  361. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  362. MyLoadString(szBuffer2, IDS_STRING);
  363. MyLoadString(szBuffer3, lpFileNode->bSigned ? IDS_SIGNED : IDS_NOTSIGNED);
  364. wsprintf(szBuffer, szBuffer2, szBuffer3);
  365. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  366. if (lpFileNode->lpCatalog) {
  367. lstrcpy(szBuffer3, lpFileNode->lpCatalog);
  368. } else {
  369. MyLoadString(szBuffer3, IDS_NA);
  370. }
  371. MyLoadString(szBuffer2, IDS_STRING);
  372. wsprintf(szBuffer, szBuffer2, szBuffer3);
  373. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  374. if (lpFileNode->lpSignedBy) {
  375. WriteFile(hFile, lpFileNode->lpSignedBy, lstrlen(lpFileNode->lpSignedBy) * sizeof(TCHAR), &dwBytesWritten, NULL);
  376. }
  377. MyLoadString(szBuffer, IDS_LINEFEED);
  378. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  379. }
  380. }
  381. }
  382. void PrintFileList(void)
  383. {
  384. HANDLE hFile;
  385. DWORD dwBytesWritten;
  386. TCHAR szBuffer[MAX_PATH*2];
  387. TCHAR szBuffer2[MAX_PATH];
  388. TCHAR szBuffer3[MAX_PATH];
  389. LPTSTR lpString = NULL;
  390. OSVERSIONINFO osinfo;
  391. SYSTEM_INFO sysinfo;
  392. int iRet;
  393. BOOL bMirroredApp;
  394. bMirroredApp = (GetWindowLong(g_App.hDlg, GWL_EXSTYLE) & WS_EX_LAYOUTRTL);
  395. //
  396. // Bail if logging is disabled or there's no file list
  397. //
  398. if (!g_App.bLoggingEnabled || !g_App.lpFileList) {
  399. return;
  400. }
  401. //
  402. // Get the Windows directory and make it the current directory.
  403. //
  404. if (GetWindowsDirectory(szBuffer, MAX_PATH)) {
  405. SetCurrentDirectory(szBuffer);
  406. }
  407. hFile = CreateFile( g_App.szLogFile,
  408. GENERIC_READ | GENERIC_WRITE,
  409. FILE_SHARE_READ,
  410. NULL,
  411. OPEN_ALWAYS,
  412. FILE_ATTRIBUTE_NORMAL,
  413. NULL);
  414. if (hFile == INVALID_HANDLE_VALUE) {
  415. MyErrorBoxId(IDS_CANTOPENLOGFILE);
  416. return;
  417. }
  418. //
  419. // If the overwrite flag is set, truncate the file.
  420. //
  421. if (g_App.bOverwrite) {
  422. SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
  423. SetEndOfFile(hFile);
  424. } else SetFilePointer(hFile, 0, NULL, FILE_END);
  425. #ifdef UNICODE
  426. //
  427. // If we are using UNICODE, then write the 0xFF and 0xFE bytes at the beginning of the file.
  428. //
  429. if (g_App.bOverwrite || (GetFileSize(hFile, NULL) == 0)) {
  430. szBuffer[0] = 0xFEFF;
  431. WriteFile(hFile, szBuffer, sizeof(TCHAR), &dwBytesWritten, NULL);
  432. }
  433. #endif
  434. //
  435. // Write the header to the logfile.
  436. //
  437. MyLoadString(szBuffer, IDS_LOGHEADER1);
  438. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  439. //
  440. // Get the date format, so we are localizable...
  441. //
  442. MyLoadString(szBuffer2, IDS_UNKNOWN);
  443. iRet = GetDateFormat(LOCALE_SYSTEM_DEFAULT,
  444. bMirroredApp ?
  445. DATE_RTLREADING | DATE_SHORTDATE :
  446. DATE_SHORTDATE,
  447. NULL,
  448. NULL,
  449. NULL,
  450. 0
  451. );
  452. if (iRet) {
  453. lpString = MALLOC((iRet + 1) * sizeof(TCHAR));
  454. if (lpString) {
  455. iRet = GetDateFormat(LOCALE_SYSTEM_DEFAULT,
  456. bMirroredApp ?
  457. DATE_RTLREADING | DATE_SHORTDATE :
  458. DATE_SHORTDATE,
  459. NULL,
  460. NULL,
  461. lpString,
  462. iRet
  463. );
  464. if (iRet) {
  465. lstrcpy(szBuffer2, lpString);
  466. }
  467. FREE(lpString);
  468. }
  469. }
  470. //
  471. // Get the time format, so we are localizable...
  472. //
  473. iRet = GetTimeFormat(LOCALE_SYSTEM_DEFAULT,TIME_NOSECONDS,NULL,NULL,NULL,0);
  474. if (iRet) {
  475. lpString = MALLOC((iRet + 1) * sizeof(TCHAR));
  476. if (lpString) {
  477. iRet = GetTimeFormat(LOCALE_SYSTEM_DEFAULT,TIME_NOSECONDS,NULL,NULL,lpString,iRet);
  478. }
  479. }
  480. MyLoadString(szBuffer3, IDS_LOGHEADER2);
  481. if (lpString) {
  482. wsprintf(szBuffer, szBuffer3, szBuffer2, lpString);
  483. FREE(lpString);
  484. } else {
  485. wsprintf(szBuffer, szBuffer3, szBuffer2, szBuffer2);
  486. }
  487. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  488. //
  489. // Get the OS Platform string for the log file.
  490. //
  491. MyLoadString(szBuffer, IDS_OSPLATFORM);
  492. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  493. ZeroMemory(&osinfo, sizeof(OSVERSIONINFO));
  494. osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  495. GetVersionEx(&osinfo);
  496. switch (osinfo.dwPlatformId) {
  497. case VER_PLATFORM_WIN32_NT:
  498. MyLoadString(szBuffer, IDS_WINNT);
  499. break;
  500. case VER_PLATFORM_WIN32_WINDOWS:
  501. MyLoadString(szBuffer, IDS_WIN9X);
  502. break;
  503. case VER_PLATFORM_WIN32s:
  504. MyLoadString(szBuffer, IDS_WIN3X);
  505. break;
  506. default:
  507. MyLoadString(szBuffer, IDS_UNKNOWN);
  508. break;
  509. }
  510. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  511. //
  512. // If this is NT, then get the processor architecture and log it
  513. //
  514. if (osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT) {
  515. ZeroMemory(&sysinfo, sizeof(SYSTEM_INFO));
  516. GetSystemInfo(&sysinfo);
  517. //
  518. // Initialize szBuffer to zeroes in case of an unknown architecture
  519. //
  520. ZeroMemory(szBuffer, sizeof(szBuffer));
  521. switch (sysinfo.wProcessorArchitecture) {
  522. case PROCESSOR_ARCHITECTURE_INTEL:
  523. MyLoadString(szBuffer, IDS_X86);
  524. break;
  525. case PROCESSOR_ARCHITECTURE_MIPS:
  526. MyLoadString(szBuffer, IDS_MIPS);
  527. break;
  528. case PROCESSOR_ARCHITECTURE_ALPHA:
  529. MyLoadString(szBuffer, IDS_ALPHA);
  530. break;
  531. case PROCESSOR_ARCHITECTURE_PPC:
  532. MyLoadString(szBuffer, IDS_PPC);
  533. break;
  534. }
  535. if (*szBuffer) {
  536. //
  537. // Now write the processor type to the file
  538. //
  539. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  540. }
  541. }
  542. //
  543. // Get the OS Version, Build, and CSD information and log it.
  544. //
  545. MyLoadString(szBuffer2, IDS_OSVERSION);
  546. wsprintf(szBuffer, szBuffer2, osinfo.dwMajorVersion, osinfo.dwMinorVersion, (osinfo.dwBuildNumber & 0xFFFF), osinfo.szCSDVersion);
  547. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  548. //
  549. // Print out the total/signed/unsigned results right before the file list
  550. //
  551. MyLoadString(szBuffer2, IDS_TOTALS);
  552. wsprintf(szBuffer, szBuffer2, g_App.dwFiles, g_App.dwSigned, g_App.dwUnsigned,
  553. g_App.dwFiles - g_App.dwSigned - g_App.dwUnsigned);
  554. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  555. //
  556. // If we are doing a user-defined search, then log the parameters.
  557. //
  558. if (g_App.bUserScan) {
  559. //
  560. // Write the user-specified directory
  561. //
  562. MyLoadString(szBuffer2, IDS_LOGHEADER3);
  563. wsprintf(szBuffer, szBuffer2, g_App.szScanPattern);
  564. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  565. //
  566. // Write the user-specified search pattern
  567. //
  568. MyLoadString(szBuffer2, IDS_LOGHEADER4);
  569. wsprintf(szBuffer, szBuffer2, g_App.szScanPath);
  570. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  571. }
  572. //
  573. // Write the column headers to the log file
  574. //
  575. MyLoadString(szBuffer, IDS_LOGHEADER5);
  576. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  577. MyLoadString(szBuffer, IDS_LOGHEADER6);
  578. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  579. PrintFileListItems(hFile);
  580. //
  581. // Write the unscanned file headers to the log file
  582. //
  583. if (g_App.dwFiles > (g_App.dwSigned + g_App.dwUnsigned)) {
  584. MyLoadString(szBuffer, IDS_LOGHEADER7);
  585. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  586. MyLoadString(szBuffer, IDS_LOGHEADER8);
  587. WriteFile(hFile, szBuffer, lstrlen(szBuffer) * sizeof(TCHAR), &dwBytesWritten, NULL);
  588. PrintUnscannedFileListItems(hFile);
  589. }
  590. CloseHandle(hFile);
  591. }