在远程 Windows 机器上动态运行 DLL?
有没有办法在远程 Windows 机器上动态运行 DLL?
假设用户想要将自己的 DLL 文件发送到远程服务器并在远程站点运行该 DLL 中的函数。用户也许能够提供函数入口点以及所需的参数,但仅此而已。 (例如没有头文件)
我正在考虑在远程站点设置一个代理可执行文件,它可以(1)动态加载和绑定未知的DLL以及(2)运行带参数的函数。这是一个好的方法,还是这样的可执行文件可能?
Is there a way of dynamically running a DLL at a remote Windows box?
Say a user wants to send a his own DLL file to a remote server and run a function in that DLL at the remote site. The user may be able to provide function entry points as well as required parameters, but no more. (e.g. no header file)
I am thinking of setting up an agent executable at the remote site that can (1) dynamically load and bind a unknown DLL and (2) run a function with parameters. Is this a good a approach, or is such an executable possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Andrew Cash 的回复对于非托管代码来说是合理的。他围绕 GetProcAddress 描述的技术本质上就是 RunDll32.exe做。 RunDll32.exe 是 Windows 的一部分,专门加载任意 DLL 并执行其代码。你可以像这样运行它:
当您执行此操作时,RunDll32 将在 DLL 上调用 LoadLibrary,然后在您指定的入口点名称上调用 GetProcAddress 。如果一切顺利,那么它将调用入口点函数。
为了使其真正起作用,需要导出入口点函数。它还必须这样声明:
Andrew Cash's reply is sound for unmanaged code. The technique he describes around GetProcAddress is essentially what RunDll32.exe does. RunDll32.exe is part of Windows and specializes at loading arbitrary DLLs and executing their code. You can run it like this:
When you do this, RunDll32 will call LoadLibrary on the DLL and then GetProcAddress on the entrypoint name you give it. If all that goes well then it calls the entry point function.
For this to actually work the entrypoint function needs to be exported. It must also be declared like this:
是的,您可以使用此信息编写运行 DLL 函数的小程序,并使用类似 PSEXEC 来自 sysinternals。
Yes you could write small program that runs the DLL function using this information and call it remotely using the something like PSEXEC from sysinternals.
您可以使用动态加载 DLL 的技术。
通常,您通过将 .LIB 静态链接到项目中并编译它来使用 DLL。要在运行时动态加载 DLL,您可以使用以下 WIN32 API 函数和一些其他技巧。
加载Libaray();
LoadLibarayEx();
获取过程地址();
免费图书馆();
还有一些其他技巧涉及
以下 wiki 文章中对此进行了全部解释 - http://en。 wikipedia.org/wiki/Dynamic-link_library
您在远程计算机上安装可执行文件的想法是个好主意。只要您与用户同意函数名称和参数即可。如果 dll 符合此要求,则可以随时更改 dll,而不需要更改 EXE。一旦设置并运行,添加额外功能就很简单。
You can use a technique of Dynamically loading your DLL's.
Normally you use a DLL by statically linking a .LIB into your project and compiling it. To load a DLL dynamically at runtime you use the following WIN32 API functions and a few other tricks.
LoadLibaray();
LoadLibarayEx();
GetProcAddress();
FreeLibrary();
There are some other tricks involved
It is all explained in the following wiki article - http://en.wikipedia.org/wiki/Dynamic-link_library
Your idea of installing an executable on the remote machine is a good one. So long as you agree on the function names and parameters with the user. If the dll complies with this then the dll can be changed at any time without requiring you EXE to be changed. Once set up and working it is simple to add extra functions.