链接到 Windows API 的 PatchAPI
我想使用 Windows API 的 PatchAPI 来应用一些补丁。 补丁的应用是在 mspatcha.dll 中实现的,它应该位于系统的 system32 文件夹中。
在阅读了各个地方(例如他们的参考文献和谷歌搜索)之后,我还没有找到链接到这个 DLL 的正确方法。我想静态链接,处理 LoadLibrary 看起来很混乱,并且有点违背了 patchapi.h 标头的目的。由于我没有找到要链接的 .lib 文件,因此我使用以下命令创建了自己的文件:
1) dumpbin /exports C:\windows\system32\mspatcha.dll
2) 创建一个 mspatcha.def 文件,写入“ EXPORTS”行,后跟 dumpbin 输出中出现的每个函数名称一行
3) lib /def:mspatcha.def /out:mspatcha.lib
虽然我确信这不是与 patchapi 静态链接的正确方法,我还没有找到正确的方法。 无论如何,在遵循这些步骤并编写一个由对ApplyPatchToFileExA()的单个调用组成的简单测试用例之后,我仍然在符号_ApplyPatchToFileA@16上收到链接器错误。 查看我新创建的 mspatcha.lib 的导出符号,这些函数似乎使用了错误的名称约定
D:\tmp\mspatcha>dumpbin /exports mspatcha.lib|找到“ApplyPatchToFileExA”
<前><代码> _ApplyPatchToFileExA
除非我错了,否则这表明 lib 使用 cdecl 导出函数,而 dll 使用 stdcall (或者至少将函数声明为 _stdcall) 。请参阅:Microsoft Windows 中的 C 名称修饰。
我的问题是:在我的应用程序中使用 mspatcha.dll 的正确方法是什么?从 dll 创建 lib 以便我可以进行静态链接的过程出了什么问题?
我的终端的详细输出可以在这里找到: http://pastebin.com/q4FV4Se6
I would like to use Windows API's PatchAPI in order to apply some patches.
Applying of patches is implemented in mspatcha.dll, which should be located in one's system32 folder.
After reading in various places, such as their ref and googling, I have yet to find the right way to link to this DLL. I would like to link statically, dealing with LoadLibrary seems messy and sort of defeats the purpose of their patchapi.h header. Since I have found no .lib file I am to link to, I created my own using the following commands:
1) dumpbin /exports C:\windows\system32\mspatcha.dll
2) Create a mspatcha.def file, write an "EXPORTS" line, followed by one line for each function name that appears in the output of dumpbin
3) lib /def:mspatcha.def /out:mspatcha.lib
Although I'm sure this is not the right way to statically link with patchapi, I have not found the right way to do so.
Anyway, after following these steps and writing a simple testcase made of a single call to ApplyPatchToFileExA(), I still get a linker error on the symbol _ApplyPatchToFileA@16.
Taking a look at the exported symbols of my newly created mspatcha.lib, it appears that the functions use the wrong name convention
D:\tmp\mspatcha>dumpbin /exports mspatcha.lib|find "ApplyPatchToFileExA"
_ApplyPatchToFileExA
Unless I'm wrong, this indicates that the lib exported functions using cdecl whereas the dll is using stdcall (or at least is declaring the function as _stdcall). See: C name decoration in Microsoft Windows.
My questions are: what is the right way to use mspatcha.dll in my application and what was wrong with my process of creating a lib from a dll so I can do static linking?
The detailed output of my terminal can be found here: http://pastebin.com/q4FV4Se6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
作为术语点,您试图隐式链接而不是静态链接,这意味着完全不同的东西。
如果您确实无法获得 .lib 文件,那么生成该文件的一种简单方法是为每个函数创建一个带有空存根的虚拟 DLL。调用 DLL mspatcha.dll。确保使用 .def 文件和 stdcall。
构建完 DLL 后,将其丢弃,但保留 .lib 文件!
我过去曾这样做过,为使用不生成 .lib 文件的工具链构建的 DLL 生成 .lib 文件。
您使用的技术仅适用于 cdecl 函数。
As a point of terminology you are attempting to link implicitly rather than statically which means something quite different.
If you really can't get hold of a .lib file then one easy way to generate one is to create a dummy DLL with empty stubs for each function. Call the DLL mspatcha.dll. Make sure you use a .def file and stdcall.
When you've built the DLL, throw it away but keep the .lib file!
I've done this in the past to generate .lib files for DLLs built with tool chains that don't emit .lib files.
The technique that you used only works for cdecl functions.