I'm inspecting a binary file. I have a rough idea of what is inside but there are some characters present which I am not sure how they got there. My question is highlighted in bold below. Thanks.

To speed things up the first 28 bytes are reserved for the date & time, it finishes about 24 bytes in, which I expected. However at 29 bytes there is a control code 'EOF' (04). At 30 bytes in is another unexpected control code 'FS' (1c). Are these control codes typically used to seperate contents in a binary file? Would they have to have been placed purposely on generation? At first I thought maybe an old time and date function would have returned an array with this value at the end but it falls out of the 28 byte range.

Originally this was apparently generated on an old UNIX SYSTEM 5 system and possibly used the POSIX libs.

Here is the contents binary file through a hex editor...

54 75 65 20 4e 6f 76 20 32 39 20 30 39 3a 32 35 3a 34 35 20 32 30 31 31 00 00 00 00 04 00 1c 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ab 00 39 00 82 46 40 02 13 00 37 00 3b 00 ec 45 18 47 40 02 58 02 41 65 00 00 00 00 84 00 67 00 f2 2b 7d 04 37 00 66 00 69 00 8e 2b 56 2c 4c 04 a5 04 f9 c9 00 00 00 00 60 00 59 00 ac 0d 29 05 08 00 57 00 5b 00 48 0d ac 0d 19 05 29 05 4e e8 00 00 00 00 62 00 58 00 7a 0d 41 05 03 00 55 00 58 00 e4 0c 7a 0d 41 05 41 05 85 ec 00 00 03 00 85 00 53 00 ac 0d 49 05 05 00 50 00 54 00 16 0d 10 0e 49 05 49 05 ee ed 00 00 02 00 88 00 54 00 ac 0d 51 05 39 00 51 00 59 00 e4 0c 10 0e 21 05 79 05 56 ef 00 00

Are you attempting to create your own customized binary file? This is the freedom of binary file format because it could be different from one to others. Usually, a binary file contains header information, and it could be anything depending on what format it is and who creates it. Is it a standard to have those bits you ask? It could be yes for the owner of the format and those who use it, but it could be no for others.

I have done some more digging and found the format for the binary files- It appears though that the empty space is 48 bytes long not 24 as the document states!? As you can see someone has left a comment saying the struct is 28 bytes in total however my program im using to analyse the struct says it is 52 bytes!

The binary file, after header, should contain a number of records.

THE HEADER:

    /* headers have a bit of empty space in them for 
     * possible future addition -- make header be
     * 80 bytes
     */

    struct  ohdr                     /* file header*/
    {
        /* 52 + Bytes per record, where bytes per record equal size of SbOutput(28) = 80 bytes */

        char    date[S2LEN];                              
        short   type;                 
        short   BytesPerRecord;         
        short   empty[EMPTYSPACEHDR];   /* empty space, empty space is 24 bytes*/
    };

THE RECORD:

typedef struct SOutput
{
    /* 28 bytes in total */
    int       index;   
    int       mea;                     
    int       mer;          
    int       met;            
    unsigned  mez;            
    int       tne;                      
    int       rmin;                     
    int       rmax;                          
    int       tmin;                    
    int       tmax;                    
    unsigned  zmin;                    
    unsigned  zmax;                     
    long mpulsenum;     
}Output;

That's a really difficult bug to detect usually because the person who makes the comment does not update the comment when he/she updates the code... It's nice that you found out about it.

hmmmm so the binary file was produced by some legacy code, looks like the size mismatches are probably down to the fact that their compiler produced ints that are 2 bytes and ours are 4 bytes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.