如何实现rundll2可调用函数?

发布于 2024-09-30 10:50:01 字数 471 浏览 0 评论 0原文

我正在尝试编写一个 exe,它还导出可以使用 rundll32 调用的函数。这可能吗?如果可以,为什么它不能像这样工作?

我密切关注微软对此的建议

#define RUNDLL32(func) extern "C" __declspec(dllexport) void CALLBACK func(HWND hWnd, HINSTANCE hInst, LPSTR lpszCmdLine, int nCmdShow)

RUNDLL32(MyFunc)
{
  MessageBox(0, 0, 0, 0);
}

但是当使用 rundll32 调用时

rundll32 myprog.exe,_MyFunc@16

会崩溃/DEP 启动。

I'm trying to write an exe that also exports functions which can be called with rundll32. Is this possible and if so, why isn't it working like this?

I closely followed Microsoft's advice on this.

#define RUNDLL32(func) extern "C" __declspec(dllexport) void CALLBACK func(HWND hWnd, HINSTANCE hInst, LPSTR lpszCmdLine, int nCmdShow)

RUNDLL32(MyFunc)
{
  MessageBox(0, 0, 0, 0);
}

But when called with

rundll32 myprog.exe,_MyFunc@16

rundll32 crashes/DEP kicks in.

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

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

发布评论

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

评论(1

微暖i 2024-10-07 10:50:01

Rundll32.exe 使用 LoadLibrary() 加载可执行映像。这对于 EXE 来说不太可能有效,它不希望加载到非默认地址。这是肯定会发生的,rundll32.exe 已经占用了该默认地址。不确定您是否可以修改链接器,以便它不会忽略重定位记录。

但不必费心这种方法,只需创建 DLL 而不是 EXE。并将实际参数传递给 MessageBox()。并且,是的,使用 .def 文件重命名导出的函数。

Rundll32.exe uses LoadLibrary() to load the executable image. This is not likely to work out well for an EXE, it doesn't expect to get loaded on an address that's that not its default. Which is guaranteed to happen, rundll32.exe already occupies that default address. Not sure if you could tinker with the linker so that it doesn't omit the relocation records.

But don't bother with this approach, just create a DLL instead of an EXE. And pass real arguments to MessageBox(). And, yes, use a .def file to rename the exported function.

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