C# 解析 Jump List 文件 (*.automaticDestinations-ms) 的完整代码示例
使用 C# 解析 Jump List 文件 (.automaticDestinations-ms) 的完整代码示例\n\nJumpListsView 是一个用于查看和解析 Windows 操作系统中的 Jump List 文件 (.automaticDestinations-ms) 的工具。Jump List 文件存储了应用程序在任务栏上显示的最近使用的文件、文件夹和命令的信息。\n\n使用 C# 实现这一功能,可以使用 System.IO 命名空间中的相关类和方法来读取和解析 Jump List 文件。以下是一个使用 C# 编写的完整代码示例:\n\ncsharp\nusing System;\nusing System.Collections.Generic;\nusing System.IO;\nusing System.Runtime.InteropServices;\nusing System.Text;\n\nnamespace JumpListParser\n{\n class Program\n {\n static void Main(string[] args)\n {\n string jumpListFilePath = "@C:\\Users\\Username\\AppData\\Roaming\\Microsoft\\Windows\\Recent\\AutomaticDestinations\\XXX.automaticDestinations-ms";\n \n List<string> jumpListItems = ParseJumpList(jumpListFilePath);\n \n foreach(string item in jumpListItems)\n {\n Console.WriteLine(item);\n }\n }\n\n static List<string> ParseJumpList(string filePath)\n {\n List<string> jumpListItems = new List<string>();\n\n using (FileStream stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))\n {\n using (BinaryReader reader = new BinaryReader(stream))\n {\n // Jump List file format starts with a signature "5F 43 4B 46" (ASCII: "_CKF")\n byte[] signature = reader.ReadBytes(4);\n string signatureString = Encoding.ASCII.GetString(signature);\n\n if (signatureString != "_CKF")\n {\n throw new Exception("Invalid Jump List file");\n }\n\n // Jump List file format version\n byte version = reader.ReadByte();\n\n // Skip 12 bytes\n reader.BaseStream.Seek(12, SeekOrigin.Current);\n\n // Number of Jump List items\n int itemCount = reader.ReadInt32();\n\n // Skip 4 bytes\n reader.BaseStream.Seek(4, SeekOrigin.Current);\n\n for (int i = 0; i < itemCount; i++)\n {\n // Jump List item type\n byte itemType = reader.ReadByte();\n\n // Skip 3 bytes\n reader.BaseStream.Seek(3, SeekOrigin.Current);\n\n // Jump List item size\n int itemSize = reader.ReadInt32();\n\n // Skip 4 bytes\n reader.BaseStream.Seek(4, SeekOrigin.Current);\n\n // Jump List item data\n byte[] itemData = reader.ReadBytes(itemSize);\n\n // Parse item data based on item type\n if (itemType == 0x00) // File\n {\n string filePath = Encoding.Unicode.GetString(itemData);\n jumpListItems.Add(filePath);\n }\n else if (itemType == 0x01) // Separator\n {\n // Skip separator item\n continue;\n }\n }\n }\n }\n\n return jumpListItems;\n }\n }\n}\n\n\n在上面的代码中,jumpListFilePath变量需要替换为实际的 Jump List 文件的路径。然后,ParseJumpList函数会打开并读取该文件,解析其中的 Jump List 项,并将其存储在jumpListItems列表中。最后,程序会遍历列表并将 Jump List 项打印到控制台。\n\n需要注意的是,Jump List 文件的解析逻辑可能因不同的 Windows 版本而有所不同,上述代码适用于较新的 Windows 版本。如果在旧版本的 Windows 上运行时遇到问题,可能需要进行一些调整。\n\n此外,还需要确保以管理员权限运行代码,以便能够访问 Jump List 文件。
原文地址: https://www.cveoy.top/t/topic/p5K6 著作权归作者所有。请勿转载和采集!