在64位应用程序中加载32位DLL库

发布于 2024-08-21 08:20:03 字数 168 浏览 2 评论 0原文

有没有办法加载 32 位 DLL 库(与 LoadLibrary 具有相同用法的东西),我想将该函数与 GetProcAddress 一起使用。

我看了WOW,但似乎没有提供该功能。该功能应该存在,因为像 DependencyWalker 这样的工具能够读取 32 位 DLL 的符号,即使它是 64 位的。

Is there a way to load a 32-bit DLL library (something with the same usage as LoadLibrary) I would like to use that function along with GetProcAddress.

I looked at WOW, but it does not seem to offer the functionality. The functionality should exist, since tools like DependencyWalker are able to read the symbols of a 32-bit DLL even though its 64-bit.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

错爱 2024-08-28 08:20:03

当您将 DLL 作为数据文件加载时,只能将 32 位 DLL 加载到 64 位进程中。您无法执行该代码。 (http://support.microsoft.com/kb/282423)

Microsoft 建议您使用进程间COM 在 64 位应用程序中使用 32 位代码。 这里有一篇文章解释了该过程。

You can only load a 32bit DLL into a 64 bit process when you are loading the dll as a datafile. You can't execute the code. (http://support.microsoft.com/kb/282423)

Microsoft recommends that you use interprocess COM to use 32 bit code with a 64 bit application. Here's an article explaining the process.

枫以 2024-08-28 08:20:03

如果您只想从中获取资源,则可以作为数据文件加载:

LoadLibraryEx(exeName, NULL, LOAD_LIBRARY_AS_DATAFILE);

然后照常调用 FindResource

If all you're wanting to do is get resources from it, you can load as a datafile:

LoadLibraryEx(exeName, NULL, LOAD_LIBRARY_AS_DATAFILE);

Then call FindResource as normal.

慕巷 2024-08-28 08:20:03

读取 32 位可执行文件和在 32 位可执行文件中执行代码之间存在差异。我不相信 Windows 提供任何功能来做到这一点。

您可能能够做到这一点的唯一方法是创建一个加载 dll 的 32 位进程,然后进行进程间通信以在两个进程之间传递结果。

There's a difference between reading a 32 bit executable and executing code within a 32 bit executable. I don't believe that windows offers any functionality to do that.

The only way you're likely to be able to do that is to create a 32 bit process that loads the dll and then do interprocess communication to pass the results between the two processes.

笙痞 2024-08-28 08:20:03

理论上是的。我已经实现了一个方法。 CPU允许,操作系统不直接允许,但有一个解决方法。

它基于跳过长模式兼容性段。在 x64 中,有执行 64 位代码的“64 位”段和执行 32 位代码的“兼容性”段。虽然包含它的 GDT 结构只能从内核模式访问,但在 Windows 中,有一个预加载的 0x23 段,如果您知道方法,就可以跳转到该段。

您还必须修补导入表,但不能使用普通的 GetProcAddress 等修补,因为此函数将返回 64 位指针(因为您正在运行 x64 应用程序),而您需要修补 32 位加载的库。

此处的代码演示了所有这些理论。我的 代码项目文章 详细解释了它,我的通用 英特尔组装手册 解释 x64 内部结构。在上面链接的代码中,我创建了一个 32 位 DLL 并将其加载到 x64 进程中。

实际上,它还不能与 win32 Dll 一起工作,即使它可以工作,我也不会在生产代码中使用。我现在还在里面工作。

然而 x86 dll 现在已经死了。例如,当我最初创建音频音序器时,有大量仅限 x86 的插件,但现在几乎所有插件(可能都是)都以 x64 形式提供。

现在只是为了实验。

In theory, yes. I have implemented a way. The CPU allows it, the OS isn't directly but there's a workaround.

It is based on jumping around a long mode compatibility segment. In x64 there are "64-bit" segments which execute 64-bit code and "compatibility" segments that execute 32-bit code. While the GDT structure that contains that is only accessible from kernel mode, in Windows there's a preloaded 0x23 segment which can be jumped to if you know the way.

You also have to patch the Import Table but not with the normal GetProcAddress etc since this function will return 64-bit pointers (since you are running a x64 app) while you need to patch a 32-bit loaded library.

The code here demonstrates all that theory. My Code Project article explains it in detail and my generic Intel Assembly Manual explains the x64 internals. In the code in the above link I am creating a 32 bit DLL and loading it into the x64 process.

In practise, it doesnt work yet with win32 Dlls and even if it ever works I wouldn't use in production code. I am still working in it.

However x86 dlls are now dead. When I originally created my audio sequencer, for example, there were plenty of x86-only plugins where now almost everyhing ships (perhaps exclusively) as x64.

It's just for experimenting nowadays.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文