Beispiel #1
0
/*
 * doAutoAttatch
 */
static void doAutoAttatch( void ) {

    ProcList            info;
    ProcPlace           place;
    BOOL                rc;
    DWORD               newpid[ MAX_NEW_PROC ];
    DWORD               pidcnt;

    pidcnt = 0;
    rc = GetNextProcess( &info, &place, TRUE );
    while( rc ) {
        if( FindProcess( info.pid ) == NULL ) {
            if( !dontAttatch( info.pid ) ) {
                newpid[ pidcnt ] = info.pid;
                pidcnt++;
                if( pidcnt == MAX_NEW_PROC ) {
                    /* we need to finish the walk in order to leave
                       semaphores in the right state */
                    while( GetNextProcess( &info, &place, FALSE ) );
                    break;
                }
            }
        }
        rc = GetNextProcess( &info, &place, FALSE );
    }
    if( pidcnt > 0 ) {
        for( ;; ) {
            pidcnt --;
            CallProcCtl( MENU_ADD_RUNNING, newpid + pidcnt, ErrAdding );
            if( pidcnt == 0 ) break;
        }
    }
}
bool ProcessHelper::GetProcessPSN(const QString& path, ProcessSerialNumber& psn) {
    psn.highLongOfPSN = kNoProcess;
    psn.lowLongOfPSN = kNoProcess;

    char buffer[400];
    CFStringRef key = CFSTR("CFBundleExecutable");

    OSStatus status = GetNextProcess(&psn);
    while (status == 0){
        CFDictionaryRef processInfoDict =
            ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);

        CFStringRef value = (CFStringRef) CFDictionaryGetValue(processInfoDict, key);

        CFIndex length = CFStringGetLength(value);
        CFIndex maxSize =
            CFStringGetMaximumSizeForEncoding(length, kCFStringEncodingUTF8);
        CFStringGetCString(value, buffer, maxSize, kCFStringEncodingUTF8);

        QString curBundle;
        curBundle += buffer;
        if (path.compare(curBundle) == 0)
            return true;

        status = GetNextProcess(&psn);
    }

    return false;
}
COSXScreenSaver::COSXScreenSaver(void* eventTarget) :
	m_eventTarget(eventTarget),
	m_enabled(true)
{
	m_autoReleasePool       = screenSaverUtilCreatePool();
	m_screenSaverController = screenSaverUtilCreateController();

	// install launch/termination event handlers
	EventTypeSpec launchEventTypes[2];
	launchEventTypes[0].eventClass = kEventClassApplication;
	launchEventTypes[0].eventKind  = kEventAppLaunched;
	launchEventTypes[1].eventClass = kEventClassApplication;
	launchEventTypes[1].eventKind  = kEventAppTerminated;
	
	EventHandlerUPP launchTerminationEventHandler =
		NewEventHandlerUPP(launchTerminationCallback);
	InstallApplicationEventHandler(launchTerminationEventHandler, 2,
								launchEventTypes, this,
								&m_launchTerminationEventHandlerRef);
	DisposeEventHandlerUPP(launchTerminationEventHandler);
	
	m_screenSaverPSN.highLongOfPSN = 0;
	m_screenSaverPSN.lowLongOfPSN  = 0;

	// test if screensaver is running and find process number
	if (isActive()) {
		ProcessInfoRec	procInfo;
		Str31			procName;	// pascal string. first byte holds length.
		memset(&procInfo, 0, sizeof(procInfo));
		procInfo.processName       = procName;
		procInfo.processInfoLength = sizeof(ProcessInfoRec);

		ProcessSerialNumber	psn;
		OSErr err = GetNextProcess(&psn);
		while (err == 0) {
			memset(procName, 0, sizeof(procName));
			err = GetProcessInformation(&psn, &procInfo);
			if (err != 0) {
				break;
			}
			if (strcmp("ScreenSaverEngine", (const char*)&procName[1]) == 0) {
				m_screenSaverPSN = psn;
				break;
			}
			err = GetNextProcess(&psn);
		}
	}
}
static OSStatus FindSystemEvents(ProcessSerialNumber *psnPtr)
	// Finds the "System Events" process or, if it's not 
	// running, launches it.
{
	OSStatus		err;
	Boolean			found = false;
	ProcessInfoRec	info;
	
	assert(psnPtr != NULL);

	psnPtr->lowLongOfPSN	= kNoProcess;
	psnPtr->highLongOfPSN	= kNoProcess;

	do {
		err = GetNextProcess(psnPtr);
		if (err == noErr) {	
			memset(&info, 0, sizeof(info));
			err = GetProcessInformation(psnPtr, &info);
		}
		if (err == noErr) {
			found = (info.processSignature == kSystemEventsCreator);
		}
	} while ( (err == noErr) && ! found );

	if (err == procNotFound) {
		err = LaunchSystemEvents(psnPtr);
	}
	return err;
}
Beispiel #5
0
/*
 * InitAutoAttatch
 */
