Example #1
0
bool GetBoolParam(vector<parameters>& v,const string p){
	bool St = false;
	if (FindParam(v,p) != v.end()){//find!
		St = true;
	}
	return St;
}
void CJavaDebugAgentSettings::LoadL(RReadStream* aStream)
{
    // Read in and verify the signature
    for (TInt k=0; k<KPrefsFileSignature().Length(); k++) {
        TUint8 sig = aStream->ReadUint8L();
        if (sig != KPrefsFileSignature()[k]) {
            User::Leave(KErrCorrupt);
        }
    }

    // Read individual settings
    for (;;) {
        TInt len = 0;
        TRAPD(err, len = aStream->ReadInt32L());
        if (err != KErrNone) {
            if (err == KErrEof) break;
            User::Leave(err);
        }
        if (len < 4) User::Leave(KErrCorrupt);
        TParam* param = FindParam(aStream->ReadInt32L());
        if (param) {
            param->ReadL(aStream, len-4);
        } else {
            aStream->ReadL(len-4);
        }
    }
}
Example #3
0
bool GetBoolParam(vector<parameters>& v,const string p, bool &ret){
	ret = false;
	if (FindParam(v,p) != v.end()){//find!
		ret = true;
	}
	return ret;
}
Example #4
0
status GetStringParam(vector<parameters>& v,const string p, string& result, const string def){
	status St;
	auto it = FindParam(v,p);
	if (it != v.end()){//find!
		if (it->elements.begin() != it->elements.end()){
			result = it->elements.front();
		}
		else{
			result = def;
		}
		St = SUCCESS;
	}
	else{
		result = def;
		St = NOT_FOUND;
	}
	return St;
}
// Help on specific command
//===========================================================================
Update_t CmdHelpSpecific (int nArgs)
{
	int iArg;
	TCHAR sText[ CONSOLE_WIDTH ];
	ZeroMemory( sText, CONSOLE_WIDTH );

	if (! nArgs)
	{
//		ConsoleBufferPush( TEXT(" [] = optional, {} = mandatory.  Categories are: ") );

		_tcscpy( sText, TEXT("Usage: [{ ") );
		for (int iCategory = _PARAM_HELPCATEGORIES_BEGIN ; iCategory < _PARAM_HELPCATEGORIES_END; iCategory++)
		{
			TCHAR *pName = g_aParameters[ iCategory ].m_sName;
			if (! TestStringCat( sText, pName, g_nConsoleDisplayWidth - 3 )) // CONSOLE_WIDTH
			{
				ConsoleBufferPush( sText );
				_tcscpy( sText, TEXT("    ") );
			}

			StringCat( sText, pName, CONSOLE_WIDTH );
			if (iCategory < (_PARAM_HELPCATEGORIES_END - 1))
			{
				StringCat( sText, TEXT(" | "), CONSOLE_WIDTH );
			}
		}
		StringCat( sText, TEXT(" }]"), CONSOLE_WIDTH );
		ConsoleBufferPush( sText );

		wsprintf( sText, TEXT("Note: [] = optional, {} = mandatory"), CONSOLE_WIDTH );
		ConsoleBufferPush( sText );
	}


	bool bAllCommands = false;
	bool bCategory = false;

	if (! _tcscmp( g_aArgs[1].sArg, g_aParameters[ PARAM_WILDSTAR ].m_sName))
	{
		bAllCommands = true;
		nArgs = NUM_COMMANDS;
	}

	// If Help on category, push command name as arg
	int nNewArgs  = 0;
	int iCmdBegin = 0;
	int iCmdEnd   = 0;
	for (iArg = 1; iArg <= nArgs; iArg++ )
	{
		int iParam;
		int nFoundCategory = FindParam( g_aArgs[ iArg ].sArg, MATCH_EXACT, iParam, _PARAM_HELPCATEGORIES_BEGIN, _PARAM_HELPCATEGORIES_END );
		switch( iParam )
		{
			case PARAM_CAT_BREAKPOINTS: iCmdBegin = CMD_BREAKPOINT      ; iCmdEnd = CMD_BREAKPOINT_SAVE    + 1; break;
			case PARAM_CAT_CONFIG     : iCmdBegin = CMD_CONFIG_COLOR    ; iCmdEnd = CMD_CONFIG_SAVE        + 1; break;
			case PARAM_CAT_CPU        : iCmdBegin = CMD_ASSEMBLE        ; iCmdEnd = CMD_TRACE_LINE         + 1; break;
			case PARAM_CAT_FLAGS      : iCmdBegin = CMD_FLAG_CLEAR      ; iCmdEnd = CMD_FLAG_SET_N         + 1; break;
			case PARAM_CAT_MEMORY     : iCmdBegin = CMD_MEMORY_COMPARE  ; iCmdEnd = CMD_MEMORY_FILL        + 1; break;
			case PARAM_CAT_SYMBOLS    : iCmdBegin = CMD_SYMBOLS_LOOKUP  ; iCmdEnd = CMD_SYMBOLS_LIST       + 1; break;
			case PARAM_CAT_WATCHES    : iCmdBegin = CMD_WATCH_ADD       ; iCmdEnd = CMD_WATCH_LIST         + 1; break;
			case PARAM_CAT_WINDOW     : iCmdBegin = CMD_WINDOW          ; iCmdEnd = CMD_WINDOW_OUTPUT      + 1; break;
			case PARAM_CAT_ZEROPAGE   : iCmdBegin = CMD_ZEROPAGE_POINTER; iCmdEnd = CMD_ZEROPAGE_POINTER_SAVE+1;break;
			default: break;
		}
		nNewArgs = (iCmdEnd - iCmdBegin);
		if (nNewArgs > 0)
			break;
	}

	if (nNewArgs > 0)
	{
		bCategory = true;

		nArgs = nNewArgs;
		for (iArg = 1; iArg <= nArgs; iArg++ )
		{
			g_aArgs[ iArg ].nVal2 = iCmdBegin + iArg - 1;
		}
	}

	CmdFuncPtr_t pFunction;
	
	for (iArg = 1; iArg <= nArgs; iArg++ )
	{	
		int iCommand = 0;
		int nFound = FindCommand( g_aArgs[iArg].sArg, pFunction, & iCommand );

		if (bCategory)
		{
			iCommand = g_aArgs[iArg].nVal2;
		}

		if (bAllCommands)
		{
			iCommand = iArg;
			if (iCommand == NUM_COMMANDS) // skip: Internal Consistency Check __COMMANDS_VERIFY_TXT__
				continue;
		}

		if (nFound > 1)
		{
			DisplayAmbigiousCommands( nFound );
		}

		if (iCommand > NUM_COMMANDS)
			continue;

		if ((nArgs == 1) && (! nFound))
			iCommand = g_aArgs[iArg].nVal1;

		Command_t *pCommand = & g_aCommands[ iCommand ];

		if (! nFound)
		{
			iCommand = NUM_COMMANDS;
			pCommand = NULL;
		}
		
		if (nFound && (! bAllCommands))
		{
			TCHAR sCategory[ CONSOLE_WIDTH ];
			int iCmd = g_aCommands[ iCommand ].iCommand; // Unaliased command

			// HACK: Major kludge to display category!!!
			if (iCmd <= CMD_TRACE_LINE)
				wsprintf( sCategory, "Main" );
			else
			if (iCmd <= CMD_BREAKPOINT_SAVE)
				wsprintf( sCategory, "Breakpoint" );
			else
			if (iCmd <= CMD_PROFILE)
				wsprintf( sCategory, "Profile" );
			else
			if (iCmd <= CMD_CONFIG_SAVE)
				wsprintf( sCategory, "Config" );
			else
			if (iCmd <= CMD_CURSOR_PAGE_DOWN_4K)
				wsprintf( sCategory, "Scrolling" );
			else
			if (iCmd <= CMD_FLAG_SET_N)
				wsprintf( sCategory, "Flags" );
			else
			if (iCmd <= CMD_MOTD)
				wsprintf( sCategory, "Help" );
			else
			if (iCmd <= CMD_MEMORY_FILL)
				wsprintf( sCategory, "Memory" );
			else
			if (iCmd <= CMD_REGISTER_SET)
				wsprintf( sCategory, "Registers" );
			else
			if (iCmd <= CMD_SYNC)
				wsprintf( sCategory, "Source" );
			else
			if (iCmd <= CMD_STACK_PUSH)
				wsprintf( sCategory, "Stack" );
			else
			if (iCmd <= CMD_SYMBOLS_LIST)
				wsprintf( sCategory, "Symbols" );
			else
			if (iCmd <= CMD_WATCH_SAVE)
				wsprintf( sCategory, "Watch" );
			else
			if (iCmd <= CMD_WINDOW_OUTPUT)
				wsprintf( sCategory, "Window" );
			else
			if (iCmd <= CMD_ZEROPAGE_POINTER_SAVE)
				wsprintf( sCategory, "Zero Page" );
			else
				wsprintf( sCategory, "Unknown!" );

			wsprintf( sText, "Category: %s", sCategory );
			ConsoleBufferPush( sText );
		}
		
		if (pCommand)
		{
			char *pHelp = pCommand->pHelpSummary;
			if (pHelp)
			{
				wsprintf( sText, "%s, ", pCommand->m_sName );
				if (! TryStringCat( sText, pHelp, g_nConsoleDisplayWidth ))
				{
					if (! TryStringCat( sText, pHelp, CONSOLE_WIDTH ))
					{
						StringCat( sText, pHelp, CONSOLE_WIDTH );
						ConsoleBufferPush( sText );
					}
				}
				ConsoleBufferPush( sText );
			}
			else
			{
				wsprintf( sText, "%s", pCommand->m_sName );
				ConsoleBufferPush( sText );
	#if DEBUG_COMMAND_HELP
				if (! bAllCommands) // Release version doesn't display message
				{			
					wsprintf( sText, "Missing Summary Help: %s", g_aCommands[ iCommand ].aName );
					ConsoleBufferPush( sText );
				}
	#endif
			}
		}		

		// MASTER HELP
		switch (iCommand)
		{	
	// CPU / General
		case CMD_ASSEMBLE:
			ConsoleBufferPush( TEXT(" Built-in assember isn't functional yet.") );
			break;
		case CMD_UNASSEMBLE:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol}") );
			ConsoleBufferPush( TEXT("  Disassembles memory.") );
			break;
		case CMD_CALC:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol | + | - }"    ) );
			ConsoleBufferPush( TEXT(" Output order is: Hex Bin Dec Char"     ) );
			ConsoleBufferPush( TEXT("  Note: symbols take piority."          ) );
			ConsoleBufferPush( TEXT("i.e. #A (if you don't want accum. val)" ) );
			ConsoleBufferPush( TEXT("i.e. #F (if you don't want flags val)"  ) );
			break;
		case CMD_GO:
			ConsoleBufferPush( TEXT(" Usage: [address | symbol [Skip,End]]") );
			ConsoleBufferPush( TEXT(" Skip: Start address to skip stepping" ) );
			ConsoleBufferPush( TEXT(" End : End address to skip stepping" ) );
			ConsoleBufferPush( TEXT("  If the Program Counter is outside the" ) );
			ConsoleBufferPush( TEXT(" skip range, resumes single-stepping." ) );
			ConsoleBufferPush( TEXT("  Can be used to skip ROM/OS/user code." ));
			ConsoleBufferPush( TEXT(" i.e.  G C600 F000,FFFF" ) );
			break;
		case CMD_NOP:
			ConsoleBufferPush( TEXT("  Puts a NOP opcode at current instruction") );
			break;
		case CMD_JSR:
			ConsoleBufferPush( TEXT(" Usage: {symbol | address}") );
			ConsoleBufferPush( TEXT("  Pushes PC on stack; calls the named subroutine.") );
			break;
		case CMD_PROFILE:
			wsprintf( sText, TEXT(" Usage: [%s | %s | %s]")
				, g_aParameters[ PARAM_RESET ].m_sName
				, g_aParameters[ PARAM_SAVE  ].m_sName
				, g_aParameters[ PARAM_LIST  ].m_sName
			);
			ConsoleBufferPush( sText );
			ConsoleBufferPush( TEXT(" No arguments resets the profile.") );
			break;
		case CMD_SOURCE:
			ConsoleBufferPush( TEXT(" Reads assembler source file." ) );
			wsprintf( sText, TEXT(" Usage: [ %s | %s ] \"filename\""            ), g_aParameters[ PARAM_SRC_MEMORY  ].m_sName, g_aParameters[ PARAM_SRC_SYMBOLS ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT("   %s: read source bytes into memory."        ), g_aParameters[ PARAM_SRC_MEMORY  ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT("   %s: read symbols into Source symbol table."), g_aParameters[ PARAM_SRC_SYMBOLS ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT(" Supports: %s."                              ), g_aParameters[ PARAM_SRC_MERLIN  ].m_sName ); ConsoleBufferPush( sText );
			break;
		case CMD_STEP_OUT: 
			ConsoleBufferPush( TEXT("  Steps out of current subroutine") );
			ConsoleBufferPush( TEXT("  Hotkey: Ctrl-Space" ) );
			break;
		case CMD_STEP_OVER: // Bad name? FIXME/TODO: do we need to rename?
			ConsoleBufferPush( TEXT(" Usage: [#]") );
			ConsoleBufferPush( TEXT("  Steps, # times, thru current instruction") );
			ConsoleBufferPush( TEXT("  JSR will be stepped into AND out of.") );
			ConsoleBufferPush( TEXT("  Hotkey: Ctrl-Space" ) );
			break;
		case CMD_TRACE:
			ConsoleBufferPush( TEXT(" Usage: [#]") );
			ConsoleBufferPush( TEXT("  Traces, # times, current instruction(s)") );
			ConsoleBufferPush( TEXT("  JSR will be stepped into") );
			ConsoleBufferPush( TEXT("  Hotkey: Shift-Space" ) );
		case CMD_TRACE_FILE:
			ConsoleBufferPush( TEXT(" Usage: [filename]") );
			break;
		case CMD_TRACE_LINE:
			ConsoleBufferPush( TEXT(" Usage: [#]") );
			ConsoleBufferPush( TEXT("  Traces into current instruction") );
			ConsoleBufferPush( TEXT("  with cycle counting." ) );
			break;
	// Breakpoints
		case CMD_BREAKPOINT:
			wsprintf( sText, " Maximum breakpoints are: %d", MAX_BREAKPOINTS );
			ConsoleBufferPush( sText );
			break;
		case CMD_BREAKPOINT_ADD_REG:
			ConsoleBufferPush( TEXT(" Usage: [A|X|Y|PC|S] [<,=,>] value") );
			ConsoleBufferPush( TEXT("  Set breakpoint when reg is [op] value") );
			break;
		case CMD_BREAKPOINT_ADD_SMART:
		case CMD_BREAKPOINT_ADD_PC:
			ConsoleBufferPush( TEXT(" Usage: [address]") );
			ConsoleBufferPush( TEXT("  Sets a breakpoint at the current PC") );
			ConsoleBufferPush( TEXT("  or at the specified address.") );
			break;
		case CMD_BREAKPOINT_ENABLE:
			ConsoleBufferPush( TEXT(" Usage: [# [,#] | *]") );
			ConsoleBufferPush( TEXT("  Re-enables breakpoint previously set, or all.") );
			break;
	// Config - Color
		case CMD_CONFIG_COLOR:
			ConsoleBufferPush( TEXT(" Usage: [{#} | {# RR GG BB}]" ) );
			ConsoleBufferPush( TEXT("  0 params: switch to 'color' scheme" ) );
			ConsoleBufferPush( TEXT("  1 param : dumps R G B for scheme 'color'") );
			ConsoleBufferPush( TEXT("  4 params: sets  R G B for scheme 'color'" ) );
			break;
		case CMD_CONFIG_MONOCHROME:
			ConsoleBufferPush( TEXT(" Usage: [{#} | {# RR GG BB}]" ) );
			ConsoleBufferPush( TEXT("  0 params: switch to 'monochrome' scheme" ) );
			ConsoleBufferPush( TEXT("  1 param : dumps R G B for scheme 'monochrome'") );
			ConsoleBufferPush( TEXT("  4 params: sets  R G B for scheme 'monochrome'" ) );
			break;
		case CMD_OUTPUT:
			ConsoleBufferPush( TEXT(" Usage: {address8 | address16 | symbol} ## [##]") );
			ConsoleBufferPush( TEXT("  Ouput a byte or word to the IO address $C0xx" ) );
			break;
	// Config - Font
		case CMD_CONFIG_FONT:
			wsprintf( sText, TEXT(" Usage: [%s | %s] \"FontName\" [Height]" ),
				g_aParameters[ PARAM_FONT_MODE ].m_sName, g_aParameters[ PARAM_DISASM ].m_sName );
			ConsoleBufferPush( sText );
			ConsoleBufferPush( TEXT(" i.e. FONT \"Courier\" 12" ) );
			ConsoleBufferPush( TEXT(" i.e. FONT \"Lucida Console\" 12" ) );
			wsprintf( sText, TEXT(" %s Controls line spacing."), g_aParameters[ PARAM_FONT_MODE ].m_sName );
			ConsoleBufferPush( sText );
			wsprintf( sText, TEXT(" Valid values are: %d, %d, %d." ),
				FONT_SPACING_CLASSIC, FONT_SPACING_CLEAN, FONT_SPACING_COMPRESSED );
			ConsoleBufferPush( sText );
			break;
	// Memory
		case CMD_MEMORY_ENTER_BYTE:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol} ## [## ... ##]") );
			ConsoleBufferPush( TEXT("  Sets memory to the specified 8-Bit Values (bytes)" ) );
			break;
		case CMD_MEMORY_ENTER_WORD:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol} #### [#### ... ####]") );
			ConsoleBufferPush( TEXT("  Sets memory to the specified 16-Bit Values (words)" ) );
			break;
		case CMD_MEMORY_FILL:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol} {address | symbol} ##" ) ); 
			ConsoleBufferPush( TEXT("  Fills the memory range with the specified byte" ) );
			ConsoleBufferPush( TEXT("  Can't fill IO address $C0xx" ) );
			break;
//		case CMD_MEM_MINI_DUMP_ASC_1:
//		case CMD_MEM_MINI_DUMP_ASC_2:
		case CMD_MEM_MINI_DUMP_ASCII_1:
		case CMD_MEM_MINI_DUMP_ASCII_2:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol}") ); 
			ConsoleBufferPush( TEXT("  Displays ASCII text in the Mini-Memory area") ); 
			ConsoleBufferPush( TEXT("  ASCII control chars are hilighted") );
			ConsoleBufferPush( TEXT("  ASCII hi-bit chars are normal") ); 
