commit 700bedbe397a72b9e6da9ff2685f08c0fe37713c Author: woni <320753691@qq.com> Date: Fri Jan 26 18:10:13 2024 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..961054e --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +./x64 diff --git a/SimpleDLLInjection.cpp b/SimpleDLLInjection.cpp new file mode 100644 index 0000000..fe29d88 --- /dev/null +++ b/SimpleDLLInjection.cpp @@ -0,0 +1,82 @@ +#include +#include +#include +#include + + +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; +} \ No newline at end of file diff --git a/SimpleDLLInjection.vcxproj b/SimpleDLLInjection.vcxproj new file mode 100644 index 0000000..c48bc4f --- /dev/null +++ b/SimpleDLLInjection.vcxproj @@ -0,0 +1,155 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + {04644C73-58AD-4726-A958-9E3BEDC94C2F} + Win32Proj + StandardInjection + 10.0 + SimpleDLLInjection + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + NotSet + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + \ No newline at end of file diff --git a/SimpleDLLInjection.vcxproj.filters b/SimpleDLLInjection.vcxproj.filters new file mode 100644 index 0000000..ed377fe --- /dev/null +++ b/SimpleDLLInjection.vcxproj.filters @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/SimpleDLLInjection.vcxproj.user b/SimpleDLLInjection.vcxproj.user new file mode 100644 index 0000000..88a5509 --- /dev/null +++ b/SimpleDLLInjection.vcxproj.user @@ -0,0 +1,4 @@ + + + + \ No newline at end of file