void InitAutoAttatch( void ) {

    ProcList            info;
    ProcPlace           place;
    BOOL                rc;
//    DWORD             threadid;

    RefreshInfo();
    rc = GetNextProcess( &info, &place, TRUE );
    while( rc ) {
        addDontAttatch( info.pid );
        rc = GetNextProcess( &info, &place, FALSE );
    }
//    CreateThread( NULL, 0, AutoAttatchMain, 0, 0, &threadid );
    _beginthread( AutoAttatchMain, 0, 0 );
}
Beispiel #6
0
OSErr
FindProcessBySignature(
					   OSType				type,
					   OSType				creator,
					   ProcessSerialNumber	*psn )
{
    ProcessSerialNumber tempPSN = { 0, kNoProcess };
    ProcessInfoRec procInfo = {0};
    OSErr err = noErr;
    
    procInfo.processInfoLength = sizeof( ProcessInfoRec );
    procInfo.processName = nil;
    //procInfo.processAppSpec = nil;
    
    while( !err ) {
        err = GetNextProcess( &tempPSN );
        if( !err )
            err = GetProcessInformation( &tempPSN, &procInfo );
        if( !err
		   && procInfo.processType == type
		   && procInfo.processSignature == creator ) {
            *psn = tempPSN;
            return noErr;
        }
    }
    
    return err;
}
Beispiel #7
0
static Boolean appRunning (OSType appid) {
	
	/*
	return true if the server application is running. 
	*/
	
	ProcessInfoRec info;
	ProcessSerialNumber psn;
	Str255 bsname;
	FSSpec fss;
	
	info.processInfoLength = sizeof (info);
	
	info.processName = bsname; /*place to store process name*/
	
	info.processAppSpec = &fss; /*place to store process filespec*/
	
	psn.highLongOfPSN = kNoProcess;
	
	psn.lowLongOfPSN = kNoProcess;
	
	while (GetNextProcess (&psn) == noErr) {
		
	 	info.processInfoLength = sizeof (ProcessInfoRec);
	 	
		if (GetProcessInformation (&psn, &info) != noErr)
			continue; /*keep going -- ignore error*/
		
		if (info.processSignature == appid)
			return (true);
		} /*while*/
	
	return (false); /*loop completed, no server*/
	} /*appRunning*/
