Exemple #1
0
static PTEXT GetSubst( int _2bytecode )
{
	DECLTEXTSZ( subst, 2);
   subst.data.size = 1;
	switch( _2bytecode )
	{
	case '+': subst.data.data[0] = ' '; return SegDuplicate( (PTEXT)&subst );
	case '02': subst.data.data[0] = '\x20'; return SegDuplicate( (PTEXT)&subst );
	case 'c2': case 'C2': subst.data.data[0] = '\x2C'; return SegDuplicate( (PTEXT)&subst );
	case 'b5': case 'B5': subst.data.data[0] = '\x5B'; return SegDuplicate( (PTEXT)&subst );
	case 'd5': case 'D5': subst.data.data[0] = '\x5D'; return SegDuplicate( (PTEXT)&subst );
	case 'f2': case 'F2': subst.data.data[0] = '\x2F'; return SegDuplicate( (PTEXT)&subst );
	case '22': subst.data.data[0] = '\x22'; return SegDuplicate( (PTEXT)&subst );
	case '72': subst.data.data[0] = '\x27'; return SegDuplicate( (PTEXT)&subst );
	case '62': subst.data.data[0] = '\x26'; return SegDuplicate( (PTEXT)&subst );
	}
   return NULL;
}
Exemple #2
0
int CPROC MakeProcess( PSENTIENT ps, PENTITY peInit, PTEXT parameters )
{
	// parameters specify command and parameters to launch...
	// perhaps a working directory? May or may not want it
	// in the current directory...
	// /make process test WIDE("command arguments") WIDE("work path") <attributes?>
	// /make process test WIDE("notepad trigger.txt") 
	PSENTIENT ps2;
	PPROCESS process = New( PROCESS );
	TEXTCHAR MyPath[256];
	GetCurrentPath( MyPath, sizeof( MyPath ) );
	ps2 = CreateAwareness( peInit );
	MemSet( process, 0, sizeof( PROCESS ) );
	Log( WIDE("Have a process, and woke it up... setting the link") );
	SetLink( &peInit->pPlugin, iProcess, process );
	SetLink( &peInit->pDestroy, iProcess, DestroyProcess );
	Log( WIDE("Set the link, getting params...") );
	{
		PTEXT text, cmd = NULL;
		text = GetParam( ps, &parameters );
		if( text && TextIs( text, WIDE("\"") ) )
		{
	      Log( WIDE("Found a quote, getting command line") );
			while( (text = GetParam( ps, &parameters )) && !TextIs( text, WIDE("\"") ) )
			{
				cmd = SegAppend( cmd, SegDuplicate( text ) );
			}
			cmd->format.position.offset.spaces = 0;
			process->command = BuildLine( cmd );
			if( text ) // closed, and may have start path....
			{
				text = GetParam( ps, &parameters );
		   	if( text && TextIs( text, WIDE("\"") ) )
				{
					Log( WIDE("Found a quote, getting the path") );
					while( (text = GetParam( ps, &parameters )) && !TextIs( text, WIDE("\"") ) )
					{
						cmd = SegAppend( cmd, SegDuplicate( text ) );
		   		}
		   		cmd->format.position.offset.spaces = 0;
		   		process->directory = BuildLine( cmd );
				}
			}
		}
		else
		{
			DECLTEXT( msg, WIDE("Must specify process to execute in quotes (\")") );
			EnqueLink( &ps->Command->Output, &msg );
		WakeAThread( ps2 );
			return -1; // abort creation.
		}
	}
	Log2( WIDE("Starting %s in %s"), GetText( process->command ), GetText( process->directory ) );
	process->si.cb = sizeof( process->si );
	// remaining startup info members are NULL - specifying we do NOT care
	// why why when where how the process starts.
	if( StartProcess( process ) )
	{
		DECLTEXTSZ( msg, 256 );
		msg.data.size = snprintf( msg.data.data, 256*sizeof(TEXTCHAR), WIDE("Failed to start \"%s\" in \"%s\" error: %ld"),
										 GetText( process->command ),
										 GetText( process->directory ),
										 GetLastError() );
		EnqueLink( &ps->Command->Output, SegDuplicate( (PTEXT)&msg ) );
		WakeAThread( ps2 );
		return -1; // abort creation.
	}
	// well otherwise would seem we've launched a valid application
	// we have valid process and thread handles to it which can be monitored
	// and well that's about that.
	WakeAThread( ps2 );
	return 0;
}