如何在Delphi中调用WinAPI函数SetDllDirectory()?
我想防止通过访问当前工作目录来加载恶意 DLL,如 http://msdn.microsoft.com/en-us/library/ff919712(VS.85).aspx
在我们的 C++ 应用程序中实现的解决方案是对 SetDllDirectory("" ),这将有效地从 Windows DLL 加载搜索路径中删除当前工作目录。然而,这个解决方案似乎不适用于我们的 Delphi 应用程序,因为 SetDllDirectory() 函数不存在。
Delphi 中是否有等效的调用与 SetDllDirectory("") 执行相同的操作?谢谢!
I would like to prevent loading of malicious DLLs that may be possible through access of the current working directory as described in http://msdn.microsoft.com/en-us/library/ff919712(VS.85).aspx
The solution implemented in our C++ apps was to make a WinAPI call to SetDllDirectory(""), which would effectively remove the current working directory from the Windows DLL loading search path. However, it seems this solution is not available for our Delphi apps because the SetDllDirectory() function doesn't exist.
Is there an equivalent call in Delphi that does the same thing as SetDllDirectory("")? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这应该可以解决问题:
This should do the trick:
调用 SetDllDirectory('') 不起作用?我发现它在最新版本的 Windows.pas 中已正确声明。如果您有一个未声明的 Delphi 版本,您可以升级到最新版本的 Delphi,或自行声明。
更新:就是这样... Jens 刚刚发布了声明。
Calling SetDllDirectory('') doesn't work? I see that it is declared properly in the latest versions of Windows.pas. If you have a version of Delphi in which it isn't declared, you can upgrade to the latest version of Delphi, or declare it yourself.
Update: And there you go... Jens just posted the declaration.
DSiSetDllDirectory 还将负责动态链接,并在 XP SP1 之前的系统上正常失败。
DSiWin32 作为免费软件发布。
DSiSetDllDirectory will also take care of dynamic linking and will fail gracefully on pre-XP SP1 systems.
DSiWin32 is released as a freeware.