Beispiel #8
0
// ---------------------------------------------------------------------------
OSErr FindProcess (OSType typeToFind, OSType creatorToFind, ProcessSerialNumberPtr processSN)
{
    ProcessInfoRec tempInfo;
    FSSpec procSpec;
    Str31 processName;
    OSErr myErr = noErr;
    /* null out the PSN so we're starting at the beginning of the list */
    processSN->lowLongOfPSN = kNoProcess;
    processSN->highLongOfPSN = kNoProcess;
    /* initialize the process information record */
    tempInfo.processInfoLength = sizeof(ProcessInfoRec);
    tempInfo.processName = processName;
    tempInfo.processAppSpec = &procSpec;
    /* loop through all the processes until we */
    /* 1) find the process we want */
    /* 2) error out because of some reason (usually, no more processes) */
    do {
        myErr = GetNextProcess(processSN);
        if (myErr == noErr)
            GetProcessInformation(processSN, &tempInfo);
    }
            while ((tempInfo.processSignature != creatorToFind || tempInfo.processType != typeToFind) &&
                   myErr == noErr);
    return(myErr);
}
Beispiel #9
0
static void logProcessList( void ) {

    ProcList    info;
    ProcPlace   place;
    BOOL        rc;

    RefreshInfo();
    logPrintf( STR_CURRENT_PROCESSES );
    rc = GetNextProcess( &info, &place, TRUE );
    while( rc ) {
        logStrPrintf( "%*s%08lX %s\n", INDENT, "", info.pid, info.name );
        if( LogData.log_modules ) {
            logModules( info.pid, INDENT + 9 );
        }
        rc = GetNextProcess( &info, &place, FALSE );
    }
}
Beispiel #10
0
ProcessSerialNumber WBProcessGetProcessWithSignature(OSType type) {
  ProcessSerialNumber serialNumber = {kNoProcess, kNoProcess};
  if (type) {
    while (procNotFound != GetNextProcess(&serialNumber))  {
      if (WBProcessGetSignature(&serialNumber) == type) {
        break;
      }
    }
  }
  return serialNumber;
}
Beispiel #11
0
void list_open_applications()
{
	OSStatus status;
    ProcessSerialNumber currentProcessPSN = {kNoProcess, kNoProcess};

	status = GetNextProcess(&currentProcessPSN);
	while (status == noErr) {
		CFStringRef processName = NULL;
		char name[32];
		
		status = CopyProcessName(&currentProcessPSN, &processName);
		if (status != noErr)
			die("CopyProcessName failed");
		if (NULL == processName)
			die("CopyProcessName succeeded, but the process name is NULL!");
			
		CFStringGetCString(processName, &name[0], 32, kCFStringEncodingUTF8);
		printf("{ 0x%x, 0x%08x }  %s\n",
			currentProcessPSN.highLongOfPSN, currentProcessPSN.lowLongOfPSN,
			&name);
		
		status = GetNextProcess(&currentProcessPSN);
	}
}
void
getProcessSerialNumber(const char* name, ProcessSerialNumber& psn)
{
	ProcessInfoRec procInfo;
	Str31 procName;	// pascal string. first byte holds length.
	memset(&procInfo, 0, sizeof(procInfo));
	procInfo.processName = procName;
	procInfo.processInfoLength = sizeof(ProcessInfoRec);

	ProcessSerialNumber	checkPsn;
	OSErr err = GetNextProcess(&checkPsn);
	while (err == 0) {
		memset(procName, 0, sizeof(procName));
		err = GetProcessInformation(&checkPsn, &procInfo);
		if (err != 0) {
			break;
		}
		if (strcmp(name, (const char*)&procName[1]) == 0) {
			psn = checkPsn;
			break;
		}
		err = GetNextProcess(&checkPsn);
	}
}
Beispiel #13
0
static void noise_get_processes(void (*func) (void *, int))
{
    ProcessSerialNumber psn = {0, kNoProcess};
    ProcessInfoRec info;

    for (;;) {
        GetNextProcess(&psn);
        if (psn.highLongOfPSN == 0 && psn.lowLongOfPSN == kNoProcess) return;
        info.processInfoLength = sizeof(info);
        info.processName = NULL;
        info.processAppSpec = NULL;
        GetProcessInformation(&psn, &info);
        func(&info, sizeof(info));
    }
}
Beispiel #14
0
bool application_is_open(CFStringRef appName, ProcessSerialNumber *psn)
{
	OSStatus status;
    ProcessSerialNumber currentProcessPSN = {kNoProcess, kNoProcess};

	status = GetNextProcess(&currentProcessPSN);
	while (status == noErr) {
		CFStringRef processName = NULL;
		
		status = CopyProcessName(&currentProcessPSN, &processName);
		if (status != noErr)
			die("CopyProcessName failed");
		if (NULL == processName)
			die("CopyProcessName succeeded, but the process name is NULL!");
			
		if (kCFCompareEqualTo == CFStringCompare(processName, appName, 0))
		{
			memcpy(psn, &currentProcessPSN, sizeof(*psn));
			return TRUE;
		}
		status = GetNextProcess(&currentProcessPSN);
	}
	return FALSE;
}
Beispiel #15
0
ProcessSerialNumber WBProcessGetProcessWithProperty(CFStringRef property, CFPropertyListRef value) {
  ProcessSerialNumber serialNumber = {kNoProcess, kNoProcess};
  if (!value)
    return serialNumber;

  while (procNotFound != GetNextProcess(&serialNumber))  {
    CFDictionaryRef info = ProcessInformationCopyDictionary(&serialNumber, (UInt32)kProcessDictionaryIncludeAllInformationMask);
    if (info) {
      CFPropertyListRef procValue = CFDictionaryGetValue(info, property);
      if (procValue && (CFEqual(procValue, value))) {
        CFRelease(info);
        break;
      }
      CFRelease(info);
    }
  }
  return serialNumber;
}
int
IsSkypeRunning(void)
{
	OSStatus status = noErr;
	ProcessSerialNumber psn = {kNoProcess, kNoProcess};
	unsigned int procNameLength = 32;
	unsigned char procName[procNameLength];
	unsigned int i = 0;
	ProcessInfoRec info;
	info.processInfoLength = sizeof(ProcessInfoRec);
	info.processName = procName;
#if __LP64__
	info.processAppRef = NULL;
#else
	info.processAppSpec = NULL;
#endif
	pid_t pid = 0;
	
	while(status == noErr)
	{
		for(i = 0; i < procNameLength; i++)
			procName[i] = '\0';
		
		status = GetNextProcess(&psn);
		if (status == noErr)
		{
			if (GetProcessInformation(&psn, &info) == noErr)
			{
				//for some reason first character is poisioned
				if (g_str_equal((char *)&procName[1], "Skype"))
				{
					if (GetProcessPID(&psn, &pid) == noErr)
					{
						return (int)pid;
					}
				}
			}
		}
	}
	return 0;
}
Beispiel #17
0
OSStatus FindPIDForWoW(pid_t *pid) {
    CFURLRef outAppURL;
    OSErr err;
	err = LSFindApplicationForInfo(NULL,
								   (CFStringRef)@"com.blizzard.worldofwarcraft",
								   NULL,
								   NULL,
								   &outAppURL);
    err = 0;
	FSRef desired, found;
	ProcessSerialNumber psn = {0, kNoProcess};
    
	if (!CFURLGetFSRef(outAppURL, &desired)) return errFSBadFSRef;
	do {
		err = GetNextProcess(&psn);
		if (err) return err; // -600 = process not found
		err = GetProcessBundleLocation(&psn, &found);
	} while (err || FSCompareFSRefs(&desired, &found));
	err = GetProcessPID(&psn, pid);
	if (err) return err;
	return noErr;
}
Beispiel #18
0
// Finds the "System Events" process or, if it's not running, launches it.
static
OSStatus WBFindSystemEvents(ProcessSerialNumber *psnPtr) {
  if (!psnPtr) return paramErr;

  psnPtr->lowLongOfPSN	= kNoProcess;
  psnPtr->highLongOfPSN	= kNoProcess;

  OSStatus err;
  Boolean found = false;
  do {
    err = GetNextProcess(psnPtr);
    if (err == noErr) {
      ProcessInfoRec info = { .processInfoLength = 0 };
      err = GetProcessInformation(psnPtr, &info);
      if (err == noErr)
        found = (info.processSignature == kSystemEventsCreator);
    }
  } while ( (err == noErr) && !found );

  if (err == procNotFound)
    err = WBLaunchSystemEvents(psnPtr);
  return err;
}
Beispiel #19
0
pascal OSStatus MoreProcFindProcessByCreator(const OSType pCreator,ProcessSerialNumber *pPSN)
{
	OSStatus anErr = noErr;

	if (!(MoreAssert (pPSN)))
		anErr = paramErr;
	else
	{
		pPSN->lowLongOfPSN	= kNoProcess;
		pPSN->highLongOfPSN	= kNoProcess;

		while (!(anErr = GetNextProcess (pPSN)))
		{
			ProcessInfoRec pir;

			if (!(anErr = MoreProcGetProcessInformation (pPSN,&pir)))
				if (pCreator == pir.processSignature)
					break;
		}
	}

	return anErr;
}
Beispiel #20
0
static PyObject *AE_PSNDescForApplicationPath(PyObject* self, PyObject* args)
{
	ProcessSerialNumber psn = {0, kNoProcess};
	FSRef appRef, foundRef;
	AEDesc result;
	OSStatus err;
	
	if (!PyArg_ParseTuple(args, "O&", 
								AE_GetFSRef, &appRef))
		return NULL;
	while (1) {
		err = GetNextProcess(&psn);
		if (err) return AE_MacOSError(err);
		err = GetProcessBundleLocation(&psn, &foundRef);
		if (err == noErr && FSCompareFSRefs(&appRef, &foundRef) == noErr) break;
	}
	err = AECreateDesc(typeProcessSerialNumber,
	                   &psn, sizeof(psn),
	                   &result);
	if (err != noErr) return AE_MacOSError(err);
	return Py_BuildValue("O&",
	                     AE_AEDesc_New, &result);
}
Beispiel #21
0
/** Check if a process with a given name is running
 *  @param names list of names to filter on. All processes if empty list.
 *  @return list of processname, process ID pairs.
 */
