A binary file has the following layout:
[FileIdentifier][HeaderStruct][ItemStruct]*[MuchBinaryData]
The [HeaderStruct]
contains a Count
field, indicating how many [ItemStruct]
records follow. Without analyzing this data, I can't access [MuchBinaryData]
.
The fixed-length structures look as follows:
Public Structure HeaderStruct
Public MajorVersion As Integer
Public MinorVersion As Integer
Public Count As Integer 'Number of contained ItemStruct.
End Structure
Public Structure ItemStruct
Public ItemType As Type
Public Length As Long
...
End Structure
Retrieving the [FileIdentifier]
field is trivial, it's just a field of 6 bytes.
Public Sub New(sFileName As String)
Dim abFileID(0 To FILEIDENTIFIER.Length - 1) As Byte
If File.Exists(gsFileName) Then
Using oFS = File.Open(sFileName, FileMode.Open, FileAccess.Read)
oFS.Read(abFileID, 0, abFileID.Length)
...
End Using
End If
End Sub
So my question is: how can I retrieve these (variable number) of structures as, well, structures?
Do I really need to access each byte, compose a value with lower Endian in mind, and manually assign the calculated value to the structures' fields?
Edit
I found this suggestion using GCHandle
and IntPtr
: Is there a way to convert a structure to a byte array?
(It definitely needs being wrapped.)
Is this the best I can hope for?