简体   繁体   English

C++ DLL 注入

[英]DLL Injection with C++

#include <Windows.h>
HANDLE h = OpenProcess(PROCESS_CREATE_THREAD, FALSE, 34808); //Creating a remote thread 
int main() {
    LPVOID path = "MessageBoxDLL.dll";
    CreateRemoteThread(h, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, path, 0, NULL);
}

When I try to run my code it returns the error "cannot convert from const char to lpvoid" Im a bit lost with why its not letting me give it a vaild path or even why it needs to convert my value.当我尝试运行我的代码时,它返回错误“无法从 const char 转换为 lpvoid”我有点迷茫,为什么它不让我给它一个有效的路径,甚至为什么它需要转换我的值。 I played around a bit more but couldn't find any viable solutions.我玩了更多,但找不到任何可行的解决方案。 https://i.stack.imgur.com/Ne0bp.png <---Image of error https://i.stack.imgur.com/Ne0bp.png <---错误图片

Why is it converting to LPVOID?为什么要转换为 LPVOID? Because you told it to.因为你告诉了它。 Let's trim this down and notice the error remains:让我们修剪它并注意错误仍然存​​在:

int main() {
    void* x = "characters";
}

error C2440: 'initializing': cannot convert from 'const char [11]' to 'void *'错误 C2440:“正在初始化”:无法从“const char [11]”转换为“void *”

I want to be clear, I'm just answering the question.我想说清楚,我只是在回答这个问题。 I make no claims about the rest of the code.我对代码的其余部分不做任何声明。

Normally, old style casts are considered poor practice, but for an old style function that's expecting void*, go for it:通常,旧式强制转换被认为是不好的做法,但是对于期望 void* 的旧式函数,请使用它:

#include <Windows.h>
int main() {
    const char *path = "MessageBoxDLL.dll";
    HANDLE h = OpenProcess(PROCESS_CREATE_THREAD, FALSE, 34808); //Creating a remote thread 
    CreateRemoteThread(h, NULL, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, (LPVOID)path, 0, NULL);
}

Since the function doesn't do any type checking, you're on your own for passing it the right arguments.由于该函数不进行任何类型检查,因此您需要自行向它传递正确的参数。 Documentation and example code should help.文档和示例代码应该会有所帮助。 Casting to void* makes sense for an OS thread function, since the OS doesn't know what you're going to pass.强制转换为 void* 对于 OS 线程函数是有意义的,因为 OS 不知道您要传递什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM