windows快捷方式的格式结构.doc_第1页
windows快捷方式的格式结构.doc_第2页
windows快捷方式的格式结构.doc_第3页
windows快捷方式的格式结构.doc_第4页
windows快捷方式的格式结构.doc_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

查看文章【转】 快捷方式lnk文件格式详解(英文)(中文)2009-11-07 10:55转自:/art6-Shortcut-File-Format-lnk.htmlYou 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. .LNK File Format1. Header2. Shell Item Id List3. File Location Info4. Description5. Relative Path6. Working Directory7. Command Line Arguments8. Icon Filename9. Additonal Info1. HeaderSizeContentsDescription4 bytesAlways 4C 00 00 00This is how windows knows it is a shortcut file16 bytesGUID for shortcut filesThe current GUID for shortcuts. It may change in the future. 01 14 02 00 00 00 00 00 C0 00 00 00 00 00 461 dwordShortcut flagsShortcut flags are explained below1 dwordTarget file flagsFlags are explained below1 qwordCreation time1 qwordLast access time1 qwordModification time1 dwordFile lengthThe length of the target file. 0 if the target is not a file. This value is used to find the target when the link is broken.1 dwordIcon numberIf the file has a custom icon (set by the flags bit 6), then this long integer indicates the index of the icon to use. Otherwise it is zero.1 dwordShow Windowthe ShowWnd value to pass to the target application when starting it. 1:Normal Window 2:Minimized 3:Maximized1 dwordHot KeyThe hot key assigned for this shortcut1 dwordReservedAlways 01 dwordReservedAlways 0Shortcut flagsBitMeaning0Shell item id list is present1Target is a file or directory2Has a description3Has a relative path4Has a working directory5Has command line arguments6Has a custom icon.Target flagsBitMeaning0Target is read only.1Target is hidden.2Target is a system file.3Target is a volume label. (Not possible)4Target is a directory.5Target has been modified since last backup. (archive)6Target is encrypted (NTFS partitions)7Target is Normal8Target is temporary.9Target is a sparse file.10Target has reparse point data.11Target is compressed.12Target is offline.Last Access and Modified time offsets corrected thanks to JimmyW Shell Item Id List Note: This section exists only if the first bit for shortcut flags is set the header section. If that bit is not set then this section does not exists. The first word contains the size of the list in bytes. Each item (except the last) in the list contains its size in a word fallowed by the content. The size includes and the space used to store it. The last item has the size 0. These items are used to store various informations. For more info read the SHITEMID documentation. File Location Info This section is always present, but if bit 1 is not set in the flags value, then the length of this section will be zero. The header of this section is described below. SizeDescription1 dwordThis length value includes all the assorted pathnames and other data structures. All offsets are relative to the start of this section.1 dwordThe offset at which the basic file info structure ends. Should be 1C.1 dwordFile available on local volume (0) or network share(1)1 dwordOffset to the local volume table.1 dwordOffset to the base path on the local volume.1 dwordOffset to the network volume table.1 dwordOffset to the final part of the pathname.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 tableSizeDescription1 dwordLength of this structure including the volume label string.1 dwordType of volume (code below)1 dwordVolume serial number1 dwordOffset of the volume name (Always 0x10)ASCIZVolume labelType of volumesCodeDescription0Unknown1No root directory2Removable (Floppy, Zip .)3Fixed (Hard disk)4Remote (Network drive)5CD-ROM6Ram driveThe network volume tableSizeDescription1 dwordLength of this structure1 dwordAlways 021 dwordOffset of network share name (Always 0x14)1 dwordReserved 01 dwordAlways 0x20000ASCIZNetwork share nameDescription 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在桌面上的快捷方式为例。一、文件的整体结构.LNK 文件格式1. 文件头2. Shell Item Id List 段3. 文件位置信息段4. 描述字符段5. 相对路径段6. 工作目录段7. 命令行段8. 图标文件段9. 附加信息段二、文件头文件头结构,参照下面表格: OffsetSize/TypeDescription0h1 dword值常为0000004CH,为字符L4h16 bytesGUID14h1 dwordFlags,用来标识快捷方式文件中有哪些可选属性,后面有表单独解释每一位的意义。18h1 dword目标文件属性,后面解释。1ch1 qword文件创建时间24h1 qword文件修改时间2ch1 qword文件最后一次访问时间34h1 dword目标文件长度38h1 dword自定义图标个数,3ch1 dword目标文件执行时窗口显示方式:1、 正常显示2、 最小化3、 最大化40h1 dword热键44h2 dword暂时还不清楚用途值常为0 偏移14h开始的标志标示有哪些可选属性,见下表:Bit所在位为1时表示0有shell item id list1指向文件或文件夹,如果此位为0表示指向其他。2存在描述字符串3存在相对路径4存在工作路径5存在命令行参数6存在自定义图标 偏移18h开始的目标文件属性:Bit 所在位为1时表示0快捷方式所指目标文件有只读属性1快捷方式所指目标文件有隐藏属性2快捷方式所指目标文件是系统文件3快捷方式所指目标是卷标4快捷方式所指目标是文件夹5快捷方式所指目标文件上次存档后被改变过6快捷方式所指目标文件被加密7快捷方式所指目标文件属性为一般8快捷方式所指目标文件为临时9快捷方式所指目标文件为稀疏文件(sparse file)10快捷方式所指目标文件有重分析点数据(reparse point)11快捷方式所指目标文件被压缩12快捷方式所指目标文件脱机例: 偏移 数据 解释0000 4c 00 00 00 字符L0004 01 14 02 00 快捷方式的GUID。值固定 00 00 00 00 C0 00 00 00 00 00 00 460014 8F 00 00 00 flags。对照表可知 有shell item id list 目标是文件 存在描述字符串 存在相对路径0018 20 00 00 00 文件属性,具体内容可以查上面的属性说明表001C 40 51 0A 0C 文件创建时间 AD CB C4 010024 C4 D8 A5 91 文件修改时间 AD CB C4 01002C 00 33 16 74 文件最后一次访问时间 F6 C7 C3 010034 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 00三、Shell item ID list段当文件头中1的第0位置位时才有。第一个unsigned short integer表示item ID list段的总长度。后面紧跟着SHITEMID结构。SHITEMID的定义如下: typedef struct _SHITEMID USHORT cb; BYTE abID0; 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 9D0062 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 93007B 25 00007D 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 0000A0 2C 0000A2 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 0000CC 1C 0000CE 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 0000E8 00 00 item ID list段结束四、文件位置信息段开始的一个long integer表示此段的总长度,当文件头中1的第1位没有置位时表示既不是文件也不是文件夹,所以这个信息没有意义,所以总长度为0。先让我们看一下 这个段的头:OffsetSize/TypeDescription0h1 dword此段的总长度4h1 dword头结构长度,固定为1ch8h1 dwordFlags指示文件在哪些卷有效,这里只用到低两位,第一位置位表示本地卷有效,反之无效。第二位置位表示网络 卷有效,反之无效。ch1 dword本地卷信息表的偏移(固定1ch)10h1 dword本地路径信息的偏移14h1 dword网络卷信息表的偏移18h1 dword附加信息的偏移如果文件在本地卷,那么文件名为:本地路径信息+附加信息如果文件在网络卷,那么文件名为:网络卷信息中的共享名+附加信息紧 跟在段头后面的是本地卷信息表(段内偏移为1ch),结构如下:OffsetSize/TypeDescription0h1 dword本地卷信息表的长度4h1 dword卷类型:0 Unknown1 No root directory2 Removable (Floppy, Zip, etc.)3 Fixed (Hard disk)4 Remote (Network drive)5 CD-ROM6 Ram drive (Shortcuts to stuff on a ram drive, now thats smart.)8h1 dword卷序列号ch1 dword固定长度部分的大小,固定为10h10h可变长度卷标签然后是本地路径信息串段内偏移决定于10h的值。再往后就是网络卷信息表段内偏移决定于14h的 值。结构如下:OffsetSize/TypeDescription0h1 dword网络卷信息表的长度4h1 dword固定为2h8h1 dword固定长度部分的大小,固定为14hch1 dword固定为0h10h1 dword固定为20000h14h可变长度网络共享名最后是附加信息串段内偏移决定于18h的值 例: 偏移 数据 解释段头00EA 67 00 00 00 文件位置信息段总长度00EE 1C 00 00 00 段头长度,固定为1ch00F2 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 固定为10h0116 73 79 73 74 卷标system 65 6D 00本地路径信息串 011D 43 3A 5C 50 C:Program FilesWindows Media Playerwmplayer.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 00五、描述字符段 当文件头中1的第2位置位时才有。开始的一个unsigned short int表示描述字符串的长度(描述字符为Unicode字符,所以字

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论