first commit

This commit is contained in:
jianxin committed 2024-01-26 18:10:13 +08:00
commit 700bedbe39
5 files changed
+248

No files matched your search

+82
View File
@@ -0,0 +1,82 @@
#include <iostream>
#include <Windows.h>
#include <TlHelp32.h>
#include <direct.h>
using namespace std;
DWORD GetPIDByProcessName(LPCSTR ProcessName);
int main()
{
// get current path
char buffer[MAX_PATH];
_getcwd(buffer, MAX_PATH);
cout << "Current path: " << buffer << endl;
// current path add WeChatHookDll.dll
#pragma warning(disable : 4996)
//LPCSTR DllPath = strcat(buffer, "\\WeChatHookDll.dll");
LPCSTR DllPath = "C:\\Users\\32075\\OneDrive\\Îĵµ\\Code\\csex\\WeChatHookDll\\x64\\Debug\\WeChatHookDll.dll"; // The Path to our DLL
//LPCSTR DllPath = "C:\\Users\\32075\\OneDrive\\Îĵµ\\Code\\csex\\Simple-DLL-Injection-master\\Simple-DLL-Injection-master\\C++\\x64\\Debug\\testlib.dll"; // The Path to our DLL
DWORD procID = GetPIDByProcessName("WeChat.exe");
if (procID == 0)
{
cout << "GetPIDByProcessName() failed: " << GetLastError() << endl;
return 0;
}
cout << "Process ID: " << procID << endl;
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, procID); // Opening the Process with All Access
if (handle == NULL)
{
cout << "OpenProcess() failed: " << GetLastError() << endl;
return 0;
}
// Allocate memory for the dllpath in the target process, length of the path string + null terminator
LPVOID pDllPath = VirtualAllocEx(handle, 0, strlen(DllPath) + 1, MEM_COMMIT, PAGE_READWRITE);
// Write the path to the address of the memory we just allocated in the target process
WriteProcessMemory(handle, pDllPath, (LPVOID)DllPath, strlen(DllPath) + 1, 0);
// Create a Remote Thread in the target process which calls LoadLibraryA as our dllpath as an argument -> program loads our dll
HANDLE hLoadThread = CreateRemoteThread(handle, 0, 0,
(LPTHREAD_START_ROUTINE)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "LoadLibraryA"), pDllPath, 0, 0);
WaitForSingleObject(hLoadThread, INFINITE); // Wait for the execution of our loader thread to finish
cout << "Dll path allocated at: " << hex << pDllPath << endl;
VirtualFreeEx(handle, pDllPath, strlen(DllPath) + 1, MEM_RELEASE); // Free the memory allocated for our dll path
CloseHandle(handle);
CloseHandle(hLoadThread);
return 0;
}
DWORD GetPIDByProcessName(LPCSTR ProcessName)
{
HANDLE ProcesllAll = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
PROCESSENTRY32 processInfo = { 0 };
processInfo.dwSize = sizeof(PROCESSENTRY32);
do
{
if (strcmp(ProcessName, processInfo.szExeFile) == 0)
{
return processInfo.th32ProcessID;
}
} while (Process32Next(ProcesllAll, &processInfo));
return 0;
}