使用参数调用远程进程中的函数(注入的 DLL)

Calling a function in a remote process with parameters (injected DLL)

本文关键字:函数 DLL 注入 进程 参数 调用 程进程      更新时间:2023-10-16

我一直在尝试使用DLL injector进程调用驻留在注入DLL中的函数。这个答案中的代码在没有参数的情况下工作正常,但传递参数会导致随机(未初始化(乱码(如-1733099520(传递给函数而不是所需的DWORD

DWORD speed_up = 1;
RemoteLibraryFunction(hProcess, targetDll, "set_speedup", &speed_up, sizeof speed_up, &lpReturn);

我调用的DLL函数定义为:

#define DLL_EXPORT extern "C" __declspec(dllexport)
DLL_EXPORT void set_speedup(const DWORD new_speed)
{
sprintf_s(debug_message_buffer, "Setting new speed to: %in", new_speed);
OutputDebugStringA(debug_message_buffer);
speed = new_speed;
}

请注意,我正在使用DebugView++来观察OutputDebugStringA()的输出。

我做错了什么?似乎参数未正确设置/传递,但代码似乎正确,并且没有函数失败。

事实证明,传递的参数是作为DWORD的地址而不是DWORD传递的。这可以通过将被调用函数的签名更改为如下所示的内容来修复:

#define DLL_EXPORT extern "C" __declspec(dllexport)
DLL_EXPORT void set_speedup(const LPVOID acceleration_pointer)
{
const auto acceleration = *static_cast<DWORD*>(acceleration_pointer);
speed = acceleration;
}

调用约定无关紧要。现在,调用按预期工作。