QMap<QString, QList<int> > Utils::findRunningProcess(QStringList names)
{
    QMap<QString, QList<int> > processlist;
    QMap<QString, QList<int> > found;
#if defined(Q_OS_WIN32)
    HANDLE hdl;
    PROCESSENTRY32 entry;
    bool result;

    hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hdl == INVALID_HANDLE_VALUE) {
        LOG_ERROR() << "CreateToolhelp32Snapshot failed.";
        return found;
    }
    entry.dwSize = sizeof(PROCESSENTRY32);
    entry.szExeFile[0] = '\0';
    if(!Process32First(hdl, &entry)) {
        LOG_ERROR() << "Process32First failed.";
        return found;
    }

    do {
        int pid = entry.th32ProcessID;  // FIXME: DWORD vs int!
        QString name = QString::fromWCharArray(entry.szExeFile);
        if(processlist.find(name) == processlist.end()) {
            processlist.insert(name, QList<int>());
        }
        processlist[name].append(pid);
        entry.dwSize = sizeof(PROCESSENTRY32);
        entry.szExeFile[0] = '\0';
        result = Process32Next(hdl, &entry);
    } while(result);
    CloseHandle(hdl);
#endif
#if defined(Q_OS_MACX)
    ProcessSerialNumber psn = { 0, kNoProcess };
    OSErr err;
    do {
        pid_t pid;
        err = GetNextProcess(&psn);
        err = GetProcessPID(&psn, &pid);
        if(err == noErr) {
            char buf[32] = {0};
            ProcessInfoRec info;
            memset(&info, 0, sizeof(ProcessInfoRec));
            info.processName = (unsigned char*)buf;
            info.processInfoLength = sizeof(ProcessInfoRec);
            err = GetProcessInformation(&psn, &info);
            if(err == noErr) {
                // some processes start with nonprintable characters. Skip those.
                int i;
                for(i = 0; i < 32; i++) {
                    if(isprint(buf[i])) break;
                }
                // avoid adding duplicates.
                QString name = QString::fromUtf8(&buf[i]);
                if(processlist.find(name) == processlist.end()) {
                    processlist.insert(name, QList<int>());
                }
                processlist[name].append(pid);
            }
        }
    } while(err == noErr);
#endif
#if defined(Q_OS_LINUX)
    // not implemented for Linux!
