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()); }
void StringHash::ReadLinesFromFile(const char * filename) { IFILE f = ifopen(filename, "rb"); if (f == NULL) return; ReadLinesFromFile(f); ifclose(f); }
void GetHashList(const char *filename) { std::vector<std::string>vLine; ReadLinesFromFile((std::string)filename, vLine); int i, len, max; if ((int)vLine.size() > MAX_HASHES) max = MAX_HASHES; else max = (int)vLine.size(); for (i = 0; i < max; i++) { len = strlen(vLine[i].c_str()); gtk_list_store_append(gui.hash.store, &gui.hash.iter[db.n_hashes]); if (len == 32) gtk_list_store_set(gui.hash.store, &gui.hash.iter[db.n_hashes], 0, "MD5 | NTLM", 1, len, 2, vLine[i].c_str(), -1); else if (len == 40) gtk_list_store_set(gui.hash.store, &gui.hash.iter[db.n_hashes], 0, "SHA1", 1, len, 2, vLine[i].c_str(), -1); db.hashes.push_back(vLine[i]); db.n_hashes++; } db.fCrackerType = true; if ((int)vLine.size() > MAX_HASHES) MessageStackPush("col-red", "Maximum amount of hashes is %d\n", MAX_HASHES); }
void SyntheticDataGenerator::ReadJointAndTipTrajectory(std::string _jointTipTrajectoryfile, bool isEMmeasurement) { int numTubes = this->robot->GetNumOfTubes(); this->jointTrajectory.clear(); this->tipTrajectory.clear(); std::vector<::std::string> lineVector = ReadLinesFromFile(_jointTipTrajectoryfile); for(int i = 0; i < lineVector.size() ; ++i) { std::vector<double> doubleLineVector = DoubleVectorFromString(lineVector[i]); std::vector<double> joint(doubleLineVector.begin(), doubleLineVector.begin() + 2*numTubes+1), tip(doubleLineVector.begin()+2*numTubes+1, doubleLineVector.end()); // For now, tip has EM tracker frame. EM tracker has been attached on the robot tip // with its x-axis colinearly aligned to z-axis of robot tip in opposite direction. // So, the following lines swaps the x- and z-axes with proper signs. // Note that it doesn't mean 'tip' is the correct tip orientation. It is correct with z-axis, // but not correct with x- and y- axis. if(isEMmeasurement) for(int j = 0 ; j < 3; j++) { double temp = tip[3+j]; tip[3+j] = tip[9+j]; tip[9+j] = -temp; } this->jointTrajectory.push_back(joint); this->tipTrajectory.push_back(tip); } }
int main(int argc, char** argv) { if (argc != 3) { std::cout << "Error: Incorrect input arguments!" << std::endl; PrintUsage(); return 1; } String method = argv[1]; String input = argv[2]; std::vector<String> lines = ReadLinesFromFile(input); const String* knowledgeBase = nullptr; const String* query = nullptr; for (int i = 0; i < lines.size(); i++) { const String& line = lines[i]; if (Contains(line, "TELL")) knowledgeBase = &lines[++i]; else if (Contains(line, "ASK")) query = &lines[++i]; } // Apply natural language processing and solve via truth table if (method == "ENG") { String sentence = *knowledgeBase + ";"; sentence = ParseEnglish(sentence); std::vector<Statement*> statements = ParseStatements(sentence, true); TruthTableSolution(*query, statements, true); return 0; } if (!knowledgeBase || !query) { std::cout << "Error: invalid input file format!" << std::endl; PrintUsage(); return 2; } std::vector<Statement*> statements = ParseStatements(*knowledgeBase); if (method == "TT") TruthTableSolution(*query, statements); else if (method == "FC") ForwardChainingSolution(*query, statements); else if (method == "BC") BackwardChainingSolution(*query, statements); else { std::cout << "Error: Invalid method!"; PrintUsage(); return 3; } return 0; }
SyntheticDataGenerator::SyntheticDataGenerator(CTR* _robot, std::string _jointTrajectoryFile) : lineCounter(0) { this->robot = _robot; this->kinematics = new MechanicsBasedKinematics(_robot); this->kinematics->ActivateIVPJacobian(); std::vector<::std::string> lineVector = ReadLinesFromFile(_jointTrajectoryFile); for(int i = 0; i < lineVector.size() ; ++i) { std::vector<double> doubleLineVector = DoubleVectorFromString(lineVector[i]); doubleLineVector.erase(doubleLineVector.begin()+1+2*this->robot->GetNumOfTubes(), doubleLineVector.end()); this->jointTrajectory.push_back(doubleLineVector); } }
// 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(); } }
int main(int argc, char* argv[]) { #ifdef _WIN32 if (argc != 4) { Usage(); return 0; } string sWildCharPathName = argv[1]; string sInputType = argv[2]; string sInput = argv[3]; // vPathName vector<string> vPathName; GetTableList(sWildCharPathName, vPathName); #else if (argc < 4) { Usage(); return 0; } string sInputType = argv[argc - 2]; string sInput = argv[argc - 1]; // vPathName vector<string> vPathName; GetTableList(argc, argv, vPathName); #endif if (vPathName.size() == 0) { printf("no rainbow table found\n"); return 0; } // fCrackerType, vHash, vUserName, vLMHash bool fCrackerType; // true: hash cracker, false: lm cracker vector<string> vHash; // hash cracker vector<string> vUserName; // lm cracker vector<string> vLMHash; // lm cracker vector<string> vNTLMHash; // lm cracker if (sInputType == "-h") { fCrackerType = true; string sHash = sInput; if (NormalizeHash(sHash)) vHash.push_back(sHash); else printf("invalid hash: %s\n", sHash.c_str()); } else if (sInputType == "-l") { fCrackerType = true; string sPathName = sInput; vector<string> vLine; if (ReadLinesFromFile(sPathName, vLine)) { int i; for (i = 0; i < vLine.size(); i++) { string sHash = vLine[i]; if (NormalizeHash(sHash)) vHash.push_back(sHash); else printf("invalid hash: %s\n", sHash.c_str()); } } else printf("can't open %s\n", sPathName.c_str()); } else if (sInputType == "-f") { fCrackerType = false; string sPathName = sInput; LoadLMHashFromPwdumpFile(sPathName, vUserName, vLMHash, vNTLMHash); } else { Usage(); return 0; } if (fCrackerType && vHash.size() == 0) return 0; if (!fCrackerType && vLMHash.size() == 0) return 0; // hs CHashSet hs; if (fCrackerType) { int i; for (i = 0; i < vHash.size(); i++) hs.AddHash(vHash[i]); } else { int i; for (i = 0; i < vLMHash.size(); i++) { hs.AddHash(vLMHash[i].substr(0, 16)); hs.AddHash(vLMHash[i].substr(16, 16)); } } // Run CCrackEngine ce; ce.Run(vPathName, hs); // Statistics //printf("statistics\n"); //printf("-------------------------------------------------------\n"); //printf("plaintext found: %d of %d (%.2f%%)\n", hs.GetStatHashFound(), // hs.GetStatHashTotal(), // 100.0f * hs.GetStatHashFound() / hs.GetStatHashTotal()); //printf("total disk access time: %.2f s\n", ce.GetStatTotalDiskAccessTime()); //printf("total cryptanalysis time: %.2f s\n", ce.GetStatTotalCryptanalysisTime()); //printf("total chain walk step: %d\n", ce.GetStatTotalChainWalkStep()); //printf("total false alarm: %d\n", ce.GetStatTotalFalseAlarm()); //printf("total chain walk step due to false alarm: %d\n", ce.GetStatTotalChainWalkStepDueToFalseAlarm()); //printf("\n"); // Result //printf("result\n"); //printf("-------------------------------------------------------\n"); if (fCrackerType) { int i; for (i = 0; i < vHash.size(); i++) { string sPlain, sBinary; if (!hs.GetPlain(vHash[i], sPlain, sBinary)) { sPlain = "<notfound>"; sBinary = "<notfound>"; } //printf("%s %s hex:%s\n", vHash[i].c_str(), sPlain.c_str(), sBinary.c_str()); } } else { int i; for (i = 0; i < vLMHash.size(); i++) { string sPlain1, sBinary1; bool fPart1Found = hs.GetPlain(vLMHash[i].substr(0, 16), sPlain1, sBinary1); if (!fPart1Found) { sPlain1 = "<notfound>"; sBinary1 = "<notfound>"; } string sPlain2, sBinary2; bool fPart2Found = hs.GetPlain(vLMHash[i].substr(16, 16), sPlain2, sBinary2); if (!fPart2Found) { sPlain2 = "<notfound>"; sBinary2 = "<notfound>"; } string sPlain = sPlain1 + sPlain2; string sBinary = sBinary1 + sBinary2; // Correct case if (fPart1Found && fPart2Found) { unsigned char NTLMHash[16]; int nHashLen; ParseHash(vNTLMHash[i], NTLMHash, nHashLen); if (nHashLen != 16) printf("debug: nHashLen mismatch\n"); string sNTLMPassword; if (LMPasswordCorrectCase(sPlain, NTLMHash, sNTLMPassword)) { sPlain = sNTLMPassword; sBinary = HexToStr((const unsigned char*)sNTLMPassword.c_str(), sNTLMPassword.size()); } else printf("case correction for password %s fail!\n", sPlain.c_str()); } // Display //printf("%-14s %s hex:%s\n", vUserName[i].c_str(), // sPlain.c_str(), // sBinary.c_str()); } } return 0; }
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; }
KeySpace *KeySpace::load(const char *fileName, uint32_t charaterEncoding) { std::vector<std::string> lines; std::ifstream fin(fileName, std::ifstream::in); std::string line, name, charSet; std::map<std::string,std::string> charSets; std::map<std::string,std::string>::iterator charSetMapIt; std::list<std::string> subKeySpace; std::list<std::list<std::string> > subKeySpaces; std::list<std::string>::iterator charSetIt; std::list<std::list<std::string> >::iterator subKeySpaceIt; size_t pos, pos2; uint32_t len, lineNumber = 0; bool multiCharNames = false; char ch[2] = {0, 0}; #ifdef BOINC if (!boinc_ReadLinesFromFile(fileName, lines)) #else if (!ReadLinesFromFile(fileName, lines)) #endif { fprintf(stderr, "ERROR: Can't open key space file '%s'\n", fileName); return NULL; } // Read character sets while (1) { // Read line if (lineNumber >= lines.size()) { // eof fprintf(stderr, "ERROR: '%s' is not a valid key space file\n", fileName); return NULL; } line = lines[lineNumber]; lineNumber++; if (line.length() == 0 || line[0] == '#') { continue; } if (line[line.length() - 1] != ']') { break; } // Get character set name pos = line.find_first_of(" \t", 0, 2); if (pos == std::string::npos) { break; } name = line.substr(0, pos); // Get character set pos = line.find_first_not_of(" \t", pos, 2); if (pos == std::string::npos) { break; // this is not even possible... meh } if (line[pos] == '[') { charSet = line.substr(pos + 1, line.length() - pos - 2); } else if (line[pos] == 'h' && line[pos + 1] == '[') { charSet = HexToStr((unsigned char*)line.substr(pos + 2, line.length() - pos - 3).c_str(), line.length() - pos - 3); if (charSet.length() == 0 && line.length() - pos - 3 != 0) { fprintf(stderr, "ERROR: '%s' has an invalid character set on line #%u\n", fileName, lineNumber); return NULL; } } else { break; } if (charSet.length() == 0) { fprintf(stderr, "ERROR: '%s' has an empty character set on line #%u\n", fileName, lineNumber); return NULL; } // Insert into map if (charSets.find(name) == charSets.end()) { if (name.length() != 1) { multiCharNames = true; } charSets[name] = charSet; } else { fprintf(stderr, "ERROR: '%s' has a duplicate character set name on line #%u\n", fileName, lineNumber); return NULL; } } if (line[line.length() - 1] == ']') { fprintf(stderr, "ERROR line #%u: '%s' is not a valid key space file\n", lineNumber, fileName); return NULL; } // Read sub key spaces do { if (multiCharNames) { pos = 0; while (pos != std::string::npos) { // Get character set name pos2 = line.find_first_of(" \t", pos, 2); if (pos2 == std::string::npos) { pos2 = line.length(); } name = line.substr(pos, pos2 - pos); // Get character set charSetMapIt = charSets.find(name); if (charSetMapIt == charSets.end()) { fprintf(stderr, "ERROR: Character set name '%s' not found on line #%u from key space file '%s'\n", name.c_str(), lineNumber, fileName); return NULL; } subKeySpace.push_back(charSetMapIt->second); if (pos2 == line.length()) { break; } pos = line.find_first_not_of(" \t", pos2, 2); } } else { len = line.length(); for (pos = 0; pos < len; pos++) { *ch = line[pos]; if (*ch != ' ' && *ch != '\t') { charSetMapIt = charSets.find(ch); if (charSetMapIt == charSets.end()) { fprintf(stderr, "ERROR: Character set name '%c' not found on line #%u from key space file '%s'\n", *ch, lineNumber, fileName); return NULL; } subKeySpace.push_back(charSetMapIt->second); } } } subKeySpaces.push_back(subKeySpace); subKeySpace.clear(); // Read line do { if (lineNumber >= lines.size()) { line = ""; break; // eof } line = lines[lineNumber]; lineNumber++; } while ((line.length() == 0 || line[0] == '#')); } while (line.length() != 0); KeySpace *ks = KeySpace::init(subKeySpaces, charaterEncoding); if (ks != NULL) { ks->m_name = fileName; } return ks; }
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; }