gpt4 book ai didi

Load 32-bit DLL library in 64-bit application(在64位应用程序中加载32位DLL库)

转载 作者:bug小助手 更新时间:2023-10-28 13:32:18 26 4
gpt4 key购买 nike



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.

有没有办法加载32位DLL库(与LoadLibrary用法相同的库)我想将该函数与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.

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


更多回答

This is answered here: stackoverflow.com/questions/128445/… . John Knoeller's answer below is also correct.

这里有答案:Stackoverflow.com/Questions/128445/…。约翰·诺勒下面的回答也是正确的。

@John B. Lambe The title of this post is clearer than the one you linked for those who're searching the exe-call-dll thing.

@John B.Lambe这篇文章的标题比你为那些正在搜索exe-call-dll的人所链接的标题更清楚。

优秀答案推荐

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)

将32位DLL作为数据文件加载时,只能将其加载到64位进程中。你不能执行代码。(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.

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



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.

然后照常调用FindResource。



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.

读取32位可执行文件和在32位可执行文件中执行代码是不同的。我不相信Windows提供了任何这样做的功能。



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.

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



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

从理论上讲,是的。我已经实施了一种方法。CPU允许这样做,操作系统不是直接的,但有一个解决办法。


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.

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


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.

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


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.

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


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.

在实践中,它还不能在Win32动态链接库中工作,即使它能工作,我也不会在产品代码中使用。我还在工作。


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.

然而,x86dll现在已经死了。例如,当我最初创建我的音频定序器时,有许多仅支持x86的插件,现在几乎所有的插件(可能只有)都是x64。


It's just for experimenting nowadays.

这只是现在的实验而已。


更多回答

Updated link for the article: blog.mattmags.com/2007/06/30/… See also stackoverflow.com/questions/128445/…

文章链接更新:…/2007/06/30另请参阅Stackoverflow.com/Questions/128445/…

Check my answer.

检查我的答案。

LOAD_LIBRARY_AS_DATAFILE is Const LOAD_LIBRARY_AS_DATAFILE = $00000002; and free also the handle: FreeLibrary(LibHandle64);

LOAD_LIBRARY_AS_DATAFILE为常量LOAD_LIBRARY_AS_DATAFILE=$00000002;也释放句柄:自由库(LibHandle64);

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com