Help me understand this binary file format

I am trying to write a small utility to create a binary file that will simulate a file created by another closed application. I used hex editors to decrypt the format, I got stuck trying to figure out what the format / encoding is so that I can create it using C ++ or C #.

The file begins with the first four bytes: 01 00 and then FF FE. I understand that the file starts with SOH, followed by the byte order sign for the little endian. After these four bytes, the program appears to write a BSTR for each of the line fields from the application GUI.

Using C #, I created a unicode file that starts with FF FE, but I'm not sure how to insert the SOH character first.

I would be forever grateful if someone could provide information about the file format or encoding and why the file starts with the SOH symbol.

Thanks in advance.

+5
source share
2 answers

If you just can't write the first four bytes, this will do it for you.

using (var stream = new FileStream("myfile.bin", FileMode.Create))
{
     using (var binaryWriter = new BinaryWriter(stream))
     {
         binaryWriter.Write((byte)1);
         binaryWriter.Write((byte)0);
         binaryWriter.Write((byte)0xFF);
         binaryWriter.Write((byte)0xFE);
         binaryWriter.Write(Encoding.Unicode.GetBytes("string"));
     }
}

This will output the following file

01 00 FF FE 73 00 74 00 72 00 69 00 6e 00 67 00  ....s.t.r.i.n.g.

Edit: added Mark H clause to write a string.

+3
source

Reverse engineering a binary file format can be a daunting task. I do not consider this an obvious, well-known file format ... but there are thousands, so who knows.

, , :

+3

All Articles