【转】 快捷方式lnk文件格式详解(英文)(中文)html
2009-11-07 10:55shell
转自:http://www.stdlib.com/art6-Shortcut-File-Format-lnk.html You should consider using the IShellLink interface which is a safe way to handle windows shortcuts. If you have a strong reason not to use that interface then I have to remind you that this file format is not documented by Microsoft. I cannot say that the info gathered here is accurate nor that it will work in the future.
1. Headerwindows
Shortcut flags网络
Target flagsapp
Last Access and Modified time offsets corrected thanks to JimmyW Shell Item Id List
Combine the base path string and the final path string to find the filename of the file on the local volume. To find the filename of the file on the network you need to combine the share name in the network volume table with the final path string. The local volume table函数
Type of volumesthis
The network volume table加密
Description This section is present if bit 2 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. It is a description of the item. Relative path string This section is present if bit 3 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. It is a relative path to the target. Working directory This section is present if bit 4 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. It is the working directory as specified in the shortcut properties. Command line arguments This section is present if bit 5 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. The command line string includes everything except the program name. Icon filename This section is present if bit 6 is set in the flags value in the header. The first word value indicates the length of the string. Following the length value is a string of ASCII characters. This the name of the file containing the icon. Additonal Info Usualy consists of a dword with the value 0. 你们知道经过IShellLink接口能够获得快捷方式的各类属性。具体怎么作,网上有不少文章,这里就不介绍了。如今主要是分析一下快捷方式文件的格 式,而且本身写一个解析程序。 为了方便你们理解,解说完每一个段后附上一个快捷方式对应部分的事例数据并附内容解说。这里以Windows Media Player在桌面上的快捷方式为例。 1、文件的总体结构
2、文件头 文件头结构,参照下面表格:
② 偏移18h开始的目标文件属性:
例: 偏移 数据 解释 0000 4c 00 00 00 字符"L" 0004 01 14 02 00 快捷方式的GUID。值固定 00 00 00 00 C0 00 00 00 00 00 00 46 0014 8F 00 00 00 flags。对照表可知 有shell item id list 目标是文件 存在描述字符串 存在相对路径 0018 20 00 00 00 文件属性,具体内容能够查上面的属性说明表 001C 40 51 0A 0C 文件建立时间 AD CB C4 01 0024 C4 D8 A5 91 文件修改时间 AD CB C4 01 002C 00 33 16 74 文件最后一次访问时间 F6 C7 C3 01 0034 00 20 01 00 文件长度 0038 00 00 00 00 自定义图标个数 003C 01 00 00 00 打开时窗口为normal状态 0040 00 00 00 00 热键 0044 00 00 00 00 暂时还不清楚用途值常为0 00 00 00 003、Shell item ID list段 当文件头中○1的第0位置位时才有。第一个unsigned short integer表示item ID list段的总长度。后面紧跟着SHITEMID结构。SHITEMID的定义以下: typedef struct _SHITEMID { USHORT cb; BYTE abID[0]; } SHITEMID, * LPSHITEMID;cb保存SHITEMID结构的大小。abID是可变长度的对象标识。具体都是什么含义没看明白,能够参阅MSDN。由于item ID list段的开始为这个段的总长度,因此在读取的时候能够把此段跳过不作处理!!:) 例:(文件头段的flags标志显示存在shell item id list段) 偏移 数据 解释 004C 9c 00 item ID list总长度(下一段的起始地址为004E+009C=00EA) 004E 14 00 第一个item ID的长度 0050 1F 50 E0 4F 第一个item ID标示内容 D0 20 EA 3A 69 10 A2 D8 08 00 2B 30 30 9D 0062 19 00 第二个item ID的长度 0064 23 43 3A 5C 第二个item ID标示内容 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 F1 93 007B 25 00 007D 31 00 00 00 00 00 70 31 47 3B 31 00 50 72 6F 67 72 61 6D 20 46 69 6C 65 73 00 50 52 4F 47 52 41 7E 31 00 00A0 2C 00 00A2 31 00 00 00 00 00 70 31 47 3B 10 00 57 69 6E 64 6F 77 73 20 4D 65 64 69 61 20 50 6C 61 79 65 72 00 57 49 4E 44 4F 57 7E 32 00 00CC 1C 00 00CE 32 00 00 20 01 00 95 2F A1 99 20 00 77 6D 70 6C 61 79 65 72 2E 65 78 65 00 00 00E8 00 00 item ID list段结束4、文件位置信息段 开始的一个long integer表示此段的总长度,当文件头中○1的第1位没有置位时表示既不是文件也不是文件夹,因此这个信息没有意义,因此总长度为0。先让咱们看一下 这个段的头:
若是文件在本地卷,那么文件名为:本地路径信息+附加信息
而后是本地路径信息串段内偏移决定于10h的值。
最后是附加信息串段内偏移决定于18h的值 例: 偏移 数据 解释 段头 00EA 67 00 00 00 文件位置信息段总长度 00EE 1C 00 00 00 段头长度,固定为1ch 00F2 01 00 00 00 本地卷 00F6 1C 00 00 00 本地卷信息表的段内偏移 00FA 33 00 00 00 本地路径信息的偏移 00FE 00 00 00 00 网络卷信息表的偏移 0102 66 00 00 00 附加信息的偏移本地卷信息表 0106 17 00 00 00 表长度 010A 03 00 00 00 Fixed (Hard disk) 010E AD C9 B2 F0 卷序列号 0112 10 00 00 00 固定为10h 0116 73 79 73 74 卷标"system" 65 6D 00本地路径信息串 011D 43 3A 5C 50 C:/Program Files/Windows Media Player/wmplayer.exe 72 6F 67 72 61 6D 20 46 69 6C 65 73 5C 57 69 6E 64 6F 77 73 20 4D 65 64 69 61 20 50 6C 61 79 65 72 5C 77 6D 70 6C 61 79 65 72 2E 65 78 65 00网络卷信息表 由于段头里flags指示仅为本地卷,而且网络卷信息表的偏移值为零。因此不存在网络卷信息表。 | 附加信 息串 0150 005、描述字符段 当文件头中○1的第2位置位时才有。开始的一个unsigned short int表示描述字符串的长度(描述字符为Unicode字符,因此字节数需乘以2,可使用API函数WideCharToMultiByte将其转换成 ANSI字符)。后面为内容。例: 偏移 数据 解释 0151 20 00 描述字符长度 0153 AD 64 3E 65 70 65 57 5B 92 5A 53 4F 0C FF 05 53 EC 62 F3 97 50 4E 01 30 C6 89 91 98 01 30 43 00 44 00 20 00 8C 54 20 00 49 00 6E 00 74 00 65 00 72 00 6E 00 65 00 74 00 20 00 35 75 F0 53 02 30转换成ANSI字符为"播放数字媒体,包括音乐、视频、CD 和 Internet 电台。 6、相对路径段 当文件头中○1的第3位置位时才有。同描述字符段同样开始的一个unsigned short int表示相对路径字符串的长度。后面为内容。 例: 偏移 数据 解释 0193 38 00 相对路径字符长度 0195 2E 00 2E 00 5C 00 2E 00 2E 00 5C 00 2E 00 2E 00 5C 00 50 00 72 00 6F 00 67 00 72 00 61 00 6D 00 20 00 46 00 69 00 6C 00 65 00 73 00 5C 00 57 00 69 00 6E 00 64 00 6F 00 77 00 73 00 20 00 4D 00 65 00 64 00 69 00 61 00 20 00 50 00 6C 00 61 00 79 00 65 00 72 00 5C 00 77 00 6D 00 70 00 6C 00 61 00 79 00 65 00 72 00 2E 00 65 00 78 00 65 00转换成ANSI字符为"../../../Program Files/Windows Media Player/wmplayer.exe" 7、工做目录段 同上。 例:由于文件头中○1flags的第四位没有置位,因此此段不存在 8、 命令行段 同上。 例:由于文件头中○1flags的第五位没有置位,因此此段不存在 9、图标文件段 同上。 例: 由于文件头中○1flags的第六位没有置位,因此此段不存在 10、 附加信息段 具体信息不清楚!!!!! 以上不少资料来自网上,并非微软文档,因此不免有理解错误的地方,请包含。所附代码只是为了 跟踪显示,没有输出,嘿嘿,本身改改看吧!!:)有兴趣能够本身写一个类,分析快捷方式的全部信息。 |