void LoadLMHashFromPwdumpFile(string sPathName, vector<string>& vUserName, vector<string>& vLMHash, vector<string>& vNTLMHash) { vector<string> vLine; if (ReadLinesFromFile(sPathName, vLine)) { int i; for (i = 0; i < vLine.size(); i++) { vector<string> vPart; if (SeperateString(vLine[i], "::::", vPart)) { string sUserName = vPart[0]; string sLMHash = vPart[2]; string sNTLMHash = vPart[3]; if (sLMHash.size() == 32 && sNTLMHash.size() == 32) { if (NormalizeHash(sLMHash) && NormalizeHash(sNTLMHash)) { vUserName.push_back(sUserName); vLMHash.push_back(sLMHash); vNTLMHash.push_back(sNTLMHash); } else printf("invalid lm/ntlm hash %s:%s\n", sLMHash.c_str(), sNTLMHash.c_str()); } } } } else printf("can't open %s\n", sPathName.c_str()); }
const std::vector<std::string> ribi::DrawCanvas::ToStrings() const noexcept { std::stringstream s; s << (*this); const std::vector<std::string> v { SeperateString(s.str(),'\n') }; return v; }
string CSimpleXml::GetAttri(const string &strPath, const string strAttri/* = "value"*/) { if(m_pDoc == NULL || m_pRoot == NULL) { return false; } TiXmlElement *pCurrNode = m_pRoot; list<string> lstNode; SeperateString(lstNode, strPath, "/"); list<string>::iterator itlstNode = lstNode.begin(); while (NULL != pCurrNode) { if (itlstNode != lstNode.end() && *itlstNode == pCurrNode->Value()) { string strShow = pCurrNode->Value(); if (++itlstNode == lstNode.end()) { return pCurrNode->Attribute(strAttri.c_str()); } pCurrNode = pCurrNode->FirstChildElement(); } else { pCurrNode = pCurrNode->NextSiblingElement(); } } return 0; }
bool CSimpleXml::AccessXmlAttri(XMLNODEINFO &xmlnode) { if(m_pDoc == NULL || m_pRoot == NULL) { return false; } TiXmlElement *pCurrNode = m_pRoot; list<string> lstNode; SeperateString(lstNode, xmlnode.strNodeName, "/"); list<string>::iterator itlstNode = lstNode.begin(); while (NULL != pCurrNode) { if (itlstNode != lstNode.end() && *itlstNode == pCurrNode->Value()) { string strShow = pCurrNode->Value(); if (++itlstNode == lstNode.end()) { xmlnode.strData = pCurrNode->Attribute(xmlnode.strAttri.c_str()); return true; } pCurrNode = pCurrNode->FirstChildElement(); } else { pCurrNode = pCurrNode->NextSiblingElement(); } } return false; }
bool CSimpleXml::AddNodes(const string &strPath, list<XMLNODEINFO> &lstaddnode) { if(m_pDoc == NULL || m_pRoot == NULL) { return false; } TiXmlElement *pCurrNode = m_pRoot; list<string> lstNode; SeperateString(lstNode, strPath, "/"); list<string>::iterator itlstNode = lstNode.begin(); while (NULL != pCurrNode) { if (itlstNode != lstNode.end() && *itlstNode == pCurrNode->Value()) { string strShow = pCurrNode->Value(); if (++itlstNode == lstNode.end()) { AddOneNode(&pCurrNode, lstaddnode); goto SIMXML; } pCurrNode = pCurrNode->FirstChildElement(); } else { pCurrNode = pCurrNode->NextSiblingElement(); } } return false; SIMXML: TiXmlPrinter printer; char szBuf[32]; memset(szBuf, 0, 32); szBuf[0] = 0x9; printer.SetIndent(szBuf); szBuf[0] = 0x0a; printer.SetLineBreak(szBuf); if(m_pDoc->Accept(&printer)) { m_strXml = printer.CStr(); } else { return false; } return true; }
// 2009-01-04 - james.dickson - Added this so we can load hashes from cain .LST files. void LoadLMHashFromCainLSTFile( std::string sPathName, std::vector<std::string>& vUserName, std::vector<std::string>& vLMHash, std::vector<std::string>& vNTLMHash ) { std::vector<std::string> vLine; if (ReadLinesFromFile(sPathName, vLine)) { uint32 index; for (index = 0; index < vLine.size(); index++) { std::vector<std::string> vPart; if (SeperateString(vLine[index], "\t\t\t\t\t\t", vPart)) { std::string sUserName = vPart[0]; std::string sLMHash = vPart[4]; std::string sNTLMHash = vPart[5]; if (sLMHash.size() == 32 && sNTLMHash.size() == 32) { if (NormalizeHash(sLMHash) && NormalizeHash(sNTLMHash)) { vUserName.push_back(sUserName); vLMHash.push_back(sLMHash); vNTLMHash.push_back(sNTLMHash); } else { std::ostringstream stringBuilder; stringBuilder << "Invalid lm/ntlm hash " << sLMHash.c_str(); std::string message = stringBuilder.str(); PyErr_SetString(PyExc_ValueError, message.c_str()); throw boost::python::error_already_set(); } } } } } else { std::ostringstream stringBuilder; stringBuilder << "Can't open " << sPathName.c_str(); std::string message = stringBuilder.str(); PyErr_SetString(PyExc_IOError, message.c_str()); throw boost::python::error_already_set(); } }
// 找到指定路径的第一个,并返回map bool CSimpleXml::FirstSpecifyNode(const string &strNode, map<string, string> &mapNode) { if(m_pDoc == NULL || m_pRoot == NULL) { return false; } m_pCurrNode = m_pRoot; list<string> lstNode; SeperateString(lstNode, strNode, "/"); string strEnd = lstNode.back(); lstNode.pop_back(); list<string>::iterator itlstNode = lstNode.begin(); while (NULL != m_pCurrNode) { if (itlstNode != lstNode.end() && *itlstNode == m_pCurrNode->Value()) { if (++itlstNode == lstNode.end()) { m_pCurrNode = m_pCurrNode->FirstChild(); if (NULL != m_pCurrNode) { GetSpecifyNode(strEnd, mapNode, m_pCurrNode); return true; } return false; } m_pCurrNode = m_pCurrNode->FirstChild(); } else { m_pCurrNode = m_pCurrNode->NextSibling(); } } return false; }
// 找到下一个 bool CSimpleXml::NextSpecifyNode(const string &strNode, map<string, string> &mapNode) { list<string> lstNode; SeperateString(lstNode, strNode, "/"); string strEnd = lstNode.back(); lstNode.pop_back(); if (NULL != m_pCurrNode) { m_pCurrNode = m_pCurrNode->NextSibling(); if (NULL != m_pCurrNode) { GetSpecifyNode(strEnd, mapNode, m_pCurrNode); if (mapNode.empty()) { return false; } return true; } } return false; }
//--------------------------------------------------------------------------- void __fastcall TFormMenu::ImageLoadExerciseClick(TObject *Sender) { if (!OpenDialog->Execute()) return; boost::shared_ptr<TStringList> s(new TStringList); s->LoadFromFile(OpenDialog->FileName); const std::string path = GetPath(OpenDialog->FileName.c_str()); if (s->Count == 0) { MessageDlg("File is empty and cannot be used", mtError, TMsgDlgButtons() << mbOK, 0); return; } if (s->Count == 1) { MessageDlg("File has only one line and thus cannot be used", mtError, TMsgDlgButtons() << mbOK, 0); return; } if (s->Count > 1 && s->operator [](0) != signature) { MessageDlg("The first line of the file must read\n" + signature + "\nTherefore the file will not be used", mtError, TMsgDlgButtons() << mbOK, 0); return; } //Parsing the questions m_questions.clear(); assert(m_questions.empty() == true); const int sz = s->Count; for (int i=1; i!=sz; ++i) //1, because first line is signature { //Obtain the string to split const std::string str_to_split_original = s->operator [](i).c_str(); if (str_to_split_original.empty() == true) continue; //Replace \, by {comma} const std::string str_to_split = ReplaceAll(str_to_split_original,"\\,","{comma}"); //Write string to split to debug const std::string debug_output = "MyDebug:" + str_to_split; OutputDebugString(debug_output.c_str()); const std::vector<std::string> v_original = SeperateString(str_to_split,","); //Replace {comma} by a comma for each std::string in v const std::vector<std::string> v = ReplaceAll(v_original,"{comma}",","); if (v.empty()==true) continue; const std::string& filename = path + '\\' + v[0]; const std::string& question = v[1]; const std::string& answer = v[2]; if (answer.empty()) continue; const std::vector<std::string> false_answers(&v[3],v.end()); if (false_answers.empty()) { //Open question const std::vector<std::string> answers(SeperateString(answer,"/")); boost::shared_ptr<Question> q( new OpenQuestion(filename,question,answers)); m_questions.push_back(q); } else { //Multiple choice question boost::shared_ptr<Question> q( new MultipleChoiceQuestion(filename,question,answer,false_answers)); m_questions.push_back(q); } } if (m_questions.empty() == false) ImageStartExercise->Visible = true; }
void __fastcall TFormMenu::ImageLoadTestClick(TObject *Sender) { //Ask for file if (!OpenDialog->Execute()) return; //Ask for key String userInput = "0"; const bool inputGiven = InputQuery( "Hometrainer 2", //The caption of the InputBox "What is the encryption key?", userInput); if (!inputGiven) return; const int key_user = userInput.ToInt(); boost::shared_ptr<TStringList> s(new TStringList); s->LoadFromFile(OpenDialog->FileName); const std::string path = GetPath(OpenDialog->FileName.c_str()); if (s->Count == 0) { MessageDlg("File is empty and cannot be used", mtError, TMsgDlgButtons() << mbOK, 0); return; } if (s->Count == 1) { MessageDlg("File has only one line and thus cannot be used", mtError, TMsgDlgButtons() << mbOK, 0); return; } //Deencrypt file { //Need of new TStringList, because TStringList::operator[]() //does not seem to support writing, use TStringList::Add() instead boost::shared_ptr<TStringList> s_new(new TStringList); Encranger e(key_user); const int sz = s->Count; for (int i=0; i!=sz; ++i) { const String s1 = s->operator [](i).c_str(); const String s2 = e.Deencrypt(s1.c_str()).c_str(); s_new->Add(s2); } //Overwrite old TStringList s = s_new; } if (s->Count > 1 && s->operator [](0) != signature) { //ShowMessage(s->operator [](0)); MessageDlg("Incorrect key given, therefore test is not loaded.", mtError, TMsgDlgButtons() << mbOK, 0); return; } //Parsing the questions m_questions.clear(); assert(m_questions.empty() == true); const int sz = s->Count; for (int i=1; i!=sz; ++i) //1, because first line is signature { const std::string str_to_split_original = s->operator [](i).c_str(); if (str_to_split_original.empty() == true) continue; //Replace \, by {comma} const std::string str_to_split = ReplaceAll(str_to_split_original,"\\,","{comma}"); const std::string debug_output = "MyDebug:" + str_to_split; OutputDebugString(debug_output.c_str()); const std::vector<std::string> v_original = SeperateString(str_to_split,","); //Replace {comma} by a comma for each std::string in v const std::vector<std::string> v = ReplaceAll(v_original,"{comma}",","); if (v.empty()==true) continue; const std::string& filename = path + '\\' + v[0]; const std::string& question = v[1]; const std::string& answer = v[2]; const std::vector<std::string> false_answers(&v[3],v.end()); if (false_answers.empty()) { //Open question const std::vector<std::string> answers(SeperateString(answer,"/")); boost::shared_ptr<Question> q( new OpenQuestion(filename,question,answers)); m_questions.push_back(q); } else { //Multiple choice question boost::shared_ptr<Question> q( new MultipleChoiceQuestion(filename,question,answer,false_answers)); m_questions.push_back(q); } } if (m_questions.empty() == false) { m_key = key_user; ImageStartTest->Visible = true; } }
bool CChainWalkSet::FindInFile(uint64_t* pIndexE, unsigned char* pHash, int nHashLen) { //This is useless because we have a new BIN every file. //Potential for speedup across tables of the same BIN, but later. return false; int gotPrecalcOnLine = -1; char precalculationLine[255]; sprintf(precalculationLine, "%s_%d_%d:%s\n", m_sHashRoutineName.c_str(), m_nRainbowTableIndex, m_nRainbowChainLen, HexToStr(pHash, nHashLen).c_str() ); std::string precalcString(precalculationLine); std::string sCurrentPrecalcPathName = ""; std::string sCurrentPrecalcIndexPathName = ""; long unsigned int offset = 0; int i; for (i = 0; i < (int)vPrecalcFiles.size() && gotPrecalcOnLine == -1; i++) { sCurrentPrecalcPathName = vPrecalcFiles[i]; sCurrentPrecalcIndexPathName = sCurrentPrecalcPathName + ".index"; offset = 0; std::vector<std::string> precalcLines; if (ReadLinesFromFile(sCurrentPrecalcIndexPathName.c_str(), precalcLines)) { int j; for (j = 0; j < (int)precalcLines.size(); j++) { if (precalcString.compare(0, precalcString.size()-1, precalcLines[j]) == 0) { gotPrecalcOnLine = j; break; } // Parse std::vector<std::string> vPart; if (SeperateString(precalcLines[j], "__:", vPart)) { //0 is hashroutine //1 is index //2 is offset //3 is hash // add to offset offset += ((atoi(vPart[2].c_str())-1) * sizeof(uint64_t)); } else { // corrupt file printf("Corrupted precalculation file!\n"); std::cout<< "filename is " <<precalcLines[j] << std::endl; gotPrecalcOnLine = -1; break; } } } } if (gotPrecalcOnLine > -1) { // if (debug) // { // std::cout << "Debug: Reading pre calculations from file, line " // << gotPrecalcOnLine << " offset " << offset << std::endl; // } FILE* fp = fopen(sCurrentPrecalcPathName.c_str(), "rb"); if (fp!=NULL) { fseek(fp, offset, SEEK_SET); // We should do some verification here, for example by recalculating the middle chain, to catch corrupted files if(fread(pIndexE, sizeof(uint64_t), (unsigned long)m_nRainbowChainLen-1, fp) != (unsigned long)m_nRainbowChainLen-1) { std::cout << "Error reading " << sCurrentPrecalcPathName << std::endl; } fclose(fp); } else { std::cout << "Cannot open precalculation file " << sCurrentPrecalcPathName << "." << std::endl; } //printf("\npIndexE[0]: %s\n", uint64tostr(pIndexE[0]).c_str()); //printf("\npIndexE[nRainbowChainLen-2]: %s\n", uint64tostr(pIndexE[m_nRainbowChainLen-2]).c_str()); return true; } return false; }
bool CChainWalkContext::LoadCharset( std::string sName ) { m_vCharset.clear(); if (sName == "byte") { stCharset tCharset; int i; for (i = 0x00; i <= 0xff; i++) tCharset.m_PlainCharset[i] = (unsigned char) i; tCharset.m_nPlainCharsetLen = MAX_PLAIN_LEN; tCharset.m_sPlainCharsetName = sName; tCharset.m_sPlainCharsetContent = "0x00, 0x01, ... 0xff"; m_vCharset.push_back(tCharset); return true; } if(sName.substr(0, 6) == "hybrid") // Hybrid charset consisting of 2 charsets { if (sName.substr(6, 2) == "3(") { size_t pos = sName.find_last_of(')'); if (pos == std::string::npos) return false; m_ks = KeySpace::load(sName.substr(8, pos - 8).c_str(), CE_ASCII_BIN8 | CE_NULL_PADDED); // hybrid3(file name)#0-0 if (m_ks == NULL) return false; m_nHybridCharset = 3; return true; } else if (sName.substr(6, 2) == "2(") m_nHybridCharset = 2; else if (sName.substr(6, 1) == "(") m_nHybridCharset = 1; else { printf("hybrid version not supported\n"); return false; } } else m_nHybridCharset = 0; bool readCharset = false; std::vector<std::string> vLine; std::vector<std::string> internal_charset; vLine.clear(); internal_charset.clear(); internal_charset.push_back("byte = []"); internal_charset.push_back("alpha = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]"); internal_charset.push_back("alpha-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]"); internal_charset.push_back("alpha-numeric = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"); internal_charset.push_back("alpha-numeric-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]"); internal_charset.push_back("alpha-numeric-symbol14 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D]"); internal_charset.push_back("alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x20]"); internal_charset.push_back("all = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F]"); internal_charset.push_back("all-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]"); internal_charset.push_back("alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]"); internal_charset.push_back("lm-frt-cp437 = [\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7D\x7E\x80\x8E\x8F\x90\x92\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA5\xE0\xE1\xE2\xE3\xE4\xE6\xE7\xE8\xE9\xEA\xEB\xEE]"); internal_charset.push_back("lm-frt-cp850 = [\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7D\x7E\x80\x8E\x8F\x90\x92\x99\x9A\x9C\x9D\x9F\xA5\xB5\xB6\xB7\xBD\xBE\xC7\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xDE\xE0\xE1\xE2\xE3\xE5\xE6\xE8\xE9\xEA\xEB\xED\xEF]"); internal_charset.push_back("lm-frt-cp437-850 = [\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7D\x7E\x80\x8E\x8F\x90\x92\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA5\xB5\xB6\xB7\xBD\xBE\xC7\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xDE\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xED\xEE\xEF]"); internal_charset.push_back("numeric = [0123456789]"); internal_charset.push_back("numeric-space = [0123456789 ]"); internal_charset.push_back("loweralpha = [abcdefghijklmnopqrstuvwxyz]"); internal_charset.push_back("loweralpha-space = [abcdefghijklmnopqrstuvwxyz ]"); internal_charset.push_back("loweralpha-numeric = [abcdefghijklmnopqrstuvwxyz0123456789]"); internal_charset.push_back("loweralpha-numeric-space = [abcdefghijklmnopqrstuvwxyz0123456789 ]"); internal_charset.push_back("loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D]"); internal_charset.push_back("loweralpha-numeric-all = [abcdefghijklmnopqrstuvwxyz0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F]"); internal_charset.push_back("loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]"); internal_charset.push_back("mixalpha = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]"); internal_charset.push_back("mixalpha-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]"); internal_charset.push_back("mixalpha-numeric = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]"); internal_charset.push_back("mixalpha-numeric-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]"); internal_charset.push_back("mixalpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D]"); internal_charset.push_back("mixalpha-numeric-all = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F]"); internal_charset.push_back("mixalpha-numeric-symbol32-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]"); internal_charset.push_back("mixalpha-numeric-all-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]"); #ifdef USE_INTEGRATED_CHARSET vLine = internal_charset; readCharset = true; #else #ifdef BOINC if ( boinc_ReadLinesFromFile( "charset.txt", vLine ) ) readCharset = true; else { vLine = internal_charset; readCharset = true; } #else if ( ReadLinesFromFile("charset.txt", vLine) ) readCharset = true; else if ( ReadLinesFromFile(GetApplicationPath() + "charset.txt", vLine) ) readCharset = true; else { vLine = internal_charset; readCharset = true; } #endif #endif if ( readCharset ) { int i; for (i = 0; (uint32_t)i < vLine.size(); i++) { // Filter comment if (vLine[i][0] == '#') continue; std::vector<std::string> vPart; if (SeperateString(vLine[i], "=", vPart)) { // sCharsetName std::string sCharsetName = TrimString(vPart[0]); if (sCharsetName == "") continue; // sCharsetName charset check bool fCharsetNameCheckPass = true; uint32_t j; for (j = 0; j < sCharsetName.size(); j++) { if ( !isalpha(sCharsetName[j]) && !isdigit(sCharsetName[j]) && (sCharsetName[j] != '-')) { fCharsetNameCheckPass = false; break; } } if (!fCharsetNameCheckPass) { printf("invalid charset name %s in charset configuration file\n", sCharsetName.c_str()); continue; } // sCharsetContent std::string sCharsetContent = TrimString(vPart[1]); if (sCharsetContent == "" || sCharsetContent == "[]") continue; if (sCharsetContent[0] != '[' || sCharsetContent[sCharsetContent.size() - 1] != ']') { printf("invalid charset content %s in charset configuration file\n", sCharsetContent.c_str()); continue; } sCharsetContent = sCharsetContent.substr(1, sCharsetContent.size() - 2); if (sCharsetContent.size() > MAX_PLAIN_LEN) { printf("charset content %s too long\n", sCharsetContent.c_str()); continue; } //printf("%s = [%s]\n", sCharsetName.c_str(), sCharsetContent.c_str()); // Is it a hybrid? if( m_nHybridCharset != 0 ) { std::vector<tCharset> vCharsets; if ( !GetHybridCharsets(sName, vCharsets) ) { std::cout << "Failed to GetHybridCharsets: " << sName << std::endl; return false; } if(sCharsetName == vCharsets[m_vCharset.size()].sName) { stCharset tCharset; tCharset.m_nPlainCharsetLen = sCharsetContent.size(); memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen); tCharset.m_sPlainCharsetName = sCharsetName; tCharset.m_sPlainCharsetContent = sCharsetContent; tCharset.m_nPlainLenMin = vCharsets[m_vCharset.size()].nPlainLenMin; tCharset.m_nPlainLenMax = vCharsets[m_vCharset.size()].nPlainLenMax; m_vCharset.push_back(tCharset); if(vCharsets.size() == m_vCharset.size()) return true; //i = 0; // Start the lookup over again for the next charset // Sc00bz indicates this fixes a bug of skipping line 1 // of charset.txt i = -1; // Start the lookup over again for the next charset } } else if (sCharsetName == sName) { stCharset tCharset; tCharset.m_nPlainCharsetLen = sCharsetContent.size(); memcpy(tCharset.m_PlainCharset, sCharsetContent.c_str(), tCharset.m_nPlainCharsetLen); tCharset.m_sPlainCharsetName = sCharsetName; tCharset.m_sPlainCharsetContent = sCharsetContent; m_vCharset.push_back(tCharset); return true; } } } printf("charset %s not found in charset.txt\n", sName.c_str()); } else printf("can't open charset configuration file\n"); return false; }
bool CChainWalkContext::SetupWithPathName( std::string sPathName, int& nRainbowChainLen, int& nRainbowChainCount) { // something like lm_alpha#1-7_0_100x16_test.rt #ifdef _WIN32 std::string::size_type nIndex = sPathName.find_last_of('\\'); #else std::string::size_type nIndex = sPathName.find_last_of('/'); #endif if (nIndex != std::string::npos) sPathName = sPathName.substr(nIndex + 1); if (sPathName.size() < 3) { printf("%s is not a rainbow table\n", sPathName.c_str()); return false; } if (sPathName.substr(sPathName.size() - 5) == ".rti2") { RTfileFormatId = getRTfileFormatId( "RTI2" ); } else if (sPathName.substr(sPathName.size() - 4) == ".rti") { RTfileFormatId = getRTfileFormatId( "RTI" ); } else if (sPathName.substr(sPathName.size() - 3) == ".rt") { RTfileFormatId = getRTfileFormatId( "RT" ); } else { printf("%s is not a rainbow table\n", sPathName.c_str()); return false; } // Parse std::vector<std::string> vPart; if (!SeperateString(sPathName, "___x_", vPart)) { printf("filename %s not identified\n", sPathName.c_str()); return false; } std::string sHashRoutineName = vPart[0]; int nRainbowTableIndex = atoi(vPart[2].c_str()); nRainbowChainLen = atoi(vPart[3].c_str()); nRainbowChainCount = atoi(vPart[4].c_str()); // Parse charset definition std::string sCharsetDefinition = vPart[1]; std::string sCharsetName; int nPlainLenMin = 0, nPlainLenMax = 0; // printf("Charset: %s", sCharsetDefinition.c_str()); if(sCharsetDefinition.substr(0, 6) == "hybrid") // Hybrid table { sCharsetName = sCharsetDefinition; } else { if ( sCharsetDefinition.find('#') == std::string::npos ) // For backward compatibility, "#1-7" is implied { sCharsetName = sCharsetDefinition; nPlainLenMin = 1; nPlainLenMax = 7; } else { std::vector<std::string> vCharsetDefinitionPart; if (!SeperateString(sCharsetDefinition, "#-", vCharsetDefinitionPart)) { printf("filename %s not identified\n", sPathName.c_str()); return false; } else { sCharsetName = vCharsetDefinitionPart[0]; nPlainLenMin = atoi(vCharsetDefinitionPart[1].c_str()); nPlainLenMax = atoi(vCharsetDefinitionPart[2].c_str()); } } } // Setup if (!SetHashRoutine(sHashRoutineName)) { printf("hash routine %s not supported\n", sHashRoutineName.c_str()); return false; } if (!SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax)) return false; if (!SetRainbowTableIndex(nRainbowTableIndex)) { printf("invalid rainbow table index %d\n", nRainbowTableIndex); return false; } return true; }
//--------------------------------------------------------------------------- //Assumes v is shuffled and v[0] is the copyright line const std::vector<std::string> CreateDoc( const std::vector<std::string> text_in, const int n_questions_desired) { std::vector<std::string> text_out; text_out.push_back("<head>"); text_out.push_back("<title>Hometrainer 2 test</title>"); text_out.push_back("</head>"); text_out.push_back("<html>"); text_out.push_back("<body>"); text_out.push_back("<font size=\"4\" face=\"Courier New\" >"); //Parsing the questions const int sz = std::min(static_cast<int>(text_in.size()), n_questions_desired + 1); for (int i=1; i!=sz; ++i) //1, because first line is signature { //Obtain the string to split const std::string str_to_split_original = text_in[i]; if (str_to_split_original.empty() == true) continue; //Replace \, by {comma} const std::string str_to_split = ReplaceAll(str_to_split_original,"\\,","{comma}"); //Write string to split to debug const std::string debug_output = "MyDebug:" + str_to_split; OutputDebugString(debug_output.c_str()); const std::vector<std::string> v_original = SeperateString(str_to_split,","); //Replace {comma} by a comma for each std::string in v const std::vector<std::string> v = ReplaceAll(v_original,"{comma}",","); if (v.empty()==true) continue; const std::string filename = v[0]; //const std::string filename = m_path + '\\' + v[0]; const std::string& question = v[1]; const std::string& answer = v[2]; if (answer.empty()) continue; if (!filename.empty()) { text_out.push_back("<img src = \"" + filename + "\" />"); //text_out.push_back("<img src = \"" + filename + "\" alt = \"My Image\" />"); } const std::vector<std::string> false_answers(&v[3],v.end()); if (false_answers.empty()) { //Open question //Create the doc const std::string question_line = "<p>" + boost::lexical_cast<std::string>(i) + ". " + question + "</p>"; text_out.push_back(question_line); const std::string line_to_write_on = "<p>" + std::string("_",40) + "</p>"; text_out.push_back(line_to_write_on); } else { //Multiple choice question //Prepare the answers std::vector<std::string> answers; answers.push_back(answer); std::copy(false_answers.begin(),false_answers.end(),std::back_inserter(answers)); std::sort(answers.begin(),answers.end()); //Create the doc const std::string question_line = "<p>" + boost::lexical_cast<std::string>(i) + ". " + question + "</p>"; text_out.push_back(question_line); text_out.push_back("<ul type=\"disc\" >"); const int n_answers = answers.size(); for (int i=0; i!=n_answers; ++i) { const std::string s = "<li> " + answers[i] + "</li>"; text_out.push_back(s); } text_out.push_back("</ul>"); text_out.push_back("<p></p>"); //Empty line } } text_out.push_back("</font>"); text_out.push_back("</body>"); text_out.push_back("</html>"); return text_out; }
///Parse a line in a Parameter file. void ribi::gtst::Parameters::Parse(const std::string& s) { if (s.empty()) return; if (s.size() > 0 && s.substr(0,1) == "#") return; if (s.size() > 1 && s.substr(0,2) == "//") return; ///Parameters starting with finished_ are parsed by ParametersFinished if (s.size() > 9 && s.substr(0,9) == "finished_") { const std::string t = s.substr(9,s.size()-9); this->GetFinished()->Parse(t); return; } ///Parameters starting with finished_ are parsed by ParametersGroupReAssign if (s.size() > 13 && s.substr(0,13) == "group_assign_") { const std::string t = s.substr(13,s.size()-13); this->GetGroupAssign()->Parse(t); return; } ///Parameters starting with finished_ are parsed by ParametersGroupReAssign if (s.size() > 15 && s.substr(0,15) == "group_reassign_") { const std::string t = s.substr(15,s.size()-15); this->GetGroupReAssign()->Parse(t); return; } ///Parameters starting with finished_ are parsed by ParametersGroupReAssign if (s.size() > 14 && s.substr(0,14) == "assign_payoff_") { const std::string t = s.substr(14,s.size()-14); this->GetAssignPayoff()->Parse(t); return; } ///Parameters starting with finished_ are parsed by ParametersViewResultsGroup if (s.size() > 20 && s.substr(0,20) == "view_results_voting_") { const std::string t = s.substr(20,s.size()-20); this->GetViewResultsVoting()->Parse(t); return; } ///Parameters starting with finished_ are parsed by ParametersViewResultsGroup if (s.size() > 19 && s.substr(0,19) == "view_results_group_") { const std::string t = s.substr(19,s.size()-19); this->GetViewResultsGroup()->Parse(t); return; } ///Parameters starting with finished_ are parsed by ParametersViewResultsGroup if (s.size() > 14 && s.substr(0,14) == "assign_payoff_") { const std::string t = s.substr(14,s.size()-14); this->GetAssignPayoff()->Parse(t); return; } if (s.size() > 14 && s.substr(0,14) == "choose_action_") { const std::string t = s.substr(14,s.size()-14); this->GetChooseAction()->Parse(t); return; } if (s.size() > 5 && s.substr(0,5) == "chat_") { const std::string t = s.substr(5,s.size()-5); this->GetChat()->Parse(t); return; } if (s.size() > 7 && s.substr(0,7) == "voting_") { const std::string t = s.substr(7,s.size()-7); this->GetVoting()->Parse(t); return; } //Participants if (s.size() > 12 && s.substr(0,12) == "participant=") { const std::string t = s.substr(12,s.size() - 12); const std::vector<std::string> v = SeperateString(t,','); if (v.size() != 2) { throw std::runtime_error((std::string("Incorrectly formed participant line: ") + s).c_str());; } assert(v.size() == 2 && "Participant must have two elements"); boost::shared_ptr<GroupAssigner> group_assigner = GroupAssigner::CreateAssigner(v[0]); const std::string ip_address_str = v[1]; boost::shared_ptr<Participant> participant( new Participant(group_assigner,m_server) ); if (ip_address_str!="*") { try { boost::shared_ptr<SafeIpAddress> ip_address(new SafeIpAddress(ip_address_str)); participant->SetIpAddress(ip_address); } catch (std::logic_error&) { throw std::runtime_error((std::string("Incorrectly formed IP address: ") + ip_address_str).c_str()); } } m_participants.push_back(participant); return; } throw std::runtime_error((std::string("Unparsable parameter file line: ") + s).c_str()); }
//--------------------------------------------------------------------------- void TFormScoreTests::ReadFile(const String& filename) { const int row = StringGridStudents->RowCount - 1; const std::string file_stripped = RemoveExtension(RemovePath(filename.c_str())); ++StringGridStudents->RowCount; StringGridStudents->Cells[0][row] = row; StringGridStudents->Cells[1][row] = file_stripped.c_str(); StringGridStudents->Cells[2][row] = ""; StringGridStudents->Cells[3][row] = ""; const int key = EditKey->Text.ToInt(); const int penalty = EditPenalty->Text.ToInt(); const Encranger e(key); //Load file std::vector<std::string> v = FileToVector(filename.c_str()); const int sz = v.size(); for (int i=0; i!=sz; ++i) { //Deencrypt file v[i] = e.Deencrypt(v[i]); //Remove asterisks v[i] = ReplaceAll(v[i],"*",""); } const std::string username = FindUserName(v); if (username.empty()) { StringGridStudents->Cells[3][row] = "Username not found"; StringGridStudents->Cells[2][row] = "1.0 or 1.1"; return; } if (username != file_stripped) { StringGridStudents->Cells[3][row] = "Filename differs from username"; StringGridStudents->Cells[2][row] = "1.1"; return; } int n_correct = 0; const int n_questions = CountQuestions(v); LabelNquestions->Caption = "#questions: " + IntToStr(n_questions); for (int i=0; i!=sz; ++i) { if (v[i].empty()) continue; const std::vector<std::string> line_markup = SeperateString(v[i],","); //Replace {comma} by a comma for each std::string in v const std::vector<std::string> line = ReplaceAll(line_markup,"{comma}",","); OutputDebugString(line.size() >= 1 ? line[0].c_str() : "line[0] = {}"); OutputDebugString(line.size() >= 2 ? line[1].c_str() : "line[1] = {}"); OutputDebugString(line.size() >= 3 ? line[2].c_str() : "line[2] = {}"); OutputDebugString(line.size() >= 4 ? line[3].c_str() : "line[3] = {}"); //assert(line.size() == 2); WORKAROUND if (line[0]=="NAME") continue; const bool is_correct = (line[line.size()-1]=="Y"); //WORKAROUND assert(line[line.size()-1]=="Y" || line[line.size()-1]=="N"); //WORKAROUND if (is_correct) ++n_correct; ScoreQuestion(line[0],is_correct); } //Calculate student's score assert(n_questions - penalty > 0); const double fraction = static_cast<double>(n_correct - penalty) / static_cast<double>(n_questions - penalty); const double init_score = 1.0 + (9.0 * fraction); const double score_above_one = (init_score < 1.0 ? 1.0 : init_score); const double score_below_ten = (score_above_one > 10.0 ? 10.0 : score_above_one); const double score = score_below_ten; StringGridStudents->Cells[2][row] = score; }