Допиши полностью идеально функцию anti DLL inject в ProtectProcess. #include <Windows.h>…
- User
Допиши полностью идеально функцию anti DLL inject в ProtectProcess. #include <Windows.h> #include #include #include #include <TlHelp32.h>
bool EnableAntiDllInjection() { std::cout << "Anti - DLL Injection On" << std::endl; return true; // Возвращаем true, чтобы показать успешную активацию защиты }
bool ProtectProcess(const std::wstring& processName) { std::cout << "Protecting process:" << processName << std::endl;
// Получаем процесс по имени HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (hSnap == INVALID_HANDLE_VALUE) { std::cerr << "Failed to create snapshot" << std::endl; return false; } PROCESSENTRY32 procEntry; procEntry.dwSize = sizeof(PROCESSENTRY32); if (!Process32First(hSnap, &procEntry)) { std::cerr << "Failed to get process information" << std::endl; CloseHandle(hSnap); return false; } DWORD targetProcessId = 0; std::vector<DWORD> targetThreadIds; while (Process32Next(hSnap, &procEntry)) { if (processName == procEntry.szExeFile) { targetProcessId = procEntry.th32ProcessID; break; } } if (targetProcessId == 0) { std::cerr << "Process not found" << std::endl; CloseHandle(hSnap); return false; } // Получаем идентификаторы потоков процесса THREADENTRY32 threadEntry; threadEntry.dwSize = sizeof(THREADENTRY32); if (!Thread32First(hSnap, &threadEntry)) { std::cerr << "Failed to get thread information" << std::endl; CloseHandle(hSnap); return false; } do { if (threadEntry.th32OwnerProcessID == targetProcessId) { targetThreadIds.push_back(threadEntry.th32ThreadID); } } while (Thread32Next(hSnap, &threadEntry)); CloseHandle(hSnap); // Здесь необходимо добавить вашу логику защиты, например, использовать SetWindowsHookEx // для перехвата функций, связанных с внедрением DLL // Пример возврата true для успешного завершения защиты процесса return true;}
int main() { if (EnableAntiDllInjection()) { std::wstring processName; std::wcout << "Enter the process name to protect from DLL injection: "; std::getline(std::wcin, processName);
if (ProtectProcess(processName)) { std::cout << "Press any key to exit…" << std::endl; std::cin.ignore(); } else { std::cerr << "Failed to protect process" << std::endl; } } else { std::cerr << "Failed to enable Anti - DLL Injection" << std::endl; } return 0;}
- Assistant