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.

1664 lines
46 KiB

  1. #include "ulib.hxx"
  2. #include "list.hxx"
  3. #include "iterator.hxx"
  4. #include "drive.hxx"
  5. #include "ifssys.hxx"
  6. #include "ntfssa.hxx"
  7. #include "frs.hxx"
  8. #include "attrib.hxx"
  9. #include "mftfile.hxx"
  10. #include "bitfrs.hxx"
  11. #include "ntfsbit.hxx"
  12. #include "upfile.hxx"
  13. #include "upcase.hxx"
  14. #include "rfatsa.hxx"
  15. #include "secio.hxx"
  16. #include "clusio.hxx"
  17. #include "frsio.hxx"
  18. #include "rootio.hxx"
  19. #include "chainio.hxx"
  20. #include "fileio.hxx"
  21. #include "logrecio.hxx"
  22. #include "secedit.hxx"
  23. #include "frsedit.hxx"
  24. #include "indxedit.hxx"
  25. #include "secstr.hxx"
  26. #include "bootedit.hxx"
  27. #include "nbedit.hxx"
  28. #include "ofsbedit.hxx"
  29. #include "partedit.hxx"
  30. #include "gptedit.hxx"
  31. #include "restarea.hxx"
  32. #include "logreced.hxx"
  33. #include "rcache.hxx"
  34. #include "hmem.hxx"
  35. #include "attrio.hxx"
  36. #include "recordpg.hxx"
  37. #include "crack.hxx"
  38. #include "atrlsted.hxx"
  39. #include "diskedit.h"
  40. extern "C" {
  41. #include <stdio.h>
  42. }
  43. DECLARE_CLASS( IO_COUPLE );
  44. class IO_COUPLE : public OBJECT {
  45. public:
  46. DECLARE_CONSTRUCTOR( IO_COUPLE );
  47. VIRTUAL
  48. ~IO_COUPLE(
  49. ) { Destroy(); };
  50. PHMEM Mem;
  51. PIO_OBJECT IoObject;
  52. PEDIT_OBJECT EditObject;
  53. PEDIT_OBJECT OtherEditObject;
  54. PEDIT_OBJECT SplitEditObject;
  55. private:
  56. NONVIRTUAL
  57. VOID
  58. Construct() {
  59. Mem = NULL;
  60. IoObject = NULL;
  61. EditObject = NULL;
  62. OtherEditObject = NULL;
  63. SplitEditObject = NULL;
  64. };
  65. NONVIRTUAL
  66. VOID
  67. Destroy(
  68. );
  69. };
  70. enum SPLIT_OPERATION {
  71. eSplitToggle,
  72. eSplitCreate,
  73. eSplitDestroy,
  74. eSplitQuery
  75. };
  76. extern BOOLEAN SplitView(HWND, SPLIT_OPERATION);
  77. DEFINE_CONSTRUCTOR( IO_COUPLE, OBJECT );
  78. VOID
  79. IO_COUPLE::Destroy(
  80. )
  81. {
  82. DELETE(Mem);
  83. DELETE(IoObject);
  84. DELETE(EditObject);
  85. DELETE(OtherEditObject);
  86. DELETE(SplitEditObject);
  87. }
  88. #define IoCoupleSetEdit(IoCouple,type,hWnd,hwndChild,ClientHeight,ClientWidth,Drive) \
  89. { \
  90. VERTICAL_TEXT_SCROLL *V = NEW type; \
  91. \
  92. do { \
  93. \
  94. if (NULL == V) { \
  95. ReportError(hwndChild, 0); \
  96. continue; \
  97. } \
  98. if (!V->Initialize(hwndChild, ClientHeight, ClientWidth, Drive)) { \
  99. DELETE(V); \
  100. ReportError(hWnd, 0); \
  101. continue; \
  102. } \
  103. \
  104. IoCouple->EditObject->KillFocus(hwndChild); \
  105. DELETE(IoCouple->OtherEditObject); \
  106. IoCouple->OtherEditObject = IoCouple->EditObject; \
  107. IoCouple->EditObject = V; \
  108. IoCouple->IoObject->GetBuf(&size); \
  109. IoCouple->EditObject->SetBuf(hwndChild, \
  110. IoCouple->IoObject->GetBuf(), size); \
  111. IoCouple->EditObject->SetFocus(hwndChild); \
  112. InvalidateRect(hwndChild, NULL, TRUE); \
  113. \
  114. if (NULL != hwndSplit) { \
  115. if (NULL == (V = NEW type)) { \
  116. ReportError(hwndSplit, 0); \
  117. continue; \
  118. } \
  119. if (!V->Initialize(hwndSplit, ClientHeight, \
  120. ClientWidth, Drive)) { \
  121. DELETE(V); \
  122. ReportError(hWnd, 0); \
  123. continue; \
  124. } \
  125. \
  126. IoCouple->SplitEditObject = V; \
  127. IoCouple->IoObject->GetBuf(&size); \
  128. IoCouple->SplitEditObject->SetBuf(hwndSplit, \
  129. IoCouple->IoObject->GetBuf(), size); \
  130. } \
  131. } while ( 0 ); \
  132. }
  133. PLOG_IO_DP_DRIVE Drive = NULL;
  134. LSN Lsn;
  135. STATIC HINSTANCE hInst;
  136. STATIC PIO_COUPLE IoCouple = NULL;
  137. STATIC PLIST IoList = NULL;
  138. STATIC PITERATOR IoListIterator = NULL;
  139. STATIC INT ClientHeight = 0;
  140. STATIC INT ClientWidth = 0;
  141. STATIC INT BacktrackFileNumber;
  142. BOOLEAN
  143. DbgOutput(
  144. PCHAR Stuff
  145. )
  146. {
  147. OutputDebugStringA(Stuff);
  148. return TRUE;
  149. }
  150. VOID
  151. ReportError(
  152. IN HWND hWnd,
  153. IN ULONG Error
  154. )
  155. {
  156. TCHAR message[64];
  157. DialogBox(hInst, TEXT("ErrorBox"), hWnd, About);
  158. if (0 != Error) {
  159. wsprintf(message, TEXT("Error code: 0x%x\n"), Error);
  160. MessageBox(hWnd, message, TEXT("Error Information"), MB_OK|MB_ICONINFORMATION);
  161. }
  162. }
  163. INT
  164. WinMain(
  165. IN HINSTANCE hInstance,
  166. IN HINSTANCE hPrevInstance,
  167. IN LPSTR lpCmdLine,
  168. IN INT nCmdShow
  169. )
  170. {
  171. MSG msg;
  172. HACCEL hAccel;
  173. HWND hWnd;
  174. HICON hIcon;
  175. if (!hPrevInstance && !InitApplication(hInstance)) {
  176. return FALSE;
  177. }
  178. if (!InitInstance(hInstance, nCmdShow, &hWnd, &hAccel)) {
  179. return FALSE;
  180. }
  181. while (GetMessage(&msg, NULL, NULL, NULL)) {
  182. if (!TranslateAccelerator(hWnd, hAccel, &msg)) {
  183. TranslateMessage(&msg);
  184. DispatchMessage(&msg);
  185. }
  186. }
  187. return (int)msg.wParam;
  188. }
  189. BOOLEAN
  190. InitApplication(
  191. IN HINSTANCE hInstance
  192. )
  193. {
  194. WNDCLASS wc;
  195. //
  196. // Class for the normal viewing window
  197. //
  198. wc.style = NULL;
  199. wc.lpfnWndProc = ChildWndProc;
  200. wc.cbClsExtra = 0;
  201. wc.cbWndExtra = 0;
  202. wc.hInstance = hInstance;
  203. wc.hIcon = LoadIcon(hInstance, TEXT("diskedit"));
  204. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  205. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  206. wc.lpszMenuName = NULL;
  207. wc.lpszClassName = TEXT("ChildWinClass");
  208. if (0 == RegisterClass(&wc))
  209. return 0;
  210. //
  211. // Class for the split, byte-view window.
  212. //
  213. wc.style = NULL;
  214. wc.lpfnWndProc = SplitWndProc;
  215. wc.cbClsExtra = 0;
  216. wc.cbWndExtra = 0;
  217. wc.hInstance = hInstance;
  218. wc.hIcon = NULL;
  219. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  220. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  221. wc.lpszMenuName = NULL;
  222. wc.lpszClassName = TEXT("SplitWinClass");
  223. if (0 == RegisterClass(&wc))
  224. return 0;
  225. //
  226. // Class for the parent window.
  227. //
  228. wc.style = NULL;
  229. wc.lpfnWndProc = MainWndProc;
  230. wc.cbClsExtra = 0;
  231. wc.cbWndExtra = 0;
  232. wc.hInstance = hInstance;
  233. wc.hIcon = LoadIcon(hInstance, TEXT("diskedit"));
  234. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  235. wc.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
  236. wc.lpszMenuName = TEXT("DiskEditMenu");
  237. wc.lpszClassName = TEXT("DiskEditWinClass");
  238. if (0 == RegisterClass(&wc))
  239. return 0;
  240. return 1;
  241. }
  242. BOOLEAN
  243. InitInstance(
  244. IN HINSTANCE hInstance,
  245. IN INT nCmdShow,
  246. OUT HWND* phWnd,
  247. OUT HACCEL* hAccel
  248. )
  249. {
  250. HDC hdc;
  251. TEXTMETRIC textmetric;
  252. hInst = hInstance;
  253. hdc = GetDC(NULL);
  254. if (hdc == NULL)
  255. return FALSE;
  256. SelectObject(hdc, GetStockObject(ANSI_FIXED_FONT));
  257. GetTextMetrics(hdc, &textmetric);
  258. ReleaseDC(NULL, hdc);
  259. *phWnd = CreateWindow(
  260. TEXT("DiskEditWinClass"),
  261. TEXT("DiskEdit"),
  262. WS_OVERLAPPEDWINDOW,
  263. CW_USEDEFAULT,
  264. CW_USEDEFAULT,
  265. 84*textmetric.tmMaxCharWidth,
  266. 36*(textmetric.tmExternalLeading + textmetric.tmHeight),
  267. NULL,
  268. NULL,
  269. hInstance,
  270. NULL
  271. );
  272. if (NULL == *phWnd) {
  273. return FALSE;
  274. }
  275. *hAccel = (HACCEL) LoadAccelerators(hInst, TEXT("DiskEditAccel"));
  276. ShowWindow(*phWnd, nCmdShow);
  277. UpdateWindow(*phWnd);
  278. return TRUE;
  279. }
  280. INT_PTR
  281. FrsNumberDialogProc(
  282. IN HWND hDlg,
  283. IN UINT message,
  284. IN WPARAM wParam,
  285. IN LPARAM lParam
  286. )
  287. /*++
  288. Routine Description:
  289. This is the dialog procedure for the dialog box which queries
  290. an FRS number to backtrack.
  291. Arguments:
  292. hDlg -- identifies the dialog box
  293. message -- supplies the message ID received by the dialog box
  294. wParam -- message-type-dependent parameter
  295. lParam -- message-type-dependent parameter
  296. Returns:
  297. TRUE if this procedure handled the message, FALSE if it
  298. did not.
  299. --*/
  300. {
  301. UNREFERENCED_PARAMETER(lParam);
  302. switch (message) {
  303. case WM_INITDIALOG:
  304. return TRUE;
  305. case WM_COMMAND:
  306. if (LOWORD(wParam) == IDCANCEL) {
  307. EndDialog(hDlg, FALSE);
  308. return TRUE;
  309. }
  310. if (LOWORD(wParam) == IDOK) {
  311. TCHAR buf[1024];
  312. INT n;
  313. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  314. buf[n] = 0;
  315. swscanf(buf, TEXT("%x"), &BacktrackFileNumber);
  316. EndDialog(hDlg, TRUE);
  317. return TRUE;
  318. }
  319. break;
  320. }
  321. return FALSE;
  322. }
  323. STATIC HWND hwndChild = NULL;
  324. STATIC HWND hwndSplit = NULL;
  325. LRESULT
  326. MainWndProc(
  327. IN HWND hWnd,
  328. IN UINT message,
  329. IN WPARAM wParam,
  330. IN LPARAM lParam
  331. )
  332. {
  333. HDC hDC;
  334. PAINTSTRUCT ps;
  335. PDOS_BOOT_EDIT boot_edit;
  336. PNTFS_BOOT_EDIT ntboot_edit;
  337. PPARTITION_TABLE_EDIT part_edit;
  338. PGUID_PARTITION_TABLE_EDIT guid_part_edit;
  339. PRESTART_AREA_EDIT rest_area_edit;
  340. PRECORD_PAGE_EDIT rec_page_edit;
  341. PLOG_RECORD_EDIT log_rec_edit;
  342. ULONG size;
  343. WORD command;
  344. BOOLEAN error;
  345. ULONG error_status = 0;
  346. PIO_COUPLE next_couple;
  347. PEDIT_OBJECT tmp_edit;
  348. switch (message) {
  349. case WM_SETFOCUS:
  350. IoCouple->EditObject->SetFocus(hwndChild);
  351. break;
  352. case WM_CREATE:
  353. if (!DEFINE_CLASS_DESCRIPTOR( IO_COUPLE ) ||
  354. !(IoCouple = NEW IO_COUPLE) ||
  355. !(IoCouple->IoObject = NEW IO_OBJECT) ||
  356. !(IoCouple->EditObject = NEW EDIT_OBJECT) ||
  357. !(IoCouple->OtherEditObject = NEW EDIT_OBJECT) ||
  358. !(IoList = NEW LIST) ||
  359. !IoList->Initialize() ||
  360. !IoList->Put((POBJECT) IoCouple) ||
  361. !(IoListIterator = IoList->QueryIterator()) ||
  362. !IoListIterator->GetNext()) {
  363. PostQuitMessage(0);
  364. }
  365. hwndChild = CreateWindow(
  366. TEXT("ChildWinClass"),
  367. TEXT("PrimaryView"),
  368. WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE,
  369. 0, 0,
  370. ClientWidth, ClientHeight,
  371. hWnd,
  372. NULL,
  373. hInst,
  374. NULL
  375. );
  376. if (NULL == hwndChild) {
  377. int error = GetLastError();
  378. PostQuitMessage(0);
  379. }
  380. ShowWindow(hwndChild, SW_SHOW);
  381. UpdateWindow(hwndChild);
  382. SetWindowPos(hwndChild, HWND_TOP, 0, 0, ClientWidth, ClientHeight,
  383. SWP_SHOWWINDOW);
  384. break;
  385. case WM_SIZE:
  386. ClientHeight = HIWORD(lParam);
  387. ClientWidth = LOWORD(lParam);
  388. if (NULL == hwndSplit) {
  389. IoCouple->EditObject->ClientSize(ClientHeight, ClientWidth);
  390. SetWindowPos(hwndChild, HWND_TOP, 0, 0, ClientWidth, ClientHeight,
  391. SWP_SHOWWINDOW);
  392. } else {
  393. IoCouple->EditObject->ClientSize(ClientHeight, ClientWidth / 2);
  394. IoCouple->SplitEditObject->ClientSize(ClientHeight, ClientWidth / 2);
  395. SetWindowPos(hwndChild, HWND_TOP, 0, 0, ClientWidth / 2,
  396. ClientHeight, SWP_SHOWWINDOW);
  397. SetWindowPos(hwndSplit, HWND_TOP, ClientWidth / 2, 0,
  398. ClientWidth / 2, ClientHeight, SWP_SHOWWINDOW);
  399. }
  400. break;
  401. case WM_COMMAND:
  402. switch (LOWORD(wParam)) {
  403. case IDM_ABOUT:
  404. DialogBox(hInst, TEXT("AboutBox"), hWnd, About);
  405. break;
  406. case IDM_EXIT:
  407. DestroyWindow(hWnd);
  408. break;
  409. case IDM_OPEN:
  410. if (!DialogBox(hInst, TEXT("OpenVolumeBox"), hWnd, OpenVolume)) {
  411. ReportError(hWnd, 0);
  412. }
  413. SplitView(hWnd, eSplitDestroy);
  414. IoCouple->EditObject->KillFocus(hwndChild);
  415. IoListIterator->Reset();
  416. IoList->DeleteAllMembers();
  417. if (!(IoCouple = NEW IO_COUPLE) ||
  418. !(IoCouple->IoObject = NEW IO_OBJECT) ||
  419. !(IoCouple->EditObject = NEW EDIT_OBJECT) ||
  420. !(IoCouple->OtherEditObject = NEW EDIT_OBJECT) ||
  421. !IoList->Initialize() ||
  422. !IoList->Put(IoCouple) ||
  423. !IoListIterator->GetNext()) {
  424. PostQuitMessage(0);
  425. }
  426. SetWindowText(hWnd, TEXT("DiskEdit"));
  427. InvalidateRect(hWnd, NULL, TRUE);
  428. InvalidateRect(hwndChild, NULL, TRUE);
  429. break;
  430. case IDM_READ_SECTORS:
  431. case IDM_READ_CLUSTERS:
  432. case IDM_READ_FRS:
  433. case IDM_READ_ROOT:
  434. case IDM_READ_CHAIN:
  435. case IDM_READ_FILE:
  436. case IDM_READ_ATTRIBUTE:
  437. case IDM_READ_LOG_RECORD:
  438. if (!(next_couple = NEW IO_COUPLE)) {
  439. break;
  440. }
  441. switch (LOWORD(wParam)) {
  442. case IDM_READ_SECTORS:
  443. next_couple->IoObject = NEW SECTOR_IO;
  444. command = IDM_VIEW_BYTES;
  445. break;
  446. case IDM_READ_CLUSTERS:
  447. next_couple->IoObject = NEW CLUSTER_IO;
  448. command = IDM_VIEW_BYTES;
  449. break;
  450. case IDM_READ_FRS:
  451. next_couple->IoObject = NEW FRS_IO;
  452. command = IDM_VIEW_FRS;
  453. break;
  454. case IDM_READ_ATTRIBUTE:
  455. next_couple->IoObject = NEW ATTR_IO;
  456. command = IDM_VIEW_BYTES;
  457. break;
  458. case IDM_READ_LOG_RECORD:
  459. next_couple->IoObject = NEW LOG_RECORD_IO;
  460. command = IDM_VIEW_LOG_RECORD;
  461. break;
  462. case IDM_READ_ROOT:
  463. next_couple->IoObject = NEW ROOT_IO;
  464. command = IDM_VIEW_BYTES;
  465. break;
  466. case IDM_READ_CHAIN:
  467. next_couple->IoObject = NEW CHAIN_IO;
  468. command = IDM_VIEW_BYTES;
  469. break;
  470. case IDM_READ_FILE:
  471. next_couple->IoObject = NEW FILE_IO;
  472. command = IDM_VIEW_BYTES;
  473. break;
  474. default:
  475. next_couple->IoObject = NULL;
  476. break;
  477. }
  478. error = TRUE;
  479. if (next_couple->IoObject && (next_couple->Mem = NEW HMEM) &&
  480. next_couple->Mem->Initialize() &&
  481. next_couple->IoObject->Setup(next_couple->Mem,
  482. Drive, hInst, hwndChild, &error) &&
  483. next_couple->IoObject->Read(&error_status) &&
  484. (next_couple->EditObject = NEW EDIT_OBJECT) &&
  485. (next_couple->OtherEditObject = NEW EDIT_OBJECT) &&
  486. IoList->Put(next_couple)) {
  487. if (NULL != hwndSplit) {
  488. next_couple->SplitEditObject = NEW EDIT_OBJECT;
  489. if (NULL == next_couple->SplitEditObject) {
  490. DELETE(next_couple);
  491. break;
  492. }
  493. }
  494. IoCouple->EditObject->KillFocus(hwndChild);
  495. IoCouple = next_couple;
  496. IoCouple->EditObject->SetFocus(hwndChild);
  497. IoListIterator->Reset();
  498. IoListIterator->GetPrevious();
  499. SetWindowText(hWnd, IoCouple->IoObject->GetHeaderText());
  500. SendMessage(hWnd, WM_COMMAND, command, 0);
  501. if (NULL != hwndSplit) {
  502. SendMessage(hwndSplit, WM_COMMAND, command, 0);
  503. }
  504. } else {
  505. if (error) {
  506. ReportError(hWnd, error_status);
  507. }
  508. DELETE(next_couple);
  509. }
  510. break;
  511. case IDM_READ_PREVIOUS:
  512. if (NULL != IoListIterator->GetPrevious()) {
  513. IoCouple->EditObject->KillFocus(hwndChild);
  514. IoCouple = (PIO_COUPLE)IoListIterator->GetCurrent();
  515. IoCouple->EditObject->SetFocus(hwndChild);
  516. InvalidateRect(hWnd, NULL, TRUE);
  517. if (NULL != IoCouple->SplitEditObject && NULL == hwndSplit) {
  518. SplitView(hwndChild, eSplitCreate);
  519. InvalidateRect(hwndSplit, NULL, TRUE);
  520. }
  521. if (NULL == IoCouple->SplitEditObject && NULL != hwndSplit) {
  522. SplitView(hwndChild, eSplitDestroy);
  523. }
  524. SetWindowText(hWnd, IoCouple->IoObject->GetHeaderText());
  525. } else {
  526. ReportError(hwndChild, 0);
  527. IoListIterator->GetNext();
  528. }
  529. break;
  530. case IDM_READ_NEXT:
  531. if (IoListIterator->GetNext()) {
  532. IoCouple->EditObject->KillFocus(hwndChild);
  533. IoCouple = (PIO_COUPLE) IoListIterator->GetCurrent();
  534. IoCouple->EditObject->SetFocus(hwndChild);
  535. InvalidateRect(hwndChild, NULL, TRUE);
  536. if (NULL != IoCouple->SplitEditObject && NULL == hwndSplit) {
  537. SplitView(hwndChild, eSplitCreate);
  538. InvalidateRect(hwndSplit, NULL, TRUE);
  539. }
  540. if (NULL == IoCouple->SplitEditObject && NULL != hwndSplit) {
  541. SplitView(hwndChild, eSplitDestroy);
  542. }
  543. SetWindowText(hWnd, IoCouple->IoObject->GetHeaderText());
  544. } else {
  545. ReportError(hwndChild, 0);
  546. IoListIterator->GetPrevious();
  547. }
  548. break;
  549. case IDM_READ_REMOVE:
  550. if (IoList->QueryMemberCount() > 1) {
  551. IoCouple->EditObject->KillFocus(hwndChild);
  552. IoCouple = (PIO_COUPLE) IoList->Remove(IoListIterator);
  553. DELETE(IoCouple);
  554. IoCouple = (PIO_COUPLE) IoListIterator->GetCurrent();
  555. if (!IoCouple) {
  556. IoCouple = (PIO_COUPLE) IoListIterator->GetPrevious();
  557. }
  558. IoCouple->EditObject->SetFocus(hwndChild);
  559. InvalidateRect(hwndChild, NULL, TRUE);
  560. SetWindowText(hWnd, IoCouple->IoObject->GetHeaderText());
  561. }
  562. break;
  563. case IDM_RELOCATE_SECTORS:
  564. case IDM_RELOCATE_CLUSTERS:
  565. case IDM_RELOCATE_FRS:
  566. case IDM_RELOCATE_ROOT:
  567. case IDM_RELOCATE_CHAIN:
  568. case IDM_RELOCATE_FILE:
  569. IoCouple->IoObject->GetBuf(&size);
  570. DELETE(IoCouple->IoObject);
  571. switch (LOWORD(wParam)) {
  572. case IDM_RELOCATE_SECTORS:
  573. IoCouple->IoObject = NEW SECTOR_IO;
  574. command = IDM_VIEW_BYTES;
  575. break;
  576. case IDM_RELOCATE_CLUSTERS:
  577. IoCouple->IoObject = NEW CLUSTER_IO;
  578. command = IDM_VIEW_BYTES;
  579. break;
  580. case IDM_RELOCATE_FRS:
  581. IoCouple->IoObject = NEW FRS_IO;
  582. command = IDM_VIEW_FRS;
  583. break;
  584. case IDM_RELOCATE_ROOT:
  585. IoCouple->IoObject = NEW ROOT_IO;
  586. command = IDM_VIEW_BYTES;
  587. break;
  588. case IDM_RELOCATE_CHAIN:
  589. IoCouple->IoObject = NEW CHAIN_IO;
  590. command = IDM_VIEW_BYTES;
  591. break;
  592. case IDM_RELOCATE_FILE:
  593. IoCouple->IoObject = NEW FILE_IO;
  594. if (IoCouple->IoObject) {
  595. if (!((PFILE_IO) IoCouple->IoObject)->Initialize(size)) {
  596. DELETE(IoCouple->IoObject);
  597. }
  598. }
  599. command = IDM_VIEW_BYTES;
  600. break;
  601. default:
  602. IoCouple->IoObject = NULL;
  603. break;
  604. }
  605. error = TRUE;
  606. if (IoCouple->IoObject && IoCouple->IoObject->Setup(IoCouple->Mem,
  607. Drive, hInst, hwndChild, &error)) {
  608. SetWindowText(hWnd, IoCouple->IoObject->GetHeaderText());
  609. } else {
  610. if (error) {
  611. ReportError(hWnd, 0);
  612. }
  613. }
  614. break;
  615. case IDM_VIEW_BYTES:
  616. IoCoupleSetEdit( IoCouple,
  617. SECTOR_EDIT,
  618. hWnd, hwndChild,
  619. ClientHeight, ClientWidth,
  620. Drive );
  621. break;
  622. case IDM_VIEW_FRS:
  623. IoCoupleSetEdit( IoCouple,
  624. FRS_EDIT,
  625. hWnd, hwndChild,
  626. ClientHeight, ClientWidth,
  627. Drive );
  628. break;
  629. case IDM_VIEW_ATTR_LIST:
  630. IoCoupleSetEdit( IoCouple,
  631. ATTR_LIST_EDIT,
  632. hWnd, hwndChild,
  633. ClientHeight, ClientWidth,
  634. Drive );
  635. break;
  636. case IDM_VIEW_NTFS_INDEX:
  637. IoCoupleSetEdit( IoCouple,
  638. NAME_INDEX_BUFFER_EDIT,
  639. hWnd, hwndChild,
  640. ClientHeight, ClientWidth,
  641. Drive );
  642. break;
  643. case IDM_VIEW_NTFS_SECURITY_ID:
  644. IoCoupleSetEdit( IoCouple,
  645. SECURITY_ID_INDEX_BUFFER_EDIT,
  646. hWnd, hwndChild,
  647. ClientHeight, ClientWidth,
  648. Drive );
  649. break;
  650. case IDM_VIEW_NTFS_SECURITY_HASH:
  651. IoCoupleSetEdit( IoCouple,
  652. SECURITY_HASH_INDEX_BUFFER_EDIT,
  653. hWnd, hwndChild,
  654. ClientHeight, ClientWidth,
  655. Drive );
  656. break;
  657. case IDM_VIEW_NTFS_SECURITY_STREAM:
  658. IoCoupleSetEdit( IoCouple,
  659. SECURITY_STREAM_EDIT,
  660. hWnd, hwndChild,
  661. ClientHeight, ClientWidth,
  662. Drive );
  663. break;
  664. case IDM_VIEW_FAT_BOOT:
  665. if (NULL == (boot_edit = NEW DOS_BOOT_EDIT)) {
  666. ReportError(hwndChild, 0);
  667. break;
  668. }
  669. IoCouple->EditObject->KillFocus(hwndChild);
  670. DELETE(IoCouple->OtherEditObject);
  671. IoCouple->OtherEditObject = IoCouple->EditObject;
  672. IoCouple->EditObject = boot_edit;
  673. IoCouple->IoObject->GetBuf(&size);
  674. IoCouple->EditObject->SetBuf(hwndChild,
  675. IoCouple->IoObject->GetBuf(), size);
  676. IoCouple->EditObject->SetFocus(hwndChild);
  677. InvalidateRect(hwndChild, NULL, TRUE);
  678. break;
  679. case IDM_VIEW_NTFS_BOOT:
  680. if (ntboot_edit = NEW NTFS_BOOT_EDIT) {
  681. IoCouple->EditObject->KillFocus(hwndChild);
  682. DELETE(IoCouple->OtherEditObject);
  683. IoCouple->OtherEditObject = IoCouple->EditObject;
  684. IoCouple->EditObject = ntboot_edit;
  685. IoCouple->IoObject->GetBuf(&size);
  686. IoCouple->EditObject->SetBuf(hwndChild,
  687. IoCouple->IoObject->GetBuf(), size);
  688. IoCouple->EditObject->SetFocus(hwndChild);
  689. InvalidateRect(hwndChild, NULL, TRUE);
  690. } else {
  691. DELETE(ntboot_edit);
  692. ReportError(hWnd, 0);
  693. }
  694. break;
  695. case IDM_VIEW_PARTITION_TABLE:
  696. if ( (part_edit = NEW PARTITION_TABLE_EDIT) &&
  697. part_edit->Initialize(hwndChild, ClientHeight, ClientWidth, Drive)) {
  698. IoCouple->EditObject->KillFocus(hwndChild);
  699. DELETE(IoCouple->OtherEditObject);
  700. IoCouple->OtherEditObject = IoCouple->EditObject;
  701. IoCouple->EditObject = part_edit;
  702. IoCouple->IoObject->GetBuf(&size);
  703. IoCouple->EditObject->SetBuf(hwndChild,
  704. IoCouple->IoObject->GetBuf(), size);
  705. IoCouple->EditObject->SetFocus(hwndChild);
  706. InvalidateRect(hwndChild, NULL, TRUE);
  707. } else {
  708. DELETE( part_edit );
  709. ReportError(hWnd, 0);
  710. }
  711. break;
  712. case IDM_VIEW_GPT:
  713. if ( (guid_part_edit = NEW GUID_PARTITION_TABLE_EDIT) &&
  714. guid_part_edit->Initialize(hwndChild, ClientHeight, ClientWidth, Drive)) {
  715. IoCouple->EditObject->KillFocus(hwndChild);
  716. DELETE(IoCouple->OtherEditObject);
  717. IoCouple->OtherEditObject = IoCouple->EditObject;
  718. IoCouple->EditObject = guid_part_edit;
  719. IoCouple->IoObject->GetBuf(&size);
  720. IoCouple->EditObject->SetBuf(hwndChild,
  721. IoCouple->IoObject->GetBuf(), size);
  722. IoCouple->EditObject->SetFocus(hwndChild);
  723. InvalidateRect(hwndChild, NULL, TRUE);
  724. } else {
  725. DELETE( guid_part_edit );
  726. ReportError(hWnd, 0);
  727. }
  728. break;
  729. case IDM_VIEW_RESTART_AREA:
  730. if ((rest_area_edit = NEW RESTART_AREA_EDIT) &&
  731. rest_area_edit->Initialize(hwndChild, ClientHeight, ClientWidth, Drive )) {
  732. IoCouple->EditObject->KillFocus(hwndChild);
  733. DELETE(IoCouple->OtherEditObject);
  734. IoCouple->OtherEditObject = IoCouple->EditObject;
  735. IoCouple->EditObject = rest_area_edit;
  736. IoCouple->IoObject->GetBuf(&size);
  737. IoCouple->EditObject->SetBuf(hwndChild,
  738. IoCouple->IoObject->GetBuf(), size);
  739. IoCouple->EditObject->SetFocus(hwndChild);
  740. InvalidateRect(hwndChild, NULL, TRUE);
  741. } else {
  742. DELETE(rest_area_edit);
  743. ReportError(hWnd, 0);
  744. }
  745. break;
  746. case IDM_VIEW_RECORD_PAGE:
  747. if ((rec_page_edit = NEW RECORD_PAGE_EDIT) &&
  748. rec_page_edit->Initialize(hwndChild, ClientHeight, ClientWidth, Drive)) {
  749. IoCouple->EditObject->KillFocus(hwndChild);
  750. DELETE(IoCouple->OtherEditObject);
  751. IoCouple->OtherEditObject = IoCouple->EditObject;
  752. IoCouple->EditObject = rec_page_edit;
  753. IoCouple->IoObject->GetBuf(&size);
  754. IoCouple->EditObject->SetBuf(hwndChild,
  755. IoCouple->IoObject->GetBuf(), size);
  756. IoCouple->EditObject->SetFocus(hwndChild);
  757. InvalidateRect(hwndChild, NULL, TRUE);
  758. } else {
  759. DELETE(rec_page_edit);
  760. ReportError(hWnd, 0);
  761. }
  762. break;
  763. case IDM_VIEW_LOG_RECORD:
  764. if ((log_rec_edit = NEW LOG_RECORD_EDIT) &&
  765. log_rec_edit->Initialize(hwndChild, ClientHeight,
  766. ClientWidth, Drive)) {
  767. IoCouple->EditObject->KillFocus(hwndChild);
  768. DELETE(IoCouple->OtherEditObject);
  769. IoCouple->OtherEditObject = IoCouple->EditObject;
  770. IoCouple->EditObject = log_rec_edit;
  771. IoCouple->IoObject->GetBuf(&size);
  772. IoCouple->EditObject->SetBuf(hwndChild,
  773. IoCouple->IoObject->GetBuf(), size);
  774. IoCouple->EditObject->SetFocus(hwndChild);
  775. InvalidateRect(hwndChild, NULL, TRUE);
  776. } else {
  777. DELETE(log_rec_edit);
  778. ReportError(hWnd, 0);
  779. }
  780. break;
  781. case IDM_VIEW_LAST:
  782. IoCouple->EditObject->KillFocus(hwndChild);
  783. tmp_edit = IoCouple->EditObject;
  784. IoCouple->EditObject = IoCouple->OtherEditObject;
  785. IoCouple->OtherEditObject = tmp_edit;
  786. IoCouple->EditObject->SetFocus(hwndChild);
  787. InvalidateRect(hwndChild, NULL, TRUE);
  788. break;
  789. case IDM_VIEW_SPLIT:
  790. SplitView(hWnd, eSplitToggle);
  791. break;
  792. case IDM_WRITE_IT:
  793. if (!IoCouple->IoObject->Write()) {
  794. ReportError(hWnd, 0);
  795. }
  796. break;
  797. case IDM_CRACK_NTFS:
  798. if (DialogBox(hInst, TEXT("InputPathBox"), hWnd, InputPath)) {
  799. CrackNtfsPath(hWnd);
  800. }
  801. break;
  802. case IDM_CRACK_FAT:
  803. if (DialogBox(hInst, TEXT("InputPathBox"), hWnd, InputPath)) {
  804. CrackFatPath(hWnd);
  805. }
  806. break;
  807. case IDM_CRACK_LSN:
  808. if (DialogBox(hInst, TEXT("CrackLsnBox"), hWnd, InputLsn)) {
  809. CrackLsn(hWnd);
  810. }
  811. break;
  812. case IDM_CRACK_NEXT_LSN:
  813. if (DialogBox(hInst, TEXT("CrackNextLsnBox"), hWnd, InputLsn)) {
  814. CrackNextLsn(hWnd);
  815. }
  816. break;
  817. case IDM_BACKTRACK_FRS:
  818. if (DialogBox(hInst, TEXT("BacktrackFrsBox"), hWnd, FrsNumberDialogProc)) {
  819. BacktrackFrsFromScratch(hWnd, BacktrackFileNumber);
  820. }
  821. break;
  822. default:
  823. return DefWindowProc(hWnd, message, wParam, lParam);
  824. }
  825. break;
  826. case WM_PAINT:
  827. hDC = BeginPaint(hWnd, &ps);
  828. EndPaint(hWnd, &ps);
  829. break;
  830. case WM_DESTROY:
  831. IoCouple->EditObject->KillFocus(hwndChild);
  832. IoList->DeleteAllMembers();
  833. DELETE(IoListIterator);
  834. DELETE(IoList);
  835. DELETE(Drive);
  836. PostQuitMessage(0);
  837. break;
  838. default:
  839. return DefWindowProc(hWnd, message, wParam, lParam);
  840. }
  841. return 0;
  842. }
  843. INT_PTR
  844. About(
  845. IN HWND hDlg,
  846. IN UINT message,
  847. IN WPARAM wParam,
  848. IN LPARAM lParam
  849. )
  850. {
  851. switch (message) {
  852. case WM_INITDIALOG:
  853. return TRUE;
  854. case WM_COMMAND:
  855. if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) {
  856. EndDialog(hDlg, TRUE);
  857. return TRUE;
  858. }
  859. break;
  860. }
  861. return FALSE;
  862. }
  863. INT_PTR
  864. OpenVolume(
  865. IN HWND hDlg,
  866. IN UINT message,
  867. IN WPARAM wParam,
  868. IN LPARAM lParam
  869. )
  870. {
  871. PREAD_CACHE rcache;
  872. switch (message) {
  873. case WM_INITDIALOG:
  874. return TRUE;
  875. case WM_COMMAND:
  876. if (LOWORD(wParam) == IDCANCEL) {
  877. EndDialog(hDlg, TRUE);
  878. return TRUE;
  879. }
  880. if (LOWORD(wParam) == IDOK) {
  881. DSTRING dos_name, nt_name, tmp_name;
  882. DSTRING volfile_name, volfile_path, backslash;
  883. TCHAR volume_buf[32];
  884. TCHAR volfile_buf[32];
  885. INT n;
  886. n = GetDlgItemText(hDlg, IDTEXT, volume_buf, sizeof(volume_buf)/sizeof(TCHAR));
  887. volume_buf[n] = 0;
  888. n = GetDlgItemText(hDlg, IDTEXT2, volfile_buf, sizeof(volfile_buf)/sizeof(TCHAR));
  889. volfile_buf[n] = 0;
  890. DELETE(Drive);
  891. if (!backslash.Initialize("\\") ||
  892. !dos_name.Initialize(volume_buf)) {
  893. EndDialog(hDlg, FALSE);
  894. return TRUE;
  895. }
  896. if (dos_name.QueryChCount() > 0 &&
  897. dos_name.QueryChAt(0) >= '0' &&
  898. dos_name.QueryChAt(0) <= '9') {
  899. if (!nt_name.Initialize("\\device\\harddisk") ||
  900. !nt_name.Strcat(&dos_name) ||
  901. !tmp_name.Initialize("\\partition0") ||
  902. !nt_name.Strcat(&tmp_name)) {
  903. EndDialog(hDlg, FALSE);
  904. return TRUE;
  905. }
  906. } else {
  907. if (!IFS_SYSTEM::DosDriveNameToNtDriveName(&dos_name,
  908. &nt_name)) {
  909. EndDialog(hDlg, FALSE);
  910. return TRUE;
  911. }
  912. }
  913. if (!volfile_name.Initialize(volfile_buf)) {
  914. EndDialog(hDlg, FALSE);
  915. return TRUE;
  916. }
  917. if (0 != wcslen(volfile_buf)) {
  918. if (!volfile_path.Initialize(&nt_name) ||
  919. !volfile_path.Strcat(&backslash) ||
  920. !volfile_path.Strcat(&volfile_name)) {
  921. EndDialog(hDlg, FALSE);
  922. return TRUE;
  923. }
  924. if (NULL == (Drive = NEW LOG_IO_DP_DRIVE) ||
  925. !Drive->Initialize(&nt_name, &volfile_path)) {
  926. EndDialog(hDlg, FALSE);
  927. return TRUE;
  928. }
  929. } else {
  930. if (NULL == (Drive = NEW LOG_IO_DP_DRIVE) ||
  931. !Drive->Initialize(&nt_name)) {
  932. EndDialog(hDlg, FALSE);
  933. return TRUE;
  934. }
  935. }
  936. if ((rcache = NEW READ_CACHE) &&
  937. rcache->Initialize(Drive, 1024)) {
  938. Drive->SetCache(rcache);
  939. } else {
  940. DELETE(rcache);
  941. }
  942. if (IsDlgButtonChecked(hDlg, IDCHECKBOX) &&
  943. !Drive->Lock()) {
  944. EndDialog(hDlg, FALSE);
  945. return TRUE;
  946. }
  947. EndDialog(hDlg, TRUE);
  948. return TRUE;
  949. }
  950. break;
  951. }
  952. return FALSE;
  953. }
  954. INT_PTR
  955. InputPath(
  956. IN HWND hDlg,
  957. IN UINT message,
  958. IN WPARAM wParam,
  959. IN LPARAM lParam
  960. )
  961. {
  962. INT n;
  963. switch (message) {
  964. case WM_INITDIALOG:
  965. return TRUE;
  966. case WM_COMMAND:
  967. if (LOWORD(wParam) == IDCANCEL) {
  968. EndDialog(hDlg, FALSE);
  969. return TRUE;
  970. }
  971. if (LOWORD(wParam) == IDOK) {
  972. n = GetDlgItemText(hDlg, IDTEXT, Path, MAX_PATH);
  973. Path[n] = 0;
  974. EndDialog(hDlg, TRUE);
  975. return TRUE;
  976. }
  977. break;
  978. }
  979. return FALSE;
  980. }
  981. INT_PTR
  982. InputLsn(
  983. IN HWND hDlg,
  984. IN UINT message,
  985. IN WPARAM wParam,
  986. IN LPARAM lParam
  987. )
  988. {
  989. INT n;
  990. TCHAR buf[40];
  991. PTCHAR pch;
  992. switch (message) {
  993. case WM_INITDIALOG:
  994. wsprintf(buf, TEXT("%x:%x"), Lsn.HighPart, Lsn.LowPart);
  995. SetDlgItemText(hDlg, IDTEXT, buf);
  996. return TRUE;
  997. case WM_COMMAND:
  998. if (LOWORD(wParam) == IDCANCEL) {
  999. EndDialog(hDlg, FALSE);
  1000. return TRUE;
  1001. }
  1002. if (LOWORD(wParam) == IDOK) {
  1003. n = GetDlgItemText(hDlg, IDTEXT, buf, sizeof(buf)/sizeof(TCHAR));
  1004. buf[n] = 0;
  1005. if (NULL == (pch = wcschr(buf, ':'))) {
  1006. Lsn.HighPart = 0;
  1007. swscanf(buf, TEXT("%x"), &Lsn.LowPart);
  1008. } else {
  1009. *pch = 0;
  1010. swscanf(buf, TEXT("%x"), &Lsn.HighPart);
  1011. swscanf(pch + 1, TEXT("%x"), &Lsn.LowPart);
  1012. *pch = ':';
  1013. }
  1014. EndDialog(hDlg, TRUE);
  1015. return TRUE;
  1016. }
  1017. break;
  1018. }
  1019. return FALSE;
  1020. }
  1021. static ULONG SeqNumberBits;
  1022. ULONG
  1023. GetLogPageSize(
  1024. PLOG_IO_DP_DRIVE Drive
  1025. )
  1026. {
  1027. static ULONG PageSize;
  1028. static BOOLEAN been_here = FALSE;
  1029. static UCHAR buf[0x600];
  1030. NTFS_SA NtfsSa;
  1031. MESSAGE Msg;
  1032. NTFS_MFT_FILE Mft;
  1033. NTFS_FILE_RECORD_SEGMENT Frs;
  1034. NTFS_ATTRIBUTE Attrib;
  1035. PLFS_RESTART_PAGE_HEADER pRestPageHdr;
  1036. PLFS_RESTART_AREA pRestArea;
  1037. ULONG bytes_read;
  1038. BOOLEAN error;
  1039. if (been_here) {
  1040. return PageSize;
  1041. }
  1042. pRestPageHdr = (PLFS_RESTART_PAGE_HEADER)buf;
  1043. if (!Drive ||
  1044. !NtfsSa.Initialize(Drive, &Msg) ||
  1045. !NtfsSa.Read() ||
  1046. !Mft.Initialize(Drive, NtfsSa.QueryMftStartingLcn(),
  1047. NtfsSa.QueryClusterFactor(), NtfsSa.QueryFrsSize(),
  1048. NtfsSa.QueryVolumeSectors(), NULL, NULL) ||
  1049. !Mft.Read() ||
  1050. !Frs.Initialize((VCN)LOG_FILE_NUMBER, &Mft) ||
  1051. !Frs.Read() ||
  1052. !Frs.QueryAttribute(&Attrib, &error, $DATA) ||
  1053. !Attrib.Read((PVOID)pRestPageHdr, 0, 0x600,
  1054. &bytes_read) ||
  1055. bytes_read != 0x600) {
  1056. return 0;
  1057. }
  1058. PageSize = pRestPageHdr->LogPageSize;
  1059. pRestArea = PLFS_RESTART_AREA(PUCHAR(pRestPageHdr) + pRestPageHdr->RestartOffset);
  1060. SeqNumberBits = pRestArea->SeqNumberBits;
  1061. been_here = 1;
  1062. return PageSize;
  1063. }
  1064. ULONG
  1065. GetSeqNumberBits(
  1066. PLOG_IO_DP_DRIVE Drive
  1067. )
  1068. {
  1069. (void)GetLogPageSize(Drive);
  1070. return SeqNumberBits;
  1071. }
  1072. BOOLEAN
  1073. SplitView(
  1074. HWND hWnd,
  1075. SPLIT_OPERATION Op
  1076. )
  1077. {
  1078. static BOOLEAN CheckState = FALSE;
  1079. int flags;
  1080. PSECTOR_EDIT sector_edit;
  1081. CREATESTRUCT cs;
  1082. ULONG size;
  1083. HMENU hMenu = GetMenu(hWnd);
  1084. if (Op == eSplitToggle) {
  1085. CheckState = !CheckState;
  1086. } else if (Op == eSplitCreate) {
  1087. CheckState = TRUE;
  1088. } else if (Op == eSplitDestroy) {
  1089. CheckState = FALSE;
  1090. } else if (Op == eSplitQuery) {
  1091. DebugAssert(hWnd == NULL);
  1092. return CheckState;
  1093. } else {
  1094. return FALSE;
  1095. }
  1096. if (!CheckState) {
  1097. // Destroy the extra window, remove the checkbox from
  1098. // the menu entry.
  1099. if (NULL == hwndSplit) {
  1100. return 0;
  1101. }
  1102. DestroyWindow(hwndSplit);
  1103. hwndSplit = NULL;
  1104. flags = MF_BYCOMMAND | MF_UNCHECKED;
  1105. if (hMenu == NULL) {
  1106. return FALSE;
  1107. }
  1108. CheckMenuItem(hMenu, IDM_VIEW_SPLIT, flags);
  1109. SetWindowPos(hwndChild, HWND_TOP, 0, 0, ClientWidth, ClientHeight,
  1110. SWP_SHOWWINDOW);
  1111. IoCouple->EditObject->SetFocus(hwndChild);
  1112. SetFocus(hwndChild);
  1113. return TRUE;
  1114. }
  1115. //
  1116. // Split the window.
  1117. //
  1118. memset(&cs, 0, sizeof(cs));
  1119. cs.y = ClientWidth / 2;
  1120. cs.x = 0;
  1121. cs.cy = ClientWidth / 2;
  1122. cs.cx = ClientHeight;
  1123. hwndSplit = CreateWindow(TEXT("SplitWinClass"), TEXT("hwndSplit"),
  1124. WS_CHILD|WS_CLIPSIBLINGS|WS_VISIBLE,
  1125. ClientWidth / 2, 0,
  1126. ClientWidth / 2, ClientHeight,
  1127. hWnd,
  1128. NULL,
  1129. hInst,
  1130. &cs);
  1131. if (NULL == hwndSplit) {
  1132. int error = GetLastError();
  1133. return FALSE;
  1134. }
  1135. SetWindowPos(hwndChild, HWND_TOP, 0, 0, ClientWidth / 2, ClientHeight,
  1136. SWP_SHOWWINDOW);
  1137. flags = MF_BYCOMMAND | MF_CHECKED;
  1138. CheckMenuItem(hMenu, IDM_VIEW_SPLIT, flags);
  1139. ShowWindow(hwndSplit, SW_SHOW);
  1140. UpdateWindow(hwndSplit);
  1141. if (NULL != IoCouple->SplitEditObject) {
  1142. // use the existing edit object
  1143. return TRUE;
  1144. }
  1145. if ((sector_edit = NEW SECTOR_EDIT) &&
  1146. sector_edit->Initialize(hwndSplit, ClientHeight, ClientWidth / 2, Drive)) {
  1147. IoCouple->SplitEditObject = sector_edit;
  1148. IoCouple->IoObject->GetBuf(&size);
  1149. IoCouple->SplitEditObject->SetBuf(hwndSplit,
  1150. IoCouple->IoObject->GetBuf(), size);
  1151. IoCouple->EditObject->SetFocus(hwndChild);
  1152. SetFocus(hwndChild);
  1153. } else {
  1154. DELETE(sector_edit);
  1155. DestroyWindow(hwndSplit);
  1156. ReportError(hWnd, 0);
  1157. }
  1158. return TRUE;
  1159. }
  1160. LRESULT
  1161. ChildWndProc(
  1162. IN HWND hwnd,
  1163. IN UINT message,
  1164. IN WPARAM wParam,
  1165. IN LPARAM lParam
  1166. )
  1167. {
  1168. HDC hdc;
  1169. PAINTSTRUCT ps;
  1170. ULONG size;
  1171. WORD command;
  1172. BOOLEAN error;
  1173. ULONG error_status;
  1174. switch (message) {
  1175. default:
  1176. return DefWindowProc(hwnd, message, wParam, lParam);
  1177. case WM_PAINT:
  1178. hdc = BeginPaint(hwnd, &ps);
  1179. IoCouple->EditObject->Paint(hdc, ps.rcPaint, hwnd);
  1180. EndPaint(hwnd, &ps);
  1181. return 0;
  1182. case WM_CHAR:
  1183. IoCouple->EditObject->Character(hwnd, (CHAR)wParam);
  1184. break;
  1185. case WM_VSCROLL:
  1186. switch (LOWORD(wParam)) {
  1187. case SB_LINEUP:
  1188. IoCouple->EditObject->ScrollUp(hwnd);
  1189. break;
  1190. case SB_LINEDOWN:
  1191. IoCouple->EditObject->ScrollDown(hwnd);
  1192. break;
  1193. case SB_PAGEUP:
  1194. IoCouple->EditObject->PageUp(hwnd);
  1195. break;
  1196. case SB_PAGEDOWN:
  1197. IoCouple->EditObject->PageDown(hwnd);
  1198. break;
  1199. case SB_THUMBPOSITION:
  1200. IoCouple->EditObject->ThumbPosition(hwnd, HIWORD(wParam));
  1201. break;
  1202. default:
  1203. break;
  1204. }
  1205. break;
  1206. case WM_KEYDOWN:
  1207. switch (LOWORD(wParam)) {
  1208. case VK_UP:
  1209. IoCouple->EditObject->KeyUp(hwnd);
  1210. break;
  1211. case VK_DOWN:
  1212. IoCouple->EditObject->KeyDown(hwnd);
  1213. break;
  1214. case VK_LEFT:
  1215. IoCouple->EditObject->KeyLeft(hwnd);
  1216. break;
  1217. case VK_RIGHT:
  1218. IoCouple->EditObject->KeyRight(hwnd);
  1219. break;
  1220. case VK_PRIOR:
  1221. IoCouple->EditObject->PageUp(hwnd);
  1222. break;
  1223. case VK_NEXT:
  1224. IoCouple->EditObject->PageDown(hwnd);
  1225. break;
  1226. default:
  1227. break;
  1228. }
  1229. break;
  1230. case WM_SETFOCUS:
  1231. IoCouple->EditObject->SetFocus(hwnd);
  1232. break;
  1233. case WM_KILLFOCUS:
  1234. IoCouple->EditObject->KillFocus(hwnd);
  1235. break;
  1236. case WM_LBUTTONDOWN:
  1237. IoCouple->EditObject->Click(hwnd, LOWORD(lParam), HIWORD(lParam));
  1238. break;
  1239. }
  1240. return 0;
  1241. }
  1242. LRESULT
  1243. SplitWndProc(
  1244. IN HWND hwnd,
  1245. IN UINT message,
  1246. IN WPARAM wParam,
  1247. IN LPARAM lParam
  1248. )
  1249. {
  1250. HDC hdc;
  1251. PAINTSTRUCT ps;
  1252. ULONG size;
  1253. WORD command;
  1254. BOOLEAN error;
  1255. ULONG error_status;
  1256. switch (message) {
  1257. default:
  1258. return DefWindowProc(hwnd, message, wParam, lParam);
  1259. case WM_PAINT:
  1260. hdc = BeginPaint(hwnd, &ps);
  1261. if (NULL != IoCouple->SplitEditObject) {
  1262. IoCouple->SplitEditObject->Paint(hdc, ps.rcPaint, hwnd);
  1263. }
  1264. EndPaint(hwnd, &ps);
  1265. return 0;
  1266. case WM_CHAR:
  1267. IoCouple->SplitEditObject->Character(hwnd, (CHAR)wParam);
  1268. break;
  1269. case WM_VSCROLL:
  1270. switch (LOWORD(wParam)) {
  1271. case SB_LINEUP:
  1272. IoCouple->SplitEditObject->ScrollUp(hwnd);
  1273. break;
  1274. case SB_LINEDOWN:
  1275. IoCouple->SplitEditObject->ScrollDown(hwnd);
  1276. break;
  1277. case SB_PAGEUP:
  1278. IoCouple->SplitEditObject->PageUp(hwnd);
  1279. break;
  1280. case SB_PAGEDOWN:
  1281. IoCouple->SplitEditObject->PageDown(hwnd);
  1282. break;
  1283. case SB_THUMBPOSITION:
  1284. IoCouple->SplitEditObject->ThumbPosition(hwnd, HIWORD(wParam));
  1285. break;
  1286. default:
  1287. break;
  1288. }
  1289. break;
  1290. case WM_KEYDOWN:
  1291. switch (LOWORD(wParam)) {
  1292. case VK_UP:
  1293. IoCouple->SplitEditObject->KeyUp(hwnd);
  1294. break;
  1295. case VK_DOWN:
  1296. IoCouple->SplitEditObject->KeyDown(hwnd);
  1297. break;
  1298. case VK_LEFT:
  1299. IoCouple->SplitEditObject->KeyLeft(hwnd);
  1300. break;
  1301. case VK_RIGHT:
  1302. IoCouple->SplitEditObject->KeyRight(hwnd);
  1303. break;
  1304. case VK_PRIOR:
  1305. IoCouple->SplitEditObject->PageUp(hwnd);
  1306. break;
  1307. case VK_NEXT:
  1308. IoCouple->SplitEditObject->PageDown(hwnd);
  1309. break;
  1310. default:
  1311. break;
  1312. }
  1313. break;
  1314. case WM_SETFOCUS:
  1315. IoCouple->SplitEditObject->SetFocus(hwnd);
  1316. break;
  1317. case WM_KILLFOCUS:
  1318. IoCouple->SplitEditObject->KillFocus(hwnd);
  1319. break;
  1320. case WM_LBUTTONDOWN:
  1321. IoCouple->SplitEditObject->Click(hwnd, LOWORD(lParam), HIWORD(lParam));
  1322. break;
  1323. }
  1324. return 0;
  1325. }