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.

210 lines
5.0 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. Patchbc.c
  5. Abstract:
  6. Implementation for a module that knows how to patch translated
  7. messages into arrays that constitute Windows NT file system boot code.
  8. Author:
  9. Ted Miller (tedm) 6 May 1997
  10. Revision History:
  11. --*/
  12. /*
  13. Various modules in the Windows NT need to lay the mbr or file system
  14. boot records, such as format, setup, etc. Boot code for fat, fat32,
  15. ntfs, and the mbr is each built into a corresponding header file
  16. in sdk\inc. Each header file has an array of bytes that constitute
  17. the boot code itself. The code has no text in it, but instead has some
  18. placeholders for text that needs to be patched in at run-time by
  19. users of those header files. This allows localization of the
  20. boot messages without recompiles.
  21. As built, each boot code array has a table in a known place that
  22. indicates where in the array the messages are supposed to start.
  23. The boot code expects to look there to find the offset of any
  24. message it needs.
  25. For the file system boot code, the message offset table is located
  26. immediately before the 2-byte 55aa sig (for fat) or the 4-byte 000055aa
  27. sig (for fat32 and ntfs).
  28. Fat/Fat32 share 3 messages, whose offsets are expected to be in the
  29. following order in the offset table:
  30. NTLDR is missing
  31. Disk error
  32. Press any key to restart
  33. NTFS has 4 messages, whose offsets are expected to be in the following
  34. order in the offset table:
  35. A disk read error occurred
  36. NTLDR is missing
  37. NTLDR is compressed
  38. Press Ctrl+Alt+Del to restart
  39. For the master boot code, the message offset table is immediately before
  40. the NTFT signature and has 3 messages (thus it starts at offset 0x1b5).
  41. The offsets are expected to be in the following order:
  42. Invalid partition table
  43. Error loading operating system
  44. Missing operating system
  45. Finally note that to allow one-byte values to be stored in the message
  46. offset tables we store the offset - 256.
  47. */
  48. #include <nt.h>
  49. #include <patchbc.h>
  50. #include <string.h>
  51. BOOLEAN
  52. DoPatchMessagesIntoBootCode(
  53. IN OUT PUCHAR BootCode,
  54. IN unsigned TableOffset,
  55. IN BOOLEAN WantCrLfs,
  56. IN BOOLEAN WantTerminating255,
  57. IN unsigned MessageCount,
  58. ...
  59. )
  60. {
  61. va_list arglist;
  62. unsigned Offset;
  63. unsigned i;
  64. LPCSTR text;
  65. va_start(arglist,MessageCount);
  66. Offset = (unsigned)BootCode[TableOffset] + 256;
  67. for(i=0; i<MessageCount; i++) {
  68. text = va_arg(arglist,LPCSTR);
  69. BootCode[TableOffset+i] = (UCHAR)(Offset - 256);
  70. if(WantCrLfs) {
  71. BootCode[Offset++] = 13;
  72. BootCode[Offset++] = 10;
  73. }
  74. strcpy(BootCode+Offset,text);
  75. Offset += strlen(text);
  76. if(i == (MessageCount-1)) {
  77. //
  78. // Last message gets special treatment.
  79. //
  80. if(WantCrLfs) {
  81. BootCode[Offset++] = 13;
  82. BootCode[Offset++] = 10;
  83. }
  84. BootCode[Offset++] = 0;
  85. } else {
  86. //
  87. // Not last message.
  88. //
  89. if(WantTerminating255) {
  90. BootCode[Offset++] = 255;
  91. } else {
  92. BootCode[Offset++] = 0;
  93. }
  94. }
  95. }
  96. va_end(arglist);
  97. return(Offset <= TableOffset);
  98. }
  99. BOOLEAN
  100. PatchMessagesIntoFatBootCode(
  101. IN OUT PUCHAR BootCode,
  102. IN BOOLEAN IsFat32,
  103. IN LPCSTR MsgNtldrMissing,
  104. IN LPCSTR MsgDiskError,
  105. IN LPCSTR MsgPressKey
  106. )
  107. {
  108. BOOLEAN b;
  109. b = DoPatchMessagesIntoBootCode(
  110. BootCode,
  111. IsFat32 ? 505 : 507,
  112. TRUE,
  113. TRUE,
  114. 3,
  115. MsgNtldrMissing,
  116. MsgDiskError,
  117. MsgPressKey
  118. );
  119. return(b);
  120. }
  121. BOOLEAN
  122. PatchMessagesIntoNtfsBootCode(
  123. IN OUT PUCHAR BootCode,
  124. IN LPCSTR MsgNtldrMissing,
  125. IN LPCSTR MsgNtldrCompressed,
  126. IN LPCSTR MsgDiskError,
  127. IN LPCSTR MsgPressKey
  128. )
  129. {
  130. BOOLEAN b;
  131. b = DoPatchMessagesIntoBootCode(
  132. BootCode,
  133. 504,
  134. TRUE,
  135. FALSE,
  136. 4,
  137. MsgDiskError,
  138. MsgNtldrMissing,
  139. MsgNtldrCompressed,
  140. MsgPressKey
  141. );
  142. return(b);
  143. }
  144. BOOLEAN
  145. PatchMessagesIntoMasterBootCode(
  146. IN OUT PUCHAR BootCode,
  147. IN LPCSTR MsgInvalidTable,
  148. IN LPCSTR MsgIoError,
  149. IN LPCSTR MsgMissingOs
  150. )
  151. {
  152. BOOLEAN b;
  153. b = DoPatchMessagesIntoBootCode(
  154. BootCode,
  155. 0x1b5,
  156. FALSE,
  157. FALSE,
  158. 3,
  159. MsgInvalidTable,
  160. MsgIoError,
  161. MsgMissingOs
  162. );
  163. return(b);
  164. }