#endif
    //  Filter for names (unless empty)
    if(names.size() > 0) {
        for(int i = 0; i < names.size(); ++i) {
            QStringList k(processlist.keys());
#if defined(Q_OS_WIN32)
            // the process name might be truncated. Allow the extension to be partial.
            int index = k.indexOf(QRegExp(names.at(i) + "(\\.(e(x(e?)?)?)?)?",
                                          Qt::CaseInsensitive));
#else
            int index = k.indexOf(names.at(i));
#endif
            if(index != -1) {
                found.insert(k[index], processlist[k[index]]);
            }
        }
    }
    else {
        found = processlist;
    }
    LOG_INFO() << "Looking for processes" << names << "found" << found;
    return found;
}
Beispiel #22
0
void slowPoll( void )
	{
	RANDOM_STATE randomState;
	BYTE buffer[ RANDOM_BUFSIZE + 8 ];
	ProcessSerialNumber psn;
	GDHandle deviceHandle;
	GrafPtr currPort;
	QElemPtr queuePtr;
	QHdrPtr queueHdr;
	static BOOLEAN addedFixedItems = FALSE;

	initRandomData( randomState, buffer, RANDOM_BUFSIZE );

	/* Walk through the list of graphics devices adding information about
	   a device (IM VI 21-21) */
	deviceHandle = GetDeviceList();
	while( deviceHandle != NULL )
		{
		GDHandle currentHandle = deviceHandle;
		GDPtr devicePtr;

		HLock( ( Handle ) currentHandle );
		devicePtr = *currentHandle;
		deviceHandle = devicePtr->gdNextGD;
		addRandomData( randomState, devicePtr, sizeof( GDevice ) );
		HUnlock( ( Handle ) currentHandle );
		}

	/* Walk through the list of processes adding information about each
	   process, including the name and serial number of the process, file and
	   resource information, memory usage information, the name of the
	   launching process, launch time, and accumulated CPU time (IM VI 29-17) */
	psn.highLongOfPSN = 0;
	psn.lowLongOfPSN = kNoProcess;
	while( !GetNextProcess( &psn ) )
		{
		ProcessInfoRec infoRec;
		GetProcessInformation( &psn, &infoRec );
		addRandomData( randomState, &infoRec, sizeof( ProcessInfoRec ) );
		}

	/* Get the command type, trap address, and parameters for all commands in
	   the file I/O queue.  The parameters are quite complex and are listed
	   on page 117 of IM IV, and include reference numbers, attributes, time
	   stamps, length and file allocation information, finder info, and large
	   amounts of other volume and filesystem-related data */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
	if( ( queueHdr = GetFSQHdr() ) != NULL )
		queuePtr = queueHdr->qHead;
		while( queuePtr != NULL )
			{
			/* The queue entries are variant records of variable length so we
			   need to adjust the length parameter depending on the record
			   type */
			addRandomData( randomState, queuePtr, 32 ); /* dunno how big.. */
			queuePtr = queuePtr->qLink;
			}
#endif
	/* The following are fixed for the lifetime of the process so we only
	   add them once */
	if( !addedFixedItems )
		{
		Str255 appName, volName;
		GDHandle deviceHandle;
		Handle appHandle;
		DrvSts driveStatus;
		MachineLocation machineLocation;
		ProcessInfoRec processInfo;
		QHdrPtr vblQueue;
		SysEnvRec sysEnvirons;
		SysPPtr pramPtr;
		DefStartRec startupInfo;
		DefVideoRec videoInfo;
		DefOSRec osInfo;
		XPPParamBlock appleTalkParams;
		unsigned char *driverNames[] = {
			"\p.AIn", "\p.AOut", "\p.AppleCD", "\p.ATP", "\p.BIn", "\p.BOut", "\p.MPP",
			"\p.Print", "\p.Sony", "\p.Sound", "\p.XPP", NULL
			};
		SInt16 count, dummy, i, node, net, vRefNum, script;
		SInt32 lcount, volume;

		/* Get the current font family ID, node ID of the local AppleMumble
		   router, caret blink delay, CPU speed, double-click delay, sound
		   volume, application and system heap zone, the number of resource
		   types in the application, the number of sounds voices available,
		   the FRef of the current resource file, volume of the sysbeep,
		   primary line direction, computer SCSI disk mode ID, timeout before
		   the screen is dimmed and before the computer is put to sleep,
		   number of available threads in the thread pool, whether hard drive
		   spin-down is disabled, the handle to the i18n resources, timeout
		   time for the internal HDD, */
		addRandomValue( randomState, GetAppFont() );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		addRandomValue( randomState, GetBridgeAddress() );
#endif
		addRandomValue( randomState, GetCaretTime() );
/*		addRandomValue( randomState, GetCPUSpeed() ); */
		addRandomValue( randomState, GetDblTime() );
		GetSysBeepVolume( &volume );
		addRandomValue( randomState, volume );
		GetDefaultOutputVolume( &volume );
		addRandomValue( randomState, volume );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		addRandomValue( randomState, ApplicationZone() );
		addRandomValue( randomState, SystemZone() );
#endif
		addRandomValue( randomState, CountTypes() );
/*		CountVoices( &count ); ** seems to crash
		addRandomValue( randomState, count ); */
		addRandomValue( randomState, CurResFile() );
		GetSysBeepVolume( &lcount );
		addRandomValue( randomState, lcount );
		addRandomValue( randomState, GetSysDirection() );
/*		addRandomValue( randomState, GetSCSIDiskModeAddress() );
		addRandomValue( randomState, GetDimmingTimeout() );
		addRandomValue( randomState, GetSleepTimeout() ); */
		GetFreeThreadCount( kCooperativeThread, &count );
		addRandomValue( randomState, count );
/*		addRandomValue( randomState, IsSpindownDisabled() ); */
		addRandomValue( randomState, GetIntlResource( 0 ) );
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetTimeout( &count );
		addRandomValue( randomState, count );
#endif

		/* Get the number of documents/files which were selected when the app
		   started and for each document get the vRefNum, name, type, and
		   version -- OBSOLETE
		CountAppFiles( &dummy, &count );
		addRandomValue( randomState, count );
		while( count > 0 )
			{
			AppFile theFile;
			GetAppFiles( count, &theFile );
			addRandomData( randomState, &theFile, sizeof( AppFile ) );
			count--;
			} */

		/* Get the app's name, resource file reference number, and handle to
		   the finder information -- OBSOLETE
		GetAppParams( appName, appHandle, &count );
		addRandomData( randomState, appName, sizeof( Str255 ) );
		addRandomValue( randomState, appHandle );
		addRandomValue( randomState, count ); */

		/* Get all sorts of statistics such as physical information, disk and
		   write-protect present status, error status, and handler queue
		   information, on floppy drives attached to the system.  Also get
		   the volume name, volume reference number and number of bytes free,
		   for the volume in the drive */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !DriveStatus( 1, &driveStatus ) )
			addRandomData( randomState, &driveStatus, sizeof (DrvSts) );
#endif
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !GetVInfo( 1, volName, &vRefNum, &lcount ) )
			{
			addRandomData( randomState, volName, sizeof( Str255 ) );
			addRandomValue( randomState, vRefNum );
			addRandomValue( randomState, lcount );
			}
