![]() |
Web Development »
Applications & Tools »
Tools with source code
Intermediate
Bin2IsoBy A. RiaziA Free Tool to Convert Bin Image Format to ISO Image Format |
VC6Win2K, WinXP, Win2003, MFC, Dev
|
|
Advanced Search |
|
|
|
||||||||||||||||

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.
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.
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 are intended for the storage of computer data and contain the following fields.
Mode 1 sectors are the simplest type and are used for most CD-ROM based formats which follow the Yellow Book.
Mode 2 sectors are used for those formats based on CD-ROM XA and can be either Form 1 or 2.
Mode 2 sectors comprise the following fields:
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.
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.
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.
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.
For further information refer to the Distronics web site. They have very useful information about various CD/DVD technologies on their web site.
Enjoy!
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 21 Jul 2003 Editor: Barry Lapthorn |
Copyright 2003 by A. Riazi Everything else Copyright © CodeProject, 1999-2009 Web15 | Advertise on the Code Project |