Click here to Skip to main content
11,410,750 members (62,876 online)
Click here to Skip to main content

Bin2Iso

, 21 Jul 2003
Rate this:
Please Sign up or sign in to vote.
A Free Tool to Convert Bin Image Format to ISO Image Format

Sample Image - Bin2Iso.jpg

Introduction

This is a free tool for converting one CD image format (Bin) to another format (ISO). The conversion routine is very simple. Just read the Bin image and according to it's structure, write the data in another format. For this reason, a developer must know structure of both formats.

Image Formats

The CD-ROM specification (Yellow Book) defines the use of two types of sectors, mode 1 and mode 2. Mode 2 sectors are used for CD-ROM XA formats.

CD-ROM Sectors

Data stored on a CD-ROM disc is divided into sectors which are equivalent to the audio frames for a CD audio disc. At normal (1x) playback speed, 75 sectors are read every second. For double speed CD-ROM drives this increases to 150 sectors per second and so on. Seek times, while the disc rotates to the required starting position, will also reduce as speeds increase.

Because CDs were designed primarily for audio, their use for computer data requires the addition of header data and error correction codes which are included in every sector. There are two different types of sectors defined in the CD-ROM specification, Mode 1 and Mode 2 (the latter being used for CD-ROM XA discs).

Mode 1 Sectors

Mode 1 sectors are intended for the storage of computer data and contain the following fields.

  • Sync (12 bytes) which is used to enable the player to identify the start of each sector.
  • Header (4 bytes) consisting of Minutes, Seconds, Sectors and Mode (= 1).
  • ECC (Error Correction Code - 276 bytes), which comprises an additional level of CIRC error protection.
  • EDC (Error Detection Code - 4 bytes) for detecting errors to be corrected.

Mode 1 sectors are the simplest type and are used for most CD-ROM based formats which follow the Yellow Book.

<!--

CD-ROM Sector Formats

-->

Mode 2 Sectors

Mode 2 sectors are used for those formats based on CD-ROM XA and can be either Form 1 or 2.

  • Mode 2 Form 1 sectors contain 2048 bytes with the same ECC as Mode 1 sectors.
  • Mode 2 Form 2 sectors contain 2324 bytes of user data per sector, with no ECC are are suitable only for data where errors can be concealed (eg audio or video data).

Mode 2 sectors comprise the following fields:

  • Sync (12 bytes) which is used to enable the player to identify the start of each sector.
  • Header (4 bytes) consisting of Minutes, Seconds, Sectors and Mode (= 1).
  • Subheader (8 bytes) contains content related parameters eg data type.
  • ECC (Error Correction Code - 276 bytes) which comprises an additional level of CIRC error protection for Form 1 only.
  • EDC (Error Detection Code) for Forms 1 and 2.

Note that Mode 1 and Mode 2 Form 1 use the same error correction so can be used interchangeably, but not within the same track and preferably not on the same disc. Software used to write CD-Rs can be set for Mode 1 or Mode 2 Form 1. Almost all PCs and Macs will read Mode 2 Form 1 CD-ROMs as well as Mode 1.

Note that any CD-ROM will contain at least some Mode 1 or Mode 2 Form 1 sectors.

Capacity

The capacity of a CD-ROM depends on whether it is a Mode 1 CD-ROM or Mode 2 CD-ROM XA. Assuming the maximum size is 76 minutes 30 seconds (as recommended) this means that there are 336,300 sectors on a CD-ROM. From this must be subtracted 166 sectors at the start of track 1 plus a few sectors for the file system, amounting to, say, 200 sectors leaving 336,100 sectors for user data.

  • Mode 1 sectors contain 2048 bytes per sector giving a total capacity of 688,332,800 bytes or 656MB (where 1 MB = 1024 * 1024).
  • Mode 2 sectors contain either 2048 or 2324 bytes per sector so will have a somewhat higher data capacity depending on the mix of the two types of sector.

The above assumes a CD-ROM comprising a single track in a single session. For multiple track/session discs the data capacity will be reduced.

Solution

With this information, now it is easy to develop a program to convert one image format to another.
The main routine in program is Convert. The code below, shows you the employed technique.

