【发布时间】:2021-06-18 13:25:49
【问题描述】:
我只是编码的初学者。我知道 c++ 和 c# 的基础知识。我正在制作一个dll注入器。我还按照教程进行了部分操作。我从教程中获得的一部分内容有一个错误,它是“初始化器值太多”。我不知道那是什么意思,为什么它会在那里。错误在下一行的nullptrvoid* allocated_memory(h_process, nullptr, MAX_PATH, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
它位于第一个nullptr。如果我删除那个 nullptr,那么我会在 MAX_PATH 处收到错误
代码的最大部分:
#include <iostream>
#include <Windows.h>
#include <string>
#include <thread>
#include <libloaderapi.h>
void get_id(const char* windows_title, DWORD &process_id)
{
GetWindowThreadProcessId(FindWindow(NULL, windows_title), &process_id);
}
void error(const char* error_title, const char* error_message)
{
MessageBox(NULL, error_message, error_title, NULL);
exit(-1);
}
bool file_exists(std::string file_name)
{
struct stat buffer;
return (stat(file_name.c_str(), &buffer) == 0);
}
int main()
{
DWORD proc_id = NULL;
char dll_path(MAX_PATH);
const char* dll_name = "PW";
const char* window_title = "Pixel Worlds";
if (!file_exists(dll_name))
{
error("file_exists", "Something went wrong");
}
HANDLE h_process = OpenProcess(PROCESS_ALL_ACCESS, NULL, proc_id);
void* allocated_memory(h_process, nullptr, MAX_PATH, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
HANDLE h_thread = CreateRemoteThread(h_process, nullptr, NULL, LPTHREAD_START_ROUTINE(LoadLibraryA), allocated_memory, NULL, nullptr);
CloseHandle(h_process);
VirtualFreeEx(h_process, allocated_memory, NULL, MEM_RELEASE);
MessageBox(NULL, "Successfully injected", "Success", NULL);
}
【问题讨论】:
-
你可能想要
void* allocated_memory = some_name_of_function_to_call_here(h_process, nullptr, MAX_PATH, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE); -
我也添加了整个代码@AlanBirtles
-
我认为 Mike 的猜测是正确的,您缺少函数名称和分配