#endif
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !DriveStatus( 2, &driveStatus ) )
			addRandomData( randomState, &driveStatus, sizeof (DrvSts) );
#endif
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( !GetVInfo( 2, volName, &vRefNum, &lcount ) )
			{
			addRandomData( randomState, volName, sizeof( Str255 ) );
			addRandomValue( randomState, vRefNum );
			addRandomValue( randomState, lcount );
			}
#endif
		/* Get information on the head and tail of the vertical retrace
		   queue */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( ( vblQueue = GetVBLQHdr() ) != NULL )
			addRandomData( randomState, vblQueue, sizeof( QHdr ) );
#endif
		/* Get the parameter RAM settings */
		pramPtr = GetSysPPtr();
		addRandomData( randomState, pramPtr, sizeof( SysParmType ) );

		/* Get information about the machines geographic location */
		ReadLocation( &machineLocation );
		addRandomData( randomState, &machineLocation,
					   sizeof( MachineLocation ) );

		/* Get information on current graphics devices including device
		   information such as dimensions and cursor information, and a
		   number of handles to device-related data blocks and functions, and
		   information about the dimentions and contents of the devices pixel
		   image as well as the images resolution, storage format, depth, and
		   colour usage */
		deviceHandle = GetDeviceList();
		do
			{
			GDPtr gdPtr;

			addRandomValue( randomState, deviceHandle );
			HLock( ( Handle ) deviceHandle );
			gdPtr = ( GDPtr ) *deviceHandle;
			addRandomData( randomState, gdPtr, sizeof( GDevice ) );
			addRandomData( randomState, gdPtr->gdPMap, sizeof( PixMap ) );
			HUnlock( ( Handle ) deviceHandle );
			}
		while( ( deviceHandle = GetNextDevice( deviceHandle ) ) != NULL );

		/* Get the current system environment, including the machine and
		   system software type, the keyboard type, where there's a colour
		   display attached, the AppleTalk driver version, and the VRefNum of
		   the system folder */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		SysEnvirons( curSysEnvVers, &sysEnvirons );
		addRandomData( randomState, &sysEnvirons, sizeof( SysEnvRec ) );
#endif

		/* Get the AppleTalk node ID and network number for this machine */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( GetNodeAddress( &node, &net ) )
			{
			addRandomValue( randomState, node );
			addRandomValue( randomState, net );
			}
#endif
		/* Get information on each device connected to the ADB including the
		   device handler ID, the devices ADB address, and the address of the
		   devices handler and storage area */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		count = CountADBs();
		while( count-- > 0 )
			{
			ADBDataBlock adbInfo;

			GetIndADB( &adbInfo, count );
			addRandomData( randomState, &adbInfo, sizeof( ADBDataBlock ) );
			}
#endif
		/* Open the most common device types and get the general device
		   status information and (if possible) device-specific status.  The
		   general device information contains the device handle and flags,
		   I/O queue information, event information, and other driver-related
		   details */

/* Try something like this again.. and ur a dead man, Peter ;-)
      -xmath */

/*		for( count = 0; driverNames[ count ] != NULL; count++ )
			{
			AuxDCEHandle dceHandle;
			short driverRefNum;

			** Try and open the driver **
			if( OpenDriver( driverNames[ count ], &driverRefNum ) )
				continue;

			** Get a handle to the driver control information (this could
			   also be done with GetDCtlHandle()) **
			Status( driverRefNum, 1, &dceHandle );
			HLock( dceHandle );
			addRandomData( randomState, *dceHandle,
							 sizeof( AuxDCE ) );
			HUnlock( dceHandle );
			CloseDriver( driverRefNum );
			} */

		/* Get the name and volume reference number for the current volume */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetVol( volName, &vRefNum );
		addRandomData( randomState, volName, sizeof( Str255 ) );
		addRandomValue( randomState, vRefNum );
#endif
		/* Get the time information, attributes, directory information and
		   bitmap, volume allocation information, volume and drive
		   information, pointers to various pieces of volume-related
		   information, and details on path and directory caches, for each
		   volume */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( ( queueHdr = GetVCBQHdr() ) != NULL )
			queuePtr = queueHdr->qHead;
			while ( queuePtr != NULL )
				{
				addRandomData( randomState, queuePtr, sizeof( VCB ) );
				queuePtr = queuePtr->qLink;
				}
#endif

		/* Get the driver reference number, FS type, and media size for each
		   drive */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		if( ( queueHdr = GetDrvQHdr() ) != NULL )
			queuePtr = queueHdr->qHead;
			while ( queuePtr != NULL )
				{
				addRandomData( randomState, queuePtr, sizeof( DrvQEl ) );
				queuePtr = queuePtr->qLink;
				}
