[译]Bin2Iso
By robot-v1.0
本文链接 https://www.kyfws.com/applications/bin2iso-zh/
版权声明 本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
- 6 分钟阅读 - 2959 个词 阅读量 0[译]Bin2Iso
原文地址:https://www.codeproject.com/Articles/4596/Bin2Iso
原文作者:A. Riazi
译文由本站 robot-v1.0 翻译
前言
A Free Tool to Convert Bin Image Format to ISO Image Format
一个免费的工具,可以将Bin镜像格式转换为ISO镜像格式
介绍(Introduction)
这是一个免费工具,可以将一种CD映像格式(Bin)转换为另一种格式(ISO).转换例程非常简单.只需读取Bin图像,然后根据其结构,以另一种格式写入数据.因此,开发人员必须知道两种格式的结构.(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)
CD-ROM规范((The CD-ROM specification () [黄皮书(Yellow Book)](http://www.disctronics.co.uk/technology/cdbasics/cd_books.htm#Yellow Book) )定义了两种类型的() defines the use of two types of) [部门(sectors)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_spec.htm#CD-ROM Sectors) ,模式1和模式2.模式2扇区用于(, mode 1 and mode 2. Mode 2 sectors are used for) 光盘XA(CD-ROM XA) 格式.(formats.)
CD-ROM扇区(CD-ROM Sectors)
CD-ROM光盘上存储的数据被划分为与CD音频光盘的音频帧等效的扇区.以正常(1x)播放速度,每秒读取75个扇区.对于双速CD-ROM驱动器,该速度增加到每秒150个扇区,依此类推.当光盘旋转到所需的起始位置时,寻道时间也会随着速度的增加而减少.(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.)
由于CD主要是为音频而设计的,因此将其用于计算机数据需要添加标头数据和每个扇区都包含的纠错码. CD-ROM规范中定义了两种不同类型的扇区,(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,) [模式1(Mode 1)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_spec.htm#Mode 1 Sectors) 和(and) [模式2(Mode 2)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_spec.htm#Mode 2 Sectors) (后者用于((the latter being used for) [光盘XA(CD-ROM XA)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_formats.htm#CD-ROM XA) 光盘).(discs).)
模式1扇区(Mode 1 Sectors)
模式1扇区用于存储计算机数据,并且包含以下字段.(Mode 1 sectors are intended for the storage of computer data and contain the following fields.)
- 同步(Sync)(12个字节),用于使播放器识别每个扇区的开始.((12 bytes) which is used to enable the player to identify the start of each sector.)
- 标头(Header)(4个字节),由分钟,秒,扇区和模式(=1)组成.((4 bytes) consisting of Minutes, Seconds, Sectors and Mode (= 1).)
- 纠错码(ECC)(纠错码-276字节),其中包括CIRC错误保护的附加级别.((Error Correction Code - 276 bytes), which comprises an additional level of CIRC error protection.)
- 电子数据中心(EDC)(错误检测代码-4个字节),用于检测要纠正的错误.((Error Detection Code - 4 bytes) for detecting errors to be corrected.) 模式1扇区是最简单的类型,用于大多数基于CD-ROM的格式,它们遵循(Mode 1 sectors are the simplest type and are used for most CD-ROM based formats which follow the) [黄皮书(Yellow Book)](http://www.disctronics.co.uk/technology/cdbasics/cd_books.htm#Yellow Book) .(.)
模式2扇区(Mode 2 Sectors)
模式2扇区用于基于以下格式的那些格式(Mode 2 sectors are used for those formats based on) [光盘XA(CD-ROM XA)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_formats.htm#CD-ROM XA) 可以是1或2表格.(and can be either Form 1 or 2.)
-
**模式2表格1(Mode 2 Form 1)**扇区包含2048字节,具有与模式1扇区相同的ECC.(sectors contain 2048 bytes with the same ECC as Mode 1 sectors.)
-
**模式2表格2(Mode 2 Form 2)**扇区每个扇区包含2324字节的用户数据,没有ECC仅适用于可以掩盖错误的数据(例如,音频或视频数据).(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).) 模式2扇区包括以下字段:(Mode 2 sectors comprise the following fields:)
-
同步(Sync)(12个字节),用于使播放器识别每个扇区的开始.((12 bytes) which is used to enable the player to identify the start of each sector.)
-
标头(Header)(4个字节),由分钟,秒,扇区和模式(=1)组成.((4 bytes) consisting of Minutes, Seconds, Sectors and Mode (= 1).)
-
副标题(Subheader)(8个字节)包含与内容相关的参数,例如数据类型.((8 bytes) contains content related parameters eg data type.)
-
纠错码(ECC)(错误纠正代码-276字节),其中包括仅针对Form 1的CIRC错误保护的附加级别.((Error Correction Code - 276 bytes) which comprises an additional level of CIRC error protection for Form 1 only.)
-
电子数据中心(EDC)(错误检测代码)用于表格1和2.((Error Detection Code) for Forms 1 and 2.) 请注意,模式1和模式2格式1使用相同的错误校正,因此可以互换使用,但不能在同一磁道内使用,最好不在同一张光盘上使用.可以将用于写入CD-R的软件设置为模式1或模式2形式1.几乎所有PC和Mac都将读取模式2形式1 CD-ROM以及模式1.(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.)
请注意,任何CD-ROM都将至少包含某些模式1或模式2 Form 1扇区.(Note that any CD-ROM will contain at least some Mode 1 or Mode 2 Form 1 sectors.)
容量(Capacity)
CD-ROM的容量取决于它是否是CD-ROM.(The capacity of a CD-ROM depends on whether it is a) [模式1 CD-ROM(Mode 1 CD-ROM)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_spec.htm#Mode 1 Sectors) 要么(or) [模式2 CD-ROM XA(Mode 2 CD-ROM XA)](http://www.disctronics.co.uk/technology/cd-rom/cdrom_spec.htm#Mode 2 Sectors) .假定最大大小为76分30秒(建议),这意味着CD-ROM上有336,300个扇区.必须从磁道1的开头减去166个扇区,再减去文件系统的几个扇区,例如,等于200个扇区,剩下336,100个扇区用于用户数据.(. 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.)
- **模式1(Mode 1)**每个扇区包含2048个字节,因此总容量为688,332,800字节或656MB(其中1 MB =1024 * 1024).(sectors contain 2048 bytes per sector giving a total capacity of 688,332,800 bytes or 656MB (where 1 MB = 1024 * 1024).)
- **模式2(Mode 2)**扇区每个扇区包含2048或2324字节,因此根据两种类型扇区的混合使用,其数据容量会稍高一些.(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.) 上面假设CD-ROM在单个会话中包含单个磁道.对于多个轨道/会话光盘,数据容量将减少.(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) 网站.他们在其网站上有关于各种CD/DVD技术的非常有用的信息.(web site. They have very useful information about various CD/DVD technologies on their web site.)
请享用!(Enjoy!)
许可
本文以及所有相关的源代码和文件均已获得The Code Project Open License (CPOL)的许可。
C++ VC6 WinXP Win2003 Windows Win2K MFC Visual-Studio Dev 新闻 翻译