Shortcut File Format (.lnk)快捷方式的文件格式

http://www.stdlib.com/art6-2-Shortcut-File-Format-lnk.html

 

Shortcut File Format (.lnk)
By: Daniel


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.

你最好用IShellLink 這個比較安全的接口來處理windows快捷方式。如果你有足夠的理由不使用那個接口,那麼我要提醒你,LNK文件格式並沒有在微軟的文檔裏公佈出來。我不敢說這些格式在以後是否還有效。

 .LNK File Format (.LNK文件格式)
 1. Header (文件頭)
 2. Shell Item Id List (外殼對象ID列表)
 3. File Location Info (文件位置信息)
 4. Description (描述)
 5. Relative Path (相對路徑)
 6. Working Directory (工作目錄)
 7. Command Line Arguments (命令行參數)
 8. Icon Filename (圖標文件名)
 9. Additonal Info (額外信息)

 

1. Header(文件頭)
Size Contents Description
4 bytes Always 4C 00 00 00 This is how windows knows it is a shortcut file
16 bytes GUID for shortcut files The current GUID for shortcuts. It may change in the future. 01 14 02 00 00 00 00 00 C0 00 00 00 00 00 46
1 dword Shortcut flags Shortcut flags are explained below
1 dword Target file flags Flags are explained below
1 qword Creation time  
1 qword Last access time  
1 qword Modification time  
1 dword File length The 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 dword Icon number If 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 dword Show Window the ShowWnd value to pass to the target application when starting it. 1:Normal Window 2:Minimized 3:Maximized
1 dword Hot Key The hot key assigned for this shortcut
1 dword Reserved Always 0
1 dword Reserved Always 0

譯文:

大小 內容 描述
4 字節(8位) 總是4C 00 00 00 讓windows知道這個是快捷方式
16 字節(8位) 快捷方式的GUID 目前快捷方式的GUID,以後說不定會變; 01 14 02 00 00 00 00 00 C0 00 00 00 00 00 46
1 int32 快捷鍵標誌 後文解釋
1 int32 目標文件標誌 後文解釋
1 int64 創建時間  
1 int64 最後訪問時間  
1 int64 修改時間  
1 int32 目標文件長度 目標文件長度. 如果目標不是文件,則是0. 當鏈接斷掉時,會用這個值來查找目標。
1 int32 圖標索引 如果快捷方式有自定義圖標(目標文件標誌的第6位設置爲1),這個長整形數值指出要使用圖標的索引。否則是0.
1 int32 顯示窗口 啓動的目標程序將用這個值來決定顯示窗口的方式。1:普通窗口2:最小化3:最大化
1 int32 熱鍵 快捷方式關聯的熱鍵
1 int32 保留 總是0
1 int32 保留 總是0

 

Shortcut flags(快捷方式標誌)
Bit(位) Meaning(含義)
0

Shell item id list is present

包含外殼對象ID列表。

1

Target is a file or directory

目標是文件或文件夾

2

Has a description

有描述

3

Has a relative path

有相對路徑

4

Has a working directory

有工作目錄

5

Has command line arguments

有命令行參數

6

Has a custom icon.

有自定義圖標

 

Target flags(目標文件標誌)
Bit(位) Meaning(含義)
0

Target is read only.

目標只讀

1

Target is hidden.

隱藏目標

2

Target is a system file.

目標是系統文件

3

Target is a volume label. (Not possible)

目標是一個卷標(不可能)

4

Target is a directory.

目標是目錄

5

Target has been modified since last backup. (archive)

目標自上次備份以來修改過了(存檔)

6

Target is encrypted (NTFS partitions)

目標加密了(NTFS分區)

7

Target is Normal

目標是普通對象

8

Target is temporary.

目標是臨時的

9

Target is a sparse file.

目標是碎片文件

10

Target has reparse point data.

目標包含碎片數據

11

Target is compressed.

目標壓縮過的

12

Target is offline.

目標脫機

 

 

Shell Item Id List (外殼對象ID列表)

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.

注意:只有快捷方式標誌的第一位等於1,那麼這段纔會存在。如果不是1,那麼此段將不存在。

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.

第一個word表示列表的字節大小。列表中的每一個項(除了最後一個)都包含了自己的大小(內容緊跟在它的後面),用一個word 的位置來記錄。這個大小包括用來存儲這個大小佔用的字節數。最後一個項的這個大小爲0.這些項是用來存儲可變信息的。更多信息參見SHITEMID文檔。


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.

此段總是存在,但是,如果目標文件標誌的第2位等於0,此段的長度回事0.此段的頭信息解釋如下:

Size(大小) Description(描述)
1 dword

This length value includes all the assorted pathnames and other data structures. All offsets are relative to the start of this section.

這個長度值包含所有路徑名、其他數據結構。所有偏移量都是參照此段的開始的。 

1 dword

The offset at which the basic file info structure ends. Should be 1C.

基礎文件信息結構結束的偏移量。必須是1C

1 dword

File available on local volume (0) or network share(1)

文件在本地卷:0;在網絡共享:1;

1 dword

Offset to the local volume table.

本地卷表的偏移量。

1 dword

Offset to the base path on the local volume.

從本地卷基礎路徑的偏移量

1 dword

Offset to the network volume table.

網絡卷表的偏移量

1 dword

Offset 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 table(本地卷表)

Size(打下) Description(描述)
1 dword

Length of this structure including the volume label string.

結構體的大小,包括卷標字符串。

1 dword

Type of volume (code below)

卷類型(代碼見下)

1 dword

Volume serial number

卷序列號

1 dword

Offset of the volume name (Always 0x10)

卷名稱的偏移量(總是0x10)

ASCIZ

Volume label

卷標

Type of volumes(卷類型)

Code(代碼) Description(描述)
0

Unknown

未知

1

No root directory

非根目錄

2

Removable (Floppy, Zip ...)

可移動(軟盤/ZIP盤)

3

Fixed (Hard disk)

固定的(硬盤)

4

Remote (Network drive)

遠程(網絡驅動器)

5 CD-ROM
6

Ram drive

內存驅動器

The network volume table(網絡卷表)

Size大(大小) Description(描述)
1 dword

Length of this structure

結構體長度

1 dword

Always 02

總是0x02

1 dword

Offset of network share name (Always 0x14)

網絡共享名的偏移量(總是0x14)

1 dword

Reserved 0

保留0

1 dword

Always 0x20000

總是0x20000

ASCIZ

Network share name

網絡共享名

 

 

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.

如果快捷方式標誌的第3位等於1,此段將會出現。第一個word的值表示字符串的長度。緊跟着長度是字符串(ASCII字符)。它描述的是這個項。


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.

如果快捷方式標誌的第4位等於1,此段將會出現。第一個word的值表示字符串的長度。緊跟着長度是字符串(ASCII字符)。它是目標的相對路徑。


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.

如果快捷方式標誌的第5位等於1,此段將會出現。第一個word的值表示字符串的長度。緊跟着長度是字符串(ASCII字符)。它是快捷方式屬性裏設置的工作目錄。


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.

如果快捷方式標誌的第6位等於1,此段將會出現。第一個word的值表示字符串的長度。緊跟着長度是字符串(ASCII字符)。它是命令行參數,不包括程序名。


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.

如果快捷方式標誌的第7位等於1,此段將會出現。第一個word的值表示字符串的長度。緊跟着長度是字符串(ASCII字符)。它是包含圖標文件的路徑。


Additonal Info(額外信息)

 

Usualy consists of a dword with the value 0.

通常是等於0 的DWORD。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章