|
盒子资源分类 |
|
|
|
|
导出ISO中的引导文件 |
|
关键字:iso,bootable |
来 自:原创 |
平 台:Win2k/XP/NT,Win2003 |
下载所需:0 火柴 |
深浅度:中级 |
完成时间:2008/8/18 |
发布者:laihongbo |
发布时间:2008/8/18 |
编辑器:DELPHI7 |
语 种:简体中文 |
分 类:文件 |
下载浏览:1/7625 |
|
|
|
|
在使用Magic CD/DVD Burner控件写个生成可引导启动的ISO时,碰到引导功能不正常,为了解决该控件的BUG,首先要解决引导文件在ISO的位置与读取方式,特此写了以下代码,方解决Magic CD/DVD Burner的问题。
Program ExportBI; {$APPTYPE CONSOLE} Uses Windows, SysUtils;
type TDirectoryDescriptor2 = Packed Record LenDr: Byte; // 01-01 Extended: Byte; // 02-02 Address, // 03-06 AddressBE: LONGWORD; // 07-10 DataLength: LONGWORD; // 11-14 DataLengthBE: LONGWORD; // 15-18 Year, Month, Day: Byte; // 19-21 Hour, Min, Sec: Byte; // 22-24 TimeDiffernce: Byte; // 25-25 FileFlag: Byte; // 26-26 FileUnitSize: Byte; // 27-27 InterleaveGap: Byte; // 28-28 VolSeqnumber: WORD; // 29-32 VolSeqnumberBE: WORD; // 29-32 LenOfFileIdentifier: Byte; // 33-33 Dummy: Byte; // 34-34 End;
TVolumeDescriptor = Packed Record pdType: Byte; // 1 - 1 Identifier: Array[1..5] Of char; // 2 - 6 Version: Byte; // 7 - 7 VolumeFlag: Byte; // 8 - 8 IdSystem: Array[0..31] Of char; // 9 - 40 IdVolume: Array[0..31] Of char; // 41 - 72 IdBC: Array[0..7] Of char; // 73 - 80 NoOfSectors: LONGWORD; // 81 - 84 NoOfSectorsBE: LONGWORD; // 85 - 88 EscapeChars: Array[0..31] Of char; // 89 - 120 VolSetSize: WORD; // 121 - 124 VolSetSizeBE: WORD; // 121 - 124 VolSeqnumber: WORD; // 125 - 128 VolSeqnumberBE: WORD; // 125 - 128 SectorSize: WORD; // 129 - 132 SectorSizeBE: WORD; // 129 - 132 PathTableSize: LONGWORD; // 133 - 136 PathTableSizeBE: LONGWORD; // 137 - 140 Type1PathTable: LONGWORD; // 141 - 144 Type1PathTableBE: LONGWORD; // 145 - 148 TypeMPathTable: LONGWORD; // 149 - 152 TypeMPathTableBE: LONGWORD; // 153 - 156 RootDirRec: TDirectoryDescriptor2; // 157 - 190 IdVolumeSet: Array[0..127] Of char; // 191 - 318 IdPublisher: Array[0..127] Of char; // 319 - 446 IdPreparer: Array[0..127] Of char; // 447 - 574 IdApplication: Array[0..127] Of char; // 575 - 702 FileCopyright: Array[0..36] Of char; // 703 - 739 FileAbstract: Array[0..36] Of char; // 740 - 776 FileBibliographic: Array[0..36] Of char; // 777 - 813 DateCreation: Array[0..16] Of char; // 814 - 830 DateModification: Array[0..16] Of char; // 831 - 847 DateExpiration: Array[0..16] Of char; // 848 - 864 DateEffective: Array[0..16] Of char; // 865 - 881 FileStructureVer: Byte; // 882 - 882 UnUsed1: Byte; // 883 - 883 ApplicationData: Array[884..1024] Of char; // 884 ApplicationData2: Array[1025..1032] Of char; // 884 - 1395 ApplicationData3: Array[1033..1395] Of char; // 884 - 1395 Unused2: Array[1396..2048] Of Byte; // 1396 - 2048 End;
TBootVolumeDescriptor = Packed Record pdType: Byte; // 0 Identifier: Array[1..5] Of char; // 1 - 5 Version: Byte; // 6 Ident: Array[7..$26] Of char; // 7 - $26 UnUsed1: Array[$27..$46] Of Byte; // $27 - $46 BootCatLocation: Cardinal; Unused2: Array[$4B..$7FF] Of Byte; End; TBootCatalog = Packed Record Header: Byte; PlatformID: Byte; Reserved1: WORD; Developer: Array[$4..$1B] Of char; Checksum: WORD; KeyByte1, KeyByte2: Byte; BootIndicator: Byte; BootMediaType: Byte; LoadSegment: WORD; SystemType: Byte; UnUsed1: Byte; SectorCount: WORD; LoadRBA: DWORD; Unused2: Array[$0C..$1F] Of Byte; Unused3: Array[$30..$7EF] Of Byte; End;
Const DefaultSectorSize = 2048;
Const SystemType: Array[0..2] Of String = ('80x86', 'Power PC', 'MAC'); BootMediaType: Array[0..4] Of String = ('不模拟', '模拟1.2M的软盘', '模拟1.44M的软盘', '模拟2.88M的软盘', '模拟硬盘'); soFromBeginning = 0;
Var ISO_Handle, BOOT_Handle: THandle; PVD: TVolumeDescriptor; BVD: TBootVolumeDescriptor; BC: TBootCatalog; BootFile: String; BootImage: Pointer; BootImageSize: Integer; Begin If FileExists(ParamStr(1)) And (CompareText(ExtractFileExt(ParamStr(1)), '.ISO') = 0) Then Begin ISO_Handle := FileOpen(ParamStr(1), fmOpenReadWrite Or fmShareExclusive); FileSeek(ISO_Handle, DefaultSectorSize * 16, soFromBeginning); FillChar(PVD, SizeOf(PVD), 0); FileRead(ISO_Handle, PVD, SizeOf(PVD)); Writeln('文件卷标:' + PVD.IdVolume); FillChar(BVD, SizeOf(BVD), 0); FileRead(ISO_Handle, BVD, SizeOf(BVD));
Writeln(Format('BootCatalog 区段位置:%d', [BVD.BootCatLocation])); FileSeek(ISO_Handle, DefaultSectorSize * BVD.BootCatLocation, soFromBeginning); Writeln(Format('BootCatalog 起始地址:%d', [DefaultSectorSize * BVD.BootCatLocation])); FillChar(BC, SizeOf(BC), 0); FileRead(ISO_Handle, BC, SizeOf(BC)); Writeln('光盘制造商:' + BC.Developer); Writeln(Format('系统类型:%s', [SystemType[BC.SystemType]])); Writeln(Format('Checksum 校验值:%d', [BC.Checksum])); If BC.BootIndicator <> $88 Then Writeln('此ISO光盘不可引导。') Else Begin Writeln(Format('载入段标记:$%s', [IntToHex(BC.LoadSegment, 4)])); Writeln(Format('引导标记:$%s', [IntToHex(BC.BootIndicator, 2)])); Writeln(Format('模拟引导类型:%s', [BootMediaType[BC.BootMediaType]])); Writeln(Format('SectorCount 数:%d', [BC.SectorCount])); Writeln(Format('BootImage 区段位置:%d', [BC.LoadRBA])); FileSeek(ISO_Handle, DefaultSectorSize * BC.LoadRBA, soFromBeginning); Writeln(Format('BootImage 起始地址:%d', [DefaultSectorSize * BC.LoadRBA]));
Case BC.BootMediaType Of 0: BootImageSize := DefaultSectorSize; 1: BootImageSize := 600 * DefaultSectorSize; 2: BootImageSize := 720 * DefaultSectorSize; 3: BootImageSize := 1440 * DefaultSectorSize; Else BootImageSize := DefaultSectorSize; End; Writeln(Format('引导映像文件大小:%d', [BootImageSize])); If ParamStr(2) = '' Then BootFile := '.\BOOT.BIN' Else BootFile := ParamStr(2) + '\BOOT.BIN'; BOOT_Handle := FileCreate(BootFile); GetMem(BootImage, BootImageSize); FileRead(ISO_Handle, BootImage^, BootImageSize); FileWrite(BOOT_Handle, BootImage^, BootImageSize); FreeMem(BootImage); FileClose(BOOT_Handle); Writeln(Format('引导映像文件保存到 %s', [BootFile])); End; FileClose(ISO_Handle); End Else Begin Writeln('Export ISO BootImage v1.0'); Writeln('作者:风铃夜思雨 网站:Http://Www.SkyGz.Com'); Writeln(''); Writeln('用法:ExportBI [drive:][path][isofilename] [drive:][path]'); Writeln(''); Writeln(' [drive:][path][isofilename]'); Writeln(' 指定输入的驱动器、目录和/或ISO文件。'); Writeln(' [drive:][path]'); Writeln(' 指定引导文件输出的驱动器、目录。'); Writeln(''); Writeln('示例:ExportBI C:\Test.iso C:\'); End; End. |
|
本站原创作品,未经作者许可,严禁任何方式转载;转载作品,如果侵犯了您的权益,请联系我们! |
相关文章 |
|
|
|
相关评论 |
|
|
|
|