gpt-3.5-turbo-0613· openai
Suzhen/CodeChat
make a c++ program that will detect whenever a dll is being injected
- User
make a c++ program that will detect whenever a dll is being injected
- Assistant
Here's a sample C++ program that can detect whenever a DLL is being injected into a process using the Windows API.
#include <windows.h> #include <iostream> // Function to check if a DLL is being injected bool IsDLLInjected() { // Enumerate loaded modules HMODULE hModules[1024]; DWORD cbNeeded; if (!EnumProcessModules(GetCurrentProcess(), hModules, sizeof(hModules), &cbNeeded)) { return false; } // Get the name of each module TCHAR moduleName[MAX_PATH]; for (DWORD i = 0; i < (cbNeeded / sizeof(HMODULE)); i++) { if (GetModuleFileNameEx(GetCurrentProcess(), hModules[i], moduleName, sizeof(moduleName) / sizeof(TCHAR))) { std::wstring moduleStr(moduleName); // Check if the module name contains ".dll" if (moduleStr.find(L".dll") != std::wstring::npos) { return true; // DLL is being injected } } } return false; // No DLL injection detected } int main() { if (IsDLLInjected()) { std::cout << "DLL injected!" << std::endl; } else { std::cout << "No DLL injection detected." << std::endl; } return 0; }