UINT Convert(LPVOID pParam)
{
    PThreadData pth=(PThreadData) pParam;
    
    //Open files for reading/writing
    int   seek_header, seek_ecc, sector_size;
    long  i, source_length;
    char  buf[2352];
    const BYTE SYNC_HEADER[12] = 
        {0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0};
    
    FILE *fpSource, *fpTarget;

    fpSource = _tfopen(pth->Source, _T("rb"));
    fpTarget = _tfopen(pth->Target, _T("wb"));

    
    if ((fpSource==NULL) || (fpTarget==NULL))
    {
        ::SendMessage(pth->hwnd, WM_THREAD_TERMINATE, 0, 
                (LPARAM) FILE_FAILED);
        
        return -1;
    }
    
    fread(buf, sizeof(char), 16, fpSource);

    if (memcmp(SYNC_HEADER, buf, 12))
    {
        seek_header = 8;        
        seek_ecc = 280;
        sector_size = 2336;
    }
    else        
    {
        switch(buf[15])
        {
            case 2:
            {    
                seek_header = 24;    // Mode2/2352    
                seek_ecc = 280;
                sector_size = 2352;
                break;
            }

            case 1:
            {
                seek_header = 16;    // Mode1/2352
                seek_ecc = 288;
                sector_size = 2352;
                break;
            }

            default:
            {
                ::SendMessage(pth->hwnd, WM_THREAD_TERMINATE, 
                    0, (LPARAM) TRACK_UNSUPPORTED);

                fclose(fpTarget);
                fclose(fpSource);

                return -1;
            }
        }
    }

    fseek(fpSource, 0L, SEEK_END);
    source_length = ftell(fpSource)/sector_size;
    fseek(fpSource, 0L, SEEK_SET);

    for(i=0; i<source_length; i++)
    {
        fseek(fpSource, seek_header, SEEK_CUR);
        fread(buf, sizeof(char), 2048, fpSource);  
        fwrite(buf, sizeof(char), 2048, fpTarget);
        fseek(fpSource, seek_ecc, SEEK_CUR);

        ::SendMessage(pth->hwnd, WM_THREAD_PROGRESS, 0, 
                (LPARAM) ((i+1)*100/source_length));
    }

    fclose(fpTarget);
    fclose(fpSource);

    return 0;
}

This function called as a new thread when Convert button pressed.

Further Information

For further information refer to the Distronics web site. They have very useful information about various CD/DVD technologies on their web site.

Enjoy!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

A. Riazi
CEO Misbah3Com
Iran (Islamic Republic Of) Iran (Islamic Republic Of)
I was born in Shiraz, a very beautiful famous city in Iran. I started programming when I was 12 years old with GWBASIC. Since now, I worked with various programming languages from Basic, Foxpro, C/C++, Visual Basic, Pascal to MATLAB and now Visual C++.
I graduated from Iran University of Science & Technology in Communication Eng., and now work as a system programmer for a telecommunication industry.
I wrote several programs and drivers for Synthesizers, Power Amplifiers, GPIB, GPS devices, Radio cards, Data Acqusition cards and so many related devices.
I'm author of several books like Learning C (primary and advanced), Learning Visual Basic, API application for VB, Teach Yourself Object Oriented Programming (OOP) and etc.
I'm winner of January, May, August 2003 and April 2005 best article of month competetion, my articles are:

You can see list of my articles, by clicking here


