|
10 | 10 | Private ReadOnly _BPB As BiosParameterBlock |
11 | 11 | Private ReadOnly _FloppyImage As IFloppyImage |
12 | 12 | Private ReadOnly _Offset As UInteger |
| 13 | + |
13 | 14 | Public Enum BootSectorOffsets As UInteger |
| 15 | + FMTownsSignature = 0 |
14 | 16 | JmpBoot = 0 |
15 | 17 | OEMName = 3 |
16 | 18 | DriveNumber = 36 |
|
24 | 26 | End Enum |
25 | 27 |
|
26 | 28 | Public Enum BootSectorSizes As UInteger |
| 29 | + FMTownsSignature = 4 |
27 | 30 | JmpBoot = 3 |
28 | 31 | OEMName = 8 |
29 | 32 | DriveNumber = 1 |
|
114 | 117 |
|
115 | 118 | Public Property JmpBoot() As Byte() |
116 | 119 | Get |
117 | | - Return _FloppyImage.GetBytes(BootSectorOffsets.JmpBoot + _Offset, BootSectorSizes.JmpBoot) |
| 120 | + Return _FloppyImage.GetBytes(GetJmpBootOffset() + _Offset, BootSectorSizes.JmpBoot) |
118 | 121 | End Get |
119 | 122 | Set |
120 | | - _FloppyImage.SetBytes(Value, BootSectorOffsets.JmpBoot + _Offset, BootSectorSizes.JmpBoot, 0) |
| 123 | + _FloppyImage.SetBytes(Value, GetJmpBootOffset() + _Offset, BootSectorSizes.JmpBoot, 0) |
121 | 124 | End Set |
122 | 125 | End Property |
123 | 126 |
|
124 | 127 | Public Property OEMName() As Byte() |
125 | 128 | Get |
126 | | - Return _FloppyImage.GetBytes(BootSectorOffsets.OEMName + _Offset, BootSectorSizes.OEMName) |
| 129 | + Return _FloppyImage.GetBytes(GetOEMNameOffset() + _Offset, GetOEMNameSize()) |
127 | 130 | End Get |
128 | 131 | Set |
129 | | - _FloppyImage.SetBytes(Value, BootSectorOffsets.OEMName + _Offset, BootSectorSizes.OEMName, 0) |
| 132 | + _FloppyImage.SetBytes(Value, GetOEMNameOffset() + _Offset, GetOEMNameSize(), 0) |
130 | 133 | End Set |
131 | 134 | End Property |
132 | 135 |
|
|
158 | 161 | End Property |
159 | 162 |
|
160 | 163 | Public Function CheckJumpInstruction(CheckNOP As Boolean) As Boolean |
161 | | - Return CheckJumpInstruction(JmpBoot, CheckNOP) |
| 164 | + Return CheckJumpInstruction(JmpBoot, GetJmpBootOffset(), CheckNOP) |
162 | 165 | End Function |
163 | 166 |
|
164 | 167 | Public Function CheckJumpInstruction(CheckNOP As Boolean, CheckDestination As Boolean) As Boolean |
165 | | - Return CheckJumpInstruction(JmpBoot, CheckNOP, CheckDestination) |
| 168 | + Return CheckJumpInstruction(JmpBoot, GetJmpBootOffset(), CheckNOP, CheckDestination) |
166 | 169 | End Function |
167 | 170 |
|
168 | | - Public Shared Function CheckJumpInstruction(Jmp() As Byte, CheckNOP As Boolean) As Boolean |
169 | | - Return CheckJumpInstruction(Jmp, CheckNOP, False) |
| 171 | + Public Shared Function CheckJumpInstruction(Jmp() As Byte, JmpOffset As UInteger, CheckNOP As Boolean) As Boolean |
| 172 | + Return CheckJumpInstruction(Jmp, JmpOffset, CheckNOP, False) |
170 | 173 | End Function |
171 | 174 |
|
172 | | - Public Shared Function CheckJumpInstruction(Jmp() As Byte, CheckNOP As Boolean, CheckDestination As Boolean) As Boolean |
| 175 | + Public Shared Function CheckJumpInstruction(Jmp() As Byte, JmpOffset As UInteger, CheckNOP As Boolean, CheckDestination As Boolean) As Boolean |
173 | 176 | Dim Result As Boolean = False |
174 | 177 |
|
175 | 178 | If Jmp(0) = &HEB And (Not CheckNOP Or Jmp(2) = &H90) Then |
176 | 179 | If CheckDestination Then |
177 | | - Dim Offset As UShort = Jmp(1) + 2 |
| 180 | + Dim Offset As UShort = Jmp(1) + JmpOffset + 2 |
178 | 181 | Result = (Offset < BootSectorOffsets.BootStrapSignature) |
179 | 182 | Else |
180 | 183 | Result = True |
181 | 184 | End If |
182 | 185 | ElseIf Jmp(0) = &HE9 Then |
183 | 186 | If CheckDestination Then |
184 | | - Dim Offset As UShort = BitConverter.ToUInt16(Jmp, 1) + 3 |
| 187 | + Dim Offset As UShort = BitConverter.ToUInt16(Jmp, 1) + JmpOffset + 3 |
185 | 188 | Result = (Offset < BootSectorOffsets.BootStrapSignature) |
186 | 189 | Else |
187 | 190 | Result = True |
|
199 | 202 | End Function |
200 | 203 |
|
201 | 204 | Public Function GetBootStrapCode(Jmp() As Byte) As Byte() |
202 | | - Dim Offset = GetBootStrapOffset(Jmp) |
| 205 | + Dim Offset = GetBootStrapOffset(Jmp, GetBootStrapOffset()) |
203 | 206 |
|
204 | 207 | Return GetBootStrapCode(Offset) |
205 | 208 | End Function |
|
213 | 216 | End If |
214 | 217 | End Function |
215 | 218 |
|
216 | | - Public Shared Function GetBootStrapOffset(Jmp() As Byte) As UShort |
| 219 | + Private Shared Function GetBootStrapOffset(Jmp() As Byte, JmpOffset As UInteger) As UShort |
217 | 220 | Dim Offset As UShort |
218 | 221 |
|
219 | 222 | If Jmp(0) = &HEB Then |
220 | | - Offset = Jmp(1) + 2 |
| 223 | + Offset = Jmp(1) + JmpOffset + 2 |
221 | 224 | ElseIf Jmp(0) = &HE9 Then |
222 | | - Offset = BitConverter.ToUInt16(Jmp, 1) + 3 |
| 225 | + Offset = BitConverter.ToUInt16(Jmp, 1) + JmpOffset + 3 |
223 | 226 | Else |
224 | | - Offset = 0 |
| 227 | + Offset = JmpOffset |
225 | 228 | End If |
226 | 229 |
|
227 | 230 | If Offset >= BootSectorOffsets.BootStrapSignature Then |
228 | | - Offset = 0 |
| 231 | + Offset = JmpOffset |
229 | 232 | End If |
230 | 233 |
|
231 | 234 | Return Offset |
232 | 235 | End Function |
233 | 236 |
|
234 | 237 | Public Function GetBootStrapOffset() As UShort |
235 | | - Return GetBootStrapOffset(JmpBoot) |
| 238 | + Return GetBootStrapOffset(JmpBoot, GetJmpBootOffset()) |
236 | 239 | End Function |
237 | 240 |
|
238 | 241 | Public Function GetFileSystemTypeString() As String |
239 | 242 | Return CodePage437ToUnicode(FileSystemType) |
240 | 243 | End Function |
241 | 244 |
|
| 245 | + Public Function GetJmpBootOffset() As UInteger |
| 246 | + Dim Offset = BootSectorOffsets.JmpBoot |
| 247 | + If IsFMTowns() Then |
| 248 | + Offset += BootSectorSizes.FMTownsSignature |
| 249 | + End If |
| 250 | + Return Offset |
| 251 | + End Function |
| 252 | + |
| 253 | + Public Function GetOEMNameOffset() As UInteger |
| 254 | + Dim Offset = BootSectorOffsets.OEMName |
| 255 | + If IsFMTowns() Then |
| 256 | + Offset += BootSectorSizes.FMTownsSignature |
| 257 | + End If |
| 258 | + Return Offset |
| 259 | + End Function |
| 260 | + |
| 261 | + Public Function GetOEMNameSize() As UInteger |
| 262 | + Dim Size = BootSectorSizes.OEMName |
| 263 | + If IsFMTowns() Then |
| 264 | + Size -= BootSectorSizes.FMTownsSignature |
| 265 | + End If |
| 266 | + Return Size |
| 267 | + End Function |
| 268 | + |
242 | 269 | Public Function GetOEMNameString() As String |
243 | 270 | Return CodePage437ToUnicode(OEMName) |
244 | 271 | End Function |
|
259 | 286 | Return ValidExtendedBootSignature.Contains(ExtendedBootSignature) |
260 | 287 | End Function |
261 | 288 |
|
| 289 | + Public Function IsFMTowns() As Boolean |
| 290 | + Dim Signature = _FloppyImage.GetBytes(BootSectorOffsets.FMTownsSignature, BootSectorSizes.FMTownsSignature) |
| 291 | + |
| 292 | + If Signature(0) = &H49 AndAlso Signature(1) = &H50 AndAlso Signature(2) = &H4C AndAlso Signature(3) = &H34 Then |
| 293 | + Return True |
| 294 | + End If |
| 295 | + |
| 296 | + Return False |
| 297 | + End Function |
| 298 | + |
262 | 299 | Public Function IsWin9xOEMName() As Boolean |
263 | 300 | Dim OEMNameLocal = OEMName |
264 | 301 |
|
| 302 | + If OEMNameLocal.Length < 8 Then |
| 303 | + Return False |
| 304 | + End If |
| 305 | + |
265 | 306 | Return OEMNameLocal(5) = &H49 And OEMNameLocal(6) = &H48 And OEMNameLocal(7) = &H43 |
266 | 307 | End Function |
267 | 308 | End Class |
|
0 commit comments