UID 1
精华
积分 76361
威望 点
宅币 个
贡献 次
宅之契约 份
最后登录 1970-1-1
在线时间 小时
大家一定都知道ICO、CUR文件吧?没错,Windows的图标、光标就是这种格式的。这种格式非常简单。我来讲讲这种类型的文件的结构。
ICO和CUR文件结构几乎是一样的。一个文件里面有不止一个子图标。
大致的结构是这样的。
1、图标文件头(只有一个)
2、图标信息头(连续存储,数量等于子图标的数量)
3、子图标数据(连续存储,数量等于子图标的数量,内容就是字图标的数据)
图标文件头:6字节。我这里用C语言的表示方法来解释。
WORD 保留字; //保留字必须为0
WORD 类型; //类型:1=ICO文件,2=CUR文件
WORD 子图标数量;
图标信息头:每个16字节。
BYTE 宽度;
BYTE 高度;
BYTE 颜色数的低8位;
BYTE 保留字节;
WORD 光标的焦点X; //CUR文件的属性。ICO不使用这两个字节,值为0.
WORD 光标的焦点Y;
DWORD 子图标占用字节数;
DWORD 子图标位置偏移;
子图标数据:(有点像BMP文件,但是有区别。)
BITMAPINFO 图标位图信息;
图标位图信息的“biHeight”(高度)的值总是biWidth*2。
后面是位图数据。这里要详细说一下。
1、如果颜色深度是32位,那么位图数据就是蓝、绿、红、不透明度四个字节一个像素。
2、如果颜色深度是8位以下,则图标位图信息包含调色板。
3、如果颜色深度不是32位,那么位图数据要分成两部分:
第一部分:位图的颜色数据。格式遵循图标位图信息。
第二部分:透明通道。这是一个单色位图数据,用来指定位图的透明色。
位图的颜色数据和透明通道都是每行4字节对齐的。
下面给出一个图标文件的WinHex显示。大家可以结合上面的内容看,自己就能弄清楚图标文件的格式了。
下面打下划线的部分是位图文件头,可以看到这个图标有两个子图标。
蓝色部分是子图标1的 图标信息头,紫色部分是子图标2的 图标信息头。
Offset 0 1 2 3 4 5 6 7 8 9 A B C D E F
00000000 00 00 01 00 02 00 20 20 10 00 00 00 00 00 E8 02 ...... ......?
00000010 00 00 26 00 00 00 10 10 10 00 00 00 00 00 28 01 ..&...........(.
00000020 00 00 0E 03 00 00 28 00 00 00 20 00 00 00 40 00 ......(... ...@.
00000030 00 00 01 00 04 00 00 00 00 00 80 02 00 00 00 00 ..........?.....
00000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000050 00 00 00 00 80 00 00 80 00 00 00 80 80 00 80 00 ....?..?...??.?.
00000060 00 00 80 00 80 00 80 80 00 00 80 80 80 00 C0 C0 ..?.?.??..???.览
00000070 C0 00 00 00 FF 00 00 FF 00 00 00 FF FF 00 FF 00 ?..?..?...??.?.
00000080 00 00 FF 00 FF 00 FF FF 00 00 FF FF FF 00 77 70 ..?.?.??..???.wp
00000090 FF FF FF FF FF FF F0 07 0F FF FF FF FF FF F7 77 ???????.?????鱳
000000A0 0F FF FF FF FF FF F0 78 70 FF FF FF FF FF FF 77 .?????饃p??????w
000000B0 70 FF FF FF FF FF 07 88 77 0F FF FF FF FF FF F7 p?????.坵.??????
000000C0 70 0F FF FF FF F0 78 87 77 70 FF FF FF FF FF FF p.???饃噖p??????
000000D0 00 70 FF FF FF 07 88 7F F7 77 0F FF FF FF FF FF .p???.?鱳.?????
000000E0 07 87 0F FF F0 78 87 FF FF 77 70 FF FF FF FF F0 .??饃??wp?????
000000F0 78 87 70 FF 07 88 7F FF FF F7 77 0F FF FF FF 07 x噋?.???鱳.???.
00000100 88 77 77 00 08 87 FF FF FF FF 77 70 FF FF F0 78 坵w..????wp??饃
00000110 87 FF 77 70 08 7F FF 00 FF FF F7 70 0F FF 07 88 ?wp..?.??鱬.?.?
00000120 7F FF F7 77 07 FF FF 0F 0F FF FF 00 70 FF 78 87 .?鱳.??..??.p?x?
00000130 FF FF FF 77 70 FF 0F 0F FF FF FF 07 87 0F 88 7F ???wp?..???.??
00000140 F0 FF FF F7 77 0F F0 0F FF FF F0 78 87 70 87 FF ??鱳.???饃噋?
00000150 0F FF FF FF 77 00 FF FF FF FF 07 88 77 77 7F F0 .???w.????.坵w.?
00000160 F0 F0 FF FF F0 07 0F FF FF F0 78 87 FF 77 0F F0 痧???.??饃?w.?
00000170 FF 0F FF FF F0 78 70 FF FF 07 88 7F FF F7 70 FF ?.??饃p??.??鱬?
00000180 00 FF FF FF 07 88 77 0F F0 78 87 FF FF FF 70 0F .???.坵.饃???p.
00000190 FF FF FF F0 78 87 77 70 00 88 7F F0 FF FF 00 70 ???饃噖p.???.p
000001A0 FF FF FF 07 88 7F F7 77 00 87 FF F0 FF FF 07 87 ???.?鱳.???.?
000001B0 0F FF F0 78 87 FF FF 77 70 7F F0 00 00 FF 78 87 .?饃??wp.?.?x?
000001C0 70 FF 07 88 7F FF FF F7 77 0F FF F0 FF FF 88 77 p?.???鱳.???坵
000001D0 77 00 08 87 FF F0 FF FF 77 70 FF F0 FF FF 87 FF w..???wp????
000001E0 77 70 08 7F F0 FF 0F FF F7 70 0F FF FF FF 7F FF wp..?.?鱬.???.?
000001F0 F7 77 07 FF 0F 0F 0F FF FF 00 70 FF FF FF FF FF 鱳.?...??.p?????
00000200 FF 77 70 FF 0F F0 FF FF FF 07 87 0F FF F0 FF FF ?wp?.???.????
00000210 FF F7 77 0F F0 FF FF FF F0 78 87 70 FF 07 F0 0F ?鱳.???饃噋?.?
00000220 FF FF 77 00 FF FF FF FF 07 88 77 77 00 08 0F 0F ??w.????.坵w....
00000230 FF FF F0 07 0F FF FF F0 78 87 FF 77 70 08 FF 00 ???.??饃?wp.?.
00000240 0F FF F0 78 70 FF FF 07 88 7F FF F7 77 00 FF FF .?饃p??.??鱳.??
00000250 0F FF 07 88 77 0F F0 78 87 FF 0F FF 77 70 FF F0 .?.坵.饃?.?wp??
00000260 FF F0 78 87 77 70 00 88 7F F0 F0 FF F7 77 FF F0 ?饃噖p.?痧?鱳??
00000270 FF 07 88 7F F7 77 00 87 FF 0F F0 FF FF 77 FF FF ?.?鱳.?.??w??
00000280 F0 78 87 FF FF 77 70 7F F0 FF F0 FF FF F7 00 00 饃??wp.????.
00000290 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000002A0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000002B0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000002C0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000002D0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000002E0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
000002F0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000300 00 00 00 00 00 00 00 00 00 00 00 00 00 00 28 00 ..............(.
00000310 00 00 10 00 00 00 20 00 00 00 01 00 04 00 00 00 ...... .........
00000320 00 00 C0 00 00 00 00 00 00 00 00 00 00 00 00 00 ..?............
00000330 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 80 ............?..?
00000340 00 00 00 80 80 00 80 00 00 00 80 00 80 00 80 80 ...??.?...?.?.??
00000350 00 00 80 80 80 00 C0 C0 C0 00 00 00 FF 00 00 FF ..???.览?..?..?
00000360 00 00 00 FF FF 00 FF 00 00 00 FF 00 FF 00 FF FF ...??.?...?.?.??
00000370 00 00 FF FF FF 00 70 FF FF FF F0 0F FF FF F7 0F ..???.p???????
00000380 FF FF 08 70 FF FF FF 00 FF F0 87 F7 0F FF FF 78 ??.p???.?饑???x
00000390 0F 08 7F FF 70 FF F7 8F 70 07 F0 FF F7 0F 78 FF ...?p??p.??x?
000003A0 F7 0F 00 FF F0 80 8F 0F FF 70 FF FF 08 77 0F F0 ?.?饊..?p??.w.?
000003B0 FF F7 0F F0 87 FF 70 FF FF 78 70 08 7F FF 08 0F ??饑?p??xp..?..
000003C0 F7 8F F7 07 F0 0F 87 70 78 FF FF 70 FF FF 7F F7 ???噋x??p??.?
000003D0 0F 00 0F F0 0F FF FF FF 70 FF FF F7 80 F0 00 FF ...????p??鱻??
000003E0 F0 0F FF 78 F7 00 FF 0F 08 70 F7 8F 0F 70 FF F0 ??x??..p?.p??
000003F0 87 F7 08 F0 FF F7 00 00 00 00 00 00 00 00 00 00 圇.??.........
00000400 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000410 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000420 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
00000430 00 00 00 00 00 00 ......