예제 #1
0
ESteamProcessSearchError GetSteamProcessID( HWND hWindow, LPSTR lpszCommandLine, int * piSteamProcessID )
{
	int iNumProcesses;
	if ( strlen( lpszCommandLine ) == 0 )
	{
		*piSteamProcessID = FindSteamProcessID();
		if ( *piSteamProcessID <= 0 )
		{
			return k_ESteamProcessSearchErrorCouldNotFindSteam;
		}
	}
	else if ( !TryParseInt( lpszCommandLine, piSteamProcessID ) )
	{
		if ( !FindProcessByName( lpszCommandLine, piSteamProcessID, &iNumProcesses ) )
		{
			return k_ESteamProcessSearchErrorCouldNotFindProcessWithSuppliedName;
		}
		else if ( iNumProcesses > 1 )
		{
			return k_ESteamProcessSearchErrorFoundMultipleProcessesWithSuppliedName;
		}
	}
	
	if ( !ProcessHasModuleLoaded( *piSteamProcessID, "steamclient.dll", /* bPartialMatchFromEnd */ true ) )
	{
		return k_ESteamProcessSearchErrorTargetProcessDoesNotHaveSteamClientDllLoaded;
	}

	return k_ESteamProcessSearchErrorNone;
}
예제 #2
0
//
// Process Helpers
//
int FindSteamProcessID()
{
	int iSteamProcessID = 0;
	int iNumProcesses = 0;

	if (FindProcessByName("steam.exe", &iSteamProcessID, &iNumProcesses) && iNumProcesses == 1)
	{
		return iSteamProcessID;
	}

	return -1;
}
예제 #3
0
bool Util::DarkRadiantIsRunning()
{
	// DarkRadiant isn't existing in Mac so far
	return FindProcessByName("DarkRadiant");
}
예제 #4
0
bool Util::TDMIsRunning()
{
	return FindProcessByName("thedarkmod"); // grayman - look for TDM instead of "Doom 3".
}
예제 #5
0
bool Util::caesariaIsRunning()
{
	return FindProcessByName("caesaria.macosx"); // grayman - look for caesaria
}
예제 #6
0
int main(int argc, char * argv[])
{
    kern_return_t       err;
    bool                verbose;
    int                 ch;
    int                 argIndex;

    // Set gProgramName to the last path component of argv[0]

    gProgramName = strrchr(argv[0], '/');
    if (gProgramName == NULL) {
        gProgramName = argv[0];
    } else {
        gProgramName += 1;
    }

    // Parse our options.

    verbose = false;
    do {
        ch = getopt(argc, argv, "w");
        if (ch != -1) {
            switch (ch) {
            case 'w':
                verbose = true;
                break;
            case '?':
            default:
                PrintUsage();
                exit(EXIT_FAILURE);
                break;
            }
        }
    } while (ch != -1);

    // Handle the remaining arguments.  If none, we work against ourselves.
    // Otherwise each string is treated as a process name, and we look that
    // up using FindProcessByName.

    if (argv[optind] == NULL) {
        err = PrintProcessPortSpace(getpid(), verbose);
    } else {
        for (argIndex = optind; argIndex < argc; argIndex++) {
            pid_t   pid;

            if (argIndex > optind) {
                fprintf(stdout, "\n");
            }
            if (argv[argIndex][0] == 0) {
                err = EINVAL;
            } else {
                err = FindProcessByName(argv[argIndex], &pid);
            }
            if (err == 0) {
                fprintf(stdout, "Mach ports for '%s' (%lld):\n", argv[argIndex], (long long) pid);
                fprintf(stdout, "\n");

                err = PrintProcessPortSpace(pid, verbose);
            }

            if (err != 0) {
                break;
            }
        }
    }

    if (err != 0) {
        fprintf(stderr, "%s: Failed with error %d.\n", gProgramName, err);
    }
    return (err == 0) ? EXIT_SUCCESS : EXIT_FAILURE;
}
예제 #7
0
파일: BoykaMonitor.cpp 프로젝트: BwRy/Boyka
int
main(int argc, char *argv[])
{
	HANDLE hThisProcess = 0;
	BOYKAPROCESSINFO bpiMon;

	if(argc < 3)
	{
		printf("Usage: %s <server process name> <console IP>\n", argv[0]);
		return 1;
	}
	
	char *serverExeName = argv[1];
	char *ipConsole = argv[2];

	/////////////////////////////////////////////////////////////////////////////////////
	// Change our privileges. We need to OpenProcess() with OPEN_ALL_ACCESS
	// in order to be able to debug another process.
	/////////////////////////////////////////////////////////////////////////////////////

	if(!OpenProcessToken(
			GetCurrentProcess(),	// handle
			TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY,
			&hThisProcess
			))
		{
			printf("[Debug - PrivEsc] Error (OpenProcessToken)\n");
			DisplayError();
			return 1;
		}


	if(SetPrivilege(hThisProcess, SE_DEBUG_NAME, TRUE))
		printf("[Debug - PrivEsc] Successfully set SeDebugPrivilege :)\n");
	else {
		printf("[Debug - PrivEsc] Unable to set SeDebugPrivilege :(\n");
		DisplayError();
		return 1;
	}

	
	// This snippet must be here (after Priv Escalation) since
	// it tries to get an ALL_ACCESS handle to the process.

	// Find the process (command line argument)
	bpiMon = FindProcessByName(serverExeName);
	if(bpiMon.Pid == 0)
	{
		printf("\n[debug] Process %s NOT found. Is it running?\n", serverExeName);
		return 1;
	}



	/////////////////////////////////////////////////////////////////////////////////////
	// Here starts the action :)
	/////////////////////////////////////////////////////////////////////////////////////
	
	// If I'm attaching to the process at this point, I guess this is a good state 
	// to go back if everything gets all f****d up (access violation, for example)
	int iSaveProc = SaveProcessState(bpiMon.Pid);
	if(iSaveProc != DBG_CONTINUE)
	{
		printf("[debug] Unable to snapshot the program state :(\n");
		printf("[debug] This is FATAL. Aborting...\n");
		return(1);
	}
	else 
	{
		printf("[debug] Saved process state :)\n");
	}


	/* Winsock initialization */
	WSADATA		wsd;
	SOCKET sockMon = INVALID_SOCKET;

	if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0)
	{
		printf("[debug] Error: Can't load WinSock");
		WSACleanup();
		return 1;
	}

	
	/* Establish a TCP connection back to the Console module */

	SOCKADDR_IN toConsole;

	toConsole.sin_family = AF_INET;
	toConsole.sin_port = htons(1337);
	toConsole.sin_addr.s_addr = inet_addr(ipConsole);

	sockMon = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(sockMon == INVALID_SOCKET)
	{
		printf("[debug] Couldn't create the socket to Console.\n");
		DisplayError();
		WSACleanup();
		return 1;
	}

	// Try to connect...
	int iConRes = connect(sockMon, (SOCKADDR *)&toConsole, sizeof(toConsole));
	if(iConRes == SOCKET_ERROR)
	{
		printf("[debug] Unable to CONNECT to the Console (%s).\n", ipConsole);
		closesocket(sockMon);
		WSACleanup();
		return 1;
	}
	else
		printf("[debug] SUCCESSFULLY CONNECTED to the Console (%s).\n", ipConsole);
	

	// Let's send a test string
	char *sendbuf = "Connection to console established!";
	int iResSend = send(sockMon, sendbuf, (int)strlen(sendbuf), 0);
	if(iResSend == SOCKET_ERROR)
	{
		printf("Send() failed...\n");
		DisplayError();
	}


	/////////////////////////////////////////////////////////////////////////////////////
	// NOTE: Let's do some tests without threads for the moment.
	/////////////////////////////////////////////////////////////////////////////////////
	
		
	// Attach to the process
	BOOL bAttach = DebugActiveProcess(bpiMon.Pid);
	if(bAttach == 0) {
		printf("[Debug] Couldn't attach to %s. ErrCode: %u\n", bpiMon.szExeName, GetLastError());
		ExitProcess(1);
	} else {
		printf("[Debug] Attached to %s!\n", bpiMon.szExeName);
	}


	DEBUG_EVENT de;
	DWORD dwContinueStatus = 0;
	unsigned int lav, lso;
	char msgAV[] = "Access violation detected!";
	char msgSO[] = "Stack overflow detected!";


	while(1)
	{
		WaitForDebugEvent(&de, INFINITE);

		switch (de.dwDebugEventCode)
		{
		case EXCEPTION_DEBUG_EVENT:
			switch(de.u.Exception.ExceptionRecord.ExceptionCode)
			{
			case EXCEPTION_ACCESS_VIOLATION:
				// TODO: Maybe consolidate all this logging callbacks using OOP:
				//		 inherit from Exception Logging object or something like that
				lav = LogExceptionAccessViolation(bpiMon);
				CommunicateToConsole(sockMon, msgAV);
				WriteMiniDumpFile(&de);
				// RestoreProcessState(bpiMon.Pid);
				return 0;

				dwContinueStatus = DBG_CONTINUE;
				break;
			case EXCEPTION_STACK_OVERFLOW:
				// This is in response to a Stack Exhaustion ;)
				lso = LogExceptionStackOverflow(bpiMon);
				CommunicateToConsole(sockMon, msgSO);
				WriteMiniDumpFile(&de);
				// RestoreProcessState(bpiMon.Pid);
				return 0;

				dwContinueStatus = DBG_CONTINUE;
				break;

			default:	/* unhandled exception */
				dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
				break;
			}
			break;

		// I'm only interested in exceptions. The rest won't be processed (for now)
		default:
			dwContinueStatus = DBG_EXCEPTION_NOT_HANDLED;
			break;
		}

		ContinueDebugEvent(de.dwProcessId, de.dwThreadId, dwContinueStatus);
	}

	return 0;
}