求大神帮忙看看,注入dll总是失败
感觉像是最后远程注入的时候错了。
微信这么提醒
// Project1.cpp : 定义应用程序的入口点。
//
#include "stdafx.h"
#include "Project1.h"
#include <Windows.h>
#include "resource.h"
#include <TlHelp32.h>
#include<stdio.h>
#define WECHAT_PROCESS_NAME "WeChat.exe"
INT_PTR CALLBACK DialogProc(HWND Arg1, UINT Arg2, WPARAM Arg3, LPARAM Arg4);
VOID InjectDll();
int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
_In_opt_ HINSTANCE hPrevInstance,
_In_ LPWSTR lpCmdLine,
_In_ int nCmdShow)
{
DialogBox(hInstance, MAKEINTRESOURCE(ID_MAIN), NULL, &DialogProc);
return 0;
}
INT_PTR CALLBACK DialogProc(
HWND Arg1,
UINT Arg2,
WPARAM Arg3,
LPARAM Arg4
)
{
if (Arg2 == WM_INITDIALOG)
{
//MessageBox(NULL, "首次加载", "标题", 0);
}
if (Arg2 == WM_CLOSE) {
EndDialog(Arg1, 0);
}
if (Arg2 == WM_COMMAND) {
if (Arg3 == INJECT_DLL) {
InjectDll();
}
if (Arg3 == UIN_DLL) {
}
}
return FALSE;
}
DWORD ProcessNameFindPID(LPCSTR ProcessName) {
HANDLE ProcessALL = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, NULL);
PROCESSENTRY32 processInfo = { 0 };
processInfo.dwSize = sizeof(PROCESSENTRY32);
do
{
if (strcmp(ProcessName, processInfo.szExeFile) == 0) {
return processInfo.th32ProcessID;
}
} while (Process32Next(ProcessALL, &processInfo));
return 0;
}
VOID InjectDll() {
CHAR pathStr[0x100] = { "D://wechatdell//reader//raeder//Debug//reader.dll" };
DWORD PID = ProcessNameFindPID(WECHAT_PROCESS_NAME);
if (PID == 0)
{
MessageBox(NULL, "没有找到微信进程或者微信没有启动", "错误", 0);
return;
}
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
if (NULL == hProcess)
{
MessageBox(NULL, "进程打开失败,可能权限不足或者关闭了应用", "错误", 0);
return;
}
LPVOID dllAdd = VirtualAllocEx(hProcess, NULL, sizeof(pathStr), MEM_COMMIT, PAGE_READWRITE);
if (NULL == dllAdd) {
MessageBox(NULL, "内存分配失败", "错误", 0);
return;
}
if (WriteProcessMemory(hProcess, dllAdd, pathStr, strlen(pathStr), NULL) == 0) {
MessageBox(NULL, "路径写入失败", "错误", 0);
return;
}
CHAR test[0x100] = { 0 };
/*sprintf_s(test, "写入的地址:%p", dllAdd);
OutputDebugString(test);
*/
HMODULE k32 = GetModuleHandle("Kernel32.dll");
LPVOID loadAdd = GetProcAddress(k32, "LcadLibraryA");
/* LoadLibraryW("test.dll");*/
HANDLE exec = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)loadAdd, dllAdd, 0, NULL);
if (NULL == exec)
{
MessageBox(NULL, "y远程注入失败", "错误", 0);
return;
}
}