Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2601 lines
62 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. KernelMode.cpp
  5. Abstract:
  6. This module contains all code necessary to upload and process a
  7. Kernel mode fault through the OCA Web Site
  8. executive.
  9. Author:
  10. Steven Beerbroer (sbeer) 20-Jun-2002
  11. Environment:
  12. User mode only.
  13. Revision History:
  14. --*/
  15. #include "main.h"
  16. #include "Kernelmode.h"
  17. #include "WinMessages.h"
  18. #include "Clist.h"
  19. #include "usermode.h"
  20. #ifdef DEBUG
  21. #define KRNL_MODE_SERVER _T("Redbgitwb10")
  22. #else
  23. #define KRNL_MODE_SERVER _T("oca.microsoft.com")
  24. #endif
  25. extern TCHAR CerRoot[];
  26. extern KMODE_DATA KModeData;
  27. extern HINSTANCE g_hinst;
  28. extern HWND hKrnlMode;
  29. HWND g_hListView = NULL;
  30. BOOL g_bSortAsc = TRUE;
  31. HANDLE g_hStopEvent = NULL;
  32. //Globals
  33. HANDLE ThreadParam;
  34. DWORD BucketWindowSize = 120;
  35. DWORD TextOffset = 10;
  36. int g_CurrentIndex = -1;
  37. extern Clist CsvContents;
  38. extern TCHAR szKerenelColumnHeaders[][100];
  39. extern BOOL g_bAdminAccess;
  40. // ListView CallBacks for sorting.
  41. /*----------------------------------------------------------------------------
  42. FMicrosoftComURL
  43. Returns TRUE if we think the sz is a URL to a microsoft.com web site
  44. ----------------------------------------------------------------- MRuhlen --*/
  45. BOOL IsMicrosoftComURL(TCHAR *sz)
  46. {
  47. TCHAR *pch;
  48. if (sz == NULL || _tcslen(sz) < 20) // "http://microsoft.com
  49. return FALSE;
  50. if (_tcsncicmp(sz, szHttpPrefix, _tcslen(szHttpPrefix)))
  51. return FALSE;
  52. pch = sz + _tcslen(szHttpPrefix);
  53. while (*pch != _T('/') && *pch != _T('\0'))
  54. pch++;
  55. if (*pch == _T('\0'))
  56. return FALSE;
  57. // found the end of the server name
  58. if (_tcsncicmp(pch - strlen(_T(".microsoft.com")), _T(".microsoft.com"),_tcslen(_T(".microsoft.com"))
  59. ) &&
  60. _tcsncicmp(pch - strlen(_T("/microsoft.com")), _T("/microsoft.com"),_tcslen(_T("/microsoft.com"))
  61. ) &&
  62. _tcsncicmp(pch - _tcslen(_T(".msn.com")), _T(".msn.com") ,_tcslen(_T(".msn.com"))
  63. )
  64. #ifdef DEBUG
  65. && _tcsncicmp(pch - _tcslen(_T("ocatest.msbpn.com")), _T("ocatest.msbpn.com") ,_tcslen(_T("ocatest.msbpn.com")))
  66. && _tcsncicmp(pch - _tcslen(_T("redbgitwb10")), _T("redbgitwb10") ,_tcslen(_T("redbgitwb10")))
  67. #endif
  68. )
  69. return FALSE;
  70. return TRUE;
  71. }
  72. int CALLBACK CompareFunc (LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
  73. {
  74. int Result = -1;
  75. int SubItemIndex = (INT) lParamSort;
  76. int Item1, Item2;
  77. TCHAR String1[1000];
  78. TCHAR String2 [1000];
  79. ZeroMemory(String1, sizeof String1);
  80. ZeroMemory(String2, sizeof String2);
  81. ListView_GetItemText( g_hListView, lParam1, SubItemIndex, String1, 1000);
  82. ListView_GetItemText( g_hListView, lParam2, SubItemIndex, String2, 1000);
  83. if (! (String1 && String2) )
  84. return 1;
  85. if (lParam1 == 0)
  86. {
  87. return 0;
  88. }
  89. else
  90. {
  91. if (g_bSortAsc) // Sort Acending
  92. {
  93. if ((lParamSort == 0) || (lParamSort == 1))
  94. {
  95. // Conver to int and compare
  96. Item1 = atoi(String1);
  97. Item2 = atoi(String2);
  98. if (Item1 > Item2)
  99. Result = 1;
  100. else
  101. Result = -1;
  102. }
  103. else
  104. {
  105. Result = _tcsicmp(String1,String2);
  106. }
  107. }
  108. else // Sort Decending
  109. {
  110. if ((lParamSort == 0) || (lParamSort == 1))
  111. {
  112. // Conver to int and compare
  113. Item1 = atoi(String1);
  114. Item2 = atoi(String2);
  115. if (Item1 > Item2)
  116. Result = -1;
  117. else
  118. Result = 1;
  119. }
  120. else
  121. {
  122. Result = -_tcsicmp(String1,String2);
  123. }
  124. }
  125. }
  126. if (Result == 0)
  127. Result = -1;
  128. return Result;
  129. }
  130. int
  131. GetResponseUrl(
  132. IN TCHAR *szWebSiteName,
  133. IN TCHAR *szDumpFileName,
  134. OUT TCHAR *szResponseUrl
  135. )
  136. /*++
  137. Routine Description:
  138. This routine calles the Oca_Extension.dll and returns the URL received to the caller
  139. Arguments:
  140. szWebSiteName - Name of OCA Web Site to process the dump file
  141. szDumpFileName - Name of file returned from the UploadDumpFile() function
  142. szResponseUrl - TCHAR string to hold the URL returned from the OCA Isapi Dll
  143. Return value:
  144. 0 on Success.
  145. Win32 Error Code on failure.
  146. ++*/
  147. {
  148. TCHAR IsapiUrl[255];
  149. HINTERNET hSession = NULL;
  150. TCHAR LocalUrl[255];
  151. HINTERNET hUrlFile = NULL;
  152. TCHAR buffer[255] ;
  153. DWORD dwBytesRead = 0;
  154. BOOL bRead = TRUE;
  155. BOOL Status = FALSE;
  156. DWORD ResponseCode = 0;
  157. DWORD ResLength = 255;
  158. DWORD index = 0;
  159. ZeroMemory (buffer, sizeof buffer);
  160. ZeroMemory (IsapiUrl, sizeof IsapiUrl);
  161. ZeroMemory (LocalUrl, sizeof LocalUrl);
  162. if (StringCbPrintf (IsapiUrl,sizeof IsapiUrl, _T("http://%s/isapi/oca_extension.dll?id=%s&Type=2"),szWebSiteName, szDumpFileName)!= S_OK)
  163. {
  164. // Busted
  165. goto ERRORS;
  166. }
  167. hSession = InternetOpen(_T("CER15"),
  168. INTERNET_OPEN_TYPE_PRECONFIG,
  169. NULL,
  170. NULL,
  171. 0);
  172. if (hSession)
  173. {
  174. // Open the url we want to connect to.
  175. hUrlFile = InternetOpenUrl(hSession,
  176. IsapiUrl,
  177. NULL,
  178. 0,
  179. 0,
  180. 0);
  181. if (hUrlFile)
  182. {
  183. if (HttpQueryInfo( hUrlFile,
  184. HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
  185. &ResponseCode,
  186. &ResLength,
  187. &index) )
  188. {
  189. if ( (ResponseCode < 200 ) || (ResponseCode > 299))
  190. {
  191. Status = -1;
  192. goto ERRORS;
  193. }
  194. // Read the page returned by the isapi dll.
  195. if (hUrlFile)
  196. {
  197. bRead = InternetReadFile(hUrlFile,
  198. buffer,
  199. sizeof(buffer),
  200. &dwBytesRead);
  201. if (StringCbCopy (szResponseUrl, sizeof buffer, buffer) != S_OK)
  202. {
  203. Status = -1;
  204. goto ERRORS;
  205. }
  206. else
  207. {
  208. if (!IsMicrosoftComURL(szResponseUrl))
  209. {
  210. // Zero out the response
  211. ZeroMemory(szResponseUrl,MAX_PATH);
  212. }
  213. // Check the return value of the url if it is a time out stop
  214. // uploading and return FALSE.
  215. TCHAR *pCode = _tcsstr( szResponseUrl,_T("Code="));
  216. if (pCode)
  217. {
  218. Status = -2;
  219. }
  220. else
  221. {
  222. Status = 0;
  223. }
  224. }
  225. }
  226. else
  227. {
  228. //MessageBox(NULL,_T("Failed to open response URL"), NULL,MB_OK);
  229. Status = -1;
  230. goto ERRORS;
  231. }
  232. }
  233. }
  234. else
  235. {
  236. Status = -1;
  237. }
  238. }
  239. else
  240. {
  241. Status = -1;
  242. }
  243. ERRORS:
  244. if (Status == -1)
  245. MessageBox(hKrnlMode, _T("Failed to connect to the Internet.\r\nPlease verify your Internet connection."),NULL, MB_OK);
  246. if (hUrlFile)
  247. InternetCloseHandle(hUrlFile);
  248. if (hSession)
  249. InternetCloseHandle(hSession);
  250. return Status;
  251. }
  252. DWORD
  253. UploadDumpFile(
  254. IN TCHAR *szWebSiteName,
  255. IN TCHAR *szDumpFileName,
  256. IN TCHAR *szVirtualDir,
  257. OUT TCHAR *szUploadedDumpFileName
  258. )
  259. /*++
  260. Routine Description:
  261. This routine calles the Oca_Extension.dll and returns the URL received to the caller
  262. Arguments:
  263. szWebSiteName - Name of OCA Web Site to process the dump file
  264. szDumpFileName - Name of file to Uploaded
  265. szVirtualDir - Virtual directory to put file to.
  266. szResponseUrl - TCHAR string to hold the name the file was uploaded as
  267. Return value:
  268. 0 on Success.
  269. Win32 Error Code on failure.
  270. ++*/
  271. {
  272. static const TCHAR *pszAccept[] = {_T("*.*"), 0};
  273. // TCHAR RemoteFileName[MAX_PATH]; // Host/Virtualdirectory/filename
  274. BOOL bRet = FALSE;
  275. BOOL UploadSuccess = FALSE;
  276. DWORD dwBytesRead = 0;
  277. DWORD dwBytesWritten = 0;
  278. DWORD ResponseCode = 0;
  279. DWORD ResLength = 255;
  280. DWORD index = 0;
  281. DWORD ErrorCode = 0;
  282. HINTERNET hSession = NULL;
  283. HINTERNET hConnect = NULL;
  284. HINTERNET hRequest = NULL;
  285. INTERNET_BUFFERS BufferIn = {0};
  286. HANDLE hFile = INVALID_HANDLE_VALUE;
  287. BYTE *pBuffer = NULL;
  288. GUID guidNewGuid;
  289. char *szGuidRaw = NULL;
  290. HRESULT hResult = S_OK;
  291. wchar_t *wszGuidRaw = NULL;
  292. TCHAR DestinationName[MAX_PATH];
  293. CoInitialize(NULL);
  294. hResult = CoCreateGuid(&guidNewGuid);
  295. if (FAILED(hResult))
  296. {
  297. //-------------What do we send here....
  298. goto cleanup;
  299. ;
  300. }
  301. else
  302. {
  303. if (UuidToStringW(&guidNewGuid, &wszGuidRaw) == RPC_S_OK)
  304. {
  305. if ( (szGuidRaw = (char *) malloc ( wcslen(wszGuidRaw)*2 )) != NULL)
  306. {
  307. // clear the memory
  308. ZeroMemory(szGuidRaw, wcslen(wszGuidRaw) * 2);
  309. wcstombs( szGuidRaw, wszGuidRaw, wcslen(wszGuidRaw));
  310. }
  311. else
  312. {
  313. ErrorCode = GetLastError();
  314. goto cleanup;
  315. }
  316. }
  317. }
  318. if (StringCbPrintf(DestinationName, MAX_PATH * sizeof TCHAR, _T("\\%s\\%s_%s"),szVirtualDir,szGuidRaw + 19, PathFindFileName(szDumpFileName)) != S_OK)
  319. {
  320. goto cleanup;
  321. }
  322. //StringCbPrintf(szUploadedDumpFileName, MAX_PATH * sizeof TCHAR, _T("%s.cab"),szGuidRaw + 19);
  323. if (StringCbPrintf(szUploadedDumpFileName, MAX_PATH * sizeof TCHAR, _T("%s_%s"),szGuidRaw + 19, PathFindFileName(szDumpFileName)) != S_OK)
  324. {
  325. goto cleanup;
  326. }
  327. hSession = InternetOpen( _T("CER15"),
  328. INTERNET_OPEN_TYPE_PRECONFIG,
  329. NULL,
  330. NULL,
  331. 0);
  332. if (!hSession)
  333. {
  334. ErrorCode = 1;
  335. //MessageBox(NULL, _T("Internet Open Failed"), NULL, MB_OK);
  336. goto cleanup;
  337. }
  338. hConnect = InternetConnect(hSession,
  339. szWebSiteName,
  340. INTERNET_DEFAULT_HTTPS_PORT,
  341. NULL,
  342. NULL,
  343. INTERNET_SERVICE_HTTP,
  344. 0,
  345. NULL);
  346. if (!hConnect)
  347. {
  348. //MessageBox(NULL, _T("Internet Connect Failed"), NULL, MB_OK);
  349. ErrorCode = 1;
  350. goto cleanup;
  351. }
  352. hRequest = HttpOpenRequest( hConnect,
  353. _T("PUT"),
  354. DestinationName,
  355. NULL,
  356. NULL,
  357. pszAccept,
  358. INTERNET_FLAG_NEED_FILE|INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_SECURE,
  359. 0);
  360. if (hRequest)
  361. {
  362. hFile = CreateFile( szDumpFileName,
  363. GENERIC_READ,
  364. FILE_SHARE_READ,
  365. NULL,
  366. OPEN_EXISTING,
  367. FILE_ATTRIBUTE_NORMAL,
  368. NULL);
  369. if (hFile != INVALID_HANDLE_VALUE)
  370. {
  371. // Clear the buffer
  372. if ( (pBuffer = (BYTE *)malloc (70000)) != NULL)
  373. {
  374. BufferIn.dwStructSize = sizeof( INTERNET_BUFFERS );
  375. BufferIn.Next = NULL;
  376. BufferIn.lpcszHeader = NULL;
  377. BufferIn.dwHeadersLength = 0;
  378. BufferIn.dwHeadersTotal = 0;
  379. BufferIn.lpvBuffer = NULL;
  380. BufferIn.dwBufferLength = 0;
  381. BufferIn.dwOffsetLow = 0;
  382. BufferIn.dwOffsetHigh = 0;
  383. BufferIn.dwBufferTotal = GetFileSize (hFile, NULL);
  384. FillMemory(pBuffer, 70000,'\0'); // Fill buffer with data
  385. // DWORD dwBuffLen = sizeof DWORD;
  386. if(!HttpSendRequestEx( hRequest,
  387. &BufferIn,
  388. NULL,
  389. HSR_INITIATE,
  390. 0))
  391. {
  392. ;
  393. }
  394. else
  395. {
  396. do
  397. {
  398. dwBytesRead = 0;
  399. bRet = ReadFile(hFile,
  400. pBuffer,
  401. 70000,
  402. &dwBytesRead,
  403. NULL);
  404. if (bRet != 0)
  405. {
  406. bRet = InternetWriteFile(hRequest,
  407. pBuffer,
  408. dwBytesRead,
  409. &dwBytesWritten);
  410. if ( (!bRet) || (dwBytesWritten==0) )
  411. {
  412. ;
  413. }
  414. }
  415. } while (dwBytesRead == 70000);
  416. CloseHandle(hFile);
  417. hFile = INVALID_HANDLE_VALUE;
  418. bRet = HttpEndRequest( hRequest,
  419. NULL,
  420. 0,
  421. 0);
  422. if (bRet)
  423. {
  424. ResponseCode = 0;
  425. HttpQueryInfo(hRequest,
  426. HTTP_QUERY_STATUS_CODE |HTTP_QUERY_FLAG_NUMBER,
  427. &ResponseCode,
  428. &ResLength,
  429. &index);
  430. if ( (ResponseCode != 200) && (ResponseCode != 201))
  431. {
  432. ErrorCode=1;
  433. }
  434. else
  435. {
  436. ErrorCode = 0;
  437. UploadSuccess = TRUE;
  438. }
  439. }
  440. else
  441. {
  442. //MessageBox(NULL, _T("End Request Failed"), NULL, MB_OK);
  443. ErrorCode = 1;
  444. }
  445. }
  446. }
  447. else
  448. {
  449. //MessageBox(NULL, _T("Malloc Failed"), NULL, MB_OK);
  450. ErrorCode = 1;
  451. }
  452. }
  453. else
  454. {
  455. //MessageBox(NULL, _T("File Open Failed"), NULL, MB_OK);
  456. ErrorCode = 3;
  457. }
  458. }
  459. else
  460. {
  461. //MessageBox(NULL, _T("Internet Open Request Failed"), NULL, MB_OK);
  462. ErrorCode = 1;
  463. }
  464. cleanup:
  465. // Clean up
  466. if (hFile!= INVALID_HANDLE_VALUE)
  467. {
  468. CloseHandle (hFile);
  469. hFile = INVALID_HANDLE_VALUE;
  470. }
  471. if (hSession)
  472. {
  473. InternetCloseHandle(hSession);
  474. hSession = INVALID_HANDLE_VALUE;
  475. }
  476. if (hConnect)
  477. {
  478. InternetCloseHandle(hConnect);
  479. hConnect = INVALID_HANDLE_VALUE;
  480. }
  481. if (hRequest)
  482. {
  483. InternetCloseHandle(hRequest);
  484. hRequest = INVALID_HANDLE_VALUE;
  485. }
  486. if (pBuffer)
  487. {
  488. free (pBuffer);
  489. pBuffer = NULL;
  490. }
  491. if (wszGuidRaw)
  492. {
  493. RpcStringFreeW(&wszGuidRaw);
  494. wszGuidRaw = NULL;
  495. }
  496. if (szGuidRaw)
  497. {
  498. free(szGuidRaw);
  499. szGuidRaw = NULL;
  500. }
  501. CoUninitialize();
  502. return ErrorCode;
  503. }
  504. void UpdateKrnlList(HWND hwnd,
  505. int BucketId,
  506. TCHAR *BucketString,
  507. TCHAR *Response1,
  508. TCHAR *Response2,
  509. DWORD Count)
  510. /*++
  511. Routine Description:
  512. Adds a row to the Kernel Mode list view control
  513. Arguments:
  514. hwnd - Handle of the Dialog box to be updated
  515. BucketID - The Integer ID of the Current Bucket
  516. Response - The Microsoft response for the current bucket
  517. Count - The number of hits for the current bucket
  518. Return value:
  519. Does not return a value
  520. ++*/
  521. {
  522. LVITEM lvi;
  523. // TCHAR Temp[100];
  524. // double ElapsedTime;
  525. ZeroMemory(&lvi, sizeof LVITEM);
  526. // TCHAR tmpbuf[128];
  527. // COLORREF CurrentColor;
  528. // HWND hEditBox;
  529. TCHAR TempString [50];
  530. TCHAR *pTchar = NULL;
  531. lvi.mask = LVIF_TEXT | LVIF_STATE;
  532. lvi.state = 0;
  533. lvi.stateMask = 0;
  534. ++g_CurrentIndex;
  535. lvi.iItem = g_CurrentIndex ;
  536. // lvI.iImage = index;
  537. lvi.iSubItem = 0;
  538. if (BucketId == -2)
  539. {
  540. if (StringCbCopy(TempString, sizeof TempString, _T("Kernel Faults not reported to Microsoft")) != S_OK)
  541. {
  542. goto ERRORS;
  543. }
  544. BucketId = 0;
  545. }
  546. else
  547. {
  548. if (BucketId == -1)
  549. {
  550. if (StringCbCopy(TempString, sizeof TempString, _T("Invalid Dump File")) != S_OK)
  551. {
  552. goto ERRORS;
  553. }
  554. }
  555. else
  556. {
  557. //BucketId = 0;
  558. if (BucketId > 0)
  559. {
  560. if (StringCbPrintf(TempString, sizeof TempString, _T("%d"), BucketId) != S_OK)
  561. {
  562. goto ERRORS;
  563. }
  564. }
  565. else
  566. {
  567. // Invalid bucket id
  568. goto ERRORS;
  569. }
  570. }
  571. }
  572. lvi.pszText = TempString;
  573. ListView_InsertItem(hwnd,&lvi);
  574. lvi.iSubItem = 1;
  575. if (StringCbPrintf(TempString, sizeof TempString, _T("%d"), Count) != S_OK)
  576. {
  577. goto ERRORS;
  578. }
  579. lvi.pszText = TempString;
  580. ListView_SetItem(hwnd,&lvi);
  581. lvi.iSubItem = 2;
  582. // if response1 = -1 use response2
  583. pTchar = _tcsstr(Response1, _T("sid="));
  584. if (pTchar)
  585. {
  586. pTchar += 4;
  587. if (_ttoi(pTchar) == -1)
  588. {
  589. lvi.pszText = Response2;
  590. }
  591. else
  592. {
  593. // use response1
  594. lvi.pszText = Response1;
  595. }
  596. ListView_SetItem(hwnd,&lvi);
  597. }
  598. ERRORS:
  599. return;
  600. }
  601. void RefreshKrnlView(HWND hwnd)
  602. /*++
  603. Routine Description:
  604. Reloads the kernel mode Cer tree data and refreshes the GUI View.
  605. Arguments:
  606. hwnd - Handle of the Dialog box to be updated
  607. Return value:
  608. Does not return a value
  609. ++*/
  610. {
  611. TCHAR BucketId[100];
  612. TCHAR BucketString[MAX_PATH];
  613. TCHAR Response1[MAX_PATH];
  614. TCHAR Response2[MAX_PATH];
  615. TCHAR Count[100];
  616. // TCHAR szPolicyText[512];
  617. BOOL bEOF;
  618. ListView_DeleteAllItems(g_hListView);
  619. g_CurrentIndex = -1;
  620. TCHAR szPath[MAX_PATH];
  621. HANDLE hFind = INVALID_HANDLE_VALUE;
  622. // HANDLE hCsv = INVALID_HANDLE_VALUE;
  623. WIN32_FIND_DATA FindData;
  624. CsvContents.CleanupList();
  625. CsvContents.ResetCurrPos();
  626. CsvContents.bInitialized = FALSE;
  627. if (_tcscmp(CerRoot, _T("\0")))
  628. {
  629. ZeroMemory (szPath, sizeof szPath);
  630. // From the filetree root goto cabs/bluescreen
  631. if (StringCbCopy(szPath, sizeof szPath, CerRoot) != S_OK)
  632. {
  633. goto ERRORS;
  634. }
  635. if (StringCbCat(szPath, sizeof szPath, _T("\\cabs\\blue\\*.cab")) != S_OK)
  636. {
  637. goto ERRORS;
  638. }
  639. if (!PathIsDirectory(CerRoot))
  640. {
  641. MessageBox(NULL,_T("Failed to connect to the CER Tree."), NULL, MB_OK);
  642. }
  643. hFind = FindFirstFile(szPath, &FindData);
  644. KModeData.UnprocessedCount = 0;
  645. // Check to see if the blue.csv exists.
  646. if ( hFind != INVALID_HANDLE_VALUE)
  647. {
  648. do
  649. {
  650. ++ KModeData.UnprocessedCount;
  651. } while (FindNextFile(hFind, &FindData));
  652. FindClose(hFind);
  653. }
  654. UpdateKrnlList(g_hListView,
  655. -2,
  656. _T("Kernel Faults not reported to Microsoft"),
  657. _T(""),
  658. _T(""),
  659. KModeData.UnprocessedCount);
  660. // Search for all unprocessed (not .old) cabs and get a count
  661. if (StringCbCopy(szPath, sizeof szPath, CerRoot) != S_OK)
  662. {
  663. goto ERRORS;
  664. }
  665. if (StringCbCat(szPath, sizeof szPath, _T("\\Status\\Blue\\Kernel.csv")) != S_OK)
  666. {
  667. goto ERRORS;
  668. }
  669. CsvContents.Initialize(szPath);
  670. CsvContents.ResetCurrPos();
  671. while (CsvContents.GetNextEntry(BucketId,
  672. BucketString,
  673. Response1,
  674. Response2,
  675. Count,
  676. &bEOF))
  677. {
  678. UpdateKrnlList( g_hListView,
  679. _ttoi(BucketId),
  680. BucketString,
  681. Response1,
  682. Response2,
  683. _ttoi(Count));
  684. }
  685. // Set the kernel mode status file path
  686. // First make sure the direcory exists.
  687. if (StringCbPrintf(CsvContents.KernelStatusDir, sizeof CsvContents.KernelStatusDir, _T("%s\\Status\\blue"), CerRoot) != S_OK)
  688. {
  689. goto ERRORS;
  690. }
  691. if (!PathIsDirectory(CsvContents.KernelStatusDir))
  692. {
  693. CreateDirectory(CsvContents.KernelStatusDir, NULL);
  694. }
  695. if (StringCbCat(CsvContents.KernelStatusDir, sizeof CsvContents.KernelStatusDir, _T("\\status.txt")) != S_OK)
  696. {
  697. goto ERRORS;
  698. }
  699. if (PathFileExists(CsvContents.KernelStatusDir))
  700. {
  701. ParseKrnlStatusFile();
  702. }
  703. }
  704. SendMessage(GetDlgItem(hwnd,IDC_KRNL_EDIT ), WM_SETTEXT, NULL, (LPARAM)_T(""));
  705. //PopulateKrnlBucketData(hwnd);
  706. //SetDlgItemText(hwnd, IDC_KRNL_EDIT, szPolicyText);
  707. ERRORS:
  708. return;
  709. }
  710. void
  711. OnKrnlDialogInit(
  712. IN HWND hwnd
  713. )
  714. /*++
  715. Routine Description:
  716. This routine is called when the Kernel mode dialog is initialized.
  717. 1) Posisions all of the dialog box controls
  718. 2) Calls RefreshKrnlView()
  719. Arguments:
  720. hwnd - Handle of the Kernel mode dialog box
  721. Return value:
  722. Does not return a value
  723. ++*/
  724. {
  725. DWORD yOffset = 5;
  726. RECT rc;
  727. RECT rcButton;
  728. RECT rcDlg;
  729. RECT rcList;
  730. RECT rcStatic;
  731. //RECT rcCombo;
  732. HWND hParent = GetParent(hwnd);
  733. HWND hButton = GetDlgItem(hParent, IDC_USERMODE);
  734. GetClientRect(hParent, &rc);
  735. GetWindowRect(hButton, &rcButton);
  736. ScreenToClient(hButton, (LPPOINT)&rcButton.left);
  737. ScreenToClient(hButton, (LPPOINT)&rcButton.right);
  738. SetWindowPos(hwnd, HWND_TOP, rc.left + yOffset, rcButton.bottom + yOffset , rc.right - rc.left - yOffset, rc.bottom - rcButton.bottom - yOffset , 0);
  739. GetWindowRect(hwnd, &rcDlg);
  740. ScreenToClient(hwnd, (LPPOINT)&rcDlg.left);
  741. ScreenToClient(hwnd, (LPPOINT)&rcDlg.right);
  742. // Position the List View
  743. HWND hList = GetDlgItem(hwnd, IDC_KRNL_LIST);
  744. SetWindowPos(hList,NULL, rcDlg.left + yOffset, rcDlg.top , rcDlg.right - rcDlg.left - yOffset, rcDlg.bottom - BucketWindowSize - rcDlg.top , SWP_NOZORDER);
  745. GetWindowRect(hList, &rcList);
  746. ScreenToClient(hList, (LPPOINT)&rcList.left);
  747. ScreenToClient(hList, (LPPOINT)&rcList.right);
  748. // Position the bucket info window.
  749. HWND hBucket2 = GetDlgItem(hwnd, IDC_BUCKETTEXT);
  750. SetWindowPos(hBucket2,
  751. NULL,
  752. rcDlg.left + yOffset,
  753. rcList.bottom + TextOffset ,
  754. 0,
  755. 0,
  756. SWP_NOSIZE | SWP_NOZORDER);
  757. SetDlgItemText(hwnd, IDC_BUCKETTEXT,"Bucket Information:");
  758. //SetDlgItemText(hwnd, IDC_FLTR_RESPONSE, "All Responses");
  759. GetClientRect (hBucket2, &rcStatic);
  760. HWND hBucket = GetDlgItem (hwnd, IDC_KRNL_EDIT);
  761. SetWindowPos(hBucket,
  762. NULL,
  763. rcDlg.left + yOffset,
  764. rcList.bottom + TextOffset + (rcStatic.bottom - rcStatic.top) +5,
  765. rcDlg.right - rcDlg.left - yOffset,
  766. rcDlg.bottom - (rcList.bottom + TextOffset + (rcStatic.bottom - rcStatic.top) ),
  767. SWP_NOZORDER);
  768. LVCOLUMN lvc;
  769. int iCol;
  770. // Set the extended styles
  771. ListView_SetExtendedListViewStyleEx(hList,
  772. LVS_EX_GRIDLINES |
  773. LVS_EX_HEADERDRAGDROP |
  774. LVS_EX_FULLROWSELECT,
  775. LVS_EX_GRIDLINES |
  776. LVS_EX_FULLROWSELECT |
  777. LVS_EX_HEADERDRAGDROP);
  778. // Initialize the LVCOLUMN structure.
  779. // The mask specifies that the format, width, text, and subitem
  780. // members of the structure are valid.
  781. lvc.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  782. // Add the columns.
  783. for (iCol = 0; iCol < KRNL_COL_COUNT; iCol++)
  784. {
  785. lvc.iSubItem = iCol;
  786. lvc.pszText = szKerenelColumnHeaders[iCol];
  787. lvc.cx = 100; // width of column in pixels
  788. lvc.fmt = LVCFMT_LEFT; // left-aligned column
  789. if (ListView_InsertColumn(hList, iCol, &lvc) == -1)
  790. {
  791. ;
  792. }
  793. }
  794. ListView_SetColumnWidth(hList, KRNL_COL_COUNT-1, LVSCW_AUTOSIZE_USEHEADER);
  795. g_hListView = hList;
  796. RefreshKrnlView(hwnd);
  797. }
  798. void ResizeKrlMode(HWND hwnd)
  799. /*++
  800. Routine Description:
  801. This routine handles the vertical and horizontal dialog resizing.
  802. Arguments:
  803. hwnd - Handle of the Kernel mode dialog box
  804. Return value:
  805. Does not return a value
  806. ++*/
  807. {
  808. DWORD yOffset = 5;
  809. RECT rc;
  810. RECT rcButton;
  811. RECT rcDlg;
  812. RECT rcList;
  813. RECT rcStatic;
  814. HWND hParent = GetParent(hwnd);
  815. HWND hButton = GetDlgItem(hParent, IDC_USERMODE);
  816. //HWND hCombo = GetDlgItem(hwnd, IDC_FLTR_RESPONSE);
  817. // RECT rcCombo;
  818. GetClientRect(hParent, &rc);
  819. GetWindowRect(hButton, &rcButton);
  820. ScreenToClient(hButton, (LPPOINT)&rcButton.left);
  821. ScreenToClient(hButton, (LPPOINT)&rcButton.right);
  822. SetWindowPos(hwnd, HWND_TOP, rc.left + yOffset, rcButton.bottom + yOffset , rc.right - rc.left - yOffset, rc.bottom - rcButton.bottom - yOffset , 0);
  823. GetWindowRect(hwnd, &rcDlg);
  824. ScreenToClient(hwnd, (LPPOINT)&rcDlg.left);
  825. ScreenToClient(hwnd, (LPPOINT)&rcDlg.right);
  826. // Position the List View
  827. HWND hList = GetDlgItem(hwnd, IDC_KRNL_LIST);
  828. SetWindowPos(hList,NULL, rcDlg.left + yOffset, rcDlg.top , rcDlg.right - rcDlg.left - yOffset, rcDlg.bottom - BucketWindowSize - rcDlg.top , SWP_NOZORDER);
  829. GetWindowRect(hList, &rcList);
  830. ScreenToClient(hList, (LPPOINT)&rcList.left);
  831. ScreenToClient(hList, (LPPOINT)&rcList.right);
  832. // Position the bucket info window.
  833. HWND hBucket2 = GetDlgItem(hwnd, IDC_BUCKETTEXT);
  834. SetWindowPos(hBucket2,
  835. NULL,
  836. rcDlg.left + yOffset,
  837. rcList.bottom + TextOffset ,
  838. 0,
  839. 0,
  840. SWP_NOSIZE | SWP_NOZORDER);
  841. SetDlgItemText(hwnd, IDC_BUCKETTEXT,"Bucket Information:");
  842. //SetDlgItemText(hwnd, IDC_FLTR_RESPONSE, "All Responses");
  843. GetClientRect (hBucket2, &rcStatic);
  844. HWND hBucket = GetDlgItem (hwnd, IDC_KRNL_EDIT);
  845. SetWindowPos(hBucket,
  846. NULL,
  847. rcDlg.left + yOffset,
  848. rcList.bottom + TextOffset + (rcStatic.bottom - rcStatic.top) +5,
  849. rcDlg.right - rcDlg.left - yOffset,
  850. rcDlg.bottom - (rcList.bottom + TextOffset + (rcStatic.bottom - rcStatic.top) ),
  851. SWP_NOZORDER);
  852. ListView_SetColumnWidth(hList, KRNL_COL_COUNT-1, LVSCW_AUTOSIZE_USEHEADER);
  853. }
  854. BOOL WriteKernelStatusFile()
  855. /*++
  856. Routine Description:
  857. This routine renames a proccessed cab file from .cab to .old
  858. Arguments:
  859. ResponseUrl - Microsoft response for the recently submitted dump file.
  860. Return value:
  861. Does not return a value
  862. ++*/
  863. {
  864. BOOL bStatus = FALSE;
  865. // move the existing status file to .old
  866. TCHAR szFileNameOld[MAX_PATH];
  867. TCHAR *Temp;
  868. TCHAR Buffer[1024];
  869. HANDLE hFile = INVALID_HANDLE_VALUE;
  870. DWORD dwWritten = 0;
  871. if (StringCbCopy(szFileNameOld,sizeof szFileNameOld, CsvContents.KernelStatusDir) != S_OK)
  872. {
  873. goto ERRORS;
  874. }
  875. Temp = szFileNameOld;
  876. Temp += _tcslen(szFileNameOld) * sizeof TCHAR;
  877. while ( (*Temp != _T('.')) && (Temp != szFileNameOld))
  878. {
  879. Temp --;
  880. }
  881. if (Temp == szFileNameOld)
  882. {
  883. goto ERRORS;
  884. }
  885. else
  886. {
  887. if (StringCbCopy (Temp,sizeof szFileNameOld , _T(".old")) != S_OK)
  888. {
  889. goto ERRORS;
  890. }
  891. if (PathFileExists(CsvContents.KernelStatusDir))
  892. {
  893. MoveFileEx(CsvContents.KernelStatusDir, szFileNameOld, TRUE);
  894. }
  895. // create a new status file.
  896. hFile = CreateFile(CsvContents.KernelStatusDir,
  897. GENERIC_WRITE,
  898. NULL,
  899. NULL,
  900. CREATE_ALWAYS,
  901. FILE_ATTRIBUTE_NORMAL,
  902. NULL);
  903. // Write the StatusContents data to the new status file
  904. if (_tcscmp (CsvContents.KrnlPolicy.Tracking, _T("\0")))
  905. {
  906. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Tracking=%s\r\n"), CsvContents.KrnlPolicy.Tracking) != S_OK)
  907. {
  908. goto ERRORS;
  909. }
  910. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  911. }
  912. // Write the StatusContents data to the new status file
  913. if (_tcscmp (CsvContents.KrnlPolicy.CrashPerBucketCount, _T("\0")))
  914. {
  915. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Crashes per bucket=%s\r\n"), CsvContents.KrnlPolicy.CrashPerBucketCount) != S_OK)
  916. {
  917. goto ERRORS;
  918. }
  919. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  920. }
  921. // Write the StatusContents data to the new status file
  922. if (_tcscmp (CsvContents.KrnlPolicy.UrlToLaunch, _T("\0")))
  923. {
  924. if (StringCbPrintf(Buffer, sizeof Buffer, _T("URLLaunch=%s\r\n"), CsvContents.KrnlPolicy.UrlToLaunch) != S_OK)
  925. {
  926. goto ERRORS;
  927. }
  928. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  929. }
  930. // Write the StatusContents data to the new status file
  931. if (_tcscmp (CsvContents.KrnlPolicy.SecondLevelData, _T("\0")))
  932. {
  933. if (StringCbPrintf(Buffer, sizeof Buffer, _T("NoSecondLevelCollection=%s\r\n"), CsvContents.KrnlPolicy.SecondLevelData) != S_OK)
  934. {
  935. goto ERRORS;
  936. }
  937. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  938. }
  939. // Write the StatusContents data to the new status file
  940. if (_tcscmp (CsvContents.KrnlPolicy.FileCollection, _T("\0")))
  941. {
  942. if (StringCbPrintf(Buffer, sizeof Buffer, _T("NoFileCollection=%s\r\n"), CsvContents.KrnlPolicy.FileCollection) != S_OK)
  943. {
  944. goto ERRORS;
  945. }
  946. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  947. }
  948. // Write the StatusContents data to the new status file
  949. if (_tcscmp (CsvContents.KrnlPolicy.Response, _T("\0")))
  950. {
  951. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Response=%s\r\n"), CsvContents.KrnlPolicy.Response) != S_OK)
  952. {
  953. goto ERRORS;
  954. }
  955. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  956. }
  957. // Write the StatusContents data to the new status file
  958. if (_tcscmp (CsvContents.KrnlPolicy.BucketID, _T("\0")))
  959. {
  960. if (StringCbPrintf(Buffer, sizeof Buffer, _T("Bucket=%s\r\n"), CsvContents.KrnlPolicy.BucketID) != S_OK)
  961. {
  962. goto ERRORS;
  963. }
  964. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  965. }
  966. // Write the StatusContents data to the new status file
  967. if (_tcscmp (CsvContents.KrnlPolicy.RegKey, _T("\0")))
  968. {
  969. if (StringCbPrintf(Buffer, sizeof Buffer, _T("RegKey=%s\r\n"), CsvContents.KrnlPolicy.RegKey) != S_OK)
  970. {
  971. goto ERRORS;
  972. }
  973. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  974. }
  975. // Write the StatusContents data to the new status file
  976. if (_tcscmp (CsvContents.KrnlPolicy.iData, _T("\0")))
  977. {
  978. if (StringCbPrintf(Buffer, sizeof Buffer, _T("iData=%s\r\n"),CsvContents.KrnlPolicy.iData) != S_OK)
  979. {
  980. goto ERRORS;
  981. }
  982. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  983. }
  984. // Write the StatusContents data to the new status file
  985. if (_tcscmp (CsvContents.KrnlPolicy.WQL, _T("\0")))
  986. {
  987. if (StringCbPrintf(Buffer, sizeof Buffer, _T("WQL=%s\r\n"), CsvContents.KrnlPolicy.WQL) != S_OK)
  988. {
  989. goto ERRORS;
  990. }
  991. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  992. }
  993. // Write the StatusContents data to the new status file
  994. if (_tcscmp (CsvContents.KrnlPolicy.GetFile, _T("\0")))
  995. {
  996. if (StringCbPrintf(Buffer, sizeof Buffer, _T("GetFile=%s\r\n"), CsvContents.KrnlPolicy.GetFile) != S_OK)
  997. {
  998. goto ERRORS;
  999. }
  1000. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1001. }
  1002. // Write the StatusContents data to the new status file
  1003. if (_tcscmp (CsvContents.KrnlPolicy.GetFileVersion, _T("\0")))
  1004. {
  1005. if (StringCbPrintf(Buffer, sizeof Buffer, _T("GetFileVersion=%s\r\n"), CsvContents.KrnlPolicy.GetFileVersion) != S_OK)
  1006. {
  1007. goto ERRORS;
  1008. }
  1009. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1010. }
  1011. if (_tcscmp (CsvContents.KrnlPolicy.AllowResponse, _T("\0")))
  1012. {
  1013. if (StringCbPrintf(Buffer, sizeof Buffer, _T("NoExternalURL=%s\r\n"), CsvContents.KrnlPolicy.AllowResponse) != S_OK)
  1014. {
  1015. goto ERRORS;
  1016. }
  1017. WriteFile(hFile , Buffer, _tcslen(Buffer) *sizeof TCHAR , &dwWritten, NULL);
  1018. }
  1019. // Close the new status file
  1020. CloseHandle(hFile);
  1021. hFile = INVALID_HANDLE_VALUE;
  1022. // if all ok delete the old status file.
  1023. //DeleteFile(szFileNameOld);
  1024. }
  1025. ERRORS:
  1026. if (hFile != INVALID_HANDLE_VALUE)
  1027. {
  1028. CloseHandle(hFile);
  1029. }
  1030. return bStatus;
  1031. }
  1032. BOOL ParseKrnlStatusFile()
  1033. {
  1034. FILE *pFile = NULL;
  1035. TCHAR Buffer[100];
  1036. // TCHAR szTempDir[MAX_PATH];
  1037. TCHAR *Temp = NULL;
  1038. // int id = 0;
  1039. ZeroMemory(Buffer,sizeof Buffer);
  1040. pFile = _tfopen(CsvContents.KernelStatusDir, _T("r"));
  1041. if (pFile)
  1042. {
  1043. // Get the Cabs Gathered Count
  1044. if (!_fgetts(Buffer, sizeof Buffer, pFile))
  1045. {
  1046. goto ERRORS;
  1047. }
  1048. do
  1049. {
  1050. // Remove \r\n and force termination of the buffer.
  1051. Temp = Buffer;
  1052. while ( (*Temp != _T('\r')) && (*Temp != _T('\n')) && (*Temp != _T('\0')) )
  1053. {
  1054. ++Temp;
  1055. }
  1056. *Temp = _T('\0');
  1057. Temp = _tcsstr(Buffer, BUCKET_PREFIX);
  1058. if (Temp == Buffer)
  1059. {
  1060. Temp+= _tcslen(BUCKET_PREFIX);
  1061. if (StringCbCopy(CsvContents.KrnlPolicy.BucketID, sizeof CsvContents.KrnlPolicy.BucketID, Temp) != S_OK)
  1062. {
  1063. goto ERRORS;
  1064. }
  1065. continue;
  1066. }
  1067. Temp = _tcsstr(Buffer,RESPONSE_PREFIX);
  1068. if (Temp == Buffer)
  1069. {
  1070. Temp+= _tcslen(RESPONSE_PREFIX);
  1071. if (StringCbCopy(CsvContents.KrnlPolicy.Response, sizeof CsvContents.KrnlPolicy.Response, Temp) != S_OK)
  1072. {
  1073. goto ERRORS;
  1074. }
  1075. continue;
  1076. }
  1077. Temp = _tcsstr(Buffer, URLLAUNCH_PREFIX);
  1078. if (Temp == Buffer)
  1079. {
  1080. Temp+= _tcslen(URLLAUNCH_PREFIX);
  1081. if (StringCbCopy(CsvContents.KrnlPolicy.UrlToLaunch , sizeof CsvContents.KrnlPolicy.UrlToLaunch , Temp) != S_OK)
  1082. {
  1083. goto ERRORS;
  1084. }
  1085. continue;
  1086. }
  1087. Temp = _tcsstr(Buffer, SECOND_LEVEL_DATA_PREFIX);
  1088. if (Temp==Buffer)
  1089. {
  1090. Temp+= _tcslen(SECOND_LEVEL_DATA_PREFIX);
  1091. if (StringCbCopy(CsvContents.KrnlPolicy.SecondLevelData , sizeof CsvContents.KrnlPolicy.SecondLevelData , Temp) != S_OK)
  1092. {
  1093. goto ERRORS;
  1094. }
  1095. continue;
  1096. }
  1097. Temp = _tcsstr(Buffer, TRACKING_PREFIX);
  1098. if (Temp==Buffer)
  1099. {
  1100. Temp+= _tcslen(TRACKING_PREFIX);
  1101. if (StringCbCopy(CsvContents.KrnlPolicy.Tracking , sizeof CsvContents.KrnlPolicy.Tracking , Temp) != S_OK)
  1102. {
  1103. goto ERRORS;
  1104. }
  1105. continue;
  1106. }
  1107. Temp = _tcsstr(Buffer, CRASH_PERBUCKET_PREFIX);
  1108. if (Temp==Buffer)
  1109. {
  1110. Temp+= _tcslen(CRASH_PERBUCKET_PREFIX);
  1111. if (StringCbCopy(CsvContents.KrnlPolicy.CrashPerBucketCount , sizeof CsvContents.KrnlPolicy.CrashPerBucketCount , Temp) != S_OK)
  1112. {
  1113. goto ERRORS;
  1114. }
  1115. continue;
  1116. }
  1117. Temp = _tcsstr(Buffer, FILE_COLLECTION_PREFIX);
  1118. if (Temp==Buffer)
  1119. {
  1120. Temp+= _tcslen(FILE_COLLECTION_PREFIX);
  1121. if (StringCbCopy(CsvContents.KrnlPolicy.FileCollection , sizeof CsvContents.KrnlPolicy.FileCollection, Temp) != S_OK)
  1122. {
  1123. goto ERRORS;
  1124. }
  1125. continue;
  1126. }
  1127. Temp = _tcsstr(Buffer, REGKEY_PREFIX);
  1128. if (Temp==Buffer)
  1129. {
  1130. Temp+= _tcslen(REGKEY_PREFIX);
  1131. if (StringCbCopy(CsvContents.KrnlPolicy.RegKey , sizeof CsvContents.KrnlPolicy.RegKey , Temp) != S_OK)
  1132. {
  1133. goto ERRORS;
  1134. }
  1135. continue;
  1136. }
  1137. Temp = _tcsstr(Buffer, FDOC_PREFIX);
  1138. if (Temp==Buffer)
  1139. {
  1140. Temp+= _tcslen(FDOC_PREFIX);
  1141. if (StringCbCopy(CsvContents.KrnlPolicy.fDoc , sizeof CsvContents.KrnlPolicy.fDoc , Temp) != S_OK)
  1142. {
  1143. goto ERRORS;
  1144. }
  1145. continue;
  1146. }
  1147. Temp = _tcsstr(Buffer, IDATA_PREFIX);
  1148. if (Temp==Buffer)
  1149. {
  1150. Temp+= _tcslen(IDATA_PREFIX);
  1151. if (StringCbCopy(CsvContents.KrnlPolicy.iData , sizeof CsvContents.KrnlPolicy.iData , Temp) != S_OK)
  1152. {
  1153. goto ERRORS;
  1154. }
  1155. continue;
  1156. }
  1157. Temp = _tcsstr(Buffer, WQL_PREFIX);
  1158. if (Temp==Buffer)
  1159. {
  1160. Temp+= _tcslen(WQL_PREFIX);
  1161. if (StringCbCopy(CsvContents.KrnlPolicy.WQL , sizeof CsvContents.KrnlPolicy.WQL , Temp) != S_OK)
  1162. {
  1163. goto ERRORS;
  1164. }
  1165. continue;
  1166. }
  1167. Temp = _tcsstr(Buffer, GETFILE_PREFIX);
  1168. if (Temp==Buffer)
  1169. {
  1170. Temp+= _tcslen(GETFILE_PREFIX);
  1171. if (StringCbCopy(CsvContents.KrnlPolicy.GetFile , sizeof CsvContents.KrnlPolicy.GetFile, Temp) != S_OK)
  1172. {
  1173. goto ERRORS;
  1174. }
  1175. continue;
  1176. }
  1177. Temp = _tcsstr(Buffer, GETFILEVER_PREFIX);
  1178. if (Temp==Buffer)
  1179. {
  1180. Temp+= _tcslen(GETFILEVER_PREFIX);
  1181. if (StringCbCopy(CsvContents.KrnlPolicy.GetFileVersion , sizeof CsvContents.KrnlPolicy.GetFileVersion , Temp) != S_OK)
  1182. {
  1183. goto ERRORS;
  1184. }
  1185. continue;
  1186. }
  1187. Temp = _tcsstr(Buffer, MEMDUMP_PREFIX);
  1188. if (Temp==Buffer)
  1189. {
  1190. Temp+= _tcslen(MEMDUMP_PREFIX);
  1191. if (StringCbCopy(CsvContents.KrnlPolicy.MemoryDump , sizeof CsvContents.KrnlPolicy.MemoryDump, Temp) != S_OK)
  1192. {
  1193. goto ERRORS;
  1194. }
  1195. continue;
  1196. }
  1197. Temp = _tcsstr(Buffer, ALLOW_EXTERNAL_PREFIX);
  1198. if (Temp==Buffer)
  1199. {
  1200. Temp+= _tcslen(ALLOW_EXTERNAL_PREFIX);
  1201. if (StringCbCopy(CsvContents.KrnlPolicy.AllowResponse , sizeof CsvContents.KrnlPolicy.AllowResponse, Temp) != S_OK)
  1202. {
  1203. goto ERRORS;
  1204. }
  1205. continue;
  1206. }
  1207. ZeroMemory(Buffer, sizeof Buffer);
  1208. } while (_fgetts(Buffer, sizeof Buffer, pFile));
  1209. fclose(pFile);
  1210. return TRUE;
  1211. }
  1212. else
  1213. {
  1214. return FALSE;
  1215. }
  1216. ERRORS:
  1217. if (pFile)
  1218. {
  1219. fclose(pFile);
  1220. }
  1221. return FALSE;
  1222. }
  1223. void OnKrnlContextMenu(HWND hwnd,
  1224. LPARAM lParam)
  1225. /*++
  1226. Routine Description:
  1227. This routine Loads and provides a message pump for the Kernel mode context menu
  1228. Arguments:
  1229. hwnd - Handle of the Kernel mode dialog box
  1230. lParam - Not Used
  1231. Return value:
  1232. Does not return a value
  1233. ++*/
  1234. {
  1235. BOOL Result = FALSE;
  1236. HMENU hMenu = NULL;
  1237. HMENU hmenuPopup = NULL;
  1238. int xPos, yPos;
  1239. hMenu = LoadMenu(g_hinst, MAKEINTRESOURCE( IDR_KRNLCONTEXT));
  1240. hmenuPopup = GetSubMenu (hMenu,0);
  1241. if (!hmenuPopup)
  1242. {
  1243. //MessageBox(NULL,"Failed to get sub item", NULL,MB_OK);
  1244. ;
  1245. }
  1246. else
  1247. {
  1248. // Grey out the menu items
  1249. EnableMenuItem (hMenu, ID_SUBMIT_FAULTS, MF_BYCOMMAND| MF_GRAYED);
  1250. EnableMenuItem (hMenu, ID_REPORT_ALLKERNELMODEFAULTS, MF_BYCOMMAND| MF_GRAYED);
  1251. EnableMenuItem (hMenu, ID_VIEW_BUCKETCABFILEDIRECTORY125, MF_BYCOMMAND| MF_GRAYED);
  1252. EnableMenuItem (hMenu, ID_SPECIFIC_BUCKET, MF_BYCOMMAND| MF_GRAYED);
  1253. EnableMenuItem (hMenu, ID_VIEW_BUCKETOVERRIDERESPONSE166, MF_BYCOMMAND| MF_GRAYED);
  1254. EnableMenuItem (hMenu, ID_VIEW_CRASH, MF_BYCOMMAND| MF_GRAYED);
  1255. EnableMenuItem (hMenu, ID_VIEW_REFRESH121, MF_BYCOMMAND| MF_GRAYED);
  1256. //EnableMenuItem (hMenu, ID_EDIT_COPY147, MF_BYCOMMAND| MF_GRAYED);
  1257. EnableMenuItem (hMenu, ID_POPUP_VIEW_KERNELBUCKETPOLICY, MF_BYCOMMAND| MF_GRAYED);
  1258. EnableMenuItem (hMenu, ID_EDIT_DEFAULTREPORTINGOPTIONS, MF_BYCOMMAND| MF_GRAYED);
  1259. EnableMenuItem (hMenu, ID_EXPORT_KERNELMODEFAULTDATA172, MF_BYCOMMAND| MF_GRAYED);
  1260. if (_tcscmp(CerRoot, _T("\0")))
  1261. {
  1262. // Enable the menu items
  1263. EnableMenuItem (hMenu, ID_SUBMIT_FAULTS, MF_BYCOMMAND| MF_ENABLED);
  1264. EnableMenuItem (hMenu, ID_REPORT_ALLKERNELMODEFAULTS, MF_BYCOMMAND| MF_ENABLED);
  1265. EnableMenuItem (hMenu, ID_VIEW_BUCKETCABFILEDIRECTORY125, MF_BYCOMMAND| MF_ENABLED);
  1266. EnableMenuItem (hMenu, ID_SPECIFIC_BUCKET, MF_BYCOMMAND| MF_ENABLED);
  1267. EnableMenuItem (hMenu, ID_VIEW_BUCKETOVERRIDERESPONSE166, MF_BYCOMMAND| MF_ENABLED);
  1268. EnableMenuItem (hMenu, ID_VIEW_CRASH, MF_BYCOMMAND| MF_ENABLED);
  1269. EnableMenuItem (hMenu, ID_VIEW_REFRESH121, MF_BYCOMMAND| MF_ENABLED);
  1270. //EnableMenuItem (hMenu, ID_EDIT_COPY147, MF_BYCOMMAND| MF_ENABLED);
  1271. EnableMenuItem (hMenu, ID_POPUP_VIEW_KERNELBUCKETPOLICY, MF_BYCOMMAND| MF_ENABLED);
  1272. EnableMenuItem (hMenu, ID_EDIT_DEFAULTREPORTINGOPTIONS, MF_BYCOMMAND| MF_ENABLED);
  1273. // EnableMenuItem (hMenu, ID_EXPORT_KERNELMODEFAULTDATA172, MF_BYCOMMAND| MF_ENABLED);
  1274. if (!g_bAdminAccess)
  1275. {
  1276. EnableMenuItem (hMenu, ID_SUBMIT_FAULTS, MF_BYCOMMAND| MF_GRAYED);
  1277. EnableMenuItem (hMenu, ID_REPORT_ALLKERNELMODEFAULTS, MF_BYCOMMAND| MF_GRAYED);
  1278. EnableMenuItem (hMenu, ID_EDIT_DEFAULTREPORTINGOPTIONS, MF_BYCOMMAND| MF_GRAYED);
  1279. EnableMenuItem (hMenu, ID_POPUP_VIEW_KERNELBUCKETPOLICY, MF_BYCOMMAND| MF_GRAYED);
  1280. }
  1281. }
  1282. xPos = GET_X_LPARAM(lParam);
  1283. yPos = GET_Y_LPARAM(lParam);
  1284. Result = TrackPopupMenu (hmenuPopup, TPM_LEFTALIGN | TPM_RIGHTBUTTON, xPos,yPos,0,hwnd,NULL);
  1285. }
  1286. if (hMenu)
  1287. DestroyMenu(hMenu);
  1288. }
  1289. void DoLaunchBrowser(HWND hwnd, BOOL URL_OVERRIDE)
  1290. /*++
  1291. Routine Description:
  1292. This routine Launches the system default Web browser useing shellexec
  1293. Arguments:
  1294. hwnd - Handle of the Kernel mode dialog box
  1295. Return value:
  1296. Does not return a value
  1297. ++*/
  1298. {
  1299. TCHAR Url [255];
  1300. HWND hList = GetDlgItem(hwnd, IDC_KRNL_LIST);
  1301. // TCHAR CommandLine[512];
  1302. // STARTUPINFO StartupInfo;
  1303. // PROCESS_INFORMATION ProcessInfo;
  1304. int sel;
  1305. ZeroMemory (Url, sizeof Url);
  1306. if (!URL_OVERRIDE)
  1307. {
  1308. sel = ListView_GetNextItem(hList,-1, LVNI_SELECTED);
  1309. ListView_GetItemText(hList, sel,2, Url,sizeof Url);
  1310. }
  1311. else
  1312. {
  1313. if (StringCbCopy(Url, sizeof Url, CsvContents.KrnlPolicy.UrlToLaunch) != S_OK)
  1314. {
  1315. goto ERRORS;
  1316. }
  1317. }
  1318. if ( (!_tcsncicmp(Url, _T("http://"), _tcslen(_T("http://")))) || (!_tcsncicmp(Url, _T("https://"), _tcslen(_T("https://")))))
  1319. {
  1320. if (_tcscmp(Url, _T("\0")))
  1321. {
  1322. SHELLEXECUTEINFOA sei = {0};
  1323. sei.cbSize = sizeof(sei);
  1324. sei.lpFile = Url;
  1325. sei.nShow = SW_SHOWDEFAULT;
  1326. if (! ShellExecuteEx(&sei) )
  1327. {
  1328. // What do we display here.
  1329. ;
  1330. }
  1331. }
  1332. }
  1333. ERRORS:
  1334. ;
  1335. }
  1336. void UpdateCsv(TCHAR *ResponseUrl)
  1337. /*++
  1338. Routine Description:
  1339. This routine updates Kernel.csv with the current Microsoft response data and bucket counts.
  1340. Called by KrnlUploadThreadProc()
  1341. Arguments:
  1342. ResponseUrl - Microsoft response for the recently submitted dump file.
  1343. Return value:
  1344. Does not return a value
  1345. ++*/
  1346. {
  1347. TCHAR BucketId[100];
  1348. TCHAR BucketString[MAX_PATH];
  1349. TCHAR szResponse1[MAX_PATH];
  1350. TCHAR szResponse2[MAX_PATH];
  1351. TCHAR *SourceChar;
  1352. TCHAR *DestChar;
  1353. TCHAR GBsid[100];
  1354. int CharCount = 0;
  1355. // Parse the returned url and update the Csv file data structurs.
  1356. // Make sure the response URL has data.
  1357. if (!_tcscmp(ResponseUrl, _T("\0")))
  1358. {
  1359. goto ERRORS;
  1360. }
  1361. // TO DO--- Add a check for an SID of -1 and zero out the string if found.
  1362. SourceChar = ResponseUrl;
  1363. DestChar = szResponse1;
  1364. CharCount = sizeof szResponse1/ sizeof TCHAR - sizeof TCHAR;
  1365. while ((CharCount > 0) && (*SourceChar != _T('&')) &&( *SourceChar != _T('\0')) )
  1366. {
  1367. --CharCount;
  1368. *DestChar = *SourceChar;
  1369. ++DestChar;
  1370. ++SourceChar;
  1371. }
  1372. *DestChar = _T('\0');
  1373. ++SourceChar; // Skip the &
  1374. // Get the SBucket String
  1375. SourceChar = _tcsstr(ResponseUrl, _T("szSBucket="));
  1376. if (SourceChar)
  1377. {
  1378. CharCount = sizeof BucketString/ sizeof TCHAR - sizeof TCHAR;
  1379. SourceChar += 10;
  1380. DestChar = BucketString;
  1381. while ((CharCount > 0) && (*SourceChar != _T('&')))
  1382. {
  1383. --CharCount;
  1384. *DestChar = *SourceChar;
  1385. ++DestChar;
  1386. ++SourceChar;
  1387. }
  1388. *DestChar = _T('\0');
  1389. }
  1390. // Get the sbucket int
  1391. SourceChar = _tcsstr(ResponseUrl, _T("iSBucket="));
  1392. if (SourceChar)
  1393. {
  1394. SourceChar += 9;
  1395. DestChar = BucketId;
  1396. CharCount = sizeof BucketId/ sizeof TCHAR - sizeof TCHAR;
  1397. while ((CharCount > 0) && (*SourceChar != _T('&')) )
  1398. {
  1399. --CharCount;
  1400. *DestChar = *SourceChar;
  1401. ++DestChar;
  1402. ++SourceChar;
  1403. }
  1404. *DestChar = _T('\0');
  1405. }
  1406. // Get the gBucket sid
  1407. SourceChar = _tcsstr(ResponseUrl, _T("gsid="));
  1408. if (SourceChar)
  1409. {
  1410. SourceChar += 5;
  1411. DestChar = GBsid;
  1412. CharCount = sizeof GBsid/ sizeof TCHAR - sizeof TCHAR;
  1413. while((CharCount > 0) && (*SourceChar != _T('&')) && (*SourceChar != _T('\0')) )
  1414. {
  1415. --CharCount;
  1416. *DestChar = *SourceChar;
  1417. ++DestChar;
  1418. ++SourceChar;
  1419. }
  1420. *DestChar = _T('\0');
  1421. }
  1422. // Build the gBucket Response String
  1423. if (StringCbCopy(szResponse2,sizeof szResponse2, szResponse1) != S_OK)
  1424. {
  1425. goto ERRORS;
  1426. }
  1427. SourceChar = szResponse2;
  1428. SourceChar += _tcslen(szResponse2) * sizeof TCHAR;
  1429. if (SourceChar != szResponse2)
  1430. {
  1431. while((*(SourceChar -1) != _T('=')) && ( (SourceChar -1) != szResponse2))
  1432. {
  1433. -- SourceChar;
  1434. }
  1435. if (StringCbCopy (SourceChar, sizeof szResponse2 - (_tcslen(SourceChar) *sizeof TCHAR), GBsid) != S_OK)
  1436. {
  1437. goto ERRORS;
  1438. }
  1439. }
  1440. CsvContents.UpdateList(BucketId,BucketString, szResponse1, szResponse2);
  1441. ERRORS:
  1442. return;
  1443. }
  1444. void RenameToOld(TCHAR *szFileName)
  1445. /*++
  1446. Routine Description:
  1447. This routine renames a proccessed cab file from .cab to .old
  1448. Arguments:
  1449. ResponseUrl - Microsoft response for the recently submitted dump file.
  1450. Return value:
  1451. Does not return a value
  1452. ++*/
  1453. {
  1454. TCHAR szFileNameOld[MAX_PATH];
  1455. TCHAR *Temp;
  1456. if (StringCbCopy(szFileNameOld,sizeof szFileNameOld, szFileName) != S_OK)
  1457. {
  1458. goto ERRORS;
  1459. }
  1460. Temp = szFileNameOld;
  1461. Temp += _tcslen(szFileNameOld) * sizeof TCHAR;
  1462. while ( (*Temp != _T('.')) && (Temp != szFileNameOld))
  1463. {
  1464. Temp --;
  1465. }
  1466. if (Temp == szFileNameOld)
  1467. {
  1468. // Abort since we did not find the .cab extension.
  1469. goto ERRORS;
  1470. }
  1471. else
  1472. {
  1473. if (StringCbCopy (Temp, (_tcslen(szFileNameOld) * sizeof TCHAR) - ( _tcslen(szFileNameOld) * sizeof TCHAR - 5 * sizeof TCHAR), _T(".old")) != S_OK)
  1474. {
  1475. goto ERRORS;
  1476. }
  1477. MoveFileEx(szFileName, szFileNameOld, TRUE);
  1478. }
  1479. ERRORS:
  1480. return;
  1481. }
  1482. DWORD WINAPI KrnlUploadThreadProc (void *ThreadParam)
  1483. /*++
  1484. Routine Description:
  1485. This routine renames a proccessed cab file from .cab to .old
  1486. Arguments:
  1487. ResponseUrl - Microsoft response for the recently submitted dump file.
  1488. Return value:
  1489. Does not return a value
  1490. ++*/
  1491. {
  1492. HANDLE hFind = INVALID_HANDLE_VALUE;
  1493. WIN32_FIND_DATA FindData;
  1494. TCHAR szFileName[MAX_PATH];
  1495. // HANDLE hCsv;
  1496. TCHAR szSearchPath[MAX_PATH];
  1497. TCHAR ResponseURL[MAX_PATH];
  1498. TCHAR DestinationName[MAX_PATH];
  1499. TCHAR StaticText[MAX_PATH];
  1500. // int CurrentPos = 0;
  1501. TCHAR CsvName[MAX_PATH];
  1502. int ErrorCode = 0;
  1503. HANDLE hEvent = NULL;
  1504. ZeroMemory( szFileName, sizeof szFileName);
  1505. ZeroMemory( ResponseURL, sizeof ResponseURL);
  1506. ZeroMemory( szSearchPath, sizeof szSearchPath);
  1507. ZeroMemory( DestinationName, sizeof DestinationName);
  1508. ZeroMemory( StaticText, sizeof StaticText);
  1509. ZeroMemory( CsvName, sizeof CsvName);
  1510. hEvent = OpenEvent(EVENT_ALL_ACCESS, FALSE, _T("StopKernelUpload"));
  1511. if (!hEvent)
  1512. {
  1513. goto ERRORS;
  1514. }
  1515. else
  1516. {
  1517. if (WaitForSingleObject(hEvent, 50) == WAIT_OBJECT_0)
  1518. {
  1519. goto ERRORS;
  1520. }
  1521. }
  1522. if (StringCbPrintf(CsvName, sizeof CsvName, _T("%s\\cabs\\blue\\Kernel.csv"), CerRoot) != S_OK)
  1523. {
  1524. goto ERRORS;
  1525. }
  1526. if (StringCbPrintf(szSearchPath,sizeof szSearchPath, _T("%s\\cabs\\blue\\*.cab"), CerRoot) != S_OK)
  1527. {
  1528. goto ERRORS;
  1529. }
  1530. // Get the next file to upload
  1531. hFind = FindFirstFile(szSearchPath, &FindData);
  1532. if (hFind != INVALID_HANDLE_VALUE)
  1533. {
  1534. do {
  1535. // Did the upload get canceled
  1536. if (WaitForSingleObject(hEvent, 50) == WAIT_OBJECT_0)
  1537. {
  1538. goto Canceled;
  1539. }
  1540. if (StringCbPrintf(szFileName, sizeof szFileName, _T("%s\\cabs\\blue\\%s"), CerRoot, FindData.cFileName) != S_OK)
  1541. {
  1542. goto ERRORS;
  1543. }
  1544. // Upload the file
  1545. if (StringCbPrintf(StaticText, sizeof StaticText, _T("Uploading File: %s"), szFileName) != S_OK)
  1546. {
  1547. goto ERRORS;
  1548. }
  1549. SetDlgItemText(* ((HWND *) ThreadParam), IDC_CAB_TEXT, StaticText);
  1550. ErrorCode = UploadDumpFile(KRNL_MODE_SERVER, szFileName,_T("OCA"), DestinationName);
  1551. if (ErrorCode == 1)
  1552. {
  1553. goto ERRORS;
  1554. }
  1555. if (ErrorCode != 0) // all other errors are related to a particular file not the internet connection
  1556. { // Move on to the next file.
  1557. goto SKIPIT;
  1558. }
  1559. SendDlgItemMessage(*((HWND *) ThreadParam) ,IDC_FILE_PROGRESS, PBM_STEPIT, 0,0);
  1560. // Get the response for the file.
  1561. if (StringCbPrintf(StaticText, sizeof StaticText, _T("Retrieving response for: %s"), szFileName) != S_OK)
  1562. {
  1563. goto ERRORS;
  1564. }
  1565. else
  1566. {
  1567. SetDlgItemText(* ((HWND *) ThreadParam), IDC_CAB_TEXT, StaticText);
  1568. ErrorCode = GetResponseUrl(KRNL_MODE_SERVER, DestinationName, ResponseURL);
  1569. if (ErrorCode == -1)
  1570. {
  1571. // Internet connection error.
  1572. // We need to stop processing.
  1573. goto ERRORS;
  1574. //RenameToOld(szFileName); // we don't want to halt processing for these errors.
  1575. //ErrorCode = 2;
  1576. //goto ERRORS;
  1577. }
  1578. else
  1579. {
  1580. if (ErrorCode == -2)
  1581. {
  1582. // all other errors we just rename the file and keep going.
  1583. RenameToOld(szFileName);
  1584. goto SKIPIT;
  1585. }
  1586. else
  1587. {
  1588. RenameToOld(szFileName);
  1589. // MessageBox(NULL, ResponseURL, "Received Response", MB_OK);
  1590. SendDlgItemMessage(*((HWND *) ThreadParam) ,IDC_FILE_PROGRESS, PBM_STEPIT, 0,0);
  1591. // Update the CSV File
  1592. //
  1593. if (StringCbPrintf(StaticText, sizeof StaticText, _T("Updating local data:")) != S_OK)
  1594. {
  1595. goto ERRORS;
  1596. }
  1597. SetDlgItemText(* ((HWND *) ThreadParam), IDC_CAB_TEXT, StaticText);
  1598. SendDlgItemMessage(*((HWND *) ThreadParam) ,IDC_FILE_PROGRESS, PBM_STEPIT, 0,0);
  1599. // Update Status
  1600. UpdateCsv(ResponseURL);
  1601. //CsvContents.WriteCsv();
  1602. SendDlgItemMessage(*((HWND *) ThreadParam) ,IDC_TOTAL_PROGRESS, PBM_STEPIT, 0,0);
  1603. SendDlgItemMessage(*((HWND *) ThreadParam) ,IDC_FILE_PROGRESS, PBM_SETPOS, 0,0);
  1604. }
  1605. }
  1606. }
  1607. SKIPIT:
  1608. ;
  1609. } while (FindNextFile(hFind, &FindData));
  1610. FindClose( hFind);
  1611. hFind = INVALID_HANDLE_VALUE;
  1612. Canceled:
  1613. CsvContents.WriteCsv();
  1614. }
  1615. ERRORS:
  1616. if (ErrorCode == 1)
  1617. {
  1618. MessageBox(* ((HWND *) ThreadParam), _T("Upload to Microsoft failed.\r\nPlease check your Internet Connection"), NULL,MB_OK);
  1619. }
  1620. if (ErrorCode == 2)
  1621. {
  1622. //MessageBox(* ((HWND *) ThreadParam), _T("Failed to retrieve a response from Microsoft."), NULL,MB_OK);
  1623. }
  1624. if (hFind != INVALID_HANDLE_VALUE)
  1625. {
  1626. FindClose(hFind);
  1627. }
  1628. PostMessage(*((HWND *) ThreadParam), WmSyncDone, FALSE, 0);
  1629. if (hEvent)
  1630. {
  1631. CloseHandle(hEvent);
  1632. hEvent = NULL;
  1633. }
  1634. //RefreshKrnlView(*((HWND *) ThreadParam));
  1635. return 0;
  1636. }
  1637. LRESULT CALLBACK
  1638. KrnlSubmitDlgProc(
  1639. HWND hwnd,
  1640. UINT iMsg,
  1641. WPARAM wParam,
  1642. LPARAM lParam
  1643. )
  1644. /*++
  1645. Routine Description:
  1646. This routine renames a proccessed cab file from .cab to .old
  1647. Arguments:
  1648. ResponseUrl - Microsoft response for the recently submitted dump file.
  1649. Return value:
  1650. Does not return a value
  1651. ++*/
  1652. {
  1653. // int CurrentPos = 0;
  1654. // HWND Parent = GetParent(hwnd);
  1655. switch (iMsg)
  1656. {
  1657. case WM_INITDIALOG:
  1658. // Start the upload process in a new thread.
  1659. // Report results using WM_FILEDONE
  1660. // CreateEvent();
  1661. SendDlgItemMessage(hwnd,IDC_TOTAL_PROGRESS, PBM_SETRANGE,0, MAKELPARAM(0, KModeData.UnprocessedCount));
  1662. SendDlgItemMessage(hwnd ,IDC_TOTAL_PROGRESS, PBM_SETSTEP, MAKELONG( 1,0),0);
  1663. SendDlgItemMessage(hwnd,IDC_FILE_PROGRESS, PBM_SETRANGE,0, MAKELPARAM(0, 3));
  1664. SendDlgItemMessage(hwnd ,IDC_FILE_PROGRESS, PBM_SETSTEP, MAKELONG( 1,0),0);
  1665. g_hStopEvent = CreateEvent(NULL, FALSE, FALSE, _T("StopKernelUpload"));
  1666. if (!g_hStopEvent)
  1667. {
  1668. PostMessage(hwnd, WmSyncDone, FALSE,0);
  1669. }
  1670. PostMessage(hwnd, WmSyncStart, FALSE, 0);
  1671. break;
  1672. case WmSyncStart:
  1673. HANDLE hThread;
  1674. ThreadParam = hwnd;
  1675. hThread = CreateThread(NULL, 0,KrnlUploadThreadProc , &ThreadParam, 0 , NULL );
  1676. CloseHandle(hThread);
  1677. // OnSubmitDlgInit(hwnd);
  1678. break;
  1679. case WmSetStatus:
  1680. break;
  1681. case WmSyncDone:
  1682. if (g_hStopEvent)
  1683. {
  1684. CloseHandle(g_hStopEvent);
  1685. g_hStopEvent = NULL;
  1686. }
  1687. EndDialog(hwnd, 1);
  1688. return TRUE;
  1689. case WM_DESTROY:
  1690. if (g_hStopEvent)
  1691. {
  1692. SetEvent(g_hStopEvent);
  1693. if (g_hStopEvent)
  1694. CloseHandle(g_hStopEvent);
  1695. }
  1696. else
  1697. {
  1698. EndDialog(hwnd, 1);
  1699. }
  1700. break;
  1701. case WM_COMMAND:
  1702. switch (LOWORD(wParam))
  1703. {
  1704. case IDCANCEL:
  1705. if (g_hStopEvent)
  1706. {
  1707. SetEvent(g_hStopEvent);
  1708. CloseHandle(g_hStopEvent);
  1709. g_hStopEvent = NULL;
  1710. }
  1711. else
  1712. {
  1713. EndDialog(hwnd, 1);
  1714. }
  1715. break;
  1716. }
  1717. }
  1718. return FALSE;
  1719. }
  1720. void DoViewBucketDirectory()
  1721. {
  1722. TCHAR szPath[MAX_PATH];
  1723. if (StringCbPrintf(szPath, sizeof szPath, _T("%s\\cabs\\blue"), CerRoot) != S_OK)
  1724. return;
  1725. else
  1726. {
  1727. SHELLEXECUTEINFOA sei = {0};
  1728. sei.cbSize = sizeof(sei);
  1729. sei.lpFile = szPath;
  1730. sei.nShow = SW_SHOWDEFAULT;
  1731. if (! ShellExecuteEx(&sei) )
  1732. {
  1733. // What do we display here.
  1734. ;
  1735. }
  1736. }
  1737. }
  1738. VOID DoSubmitKernelFaults(HWND hwnd)
  1739. /*++
  1740. Routine Description:
  1741. This routine renames a proccessed cab file from .cab to .old
  1742. Arguments:
  1743. ResponseUrl - Microsoft response for the recently submitted dump file.
  1744. Return value:
  1745. Does not return a value
  1746. ++*/
  1747. {
  1748. //HANDLE hFind = INVALID_HANDLE_VALUE;
  1749. //WIN32_FIND_DATA FindData;
  1750. //TCHAR szPath[MAX_PATH];
  1751. // handled by the Progress bar dialog box.
  1752. // First check to see if there are any cabs to submit
  1753. /* if (_tcscmp(CerRoot, _T("\0")))
  1754. {
  1755. ZeroMemory (szPath, sizeof szPath);
  1756. // From the filetree root goto cabs/bluescreen
  1757. if (StringCbCopy(szPath, sizeof szPath, CerRoot) != S_OK)
  1758. {
  1759. goto ERRORS;
  1760. }
  1761. if (StringCbCat(szPath, sizeof szPath, _T("\\cabs\\blue\\*.cab")) != S_OK)
  1762. {
  1763. goto ERRORS;
  1764. }
  1765. hFind = FindFirstFile(szPath, &FindData);
  1766. if (hFind != INVALID_HANDLE_VALUE)
  1767. {
  1768. // we have at least 1 to upload
  1769. FindClose(hFind);
  1770. */
  1771. DialogBox (g_hinst,MAKEINTRESOURCE(IDD_KERNEL_SYNC) , hwnd, (DLGPROC)KrnlSubmitDlgProc);
  1772. if (g_hStopEvent)
  1773. {
  1774. CloseHandle(g_hStopEvent);
  1775. g_hStopEvent = NULL;
  1776. }
  1777. // }
  1778. ///}
  1779. RefreshKrnlView(hwnd);
  1780. //ERRORS:
  1781. return;
  1782. }
  1783. BOOL DisplayKrnlBucketData(HWND hwnd, int iItem)
  1784. {
  1785. HWND hEditBox = GetDlgItem(hwnd, IDC_KRNL_EDIT);
  1786. TCHAR *Buffer = NULL; // we have to use a dynamic buffer since we don't
  1787. // have a clue as to the text length.
  1788. DWORD BufferLength = 100000; // 100k bytes should be plenty. or 50K unicode chars.
  1789. TCHAR *Dest = NULL;
  1790. TCHAR *Source = NULL;
  1791. TCHAR TempBuffer[1000];
  1792. ZeroMemory (TempBuffer,sizeof TempBuffer);
  1793. Buffer = (TCHAR *) malloc (BufferLength);
  1794. if (Buffer)
  1795. {
  1796. ZeroMemory(Buffer,BufferLength);
  1797. // Basic data collection first.
  1798. if ( (!_tcscmp (CsvContents.KrnlPolicy.SecondLevelData, _T("YES"))) && (_tcscmp(CsvContents.KrnlPolicy.FileCollection, _T("YES"))) )
  1799. {
  1800. if (StringCbPrintf(Buffer, BufferLength, _T("The following information will be sent to Microsoft.\r\n\tHowever, this bucket's policy would prevent files and user documents from being reported.\r\n"))!= S_OK)
  1801. {
  1802. goto ERRORS;
  1803. }
  1804. }
  1805. else
  1806. {
  1807. if (!_tcscmp(CsvContents.KrnlPolicy.FileCollection, _T("YES")))
  1808. {
  1809. if (StringCbCat(Buffer,BufferLength, _T(" Microsoft would like to collect the following information but default policy\r\n\tprevents files and user documents from being reported.\r\n\t As a result, no exchange will take place.\r\n"))!= S_OK)
  1810. {
  1811. goto ERRORS;
  1812. }
  1813. }
  1814. else
  1815. {
  1816. if ( !_tcscmp (CsvContents.KrnlPolicy.SecondLevelData, _T("YES")))
  1817. {
  1818. if (StringCbPrintf(Buffer, BufferLength, _T("Microsoft would like to collect the following information but the default policy prevents the exchange.\r\n"))!= S_OK)
  1819. {
  1820. goto ERRORS;
  1821. }
  1822. }
  1823. else
  1824. {
  1825. if (StringCbPrintf(Buffer, BufferLength, _T("The following information will be sent to Microsoft:\r\n"))!= S_OK)
  1826. {
  1827. goto ERRORS;
  1828. }
  1829. }
  1830. }
  1831. }
  1832. if (_tcscmp(CsvContents.KrnlPolicy.GetFile, _T("\0")))
  1833. {
  1834. if (StringCbCat(Buffer, BufferLength, _T("These files:\r\n"))!= S_OK)
  1835. {
  1836. goto ERRORS;
  1837. }
  1838. Source = CsvContents.KrnlPolicy.GetFile;
  1839. while ((*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n')) )
  1840. {
  1841. ZeroMemory (TempBuffer, sizeof TempBuffer);
  1842. Dest = TempBuffer;
  1843. while ( (*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n'))&& (*Source != _T(';') ))
  1844. {
  1845. *Dest = *Source;
  1846. ++Dest;
  1847. ++Source;
  1848. }
  1849. if (*Source == _T(';'))
  1850. {
  1851. ++Source;
  1852. }
  1853. *Dest =_T('\0');
  1854. if (StringCbCat(Dest, sizeof TempBuffer, _T("\r\n")) != S_OK)
  1855. {
  1856. goto ERRORS;
  1857. }
  1858. if (StringCbCat(Buffer, BufferLength, _T("\t") )!= S_OK)
  1859. {
  1860. goto ERRORS;
  1861. }
  1862. if (StringCbCat(Buffer, BufferLength, TempBuffer )!= S_OK)
  1863. {
  1864. goto ERRORS;
  1865. }
  1866. }
  1867. }
  1868. if (_tcscmp(CsvContents.KrnlPolicy.RegKey, _T("\0")))
  1869. {
  1870. if (StringCbCat(Buffer, BufferLength, _T("These Registry Keys:\r\n"))!= S_OK)
  1871. {
  1872. goto ERRORS;
  1873. }
  1874. Source = CsvContents.KrnlPolicy.RegKey;
  1875. while ((*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n')) )
  1876. {
  1877. ZeroMemory (TempBuffer, sizeof TempBuffer);
  1878. Dest = TempBuffer;
  1879. while ( (*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n'))&& (*Source != _T(';') ))
  1880. {
  1881. *Dest = *Source;
  1882. ++Dest;
  1883. ++Source;
  1884. }
  1885. if (*Source == _T(';'))
  1886. {
  1887. ++Source;
  1888. }
  1889. *Dest =_T('\0');
  1890. if (StringCbCat(Dest, sizeof TempBuffer, _T("\r\n")) != S_OK)
  1891. {
  1892. goto ERRORS;
  1893. }
  1894. if (StringCbCat(Buffer, BufferLength, _T("\t") )!= S_OK)
  1895. {
  1896. goto ERRORS;
  1897. }
  1898. if (StringCbCat(Buffer, BufferLength, TempBuffer )!= S_OK)
  1899. {
  1900. goto ERRORS;
  1901. }
  1902. }
  1903. }
  1904. if (_tcscmp(CsvContents.KrnlPolicy.WQL, _T("\0")))
  1905. {
  1906. if (StringCbCat(Buffer, BufferLength, _T("The Results of these WQL queries:\r\n"))!= S_OK)
  1907. {
  1908. goto ERRORS;
  1909. }
  1910. // Replace ; with \t\r\n
  1911. Source = CsvContents.KrnlPolicy.WQL;
  1912. while ((*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n')) )
  1913. {
  1914. ZeroMemory (TempBuffer, sizeof TempBuffer);
  1915. Dest = TempBuffer;
  1916. while ( (*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n'))&& (*Source != _T(';') ))
  1917. {
  1918. *Dest = *Source;
  1919. ++Dest;
  1920. ++Source;
  1921. }
  1922. if (*Source == _T(';'))
  1923. {
  1924. ++Source;
  1925. }
  1926. *Dest =_T('\0');
  1927. if (StringCbCat(Dest, sizeof TempBuffer, _T("\r\n")) != S_OK)
  1928. {
  1929. goto ERRORS;
  1930. }
  1931. if (StringCbCat(Buffer, BufferLength, _T("\t") )!= S_OK)
  1932. {
  1933. goto ERRORS;
  1934. }
  1935. if (StringCbCat(Buffer, BufferLength, TempBuffer )!= S_OK)
  1936. {
  1937. goto ERRORS;
  1938. }
  1939. }
  1940. }
  1941. if (!_tcscmp (CsvContents.KrnlPolicy.MemoryDump, _T("YES")))
  1942. {
  1943. if (StringCbCat(Buffer, BufferLength, _T("The contents of memory\r\n"))!= S_OK)
  1944. {
  1945. goto ERRORS;
  1946. }
  1947. }
  1948. if (_tcscmp(CsvContents.KrnlPolicy.GetFileVersion, _T("\0")))
  1949. {
  1950. if (StringCbCat(Buffer, BufferLength, _T("The versions of these files:\r\n"))!= S_OK)
  1951. {
  1952. goto ERRORS;
  1953. }
  1954. Source = CsvContents.KrnlPolicy.GetFileVersion;
  1955. while ((*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n')) )
  1956. {
  1957. ZeroMemory (TempBuffer, sizeof TempBuffer);
  1958. Dest = TempBuffer;
  1959. while ( (*Source != _T('\0')) && (*Source != _T('\r')) && (*Source != _T('\n'))&& (*Source != _T(';') ))
  1960. {
  1961. *Dest = *Source;
  1962. ++Dest;
  1963. ++Source;
  1964. }
  1965. if (*Source == _T(';'))
  1966. {
  1967. ++Source;
  1968. }
  1969. *Dest =_T('\0');
  1970. if (StringCbCat(Dest, sizeof TempBuffer, _T("\r\n")) != S_OK)
  1971. {
  1972. goto ERRORS;
  1973. }
  1974. if (StringCbCat(Buffer, BufferLength, _T("\t") )!= S_OK)
  1975. {
  1976. goto ERRORS;
  1977. }
  1978. if (StringCbCat(Buffer, BufferLength, TempBuffer )!= S_OK)
  1979. {
  1980. goto ERRORS;
  1981. }
  1982. }
  1983. }
  1984. if (_tcscmp(CsvContents.KrnlPolicy.fDoc, _T("\0")))
  1985. {
  1986. if (StringCbCat(Buffer, BufferLength, _T("The users current document.\r\n"))!= S_OK)
  1987. {
  1988. goto ERRORS;
  1989. }
  1990. }
  1991. SendMessage(hEditBox, WM_SETTEXT, NULL, (LPARAM)Buffer);
  1992. }
  1993. ERRORS:
  1994. if (Buffer)
  1995. free(Buffer);
  1996. return TRUE;
  1997. }
  1998. /*
  1999. void KMCopyToClipboard(HWND hwnd)
  2000. {
  2001. if (!OpenClipboard(NULL))
  2002. return;
  2003. EmptyClipboard();
  2004. char rtfRowHeader[sizeof(rtfRowHeader1) + (sizeof(rtfRowHeader2)+6)*KRNL_COL_COUNT + sizeof(rtfRowHeader3)];
  2005. char *rtfWalk = rtfRowHeader;
  2006. memcpy(rtfWalk, rtfRowHeader1, sizeof(rtfRowHeader1));
  2007. rtfWalk += sizeof(rtfRowHeader1)-1;
  2008. DWORD cxTotal = 0;
  2009. for(int i=0;i<KRNL_COL_COUNT;i++)
  2010. {
  2011. LVCOLUMNA lv;
  2012. lv.mask = LVCF_WIDTH;
  2013. lv.iSubItem = i;
  2014. SendMessageA(GetDlgItem(hwnd,IDC_KRNL_LIST), LVM_GETCOLUMN, i, (LPARAM)&lv);
  2015. cxTotal += lv.cx;
  2016. wsprintf(rtfWalk, "%s%d", rtfRowHeader2, cxTotal);
  2017. while(*++rtfWalk)
  2018. ;
  2019. };
  2020. memcpy(rtfWalk, rtfRowHeader3, sizeof(rtfRowHeader3));
  2021. DWORD crtfHeader = strlen(rtfRowHeader);
  2022. DWORD crtf = 0, cwz = 0;
  2023. crtf += sizeof(rtfPrologue)-1;
  2024. int iSel = -1;
  2025. while ((iSel = SendMessageW(GetDlgItem(hwnd,IDC_KRNL_LIST), LVM_GETNEXTITEM, iSel, MAKELPARAM(LVNI_SELECTED, 0))) != -1)
  2026. {
  2027. crtf += crtfHeader;
  2028. for(int i=0;i<KRNL_COL_COUNT;i++)
  2029. {
  2030. WCHAR wzBuffer[1024];
  2031. LVITEMW lv;
  2032. lv.pszText = wzBuffer;
  2033. lv.cchTextMax = sizeof(wzBuffer);
  2034. lv.iSubItem = i;
  2035. lv.iItem = iSel;
  2036. cwz += SendMessageW(GetDlgItem(hwnd,IDC_KRNL_LIST), LVM_GETITEMTEXTW, iSel, (LPARAM)&lv);
  2037. cwz++;
  2038. crtf += WideCharToMultiByte(CP_ACP, 0, wzBuffer, -1, NULL, 0, NULL, NULL) - 1;
  2039. crtf += sizeof(rtfRowPref)-1;
  2040. crtf += sizeof(rtfRowSuff)-1;
  2041. };
  2042. cwz++;
  2043. crtf += sizeof(rtfRowFooter)-1;
  2044. };
  2045. crtf += sizeof(rtfEpilogue);
  2046. cwz++;
  2047. HGLOBAL hgwz = GlobalAlloc(GMEM_FIXED, cwz*sizeof(WCHAR));
  2048. HGLOBAL hgrtf = GlobalAlloc(GMEM_FIXED, crtf);
  2049. WCHAR *wz = (WCHAR *)GlobalLock(hgwz);
  2050. char *rtf = (char *)GlobalLock(hgrtf);
  2051. rtfWalk = rtf;
  2052. WCHAR *wzWalk = wz;
  2053. memcpy(rtfWalk, rtfPrologue, sizeof(rtfPrologue));
  2054. rtfWalk += sizeof(rtfPrologue)-1;
  2055. iSel = -1;
  2056. while ((iSel = SendMessageW(GetDlgItem(hwnd,IDC_KRNL_LIST), LVM_GETNEXTITEM, iSel, MAKELPARAM(LVNI_SELECTED, 0))) != -1)
  2057. {
  2058. memcpy(rtfWalk, rtfRowHeader, crtfHeader);
  2059. rtfWalk += crtfHeader;
  2060. for(int i=0;i<KRNL_COL_COUNT;i++)
  2061. {
  2062. memcpy(rtfWalk, rtfRowPref, sizeof(rtfRowPref));
  2063. rtfWalk += sizeof(rtfRowPref)-1;
  2064. LVITEMW lv;
  2065. lv.pszText = wzWalk;
  2066. lv.cchTextMax = cwz;
  2067. lv.iSubItem = i;
  2068. lv.iItem = iSel;
  2069. SendMessageW(GetDlgItem(hwnd, IDC_KRNL_LIST), LVM_GETITEMTEXTW, iSel, (LPARAM)&lv);
  2070. WideCharToMultiByte(CP_ACP, 0, wzWalk, -1, rtfWalk, crtf, NULL, NULL);
  2071. wzWalk += wcslen(wzWalk);
  2072. if (i == 11)
  2073. {
  2074. *wzWalk++ = L'\r';
  2075. *wzWalk++ = L'\n';
  2076. }
  2077. else
  2078. *wzWalk++ = L'\t';
  2079. rtfWalk += strlen(rtfWalk);
  2080. memcpy(rtfWalk, rtfRowSuff, sizeof(rtfRowSuff));
  2081. rtfWalk += sizeof(rtfRowSuff)-1;
  2082. };
  2083. memcpy(rtfWalk, rtfRowFooter, sizeof(rtfRowFooter));
  2084. rtfWalk += sizeof(rtfRowFooter)-1;
  2085. };
  2086. memcpy(rtfWalk, rtfEpilogue, sizeof(rtfEpilogue));
  2087. rtfWalk += sizeof(rtfEpilogue);
  2088. *wzWalk++ = 0;
  2089. // Assert(rtfWalk - rtf == crtf);
  2090. // Assert(wzWalk - wz == cwz);
  2091. GlobalUnlock(hgwz);
  2092. GlobalUnlock(hgrtf);
  2093. SetClipboardData(CF_UNICODETEXT, hgwz);
  2094. SetClipboardData(RegisterClipboardFormatA(szRTFClipFormat), hgrtf);
  2095. // hgwz and hgrtf are now owned by the system. DO NOT FREE!
  2096. CloseClipboard();
  2097. }
  2098. */
  2099. LRESULT CALLBACK
  2100. KrnlDlgProc(
  2101. HWND hwnd,
  2102. UINT iMsg,
  2103. WPARAM wParam,
  2104. LPARAM lParam
  2105. )
  2106. /*++
  2107. Routine Description:
  2108. This routine Is the notification handler for the Kernel Mode dialog box
  2109. Arguments:
  2110. ResponseUrl - Microsoft response for the recently submitted dump file.
  2111. Return value:
  2112. returns an LRESULT
  2113. TRUE = The message was handled.
  2114. FALSE = The message was ignored.
  2115. ++*/
  2116. {
  2117. TCHAR Temp[100];
  2118. switch (iMsg)
  2119. {
  2120. case WM_NOTIFY:
  2121. {
  2122. switch(((NMHDR *)lParam)->code)
  2123. {
  2124. case LVN_COLUMNCLICK:
  2125. _itot(((NM_LISTVIEW*)lParam)->iSubItem,Temp,10);
  2126. ListView_SortItemsEx( ((NMHDR *)lParam)->hwndFrom,
  2127. CompareFunc,
  2128. ((NM_LISTVIEW*)lParam)->iSubItem
  2129. );
  2130. g_bSortAsc = !g_bSortAsc;
  2131. break;
  2132. case NM_CLICK:
  2133. DisplayKrnlBucketData(hwnd, ((NM_LISTVIEW*)lParam)->iItem);
  2134. break;
  2135. }
  2136. return TRUE;
  2137. }
  2138. case WM_INITDIALOG:
  2139. OnKrnlDialogInit(hwnd);
  2140. return TRUE;
  2141. case WM_FileTreeLoaded:
  2142. RefreshKrnlView(hwnd);
  2143. return TRUE;
  2144. case WM_CONTEXTMENU:
  2145. OnKrnlContextMenu(hwnd, lParam );
  2146. return TRUE;
  2147. case WM_ERASEBKGND:
  2148. // Don't know why this doesn't happen automatically...
  2149. {
  2150. HDC hdc = (HDC)wParam;
  2151. HPEN hpen = (HPEN)CreatePen(PS_SOLID, 1, GetSysColor(COLOR_BTNFACE));
  2152. HPEN hpenOld = (HPEN)SelectObject(hdc, hpen);
  2153. SelectObject(hdc, GetSysColorBrush(COLOR_BTNFACE));
  2154. RECT rc;
  2155. GetClientRect(hwnd, &rc);
  2156. Rectangle(hdc, rc.left, rc.top, rc.right, rc.bottom);
  2157. SelectObject(hdc, hpenOld);
  2158. DeleteObject(hpen);
  2159. return TRUE;
  2160. }
  2161. case WM_COMMAND:
  2162. switch (LOWORD(wParam))
  2163. {
  2164. case ID_SPECIFIC_BUCKET:
  2165. DoLaunchBrowser(hwnd, FALSE);
  2166. break;
  2167. case ID_VIEW_BUCKETOVERRIDERESPONSE166:
  2168. DoLaunchBrowser(hwnd, TRUE);
  2169. break;
  2170. case ID_REPORT_ALLKERNELMODEFAULTS:
  2171. DoSubmitKernelFaults(hwnd);
  2172. //RefreshKrnlView(hwnd);
  2173. break;
  2174. case ID_VIEW_BUCKETCABFILEDIRECTORY125:
  2175. case ID_VIEW_BUCKETCABFILEDIRECTORY:
  2176. DoViewBucketDirectory();
  2177. break;
  2178. case ID_VIEW_REFRESH121:
  2179. case ID_VIEW_REFRESH:
  2180. RefreshKrnlView(hwnd);
  2181. break;
  2182. case ID_VIEW_CRASH:
  2183. ViewCrashLog();
  2184. break;
  2185. case ID_SUBMIT_FAULTS:
  2186. PostMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(ID_REPORT_ALLCRASHES,0),0);
  2187. break;
  2188. case ID_EDIT_DEFAULTREPORTINGOPTIONS:
  2189. PostMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(ID_EDIT_DEFAULTPOLICY,0),0);
  2190. break;
  2191. /// case ID_EDIT_COPY147:
  2192. // KMCopyToClipboard(hwnd);
  2193. // break;
  2194. case ID_POPUP_VIEW_KERNELBUCKETPOLICY:
  2195. PostMessage(GetParent(hwnd), WM_COMMAND, MAKEWPARAM(ID_EDIT_SELECTEDBUCKETSPOLICY,0),0);
  2196. break;
  2197. }
  2198. }
  2199. return FALSE;
  2200. }