Example #1
0
void DebugFrontend::GetProcesses(std::vector<Process>& processes) const
{

    // Get the id of this process so that we can filter it out of the list.
    DWORD currentProcessId = GetCurrentProcessId();

    HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

    if (snapshot != INVALID_HANDLE_VALUE)
    {
        
        PROCESSENTRY32 processEntry = { 0 };
        processEntry.dwSize = sizeof(processEntry);

        if (Process32First(snapshot, &processEntry))
        {
            do
            {
                if (processEntry.th32ProcessID != currentProcessId && processEntry.th32ProcessID != 0)
                {

                    Process process;

                    process.id   = processEntry.th32ProcessID;
                    process.name = processEntry.szExeFile;
                    
                    
                    HWND hWnd = GetProcessWindow(processEntry.th32ProcessID);

                    if (hWnd != NULL)
                    {
                        char buffer[1024];
                        GetWindowText(hWnd, buffer, 1024);
                        process.title = buffer;
                    }

                    processes.push_back(process);

                }
            }
            while (Process32Next(snapshot, &processEntry));
        
        }

        CloseHandle(snapshot);

    }

}
Example #2
0
void WaitForGame(const char * game_filename, PROCESS_INFORMATION * pi)
{
#define CHECK(cmd, error_msg) do { LONG lResult = cmd; \
	if (lResult != ERROR_SUCCESS) { LogLastError(error_msg); return; } \
} while (0)

	HWND game_hwnd;
	char classname[256];
	DWORD directDrawID;
	char recentAppName[256];
	DWORD size, expected_size;
	HKEY hKey;
	HKEY hSubKey;
	DWORD dwDisposition = 0;
	static unsigned char Flags[4] = {
		0x00, 0x08, 0x00, 0x00 };

	printf("Waiting for the game to start...\n");

	while (1)
	{
		DWORD processID = GetPID(game_filename);
		if (IsProcessRunning(processID))
		{
			printf("Found %s.\n", game_filename);
			game_hwnd = GetProcessWindow(processID);
			GetClassName(game_hwnd, classname, 255);
			printf("Window classname is: %s.\n", classname);
			printf("Opening registry for patching.\n");
			TerminateProcess(pi->hProcess, 0);
			CloseHandle(pi->hProcess);
			CloseHandle(pi->hThread);
			if (is64bit){
				CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
					"SOFTWARE\\Wow6432Node\\Microsoft\\DirectDraw\\MostRecentApplication", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey),
					"open DirectDraw\\MostRecentApplication");
			}
			else
			{
				CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
					"SOFTWARE\\Microsoft\\DirectDraw\\MostRecentApplication", 0, KEY_ALL_ACCESS, &hKey),
					"open DirectDraw\\MostRecentApplication");
			}

			
			size = expected_size = sizeof(directDrawID);
			CHECK(RegQueryValueEx(hKey, "ID", NULL, NULL, (LPBYTE)& directDrawID, &size),
				"query DirectDraw\\MostRecentApplication\\ID");
			if (size != expected_size)
			{
				printf("error: DirectDraw\\MostRecentApplication\\ID has wrong size: %u (expected %u)\n",
					size, expected_size);
				return;
			}

			// just to be sure, check that the recent application is in fact the one we are interested in.
			size = expected_size = sizeof(recentAppName) - 1;
			CHECK(RegQueryValueEx(hKey, "Name", NULL, NULL, (LPBYTE)recentAppName, &size),
				"query DirectDraw\\MostRecentApplication\\Name");
			if (size > expected_size)
			{
				printf("error: DirectDraw\\MostRecentApplication\\ID has wrong size: %u (expected %u or less)\n",
					size, expected_size);
				return;
			}
			recentAppName[size] = '\0';
			if (strcmp(recentAppName, game_filename))
			{
				printf("error: DirectDraw\\MostRecentApplication\\Name doesn't match the game file name: '%s' != '%s'\n",
					recentAppName, game_filename);
			}


			RegCloseKey(hKey);
			if (is64bit == TRUE){
				CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
					"SOFTWARE\\Wow6432Node\\Microsoft\\DirectDraw\\Compatibility", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hKey),
					"open DirectDraw\\Compatibility");

			}
			else
			{
				CHECK(RegOpenKeyEx(HKEY_LOCAL_MACHINE,
					"SOFTWARE\\Microsoft\\DirectDraw\\Compatibility", 0, KEY_ALL_ACCESS, &hKey),
					"open DirectDraw\\Compatibility");
			}
			CHECK(RegCreateKey(hKey, classname, &hSubKey),
				"create DirectDraw\\Compatibility subkey for window classname");

			CHECK(RegSetValueEx(hSubKey, "Name", 0, REG_SZ, (LPBYTE)game_filename, (DWORD)strlen(game_filename) + 1),
				"set Name");
			CHECK(RegSetValueEx(hSubKey, "ID", 0, REG_BINARY, (CONST BYTE*)&directDrawID, sizeof(directDrawID)),
				"set ID");
			CHECK(RegSetValueEx(hSubKey, "Flags", 0, REG_BINARY, (CONST BYTE*)Flags, 4),
				"set Flags");

			RegCloseKey(hSubKey);
			RegCloseKey(hKey);
			printf("Patching complete! Enjoy your game!\n");
			return;
		}
		Sleep(100);
	}
}
Example #3
0
void GetProcesses(std::vector<Process>& processes)
{
	static char fileName[_MAX_PATH];
	static char tempPath[_MAX_PATH];
	// Get the id of this process so that we can filter it out of the list.
	DWORD currentProcessId = GetCurrentProcessId();

	HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

	if (snapshot != INVALID_HANDLE_VALUE)
	{

		PROCESSENTRY32 processEntry = { 0 };
		processEntry.dwSize = sizeof(processEntry);

		if (Process32First(snapshot, &processEntry))
		{
			do
			{
				if (processEntry.th32ProcessID != currentProcessId && processEntry.th32ProcessID != 0)
				{

					Process process;

					process.id = processEntry.th32ProcessID;
					process.name = processEntry.szExeFile;

					HANDLE m_process = OpenProcess(PROCESS_QUERY_INFORMATION, FALSE, processEntry.th32ProcessID);
					if (m_process) {
						int err = GetModuleFileNameEx(m_process, nullptr, fileName, _MAX_PATH);
						if (err == 0) // ERROR_ACCESS_DENIED = 5
							process.path = "error";
						else process.path = fileName;

						if (!process.path.empty()) {
							char windowsPath[MAX_PATH];
							if (SHGetFolderPath(nullptr, CSIDL_WINDOWS, nullptr, SHGFP_TYPE_CURRENT, windowsPath) == 0) {
								if (process.path.find(windowsPath) == std::string::npos) {

									HWND hWnd = GetProcessWindow(processEntry.th32ProcessID);

									if (hWnd != nullptr)
									{
										char buffer[1024];
										GetWindowText(hWnd, buffer, 1024);
										process.title = buffer;
									}
									processes.push_back(process);
								}
							}
						}
					}
				}
			} while (Process32Next(snapshot, &processEntry));

		}

		CloseHandle(snapshot);

	}

}