int main(int argc, char* argv[]) { // nice title :) SetConsoleTitle("SzimatSzatyor, WoW injector sniffer"); // some info printf("Welcome to SzimatSzatyor, a WoW injector sniffer.\n"); printf("SzimatSzatyor is distributed under the GNU GPLv3 license.\n"); printf("Source code is available at: "); printf("http://github.com/Konctantin/SzimatSzatyor\n\n"); if (argc > 3) { printf("ERROR: Invalid parameters. "); printf("\"szatyor.exe [wow_exe_name] [dll_name]\" should be used.\n\n"); system("pause"); return 0; } // custom process' name else if (argc > 1) lookingProcessName = argv[1]; else if (argc > 2) injectDLLName = argv[2]; // this process will be injected DWORD processID = 0; // tries to get the PIDs PIDList& pids = GetProcessIDsByName(lookingProcessName); if (pids.empty()) { printf("'%s' process NOT found.\n", lookingProcessName); printf("Note: be sure the process which you looking for "); printf("is must be a 32 bit process.\n\n"); system("pause"); return 0; } // just one PID found else if (pids.size() == 1) { processID = pids.front(); printf("'%s' process found, PID: %u\n", lookingProcessName, processID); // checks this process is already injected or not if (IsProcessAlreadyInjected(processID, injectDLLName)) { printf("Process is already injected.\n\n"); system("pause"); return 0; } } // size > 1, multiple possible processes else { printf("Multiple '%s' processes found.\n", lookingProcessName); printf("Please select one which will be injected.\n\n"); // stores the PIDs which are already injected // so these are "invalid" PIDList injectedPIDs; unsigned int idx = 1; for (PIDList_ConstItr itr = pids.begin(); itr != pids.end(); ++itr) { DWORD pid = *itr; printf("[%u] PID: %u\n", idx++, pid); if (IsProcessAlreadyInjected(pid, injectDLLName)) { printf("Already injected!\n\n"); injectedPIDs.push_back(pid); } } // same size: there is no non-injected PID if (pids.size() == injectedPIDs.size()) { printf("All the processes are already injected.\n\n"); system("pause"); return 0; } unsigned int selectedIndex = 0; // loops until has correct PID while (1) { processID = 0; selectedIndex = 0; printf("Please select a process, use [index]: "); scanf("%u", &selectedIndex); // bigger than max index if (selectedIndex > idx - 1) { printf("Your index is too big, max index is %u.\n", idx - 1); continue; } // 0 or non int used else if (selectedIndex == 0) { printf("Your index is invalid, 1-%u should be used.\n", idx - 1); continue; } // gets PID via index PIDList_ConstItr itr = pids.begin(); std::advance(itr, selectedIndex - 1); processID = *itr; // if already injected if (std::find(injectedPIDs.begin(), injectedPIDs.end(), processID) != injectedPIDs.end()) { printf("This process is already injected. "); printf("Please choose a different one.\n"); continue; } // looks like all good break; } printf("\n"); } // stores where the injector is, so location/path of the current process char injectorPath[MAX_PATH] = { 0 }; // gets where the injector is DWORD injectorPathSize = GetModuleFileName(NULL, injectorPath, MAX_PATH); if (!injectorPathSize) { printf("ERROR: Can't get the injector's path, "); printf("ErrorCode: %u\n\n", GetLastError()); system("pause"); return 0; } // full path of the DLL char* dllPath = new char[MAX_PATH]; // copies injector's full path to dllPath strncpy_s(dllPath, MAX_PATH, injectorPath, injectorPathSize); // some magic to replace path/szatyor.exe to path/szimat.dll // removes injector's name PathRemoveFileSpec(dllPath); // appends DLL's name PathAppend(dllPath, injectDLLName); printf("DLL: %s\n", dllPath); if (InjectDLL(processID, dllPath)) { printf("\nInjection of '%s' is successful.\n\n", injectDLLName); } else { printf("\nInjection of '%s' is NOT successful.\n\n", injectDLLName); system("pause"); } delete[] dllPath; //system("pause"); return 0; }
DWORD SelectProcess() { PIDMap pids; int len = sizeof(lookingProcessName) / sizeof(std::string); for (int i = 0; i < len; ++i) GetProcessIDsByName(pids, lookingProcessName[i]); if (pids.empty()) { printf("process NOT found.\n"); system("pause"); return 0; } // just one PID found else if (pids.size() == 1) { // we already know it's not empty so we can do this safely DWORD processID = pids.begin()->first; std::string processName = pids.begin()->second; printf("%s process found, PID: %u\n", processName.c_str(), processID); // checks this process is already injected or not if (IsProcessAlreadyInjected(processID, injectDLLName)) { printf("Process is already injected.\n\n"); system("pause"); return 0; } return processID; } // size > 1, multiple possible processes else { printf("Multiple processes found.\n"); printf("Please select one which will be injected.\n\n"); // stores the PIDs which are already injected // so these are "invalid" PIDMap injectedPIDs; unsigned int idx = 1; for (PIDMap::const_iterator itr = pids.begin(); itr != pids.end(); ++itr) { DWORD pid = itr->first; printf("[%u] PID: %u\n", idx++, pid); if (IsProcessAlreadyInjected(pid, injectDLLName)) { printf("Already injected!\n\n"); injectedPIDs[pid] = itr->second; } } // same size: there is no non-injected PID if (pids.size() == injectedPIDs.size()) { printf("All the processes are already injected.\n\n"); system("pause"); return 0; } unsigned int selectedIndex = 0; // loops until has correct PID while (1) { DWORD processID = 0; selectedIndex = 0; printf("Please select a process, use [index]: "); scanf("%u", &selectedIndex); // bigger than max index if (selectedIndex > idx - 1) { printf("Your index is too big, max index is %u.\n", idx - 1); continue; } // 0 or non int used else if (selectedIndex == 0) { printf("Your index is invalid, 1-%u should be used.\n", idx - 1); continue; } // gets PID via index PIDMap::const_iterator itr = pids.begin(); std::advance(itr, selectedIndex - 1); processID = itr->first; // if already injected if (injectedPIDs.find(processID) != injectedPIDs.end()) { printf("This process is already injected. "); printf("Please choose a different one.\n"); continue; } printf("\n"); // looks like all good return processID; } } return 0; }