bool Tokenize() { TCHAR cDIR[MAX_STR_LEN]; GetCurrentDirectory(MAX_STR_LEN, cDIR); _tprintf(_T("%s>>"), cDIR); _getts_s(cmdString); _tcscpy_s(cmdHistory[historyNum++], cmdString); int nowNum = historyNum - 1; while (cmdString[0] == '!') { if (cmdString[1] == '!') { if (_tcslen(cmdString) == 2 && nowNum >= 1) { _tcscpy(cmdString, cmdHistory[nowNum - 1]); nowNum = nowNum - 1; } else { _tprintf(_T("이전 명령어가 존재하지 않습니다.\n")); return false; } } else { int num = SearchToken(); if (num != -1) { _tcscpy(cmdString, cmdHistory[num]); nowNum = num; } else { _tprintf(_T("이전 명령어가 존재하지 않습니다.\n")); return false; } } } _tcscpy_s(cmdCopy, cmdString); TCHAR * token = _tcstok(cmdString, seps); while (token != NULL){ _tcscpy( cmdTokenList[tokenNum++], StrLower(token) ); token = _tcstok(NULL, seps); } return true; }
bool CScript::IntroduceVirus() { int i, start, iFound; int found[11*2]; char* newScript; const char* names[11*2] = { "==", "!=", "!=", "==", ">", "<", "<", ">", "true", "false", "false", "true", "grab", "drop", "drop", "grab", "InFront", "Behind", "Behind", "EnergyCell", "EnergyCell", "InFront", }; iFound = 0; for ( i=0 ; i<11 ; i++ ) { start = SearchToken(m_script, names[i*2]); if ( start != -1 ) { found[iFound++] = i*2; found[iFound++] = start; } } if ( iFound == 0 ) return false; i = (rand()%(iFound/2))*2; start = found[i+1]; i = found[i+0]; newScript = new char[m_len+strlen(names[i+1])+1]; strcpy(newScript, m_script); delete[] m_script; m_script = newScript; DeleteToken(m_script, start, strlen(names[i])); InsertToken(m_script, start, names[i+1]); m_len = strlen(m_script); Compile(); // recompile with the virus return true; }