使用参数调用远程进程中的函数(注入的 DLL)
Calling a function in a remote process with parameters (injected DLL)
我一直在尝试使用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;
}
调用约定无关紧要。现在,调用按预期工作。
相关文章:
- 使用c#访问c++dll中带有char*参数的函数时发生AccessViolationException
- Visual c ++,使用字符串引用/指针调用 dll 函数
- 来自 DLL 的函数调用 [表观调用的括号前面的表达式必须具有(指向-)函数类型]
- C++ DLL 引用C++.exe中的函数和类
- 如何使用导出的函数交叉编译 DLL
- 如何在窗口中使用注入的 dll 中的参数调用函数
- 在 Microsoft Access SQL 中调用自定义 DLL 函数时传递的内存地址无效
- 加载由 MATLAB Coder 生成的带有函数的 DLL,该函数调用外部函数
- PowerShell 使用结构类型参数调用 C++ DLL 的导出函数
- 从DLL导出函数,LoadLibrary()需要用TEXT转换的字符串才能编译而不会出错
- 从 C#-DLL 调用函数的 C++ 失败
- 如何在 DLL 内的成员函数中使用互斥/关键节
- 调用 "project" 函数和调用 DLL 函数之间的区别
- 函数指针分配在创建 DLL 后导致错误
- 从动态加载的 dll 内部调用C++函数
- 函数声明中的 WINAPI 标识符C++ DLL 入口点函数中的标识符
- LNK2019某些类函数,但不在其他类函数(DLL 中的模板类)上
- 从库导入函数./ DLL 文件
- 从 ntdll 调用 Nt 函数.dll在 Win32 环境中,C++
- 如何使用ctypes将python列表传递给C函数(dll)