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.

146 lines
3.7 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. main.c
  5. Abstract:
  6. --*/
  7. #include "hexedit.h"
  8. typedef enum {
  9. NEW_FILE,
  10. OPEN_FILE,
  11. OPEN_DISK,
  12. OPEN_MEMORY
  13. } IMAGE_TYPE;
  14. STATIC
  15. VOID
  16. PrintUsage (
  17. VOID
  18. )
  19. {
  20. Print(L"\n\n %Ehex Usage%N\n");
  21. Print(L" %H[-f] Filename%N Open File For Editing\n");
  22. Print(L" %H-d Offset Size%N Open Disk Area For Editing\n");
  23. Print(L" %H-m Offset Size%N Open Memory Area For Editing\n");
  24. Print(L" %H-h%N Print This Screen\n");
  25. Print(L"\n\n");
  26. }
  27. EFI_STATUS
  28. InitializeEFIHexEditor (
  29. IN EFI_HANDLE ImageHandle,
  30. IN EFI_SYSTEM_TABLE *SystemTable
  31. )
  32. {
  33. EFI_STATUS Status;
  34. CHAR16 *Name;
  35. UINTN Offset = 0;
  36. UINTN Size = 0;
  37. IMAGE_TYPE WhatToDo = NEW_FILE;
  38. InitializeLib (ImageHandle, SystemTable);
  39. InitializeShellApplication (ImageHandle, SystemTable);
  40. Name = PoolPrint(L"New File");
  41. if ( SI->Argc > 1 ) {
  42. if (StrCmp(SI->Argv[1],L"-h") == 0) {
  43. PrintUsage();
  44. return EFI_SUCCESS;
  45. } else if (StrCmp(SI->Argv[1],L"-d") == 0) {
  46. if (SI->Argc < 5) {
  47. PrintUsage();
  48. return EFI_SUCCESS;
  49. }
  50. Name = SI->Argv[2];
  51. Offset = xtoi(SI->Argv[3]);
  52. Size = xtoi(SI->Argv[4]);
  53. WhatToDo = OPEN_DISK;
  54. } else if (StrCmp(SI->Argv[1],L"-m") == 0) {
  55. if (SI->Argc < 4) {
  56. PrintUsage();
  57. return EFI_SUCCESS;
  58. }
  59. Offset = xtoi(SI->Argv[2]);
  60. Size = xtoi(SI->Argv[3]);
  61. WhatToDo = OPEN_MEMORY;
  62. } else {
  63. if (StrCmp(SI->Argv[1],L"-f") == 0) {
  64. if (SI->Argc > 2) {
  65. Name = SI->Argv[2];
  66. } else {
  67. PrintUsage();
  68. return EFI_SUCCESS;
  69. }
  70. } else {
  71. Name = SI->Argv[1];
  72. }
  73. WhatToDo = OPEN_FILE;
  74. }
  75. }
  76. Status = MainEditor.Init(&ImageHandle);
  77. if (EFI_ERROR(Status)) {
  78. EditorError(Status,L"Initialization Failed");
  79. return EFI_SUCCESS;
  80. }
  81. Status = MainEditor.BufferImage->FileImage->Init ();
  82. if (EFI_ERROR(Status)) {
  83. EditorError(Status,L"File Handle Initialization Failed");
  84. return EFI_SUCCESS;
  85. }
  86. switch (WhatToDo) {
  87. case OPEN_FILE:
  88. MainEditor.BufferImage->FileImage->Init();
  89. MainEditor.BufferImage->FileImage->SetFilename(Name);
  90. break;
  91. case OPEN_DISK:
  92. MainEditor.BufferImage->DiskImage->Init();
  93. MainEditor.BufferImage->DiskImage->SetDevice(Name);
  94. MainEditor.BufferImage->DiskImage->SetOffset(Offset);
  95. MainEditor.BufferImage->DiskImage->SetSize(Size);
  96. break;
  97. case OPEN_MEMORY:
  98. MainEditor.BufferImage->MemImage->Init();
  99. MainEditor.BufferImage->DiskImage->SetOffset(Offset);
  100. MainEditor.BufferImage->DiskImage->SetSize(Size);
  101. break;
  102. default:
  103. ;
  104. }
  105. if (WhatToDo != NEW_FILE) {
  106. Status = MainEditor.BufferImage->Open();
  107. if ( EFI_ERROR(Status) ) {
  108. EditorError(Status,L"Could Not Open File");
  109. return EFI_SUCCESS;
  110. }
  111. MainEditor.TitleBar->SetTitleString (Name);
  112. MainEditor.BufferImage->Read();
  113. }
  114. MainEditor.Refresh ();
  115. MainEditor.MenuBar->Refresh();
  116. MainEditor.KeyInput ();
  117. MainEditor.Cleanup();
  118. return EFI_SUCCESS;
  119. }