#endif
		/* Get global script manager variables and vectors, including the
		   globals changed count, font, script, and i18n flags, various
		   script types, and cache information */
		for( count = 0; count < 30; count++ )
			addRandomValue( randomState, GetScriptManagerVariable( count ) );

		/* Get the script code for the font script the i18n script, and for
		   each one add the changed count, font, script, i18n, and display
		   flags, resource ID's, and script file information */
		script = FontScript();
		addRandomValue( randomState, script );
		for( count = 0; count < 30; count++ )
			addRandomValue( randomState, GetScriptVariable( script, count ) );
		script = IntlScript();
		addRandomValue( randomState, script );
		for( count = 0; count < 30; count++ )
			addRandomValue( randomState, GetScriptVariable( script, count ) );

		/* Get the device ID, partition, slot number, resource ID, and driver
		   reference number for the default startup device */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetDefaultStartup( &startupInfo );
		addRandomData( randomState, &startupInfo, sizeof( DefStartRec ) );
#endif
		/* Get the slot number and resource ID for the default video device */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetVideoDefault( &videoInfo );
		addRandomData( randomState, &videoInfo, sizeof( DefVideoRec ) );
#endif
		/* Get the default OS type */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		GetOSDefault( &osInfo );
		addRandomData( randomState, &osInfo, sizeof( DefOSRec ) );
#endif
		/* Get the AppleTalk command block and data size and number of
		   sessions */
#if !defined CALL_NOT_IN_CARBON || CALL_NOT_IN_CARBON
		ASPGetParms( &appleTalkParams, FALSE );
		addRandomData( randomState, &appleTalkParams,
					   sizeof( XPPParamBlock ) );
#endif
		addedFixedItems = TRUE;
		}

	/* Flush any remaining data through */
	endRandomData( randomState, 100 );
	}
CFDictionaryRef getProcessInfo(CFStringRef targetCreator, CFStringRef targetName, CFStringRef targetIdentifier) {
	/* find an applicarion process specified by theSignature(creator type) from runnning process.
	if target application can be found, get information of the process and return as a result
	*/
	CFIndex nKey = 3;
	CFMutableArrayRef keyList = CFArrayCreateMutable(NULL,nKey,&kCFTypeArrayCallBacks);
	CFArrayAppendValue(keyList, CFSTR("FileCreator"));
	CFArrayAppendValue(keyList, CFSTR("CFBundleIdentifier"));
	CFArrayAppendValue(keyList, CFSTR("CFBundleName"));

	CFIndex firstKeyIndex;
	
	if (targetCreator != NULL) {
		firstKeyIndex = 0;
	}
	else if (targetIdentifier != NULL) {
		firstKeyIndex = 1;
	}
	else {
		firstKeyIndex = 2;
	}
	if (targetCreator == NULL) targetCreator = (CFStringRef)kCFNull;
	if (targetName == NULL) targetName = (CFStringRef)kCFNull;
	if (targetIdentifier == NULL) targetIdentifier = (CFStringRef)kCFNull;

	CFMutableArrayRef valueList = CFArrayCreateMutable(NULL, nKey,&kCFTypeArrayCallBacks);
	CFArrayAppendValue(valueList, targetCreator);
	CFArrayAppendValue(valueList, targetIdentifier);
	CFArrayAppendValue(valueList, targetName);
	
	CFStringRef dictKey = CFArrayGetValueAtIndex(keyList, firstKeyIndex);
	CFArrayRemoveValueAtIndex(keyList, firstKeyIndex);
	CFStringRef targetValue = CFArrayGetValueAtIndex(valueList, firstKeyIndex);
	CFArrayRemoveValueAtIndex(valueList, firstKeyIndex);
	
	Boolean isFound = false;
	ProcessSerialNumber psn = {kNoProcess, kNoProcess};
	CFDictionaryRef pDict = NULL;
	CFComparisonResult isSameStr;
	
	OSErr err = GetNextProcess(&psn);
	while( err == noErr) {
		pDict = ProcessInformationCopyDictionary(&psn, kProcessDictionaryIncludeAllInformationMask);
		CFStringRef dictValue = CFDictionaryGetValue(pDict, dictKey);
		if (dictValue != NULL) {
			isSameStr = CFStringCompare(dictValue,targetValue,0);

			if (isSameStr == kCFCompareEqualTo){
				isFound = true;
				for (CFIndex i=0; i < 2; i++) {
					CFStringRef secondValue = CFArrayGetValueAtIndex(valueList,i);
					if (secondValue != (CFStringRef)kCFNull) {
						CFStringRef nextKey = CFArrayGetValueAtIndex(keyList, i);
						dictValue = CFDictionaryGetValue(pDict,nextKey);
						isSameStr = CFStringCompare(dictValue,secondValue,0);
						if (isSameStr != kCFCompareEqualTo) {
							isFound = false;
							break;
						}
					}
				}
				
				if (isFound) break;
			}
		}
		
		CFRelease(pDict);
		err = GetNextProcess (&psn);
	}
	
	CFRelease(keyList);
	CFRelease(valueList);
	
	if (isFound) {
#if useLog	
		printf("getProcessInfo found PSN high:%d, low:%d \n", psn.highLongOfPSN, psn.lowLongOfPSN);
#endif
        CFMutableDictionaryRef p_dict_psn = CFDictionaryCreateMutableCopy (NULL, 0, pDict);
		CFDictionaryAddValue(p_dict_psn, CFSTR("PSNLow"), 
									CFNumberCreate(NULL, kCFNumberSInt32Type, &(psn.lowLongOfPSN)));
		CFDictionaryAddValue(p_dict_psn, CFSTR("PSNHigh"), 
									CFNumberCreate(NULL, kCFNumberSInt32Type, &(psn.highLongOfPSN)));
		CFRelease(pDict);
		return p_dict_psn;
	}
	else{
		return nil;
	}
}
Beispiel #24
0
/** Check if a process with a given name is running
 *  @param names list of names to check
 *  @return list of detected processes.
 */
