Skip to content

Read Binary File

ehsan

Asked May 22, 2008, 2:16 AM EDT2 answers
Share
LinkedInX
hello,
this is an expert topic and winner have expert answer.
I have a Binary File and save multiple files in this Binary file.
this file is QuickBasic BSAVE binary data
please help me Experts
Regards,
Thanks

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    hi,
    I do not know this type of format but I`ve worked a lot with binary files, not only in c#, so, this is your header info googled:

    VB.NET
    The total length of the header is 7 bytes:
    Byte 1   IdByte     This must evaluate to &HFD to be a valid BSAVE file. In QuickBasic use ASC function of a 1 character string variable. 
    Byte 2-3 Segment
    Byte 4-5 Address
    Byte 6-7 Length     Useful if you wish to dimension an array ahead of time to hold the BLOAD.

    so it seems you need to open file stream and do a repetitive read, this read will consist in:
    1. first 7 bytes to know what data and size you have
    2. the next X bytes where X is the Length (bytes 6+7 from header)

    note that the length of the data may be bytes 6+7 from header or bytes 6+7 from header MINUS 7 cause 7 is header`s length

    for example, lets say you have this 7 bytes in the beginning:
    0x01 0x02 0x03 0x04 0x05 0x06 0x07
    you have a segment identified with 0x0203, an address of 0x0405 and a length of 0x0607 which is 1543 in decimal thus you need to read then 1543 or 1543-7 bytes (if the length includes header)

    OPEN FILE
    POSITION BEGINNING
    LOOP
      READ 7
      CHECK LENGTH
      READ LENGTH || LENGTH-7
    ENDLOOP

    hope this helps
    0
  • 0
    Hi,
    Thanks For Your response Johnny GC.
    I Found 0xFD result for valid bsave file header but I can't extract the (((Files))) into this file in C#

    this is first lines in hex editor
    .........................lq........8...mOC20.......>.OMEGA [email protected]__3USER   FAT12@.@T!.....U.......@.... `<...O.@.+..........!..% .#..&..'.....+p.-../..1 [email protected]`.7..9..;..=..?..A [email protected]`.G..I..K..M..O..Q [email protected]`.W..Y..[..].._..a [email protected]`.g..i..k..m..o..q [email protected]`.w..y..{..}...... ..@..`................. ..@..`.C............... .

    please help me more
    Thanks Advance
    Regards
    0