//			break;
//		case CMD_MEM_MINI_DUMP_TXT_LO_1:
//		case CMD_MEM_MINI_DUMP_TXT_LO_2:
		case CMD_MEM_MINI_DUMP_APPLE_1:
		case CMD_MEM_MINI_DUMP_APPLE_2:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol}") ); 
			ConsoleBufferPush( TEXT("  Displays APPLE text in the Mini-Memory area") ); 
			ConsoleBufferPush( TEXT("  APPLE control chars are inverse") );
			ConsoleBufferPush( TEXT("  APPLE hi-bit chars are normal") ); 
			break;
//		case CMD_MEM_MINI_DUMP_TXT_HI_1:
//		case CMD_MEM_MINI_DUMP_TXT_HI_2:
//			ConsoleBufferPush( TEXT(" Usage: {address | symbol}") ); 
//			ConsoleBufferPush( TEXT("  Displays text in the Memory Mini-Dump area") ); 
//			ConsoleBufferPush( TEXT("  ASCII chars with the hi-bit set, is inverse") ); 
			break;
	// Symbols
		case CMD_SYMBOLS_MAIN:
		case CMD_SYMBOLS_USER:
		case CMD_SYMBOLS_SRC :
//			ConsoleBufferPush( TEXT(" Usage: [ ON | OFF | symbol | address ]" ) );
//			ConsoleBufferPush( TEXT(" Usage: [ LOAD [\"filename\"] | SAVE \"filename\"]" ) ); 
//			ConsoleBufferPush( TEXT("  ON  : Turns symbols on in the disasm window" ) );
//			ConsoleBufferPush( TEXT("  OFF : Turns symbols off in the disasm window" ) );
//			ConsoleBufferPush( TEXT("  LOAD: Loads symbols from last/default filename" ) );
//			ConsoleBufferPush( TEXT("  SAVE: Saves symbol table to file" ) );
//			ConsoleBufferPush( TEXT(" CLEAR: Clears the symbol table" ) );
			ConsoleBufferPush( TEXT(" Usage: [ ... | symbol | address ]") );
			ConsoleBufferPush( TEXT(" Where ... is one of:" ) );
			wsprintf( sText, TEXT("  %s  " ": Turns symbols on in the disasm window"        ), g_aParameters[ PARAM_ON    ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT("  %s "  ": Turns symbols off in the disasm window"       ), g_aParameters[ PARAM_OFF   ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT("  %s"   ": Loads symbols from last/default \"filename\"" ), g_aParameters[ PARAM_SAVE  ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT("  %s"   ": Saves symbol table to \"filename\""           ), g_aParameters[ PARAM_LOAD  ].m_sName ); ConsoleBufferPush( sText );
			wsprintf( sText, TEXT(" %s"    ": Clears the symbol table"                      ), g_aParameters[ PARAM_CLEAR ].m_sName ); ConsoleBufferPush( sText );
			break;
	// Watches
		case CMD_WATCH_ADD:
			ConsoleBufferPush( TEXT(" Usage: {address | symbol}" ) );
			ConsoleBufferPush( TEXT("  Adds the specified memory location to the watch window." ) );
			break;
	// Window
		case CMD_WINDOW_CODE    : // summary is good enough
		case CMD_WINDOW_CODE_2  : // summary is good enough
		case CMD_WINDOW_SOURCE_2: // summary is good enough
			break;

	// Misc
		case CMD_VERSION:
			ConsoleBufferPush( TEXT(" Usage: [*]") );
			ConsoleBufferPush( TEXT("  * Display extra internal stats" ) );
			break;
		default:
			if (bAllCommands)
				break;
#if DEBUG_COMMAND_HELP
			wsprintf( sText, "Command help not done yet: %s", g_aCommands[ iCommand ].aName );
			ConsoleBufferPush( sText );
#endif
			if ((! nFound) || (! pCommand))
			{
				wsprintf( sText, " Invalid command." );
				ConsoleBufferPush( sText );
			}
			break;
		}

	}
	
	return ConsoleUpdate();
}
Example #6
0
/******************************************************************************
* Function				RunClient 
* Params:
* 	pbBlob				data buffer
*	bBlobLen			maximum size of data buffer
*	pbDataLength		reseived/sended data in buffer
* return:			
*	STR_OK  			if all ok
*	STR_NEED_ANSWER		if need send buffer
*	STR_NEED_DISCONNECT	if need disconnect socket
******************************************************************************/
BYTE RunClient(BYTE* pbBlob, BYTE bBlobLen, int *pbDataLength)
{
    static  enum {
        ST_REQUEST_CONNECT = 0,
        ST_WAIT_CONNECT,
        ST_REQUEST_AUTH,
        ST_WAIT_AUTH,
        ST_REQUEST_DATA,
        ST_WAIT_DATA,
        ST_SEND_DATA,
        ST_WAIT_ANSWER
    } ST_STATE = ST_REQUEST_CONNECT;
    ST_ATTRIBUTE Data[MAX_ATTRIBUTE];
    BYTE bAttributeLen = 0;
    BYTE pbMem[MEM_BUFFER_LEN];
    BYTE bMemPos = 0;	
    BYTE bBlockPos = NULL;    
    static BYTE res = STR_OK;
    BYTE AttrLen;
    BYTE j;
    BYTE* Answer; 
    if(*pbDataLength<0) {
	    ST_STATE = ST_REQUEST_CONNECT;
	    return STR_NEED_DISCONNECT;
    }  
    while(1){        
        switch(ST_STATE){
        case ST_REQUEST_CONNECT:        	
            AttrLen = 1;
            res = FormBlob(RequestConnect, AttrLen, pbBlob, bBlobLen, &bBlockPos);
            res = STR_NEED_ANSWER;
            ST_STATE = ST_WAIT_CONNECT;
            break;
        case ST_WAIT_CONNECT:
            if(*pbDataLength==0) break;
            res = ParseBlob(pbBlob, *pbDataLength, Data, &bAttributeLen, pbMem, sizeof(pbMem), &bMemPos);
            if(res != STR_OK){
                ST_STATE = ST_REQUEST_CONNECT;
                break;
            } 
            j = FindParam(Data,bAttributeLen,STA_FLAG);
            if(j==255){
                ST_STATE = ST_REQUEST_CONNECT;
                break;
            }
            if((Data[j].type == STA_FLAG)&&
                (Data[j].ulValueLen == sizeof(BYTE)))
            {
                Answer = (BYTE*)Data[j].pValue;
                switch(*Answer){
		        case STF_AUTH_NEEDED:
		            ST_STATE = ST_REQUEST_AUTH;
		            break;
		        case STF_AUTH_NOT_NEEDED:
		        case STF_ACCEPTED:
		            ST_STATE = ST_REQUEST_DATA;
		            break;
		        default:
		            ST_STATE = ST_REQUEST_CONNECT;
		            break;
                }
            }
            break;
        case ST_REQUEST_AUTH:
            AttrLen = 3;
            j = FindParam(RequestAuth,AttrLen,STA_LOGIN);
            RequestAuth[j].pValue = Login;
            RequestAuth[j].ulValueLen = strlen(Login);
            j = FindParam(RequestAuth,AttrLen,STA_PASSWORD);
            RequestAuth[j].pValue = Password;
            RequestAuth[j].ulValueLen = strlen(Password);
            res = FormBlob(RequestAuth, AttrLen, pbBlob, bBlobLen, &bBlockPos);
            res = STR_NEED_ANSWER; 
            ST_STATE = ST_WAIT_AUTH;
            break;
        case ST_WAIT_AUTH:
            if(*pbDataLength==0) break;
            res = ParseBlob(pbBlob, *pbDataLength, Data, &bAttributeLen, pbMem, sizeof(pbMem), &bMemPos);
            if(res != STR_OK){
                ST_STATE = ST_REQUEST_CONNECT;
            } else {
                ST_STATE = ST_REQUEST_DATA;
            }
            break;
        case ST_REQUEST_DATA:
            AttrLen = 2;
            res = FormBlob(RequestData, AttrLen, pbBlob, bBlobLen, &bBlockPos);
            res = STR_NEED_ANSWER; 
            ST_STATE = ST_WAIT_DATA;
            break;
        case ST_WAIT_DATA:
            if(*pbDataLength==0) break;
            res = ParseBlob(pbBlob, *pbDataLength, Data, &bAttributeLen, pbMem, sizeof(pbMem), &bMemPos);
            if(res != STR_OK){
                ST_STATE = ST_REQUEST_CONNECT;
            } else {
                ST_STATE = ST_REQUEST_DATA;
                for(j = 0; j < bAttributeLen; j++){
	                #if defined(__18CXX)
		            switch (Data[j].type){
				    case STA_COMMAND:
				    case STA_FLAG:
				    case STA_LOGIN:
				    case STA_PASSWORD:
				        break;
				    case STA_TIME_SNTP:
				    	PushAttr(Data[j]);			    
				    default:;				       	
			        };
			        #endif
			    }
			    
            }

            break;
        default: 
            ST_STATE = ST_REQUEST_CONNECT;
        };
        break;
    }
    if(res == STR_NEED_ANSWER){
        *pbDataLength = bBlockPos;
    } else {
        *pbDataLength = 0;
    }
    return res;
}
Example #7
0
BYTE RunServer(BYTE bConnectionID, BYTE* pbBlob, int* pbBlobLen)
{
    BYTE res = 0;
    BYTE i = 0;
    BYTE j = 0;
    BYTE Command = 0;
    BOOL NeedAnswer = FALSE;
    BYTE Answers = 0;

    BYTE bAttributeLen = 0;
    BYTE pbMem[MEM_BUFFER_LEN];
    ST_ATTRIBUTE Data[MAX_ATTRIBUTE];
    BYTE bMemPos = 0;
    BYTE bBlobPos = 0;

    ST_ATTRIBUTE Answer[] = {
        {STA_FLAG,  sizeof(BYTE),&Answers }
    };
    ST_ATTRIBUTE SendData[] = {
        {0,  0, 0 }
    };
    if(*pbBlobLen == 0) return STR_OK;
    if(*pbBlobLen < 0) {
	    Connection[bConnectionID].Mode = STS_NO_CONNECT;
    	return STR_NEED_DISCONNECT;
    }
    memset(pbMem,0,sizeof(pbMem));
    memset(Data,0,sizeof(Data));
    
    res = ParseBlob(pbBlob, *pbBlobLen, Data, &bAttributeLen, pbMem, sizeof(pbMem), &bMemPos);
    if(res!=STR_OK) return res;  
    
    i = FindParam(Data, bAttributeLen, STA_COMMAND); 
    if(i==255) return STR_COMMAND_UNKNOWN;
    
    Command = *((BYTE*)Data[i].pValue);	
   
	switch(Connection[bConnectionID].Mode){
    case STS_NO_CONNECT:    	
        if(Command == STC_REQEST_CONNECT) {
            Answers = STF_AUTH_NEEDED;
            Connection[bConnectionID].Mode = STS_AUTH_REQ;
        } else {
            Answers = STF_DECLINED; 
        }
        NeedAnswer = TRUE;
        break;
    case STS_AUTH_REQ:
        if(Command == STC_REQEST_AUTH) {
            BYTE login = FindParam(Data, bAttributeLen, STA_LOGIN);
            BYTE password = FindParam(Data, bAttributeLen, STA_PASSWORD); 
            if((login == 255)||(password == 255)) {
                Answers = STF_COMMAND_INCOMPLETE;
                Connection[bConnectionID].Mode = STS_NO_CONNECT;
            } else {
                //strcmp();
                if(1){ // authority check
                    Answers = STF_ACCEPTED;
                    Connection[bConnectionID].Mode = STS_CONNECTED;
                } else {
                    Answers = STF_DECLINED; 
                    Connection[bConnectionID].Mode = STS_NO_CONNECT;
                }
            }
        } else {
            Answers = STF_DECLINED; 
            Connection[bConnectionID].Mode = STS_NO_CONNECT;
        }
        NeedAnswer = TRUE;
        break;   
    case STS_CONNECTED:
    	LED1_IO = 1;
        switch(Command){
	    case STC_REQEST_DATA:
	        for(j = 0; j < bAttributeLen; j++){
	            switch (Data[j].type){
			    case STA_COMMAND:
			    case STA_FLAG:
			    case STA_LOGIN:
			    case STA_PASSWORD:
			        break;
			    case STA_NETWORK_NAME:  
			        SendData[0].type = STA_NETWORK_NAME;
			        SendData[0].ulValueLen = sizeof(AppConfig.NetBIOSName);
			        SendData[0].pValue = AppConfig.NetBIOSName;
			        res = FormBlob(SendData, 1, pbBlob, MAX_BUFFER_LEN, &bBlobPos);
			        if(res!=STR_OK){
			            Answers = STF_DATA_ERROR;
			            i = bAttributeLen; // interrupt process
			            *pbBlobLen = 0;
			            bBlobPos = 0;	
			        }else {
			            Answers = STF_DATA_READY;
			            *pbBlobLen = bBlobPos;
			        }	
			        break;
			    case STA_TIME_SNTP:
			    	{				    
				    	static DWORD dwTime;
						static BYTE vTime[11];
						dwTime = SNTPGetUTCSeconds();
						ultoa(dwTime, vTime);
						
				    	SendData[0].type = STA_TIME_SNTP;
				        SendData[0].ulValueLen = sizeof(vTime);
				        SendData[0].pValue = vTime;
				        res = FormBlob(SendData, 1, pbBlob, MAX_BUFFER_LEN, &bBlobPos);
				        if(res!=STR_OK){
				            Answers = STF_DATA_ERROR;
				            i = bAttributeLen; // interrupt process
				            *pbBlobLen = 0;
				            bBlobPos = 0;	
				        }else {
				            Answers = STF_DATA_READY;
				            *pbBlobLen = bBlobPos;
				        }				        
				    }
			        break;
			    default:
			        Answers = STF_DATA_TYPE_UNKNOWN;
			        i = bAttributeLen; // interrupt process
			        *pbBlobLen = 0;
			        bBlobPos = 0;
		        };
		    }
	        NeedAnswer = TRUE;
	        res = STR_OK;
	        break;
	    case STC_SEND_DATA:
	        res = STR_OK;
	        break;
	    default :
	        Answers = STF_COMMAND_UNKNOWN;
	        }
        break;
    default:
        res = STR_FUNCTION_FAILED;  
    }
    if(NeedAnswer) {
        res = FormBlob(Answer, 1, pbBlob, MAX_BUFFER_LEN, &bBlobPos);
        *pbBlobLen = bBlobPos;
        if(res!=STR_OK) return res;
        if(Connection[bConnectionID].Mode == STS_NO_CONNECT) {
            res = STR_NEED_DISCONNECT;
        } else {
            res = STR_NEED_ANSWER;
        }
    }
    return res;
}
//===========================================================================
Update_t _CmdSymbolsCommon ( int nArgs, int bSymbolTables )
{
	if (! nArgs)
	{
		return Help_Arg_1( g_iCommand );
	}

	Update_t iUpdate = _CmdSymbolsUpdate( nArgs, bSymbolTables );
	if (iUpdate != UPDATE_NOTHING)
		return iUpdate;

	TCHAR sText[ CONSOLE_WIDTH ];

	int iArg = 0;
	while (iArg++ <= nArgs)
	{
		int iParam;
		int nParams = FindParam( g_aArgs[iArg].sArg, MATCH_EXACT, iParam ); // MATCH_FUZZY
		if (nParams)
		{
			if (iParam == PARAM_CLEAR)
			{
				int iTable = _GetSymbolTableFromFlag( bSymbolTables );
				if (iTable != NUM_SYMBOL_TABLES)
				{
					Update_t iUpdate = _CmdSymbolsClear( (SymbolTable_Index_e) iTable );
					sprintf( sText, TEXT(" Cleared symbol table: %s%s")
						, CHC_STRING, g_aSymbolTableNames[ iTable ]
					 );
					ConsolePrint( sText );
					iUpdate |= ConsoleUpdate();
					return iUpdate;
				}
				else
				{
					// Shouldn't have multiple symbol tables selected
//					nArgs = _Arg_1( eSymbolsTable );
					ConsoleBufferPush( TEXT(" Error: Unknown Symbol Table Type") );
					return ConsoleUpdate();
				}
			}
			else
			if (iParam == PARAM_LOAD)
			{
				nArgs = _Arg_Shift( iArg, nArgs);
				Update_t bUpdate = CmdSymbolsLoad( nArgs );

				int iTable = _GetSymbolTableFromFlag( bSymbolTables );
				if (iTable != NUM_SYMBOL_TABLES)
				{
					if( bUpdate & UPDATE_SYMBOLS )
					{
						//sprintf( sText, "  Symbol Table: %s%s%s, %sloaded symbols: %s%d"
						//	, CHC_STRING, g_aSymbolTableNames[ iTable ]
						//	, CHC_DEFAULT, CHC_DEFAULT
						//	, CHC_NUM_DEC, g_nSymbolsLoaded
						//);
						_CmdSymbolsInfoHeader( iTable, sText, g_nSymbolsLoaded );
						ConsolePrint( sText );
					}
				}
				else
				{
					ConsoleBufferPush( TEXT(" Error: Unknown Symbol Table Type") );
				}
				return ConsoleUpdate();
			}
			else
			if (iParam == PARAM_SAVE)
			{
				nArgs = _Arg_Shift( iArg, nArgs);
				return CmdSymbolsSave( nArgs );
			}
			else
			if (iParam == PARAM_ON)
			{
				g_bDisplaySymbolTables |= bSymbolTables;
				int iTable = _GetSymbolTableFromFlag( bSymbolTables );
				if (iTable != NUM_SYMBOL_TABLES)
				{
					_CmdSymbolsInfoHeader( iTable, sText );
					ConsolePrint( sText );
				}
				return ConsoleUpdate() | UPDATE_DISASM;
			}
			else
			if (iParam == PARAM_OFF)
			{
				g_bDisplaySymbolTables &= ~bSymbolTables;
				int iTable = _GetSymbolTableFromFlag( bSymbolTables );
				if (iTable != NUM_SYMBOL_TABLES)
				{
					_CmdSymbolsInfoHeader( iTable, sText );
					ConsolePrint( sText );
				}
				return ConsoleUpdate() | UPDATE_DISASM;
			}
		}
		else
		{
			return _CmdSymbolsListTables( nArgs, bSymbolTables );
		}

	}

	return ConsoleUpdate();
}
/** load all parameters from the configuration file and the command line switches */
bool Parameter::LoadParam(int argc, char* argv[])
{
  // config file (-f) arg mandatory
  string configPath;
  if ( (configPath = FindParam("-f", argc, argv)) == ""
       && (configPath = FindParam("-config", argc, argv)) == "") {
    PrintCredit();
    Explain();

    UserMessage::Add("No configuration file was specified.  Use -config or -f");
    return false;
  } else {
    if (!ReadConfigFile(configPath)) {
      UserMessage::Add("Could not read "+configPath);
      return false;
    }
  }

  // overwrite parameters with values from switches
  for(PARAM_STRING::const_iterator iterParam = m_description.begin(); iterParam != m_description.end(); iterParam++) {
    const string paramName = iterParam->first;
    OverwriteParam("-" + paramName, paramName, argc, argv);
  }

  // ... also shortcuts
  for(PARAM_STRING::const_iterator iterParam = m_abbreviation.begin(); iterParam != m_abbreviation.end(); iterParam++) {
    const string paramName = iterParam->first;
    const string paramShortName = iterParam->second;
    OverwriteParam("-" + paramShortName, paramName, argc, argv);
  }

  // logging of parameters that were set in either config or switch
  int verbose = 1;
  if (m_setting.find("verbose") != m_setting.end() &&
      m_setting["verbose"].size() > 0)
    verbose = Scan<int>(m_setting["verbose"][0]);
  if (verbose >= 1) { // only if verbose
    TRACE_ERR( "Defined parameters (per moses.ini or switch):" << endl);
    for(PARAM_MAP::const_iterator iterParam = m_setting.begin() ; iterParam != m_setting.end(); iterParam++) {
      TRACE_ERR( "\t" << iterParam->first << ": ");
      for ( size_t i = 0; i < iterParam->second.size(); i++ )
        TRACE_ERR( iterParam->second[i] << " ");
      TRACE_ERR( endl);
    }
  }

  // check for illegal parameters
  bool noErrorFlag = true;
  for (int i = 0 ; i < argc ; i++) {
    if (isOption(argv[i])) {
      string paramSwitch = (string) argv[i];
      string paramName = paramSwitch.substr(1);
      if (m_valid.find(paramName) == m_valid.end()) {
        UserMessage::Add("illegal switch: " + paramSwitch);
        noErrorFlag = false;
      }
    }
  }

  // check if parameters make sense
  return Validate() && noErrorFlag;
}
Example #10
0
int main(int argc, char* argv[]) {
  int retval = 0;
  int i;

  char* progname = strrchr(argv[0], '/');
  if (progname)
    progname++;
  else
    progname = argv[0];

  if (VbArchInit()) {
    fprintf(stderr, "Failed to initialize\n");
    return -1;
  }

  /* If no args specified, print all params */
  if (argc == 1)
    return PrintAllParams(0);
  /* --all or -a prints all params including normally hidden ones */
  if (!strcasecmp(argv[1], "--all") || !strcmp(argv[1], "-a"))
    return PrintAllParams(1);

  /* Print help if needed */
  if (!strcasecmp(argv[1], "-h") || !strcmp(argv[1], "-?")) {
    PrintHelp(progname);
    return 0;
  }

  /* Otherwise, loop through params and get/set them */
  for (i = 1; i < argc && retval == 0; i++) {
    char* has_set = strchr(argv[i], '=');
    char* has_expect = strchr(argv[i], '?');
    char* name = strtok(argv[i], "=?");
    char* value = strtok(NULL, "=?");
    const Param* p;

    /* Make sure args are well-formed. '' or '=foo' or '?foo' not allowed. */
    if (!name || has_set == argv[i] || has_expect == argv[i]) {
      fprintf(stderr, "Poorly formed parameter\n");
      PrintHelp(progname);
      return 1;
    }
    if (!value)
      value=""; /* Allow setting/checking an empty string ('foo=' or 'foo?') */
    if (has_set && has_expect) {
      fprintf(stderr, "Use either = or ? in a parameter, but not both.\n");
      PrintHelp(progname);
      return 1;
    }

    /* Find the parameter */
    p = FindParam(name);
    if (!p) {
      fprintf(stderr, "Invalid parameter name: %s\n", name);
      PrintHelp(progname);
      return 1;
    }

    if (i > 1)
      printf(" ");  /* Output params space-delimited */
    if (has_set)
      retval = SetParam(p, value);
    else if (has_expect)
      retval = CheckParam(p, value);
    else
      retval = PrintParam(p);
  }

  return retval;
}