QStringList Utils::findRunningProcess(QStringList names)
{
    QStringList processlist;
    QStringList found;
#if defined(Q_OS_WIN32)
    HANDLE hdl;
    PROCESSENTRY32 entry;
    bool result;

    hdl = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
    if(hdl == INVALID_HANDLE_VALUE) {
        qDebug() << "[Utils] CreateToolhelp32Snapshot failed.";
        return found;
    }
    entry.dwSize = sizeof(PROCESSENTRY32);
    entry.szExeFile[0] = '\0';
    if(!Process32First(hdl, &entry)) {
        qDebug() << "[Utils] Process32First failed.";
        return found;
    }

    processlist.append(QString::fromWCharArray(entry.szExeFile));
    do {
        entry.dwSize = sizeof(PROCESSENTRY32);
        entry.szExeFile[0] = '\0';
        result = Process32Next(hdl, &entry);
        if(result) {
            processlist.append(QString::fromWCharArray(entry.szExeFile));
        }
    } while(result);
    CloseHandle(hdl);
#endif
#if defined(Q_OS_MACX)
    ProcessSerialNumber psn = { 0, kNoProcess };
    OSErr err;
    do {
        pid_t pid;
        err = GetNextProcess(&psn);
        err = GetProcessPID(&psn, &pid);
        if(err == noErr) {
            char buf[32] = {0};
            ProcessInfoRec info;
            memset(&info, 0, sizeof(ProcessInfoRec));
            info.processName = (unsigned char*)buf;
            info.processInfoLength = sizeof(ProcessInfoRec);
            err = GetProcessInformation(&psn, &info);
            if(err == noErr) {
                // some processes start with nonprintable characters. Skip those.
                int i;
                for(i = 0; i < 32; i++) {
                    if(isprint(buf[i])) break;
                }
                // avoid adding duplicates.
                QString process = QString::fromUtf8(&buf[i]);
                if(!processlist.contains(process)) {
                    processlist.append(process);
                }

            }
        }
    } while(err == noErr);
#endif
    // check for given names in list of processes
    for(int i = 0; i < names.size(); ++i) {
#if defined(Q_OS_WIN32)
        // the process name might be truncated. Allow the extension to be partial.
        int index = processlist.indexOf(QRegExp(names.at(i) + "(\\.(e(x(e?)?)?)?)?"));
#else
        int index = processlist.indexOf(names.at(i));
#endif
        if(index != -1) {
            found.append(processlist.at(index));
        }
    }
    qDebug() << "[Utils] Found listed processes running:" << found;
    return found;
}
Beispiel #25
0
static OSErr QuitBOINCManager(OSType signature) {
    bool			done = false;
    ProcessSerialNumber         thisPSN;
    ProcessInfoRec		thisPIR;
    OSErr                       err = noErr;
    Str63			thisProcessName;
    AEAddressDesc		thisPSNDesc;
    AppleEvent			thisQuitEvent, thisReplyEvent;
    

    thisPIR.processInfoLength = sizeof (ProcessInfoRec);
    thisPIR.processName = thisProcessName;
    thisPIR.processAppSpec = nil;
    
    thisPSN.highLongOfPSN = 0;
    thisPSN.lowLongOfPSN = kNoProcess;
    
    while (done == false) {		
        err = GetNextProcess(&thisPSN);
        if (err == procNotFound)	
            done = true;		// apparently the demo app isn't running.  Odd but not impossible
        else {		
            err = GetProcessInformation(&thisPSN,&thisPIR);
            if (err != noErr)
                goto bail;
                    
            if (thisPIR.processSignature == signature) {	// is it or target process?
                err = AECreateDesc(typeProcessSerialNumber, (Ptr)&thisPSN,
                                            sizeof(thisPSN), &thisPSNDesc);
                if (err != noErr)
                        goto bail;

                // Create the 'quit' Apple event for this process.
                err = AECreateAppleEvent(kCoreEventClass, kAEQuitApplication, &thisPSNDesc,
                                                kAutoGenerateReturnID, kAnyTransactionID, &thisQuitEvent);
                if (err != noErr) {
                    AEDisposeDesc (&thisPSNDesc);
                    goto bail;		// don't know how this could happen, but limp gamely onward
                }

                // send the event 
                err = AESend(&thisQuitEvent, &thisReplyEvent, kAEWaitReply,
                                           kAENormalPriority, kAEDefaultTimeout, 0L, 0L);
                AEDisposeDesc (&thisQuitEvent);
                AEDisposeDesc (&thisPSNDesc);
#if 0
                if (err == errAETimeout) {
                    pid_t thisPID;
                        
                    err = GetProcessPID(&thisPSN , &thisPID);
                    if (err == noErr)
                        err = kill(thisPID, SIGKILL);
                }
#endif
                done = true;		// we've killed the process, presumably
            }
        }
    }

bail:
    return err;
}