#include #include #include #include #include #include #include int GetProcessIdByName(const std::wstring& processName) { PROCESSENTRY32 entry; entry.dwSize = sizeof(PROCESSENTRY32); HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); if (Process32First(snapshot, &entry)) { do { // Convert entry.szExeFile to std::wstring std::wstring exeFileName(entry.szExeFile, entry.szExeFile + strlen(entry.szExeFile)); if (processName == exeFileName) { CloseHandle(snapshot); return entry.th32ProcessID; } } while (Process32Next(snapshot, &entry)); } CloseHandle(snapshot); return 0; } int main() { std::wcout << L"PyLoader Console Application" << std::endl; while (true) { std::wstring in; std::wcout << L"> "; std::getline(std::wcin, in); size_t spaceFound = in.find(L' ', 0); std::wstring cmdName = in.substr(0, spaceFound); std::wstring cmdParams; if (spaceFound != std::wstring::npos) { cmdParams = in.substr(spaceFound + 1, in.length() - spaceFound); } if (cmdName == L"load") { if (!cmdParams.empty()) { std::wcout << L"Loading file " << cmdParams << std::endl; // Get the PID of the target process by name int targetPID = GetProcessIdByName(L"test.exe"); // Replace with your target process name if (targetPID != 0) { std::wcout << L"Target process PID: " << targetPID << std::endl; std::wstring pythonScriptPath = L"C:\\test2.py"; // Replace with the path to your Python script if (!pythonScriptPath.empty()) { std::wcout << L"Loading file " << pythonScriptPath << std::endl; std::stringstream stream; stream << "exec(compile(open('" << pythonScriptPath.c_str() << "').read(), '" << pythonScriptPath.c_str() << "', 'exec'))"; PyGILState_STATE state = PyGILState_Ensure(); int r = PyRun_SimpleStringFlags(stream.str().c_str(), NULL); PyGILState_Release(state); if (r == 0) { std::cout << "Python script loaded!" << std::endl; } else { std::cout << "Error occurred while running the Python script." << std::endl; } } else { std::wcout << L"Python script file path required!" << std::endl; } } else { std::cout << "Target process not found or invalid PID." << std::endl; } } else { std::wcout << L"File name required!" << std::endl; } } else if (cmdName == L"help") { std::wcout << L"------------------------------------------------- \n" L"Commands: \n" L"load Loads python script.\n" L"help Displays commands. \n" L"exit Exits the program. \n" L"------------------------------------------------- " << std::endl; } else if (cmdName == L"exit") { break; } else { std::wcout << L"Unknown command! Use 'help' to display commands." << std::endl; } } return 0; }