如何防止特定的DLL加载到我的进程 [英] How to prevent a specific DLL from loading into my process

查看:201
本文介绍了如何防止特定的DLL加载到我的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我已经彻底研究了这个,我没有找到可以接受的答案。首先是广泛的笔画:Windows 8.1,Visual Studio 2013。虽然,我不认为这些是重要的。



问题如下。我正在写的应用程序使用A.dll。我们使用在HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers下安装了一个上下文菜单处理程序控件的第三方供应商产品(一个备份程序,但这又不重要)。我们来说路径是c:\Program Files\Vendor\control.dll。



现在,问题是当我的程序打开一个文件选择器对话框(这是一个Qt程序,使用QFileDialog,然后使用标准的Windows),这个控件被加载提供上下文相关的右键单击功能。此控件取决于A.dll的不同版本,当加载control.dll时,我的程序会立即崩溃。



我不需要这个额外的功能。我想做的是防止这个特定的DLL(control.dll)加载到我的进程中。在面向对象的世界中,我将简单地重载LoadLibrary(),检查这个特定的DLL,然后调用标准的。但是这似乎不可行。



有没有办法做到这一点?



谢谢!
Dan

解决方案

在这种情况下,您将启动一个标准的Windows打开文件对话框,内部托管Windows资源管理器作为部分的UI,并且Explorer加载Shell扩展DLL。为了防止这种情况,您必须:


  1. 调用 GetOpenFileName() API直接选择使用旧样式的对话框而不是较新的资源管理器样式的对话框,省略 OFN_EXPLORER 标志(较新的 IFileOpenDialog API不支持此选项)。旧样式对话框不支持Shell扩展(但它也具有过时的外观)。


  2. 不要使用标准的打开文件对话框。让你自己。


另一个选择是让Explorer正常工作,但创建并注册自己的垫片DLL作为外挂Shell扩展的替代品。调用进程是否为 explorer.exe 。如果是这样,加载并将所有操作委托给原始扩展,否则不执行任何操作。请参阅
如何在FileOpen对话框中禁用Shell扩展



另一个选项可能是为违规的Shell扩展创建一个并排的汇编清单,并且该清单会明确指出要加载哪个DLL,因此扩展程序加载自己的DLL版本,而不是您的应用程序正在使用的版本。


I think I have researched this pretty thoroughly and I have not found an acceptable answer. First the broad strokes: Windows 8.1, Visual Studio 2013. Although, I don't think these are important.

Problem as follows. The application I am writing makes use of A.dll. We use a third-party vendor product (a backup program, but again this is not important) that has installed a Context Menu Handler control under HKEY_CLASSES_ROOT\Directory\shellex\ContextMenuHandlers. Let's say the path to this is c:\Program Files\Vendor\control.dll.

Now, the issue is that when my program opens a file chooser dialog (it's a Qt program that uses QFileDialog which then uses the standard Windows one), this control is loaded to provide context-sensitive right-click functionality. This control depends on a different version of "A.dll" and when control.dll is loaded, my program promptly crashes.

I don't need this extra functionality. What I would love to do is to prevent this specific dll (control.dll) from loading in my process. In an object-oriented world I would simply overload LoadLibrary(), check for this specific DLL, and then call the standard one otherwise. However this doesn't seem feasible.

Is there an easy way to do this?

Thanks! Dan

解决方案

In this situation, you are launching a standard Windows Open File dialog that internally hosts Windows Explorer as part of its UI, and Explorer loads Shell Extension DLLs. To prevent that, you have to either:

  1. call the GetOpenFileName() API directly, opting to use the old-style dialog instead of the newer explorer-style dialog by omitting the OFN_EXPLORER flag (the newer IFileOpenDialog API does not support this option). The older-style dialog does not support Shell Extensions (but it also has an outdated look-and-feel).

  2. don't use the standard Open File dialog at all. Make you own instead.

Another option is to let Explorer do its job normally, but create and register your own shim DLL as a replacement for the offending Shell Extension. Have the shim check if the calling process is explorer.exe. If so, load and delegate all actions to the original Extension, otherwise do nothing. See How To Disable Shell Extension In FileOpen Dialog.

Another option might be to create a side-by-side assembly manifest for the offending Shell Extension, and have that manifest explicitly state which DLL to load, so the Extension loads its own version of the DLL and not the version your app is using.

这篇关于如何防止特定的DLL加载到我的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