Comments and Discussions

 
GeneralMy vote of 5 Pinmembermanoj kumar choubey26-Feb-12 20:49 
GeneralCool PinmemberHard Coder28-Mar-10 7:07 
GeneralMegalicious!! Many thanks! Pinmembercyborgjn14-Nov-07 6:41 
Generalthanx PinmemberDuong11229-Sep-07 22:43 
GeneralYour Service Required PinmemberRohit Singal1-Aug-07 1:44 
QuestionCD+ g formats Pinmemberwasif_Muhammad22-Apr-07 3:29 
GeneralHelp needed urgently!!! PinmemberMicktaxi15-Mar-07 0:48 
GeneralRe: Help needed urgently!!! PinmemberA. Riazi5-Mar-07 0:57 
GeneralRe: Help needed urgently!!! PinmemberMicktaxi15-Mar-07 1:30 
Questionhi PinmemberMember #383813817-Feb-07 0:59 
GeneralPLEASE HELP!! Pinmemberbudget010@yahoo.com22-Dec-06 23:31 
AnswerRe: PLEASE HELP!! PinmemberIrek_gier30-Dec-06 5:47 
GeneralTotal Genius =) Pinmemberjonty_rocks325-Aug-06 23:24 
GeneralRe: Total Genius =) PinmemberA. Riazi26-Aug-06 23:06 
GeneralRe: Total Genius =) Pinmemberbudget010@yahoo.com22-Dec-06 23:36 
QuestionPure plagerism! Have you no shame A. Riazi? Pinmemberpkaospwvxdkyt3-Mar-06 2:32 
AnswerRe: Pure plagerism! Have you no shame A. Riazi? PinmemberA. Riazi3-Mar-06 21:48 
Generalbin2iso Pinmemberhack3rGriMM25-Feb-06 4:08 
AnswerRe: bin2iso PinmemberA. Riazi25-Feb-06 7:42 
Questionbin2iso download? Pinmemberamirweb127-Aug-05 1:42 
AnswerRe: bin2iso download? PinmemberA. Riazi27-Aug-05 2:49 
AnswerRe: bin2iso download? Pinmemberab raijin10-Dec-05 1:11 
GeneralAwesome! PinmemberBartender21-May-05 8:32 
GeneralRe: Awesome! PinmemberA. Riazi21-May-05 9:27 
GeneralRe: Awesome! Pinmemberskittlemon27-Jun-05 9:31 
QuestionHow about a DVD image? PinsussAnonymous5-Jan-05 6:56 
AnswerRe: How about a DVD image? PinmemberA. Riazi5-Jan-05 7:52 
GeneralC# Implementation PinmemberMatt Brooks24-Nov-04 11:57 
Generaldatabase update Pinmemberotneimras24-Sep-04 11:40 
GeneralRe: database update PinmemberA. Riazi24-Sep-04 21:27 
Questionmode 1-&gt;mode 2 conversion possible? Pinmemberespy6058-Sep-04 14:38 
AnswerRe: mode 1-&gt;mode 2 conversion possible? PinsussAnonymous10-Dec-04 16:08 
Questionhello,how can I get a source code for ecc arithmetic? Pinsusschenlm17-Jun-04 17:16 
AnswerRe: hello,how can I get a source code for ecc arithmetic? Pinmemberjoysteven@yahoo.com12-Oct-05 0:10 
GeneralGood work Pinmembersoul_ripper10-May-04 13:42 
Generalcommand line Pinmemberideriev20-Feb-04 4:23 
GeneralRe: command line PinmemberA. Riazi20-Feb-04 8:33 
GeneralRe: command line Pinmemberideriev20-Feb-04 8:44 
GeneralNice tool but found one tiny bug... Pinmemberh9k31-Aug-03 5:33 
GeneralRe: Better Tool... PinmemberLarry Antram22-Jul-03 14:44 
GeneralRe: Better Tool... PinsussAnonymous2-Sep-04 17:58 
General'Kick it up a notch' by... PinmemberNitron22-Jul-03 8:51 
GeneralRe: 'Kick it up a notch' by... PinmemberA. Riazi22-Jul-03 19:02 
GeneralRe: 'Kick it up a notch' by... PinmemberSibilant20-Jul-04 13:55 
GeneralRe: 'Kick it up a notch' by... PinmemberA. Riazi20-Jul-04 22:09 
GeneralRe: 'Kick it up a notch' by... PinmemberSibilant22-Jul-04 6:52 
GeneralRe: 'Kick it up a notch' by... PinmemberA. Riazi22-Jul-04 22:20 
Generalother way round PinmemberIceMatrix22-Jul-03 6:56 
GeneralRe: other way round PinmemberA. Riazi22-Jul-03 19:08 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.5 | Last Updated 22 Jul 2003
Article Copyright 2003 by A. Riazi
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid