Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

165 lines
4.2 KiB

  1. #define UNICODE 1
  2. #include <nt.h>
  3. //#include <ntosp.h>
  4. #include <ntrtl.h>
  5. #include <nturtl.h>
  6. #include <windows.h>
  7. #pragma warning(disable:4127) // conditional expression is constant
  8. #pragma warning(disable:4213) // nonstandard extension used : cast on l-value
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #define ADD_OFFSET(_p,_o) (PVOID)((PUCHAR)(_p) + (_p)->_o)
  12. #define ALIGN_DOWN(length, type) \
  13. ((ULONG)(length) & ~(sizeof(type) - 1))
  14. #define ALIGN_UP(length, type) \
  15. (ALIGN_DOWN(((ULONG)(length) + sizeof(type) - 1), type))
  16. extern PBOOT_OPTIONS BootOptions;
  17. extern ULONG BootOptionsLength;
  18. extern PBOOT_OPTIONS OriginalBootOptions;
  19. extern ULONG OriginalBootOptionsLength;
  20. extern PULONG BootEntryOrder;
  21. extern ULONG BootEntryOrderCount;
  22. extern PULONG OriginalBootEntryOrder;
  23. extern ULONG OriginalBootEntryOrderCount;
  24. //
  25. // MY_BOOT_ENTRY is the internal representation of an EFI NVRAM boot item.
  26. // The NtBootEntry item is the structure passed to/from the NT boot entry APIs.
  27. //
  28. typedef struct _MY_BOOT_ENTRY {
  29. LIST_ENTRY ListEntry;
  30. PLIST_ENTRY ListHead;
  31. PUCHAR AllocationEnd;
  32. ULONG Status;
  33. ULONG Id;
  34. ULONG Attributes;
  35. PWSTR FriendlyName;
  36. ULONG FriendlyNameLength;
  37. PWSTR OsLoadOptions;
  38. ULONG OsLoadOptionsLength;
  39. PFILE_PATH BootFilePath;
  40. PFILE_PATH OsFilePath;
  41. PUCHAR ForeignOsOptions;
  42. ULONG ForeignOsOptionsLength;
  43. BOOT_ENTRY NtBootEntry;
  44. } MY_BOOT_ENTRY, *PMY_BOOT_ENTRY;
  45. #define MBE_STATUS_IS_NT 0x00000001
  46. #define MBE_STATUS_NEW 0x00000002
  47. #define MBE_STATUS_DELETED 0x00000004
  48. #define MBE_STATUS_MODIFIED 0x00000008
  49. #define MBE_STATUS_COMMITTED 0x80000000
  50. #define MBE_IS_NT(_be) (((_be)->Status & MBE_STATUS_IS_NT) != 0)
  51. #define MBE_IS_NEW(_be) (((_be)->Status & MBE_STATUS_NEW) != 0)
  52. #define MBE_IS_DELETED(_be) (((_be)->Status & MBE_STATUS_DELETED) != 0)
  53. #define MBE_IS_MODIFIED(_be) (((_be)->Status & MBE_STATUS_MODIFIED) != 0)
  54. #define MBE_IS_COMMITTED(_be) (((_be)->Status & MBE_STATUS_COMMITTED) != 0)
  55. #define MBE_SET_IS_NT(_be) ((_be)->Status |= MBE_STATUS_IS_NT)
  56. #define MBE_SET_NEW(_be) ((_be)->Status |= MBE_STATUS_NEW)
  57. #define MBE_SET_DELETED(_be) ((_be)->Status |= MBE_STATUS_DELETED)
  58. #define MBE_SET_MODIFIED(_be) ((_be)->Status |= MBE_STATUS_MODIFIED)
  59. #define MBE_SET_COMMITTED(_be) ((_be)->Status |= MBE_STATUS_COMMITTED)
  60. #define MBE_CLEAR_IS_NT(_be) ((_be)->Status &= ~MBE_STATUS_IS_NT)
  61. #define MBE_CLEAR_NEW(_be) ((_be)->Status &= ~MBE_STATUS_NEW)
  62. #define MBE_CLEAR_DELETED(_be) ((_be)->Status &= ~MBE_STATUS_DELETED)
  63. #define MBE_CLEAR_MODIFIED(_be) ((_be)->Status &= ~MBE_STATUS_MODIFIED)
  64. #define MBE_CLEAR_COMMITTED(_be) ((_be)->Status &= ~MBE_STATUS_COMMITTED)
  65. #define MBE_IS_ACTIVE(_be) (((_be)->Attributes & BOOT_ENTRY_ATTRIBUTE_ACTIVE) != 0)
  66. #define MBE_SET_ACTIVE(_be) ((_be)->Status |= BOOT_ENTRY_ATTRIBUTE_ACTIVE)
  67. #define MBE_CLEAR_ACTIVE(_be) ((_be)->Status &= ~BOOT_ENTRY_ATTRIBUTE_ACTIVE)
  68. #define IS_SEPARATE_ALLOCATION(_be,_p) \
  69. ((_be->_p != NULL) && \
  70. (((PUCHAR)_be->_p < (PUCHAR)_be) || \
  71. ((PUCHAR)_be->_p > (PUCHAR)_be->AllocationEnd)))
  72. #define FREE_IF_SEPARATE_ALLOCATION(_be,_p) \
  73. if (IS_SEPARATE_ALLOCATION(_be,_p)) { \
  74. MemFree(_be->_p); \
  75. }
  76. extern LIST_ENTRY BootEntries;
  77. extern LIST_ENTRY DeletedBootEntries;
  78. extern LIST_ENTRY ActiveUnorderedBootEntries;
  79. extern LIST_ENTRY InactiveUnorderedBootEntries;
  80. PVOID
  81. MemAlloc(
  82. IN SIZE_T Size
  83. );
  84. PVOID
  85. MemRealloc(
  86. IN PVOID Block,
  87. IN SIZE_T NewSize
  88. );
  89. VOID
  90. MemFree(
  91. IN PVOID Block
  92. );
  93. VOID
  94. InitializeMenuSystem (
  95. VOID
  96. );
  97. VOID
  98. MainMenu (
  99. VOID
  100. );
  101. VOID
  102. ClearMenuArea (
  103. VOID
  104. );
  105. PMY_BOOT_ENTRY
  106. SaveChanges (
  107. PMY_BOOT_ENTRY CurrentBootEntry
  108. );
  109. PWSTR
  110. GetNtNameForFilePath (
  111. IN PFILE_PATH FilePath
  112. );
  113. VOID
  114. FatalError (
  115. DWORD Error,
  116. PWSTR Format,
  117. ...
  118. );
  119. VOID
  120. SetStatusLine (
  121. PWSTR Status
  122. );
  123. VOID
  124. SetStatusLineAndWait (
  125. PWSTR Status
  126. );
  127. VOID
  128. SetStatusLine2 (
  129. PWSTR Status
  130. );
  131. VOID
  132. SetStatusLine2AndWait (
  133. PWSTR Status
  134. );