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.

196 lines
4.9 KiB

  1. #include <efisbent.h>
  2. #include <tchar.h>
  3. #include <stdlib.h>
  4. VOID
  5. TraceResult(
  6. IN PWSTR Feature,
  7. IN BOOLEAN Result
  8. )
  9. {
  10. wprintf(L"%ws : %ws\n", Feature, Result ? L"Passed" : L"Failed");
  11. if (!Result) {
  12. exit(0);
  13. }
  14. }
  15. VOID
  16. DumpFilePath(
  17. IN PFILE_PATH FilePath
  18. )
  19. {
  20. if (FilePath) {
  21. wprintf(L"%d:%ws\n",
  22. FilePath->Type,
  23. FilePath->FilePath);
  24. }
  25. }
  26. VOID
  27. DumpOsBootEntry(
  28. IN POS_BOOT_ENTRY Entry
  29. )
  30. {
  31. if (Entry) {
  32. wprintf(L"%0d=>%ws,(%ws,%ws),(%ws,%ws),%ws\n",
  33. OSBEGetId(Entry),
  34. OSBEGetFriendlyName(Entry),
  35. OSBEGetOsLoaderVolumeName(Entry),
  36. OSBEGetOsLoaderPath(Entry),
  37. OSBEGetBootVolumeName(Entry),
  38. OSBEGetBootPath(Entry),
  39. OSBEGetOsLoadOptions(Entry)
  40. );
  41. }
  42. }
  43. VOID
  44. DumpDrvBootEntry(
  45. IN PDRIVER_ENTRY This
  46. )
  47. {
  48. if (This){
  49. wprintf(L"%0d=>%ws, %ws,(%ws, %ws)\n",
  50. OSDriverGetId(This),
  51. OSDriverGetFriendlyName(This),
  52. OSDriverGetFileName(This),
  53. OSDriverGetDevicePath(This),
  54. OSDriverGetFilePath(This));
  55. }
  56. }
  57. VOID
  58. DumpOsBootOptions(
  59. IN POS_BOOT_OPTIONS Options
  60. )
  61. {
  62. if (Options) {
  63. ULONG Index;
  64. POS_BOOT_ENTRY Entry = OSBOGetFirstBootEntry(Options, &Index);
  65. PDRIVER_ENTRY DrvEntry = OSBOGetFirstDriverEntry(Options);
  66. wprintf(L"\n");
  67. while (Entry) {
  68. DumpOsBootEntry(Entry);
  69. Entry = OSBOGetNextBootEntry(Options, &Index);
  70. }
  71. for (Index=0;
  72. Index < OSBOGetOrderedBootEntryCount(Options);
  73. Index++) {
  74. wprintf(L"%04d,", OSBOGetBootEntryIdByOrder(Options, Index));
  75. }
  76. wprintf(L"\n DriverEntries \n");
  77. for (DrvEntry;
  78. DrvEntry != NULL;
  79. DrvEntry = DrvEntry->NextEntry){
  80. DumpDrvBootEntry(DrvEntry);
  81. }
  82. wprintf(L"\n\n");
  83. }
  84. }
  85. INT
  86. __cdecl
  87. main(
  88. IN INT Argc,
  89. IN CHAR *Argv[]
  90. )
  91. {
  92. POS_BOOT_OPTIONS OsBootOptions = NULL;
  93. POS_BOOT_ENTRY NewEntry;
  94. POS_BOOT_ENTRY ActiveBootEntry;
  95. POS_BOOT_ENTRY ConvertedEntry;
  96. PDRIVER_ENTRY NewDriverEntry = NULL ;
  97. PDRIVER_ENTRY FindDrvEntry = NULL;
  98. if (OSBOLibraryInit((SBEMemAllocateRoutine)malloc, (SBEMemFreeRoutine)free)) {
  99. OsBootOptions = EFIOSBOCreate();
  100. }
  101. TraceResult(L"Creating EFI OS BootOptions", (OsBootOptions != NULL));
  102. DumpOsBootOptions(OsBootOptions);
  103. //
  104. // Add test
  105. //
  106. NewEntry = OSBOAddNewBootEntry(OsBootOptions,
  107. L"Add Testing",
  108. L"\\Device\\HarddiskVolume1",
  109. L"\\setupldr.efi",
  110. L"\\Device\\HarddiskVolume3",
  111. L"\\WINDOWS",
  112. L"/dummy1 /dummy2");
  113. TraceResult(L"Add test : ", (NewEntry != NULL));
  114. DumpOsBootEntry(NewEntry);
  115. //
  116. // Search test
  117. //
  118. ActiveBootEntry = OSBOFindBootEntry(OsBootOptions, 7);
  119. TraceResult(L"Getting boot entry 0", (ActiveBootEntry != NULL));
  120. DumpOsBootEntry(ActiveBootEntry);
  121. //
  122. // Get active test
  123. //
  124. ActiveBootEntry = OSBOGetActiveBootEntry(OsBootOptions);
  125. TraceResult(L"Getting active boot entry", (ActiveBootEntry != NULL));
  126. DumpOsBootEntry(ActiveBootEntry);
  127. //
  128. // Set active test
  129. //
  130. ActiveBootEntry = OSBOSetActiveBootEntry(OsBootOptions, NewEntry);
  131. TraceResult(L"Setting active boot entry", (ActiveBootEntry != NULL));
  132. ActiveBootEntry = OSBOGetActiveBootEntry(OsBootOptions);
  133. TraceResult(L"Getting active boot entry again", (ActiveBootEntry != NULL));
  134. DumpOsBootEntry(ActiveBootEntry);
  135. DumpOsBootOptions(OsBootOptions);
  136. //
  137. // Delete boot entry test
  138. //
  139. TraceResult(L"Deleting new boot entry",
  140. OSBODeleteBootEntry(OsBootOptions, NewEntry));
  141. DumpOsBootOptions(OsBootOptions);
  142. //
  143. // Add driver test entry
  144. //
  145. NewDriverEntry = OSBOAddNewDriverEntry(OsBootOptions,
  146. L"My Test Driver Entry",
  147. L"\\Device\\HarddiskVolume1",
  148. L"\\EFI\\Microsoft\\EFIDrivers\\fpswa.sys");
  149. TraceResult(L"Add Driver entry test : ", (NewDriverEntry != NULL));
  150. DumpDrvBootEntry(NewDriverEntry);
  151. //
  152. // Delete Driver entry test
  153. //
  154. TraceResult(L"Deleting driver entry",
  155. OSBODeleteDriverEntry(OsBootOptions, NewDriverEntry->Id));
  156. DumpOsBootOptions(OsBootOptions);
  157. OSBODelete(OsBootOptions);
  158. }