读取lnk文件的一般方法
一些框架和语言似乎都有 lnk 文件解析器(C#、Java、Python,当然还有无数其他),以获取它们的目标、属性等。我想知道读取 lnk 文件的一般方法是什么,如果我想要用另一种没有上述功能的语言来解析lnk。是否有用于此目的的 Windows API?
Several frameworks and languages seem to have lnk file parsers (C#, Java, Python, certainly countless others), to get to their targets, properties, etc. I'd like to know what is the general approach to reading lnk files, if I want to parse the lnk in another language that does not have said feature. Is there a Windows API for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需使用 JAFAT 取证分析工具项目存档 中的 lnk 文件解析器即可。
请参阅 http://jafat.sourceforge.net 上的 lnk-parse-1.0.pl
似乎没有任何依赖项。语法很简单,链接文件成为标准输出中的简单文本,并且可以在 Linux 上使用。
Simply use lnk file parser at J.A.F.A.T. Archive of Forensics Analysis Tools project.
See lnk-parse-1.0.pl at http://jafat.sourceforge.net
There seems no have no dependencies. Syntax is simple and link file becomes a simple text in standard output and to be usable on Linux.
@Giorgi:实际上,lnk文件有官方规范,至少如此声明。
但是,由于某种原因,该链接似乎已失效,并且在下载整个(45 MB)文档包(
Application_Services_and_NET_Framework.zip
)后,它似乎不包含文件MS -SHLLINK.pdf
。但这真的令人惊讶吗?
一旦获得了文件格式,编写代码来读取它应该不会太难。
@Giorgi: Actually, there is an official specification of lnk files, at least it is claimed so.
However, for some reason, the link seems to be dead, and after downloading the whole (45 MB) doc package (
Application_Services_and_NET_Framework.zip
), it appears that it does not include the fileMS-SHLLINK.pdf
.But is this really surprising ?
Once you got the file format, shouldn't be too hard to write code to read it.
使用WSH相关组件似乎是在XP之后的Windows系统上读取大多数语言的
.lnk
文件的最方便的选择。您只需要访问 COM 环境并实例化WScript.Shell
组件即可。 (请记住,在 win 上,对 Shell 的引用通常是指explorer.exe
)以下代码片段例如在 PHP 上执行此操作:(PHP 5,使用COM 对象)
而另一个在 VBScript 上执行相同的操作:
该领域的大多数示例都是用 VB/VBS 编写的,但是它们翻译得很好以某种形式支持 COM 和 WSH 交互的整个语言范围。
这个简单的教程可能会派上用场,因为它列出并举例说明了
.lnk
文件的一些最有趣的属性,除了最重要的属性:TargetPath
。它们是:Using WSH-related components seems the most convenient option to read
.lnk
files in most languages on a post-XP windows system. You just need access to the COM environment and instantiate theWScript.Shell
Component. (remember that on win, references to the Shell usually refer toexplorer.exe
)The following snippet, e.g. does the thing on PHP: (PHP 5, using the COM object)
This other one, instead, does the same on VBScript:
Most examples in the field are written in VB/VBS, but they translate well on the whole range of languages supporting COM and WSH interaction in a form or another.
This simple tutorial may come handy, as it lists and exemplifies some of the most interesting properties of a
.lnk
file other than the most important:TargetPath
. Those are:WindowStyle
,Hotkey
,IconLocation
,Description
,WorkingDirectory
这里有一些使用 Shell32 API 的 C# 代码,来自我的“ClearRecentLinks”项目,位于 https://github.com/jmaton/ ClearRecentLinks
要使用此功能,您的 C# 项目必须引用 c:\windows\system32\shell32.dll
here's some C# code using the Shell32 API, from my "ClearRecentLinks" project at https://github.com/jmaton/ClearRecentLinks
To use this your C# project has to reference c:\windows\system32\shell32.dll