//static std::string & OTString::trim(std::string& str) { std::string whitespaces (" \t\f\v\n\r"); // ----------------------------------- size_t found = str.find_first_not_of(whitespaces); if (found != std::string::npos) { str.erase(0, found); } // ----------------------------------- found = str.find_last_not_of(whitespaces); if (found != std::string::npos) { str.erase(found+1); } // ----------------------------------- // OTLog::vError("(DEBUGGING OTString.cpp) CONTRACT HAS BEEN TRIMMED!!! RESULT: \n\n***BEGIN TRIM DATA:%s******END TRIM DATA\n\n", // str.c_str()); // todo temp remove return str; }
void ScriptFileInterpreter::toggleComment(bool addComment) { // Get selected text std::string whitespaces(" \t\f\r"); int selFromLine, selFromInd, selToLine, selToInd; m_editor->getSelection(&selFromLine, &selFromInd, &selToLine, &selToInd); // Expand selection to first character on start line to the end char on second // line. if (selFromLine == -1) { m_editor->getCursorPosition(&selFromLine, &selFromInd); selToLine = selFromLine; } // For each line, select it, copy the line into a new string minus the comment QString replacementText = ""; // If it's adding comment, check all lines to find the lowest index for a non // space character int minInd = -1; if (addComment) { for (int i = selFromLine; i <= selToLine; ++i) { std::string thisLine = m_editor->text(i).toUtf8().constData(); int lineFirstChar = static_cast<int>(thisLine.find_first_not_of(whitespaces + "\n")); if (minInd == -1 || (lineFirstChar != -1 && lineFirstChar < minInd)) { minInd = lineFirstChar; } } } for (int i = selFromLine; i <= selToLine; ++i) { std::string thisLine = m_editor->text(i).toUtf8().constData(); int lineFirstChar = static_cast<int>(thisLine.find_first_not_of(whitespaces + "\n")); if (lineFirstChar != -1) { if (addComment) { thisLine.insert(minInd, "#"); } else { // Check that the first character is a # if (thisLine[lineFirstChar] == '#') // Remove the comment, or ignore to add as is { thisLine = thisLine.erase(lineFirstChar, 1); } } } replacementText = replacementText + QString::fromStdString(thisLine); } m_editor->setSelection(selFromLine, 0, selToLine, m_editor->lineLength(selToLine)); replaceSelectedText(m_editor, replacementText); m_editor->setCursorPosition(selFromLine, selFromInd); }
std::string& String::trim(std::string& str) { std::string whitespaces(" \t\f\v\n\r"); std::size_t found = str.find_first_not_of(whitespaces); if (found != std::string::npos) { str.erase(0, found); } found = str.find_last_not_of(whitespaces); if (found != std::string::npos) { str.erase(found + 1); } return str; }
WCardFilter * WCFilterFactory::Leaf(string src) { string filter; string whitespaces(" \t\f\v\n\r"); size_t x = src.find_first_not_of(whitespaces); if (x != string::npos) src = src.substr(x); for (size_t i = 0; i < src.size(); i++) { unsigned char c = src[i]; if (isspace(c)) continue; if (c == '(') { //Scan to ')', call Construct. size_t end = src.find(")", i); if (end != string::npos) { string expr = src.substr(i + 1, i - end); return NEW WCFilterGROUP(Construct(expr)); } } else if (c == '{') { //Scan to '}', call Construct. size_t end = src.find("}", i); if (end != string::npos) { string expr = src.substr(i + 1, i - end); return NEW WCFilterNOT(Construct(expr)); } } else if (c == ':') { //Scan ahead to ';', inbetween this is an argument size_t end = src.find(";", i); if (end != string::npos && filter.size()) { string arg = src.substr(i + 1, end - i - 1); return Terminal(filter, arg); } } else filter += c; } return NEW WCFilterNULL(); }
std::string time_wspace() const { std::string str(to_string()); std::string whitespaces(" \t\f\v\n\r"); return str.erase(str.find_last_not_of(whitespaces)+1); }
int CHHashFileVSalted::OpenHashFile(std::string filename) { std::ifstream hashFile; std::string fileLine; std::string hashValue; std::string saltValue; HashSalted HashVectorEntry; size_t separatorPos; uint64_t fileLineCount = 0; std::string whitespaces (" \t\f\v\n\r"); size_t found; HashVectorEntry.passwordFound = 0; HashVectorEntry.passwordOutputToFile = 0; HashVectorEntry.passwordPrinted = 0; hashFile.open(filename.c_str(), std::ios_base::in); if (!hashFile.good()) { std::cout << "ERROR: Cannot open hashfile " << filename <<"\n"; exit(1); } while (std::getline(hashFile, fileLine)) { HashVectorEntry.hash.clear(); HashVectorEntry.salt.clear(); found=fileLine.find_last_not_of(whitespaces); if (found!=std::string::npos) fileLine.erase(found+1); else fileLine.clear(); #if CHHASHFILEVSALTED_DEBUG printf("Hash length: %d\n", (int)fileLine.length()); #endif // If the line length is 0, continue - blank line that we can ignore. if (fileLine.length() == 0) { continue; } // Determine the location of the separator symbol in the line. separatorPos = fileLine.find_first_of(this->SeperatorSymbol, 0); if (separatorPos == std::string::npos) { // Separator not found - abort! printf("Separator character '%c' not found on line %lu!\n", this->SeperatorSymbol, fileLineCount); exit(1); } else { #if CHHASHFILEVSALTED_DEBUG printf("Found split at %d\n", (int)separatorPos); #endif } if (this->SaltIsFirst) { // Salt is the first part of the line. // Check hash length - don't forget the length of the separator. if ((fileLine.length() - (separatorPos + 1)) != (this->HashLengthBytes * 2)) { printf("Error: Hash on line %lu is not correct length!\n", fileLineCount); exit(1); } // Copy the salt into the salt string. saltValue = fileLine.substr(0, separatorPos); // Copy the hash into the hash string - from the separator to the end of the line. hashValue = fileLine.substr(separatorPos + 1, std::string::npos); #if CHHASHFILEVSALTED_DEBUG printf("Salt:Hash format\n"); printf("Salt: %s\n", saltValue.c_str()); printf("Hash: %s\n", hashValue.c_str()); #endif } else { // Hash is the first part of the line. // Check the hash length to ensure it is correct. if (separatorPos != (this->HashLengthBytes * 2)) { printf("Error: Hash on line %lu is not correct length!\n", fileLineCount); exit(1); } // Copy the hash into the hash string. hashValue = fileLine.substr(0, separatorPos); // Copy the salt into the salt string - from the separator to the end of the line. saltValue = fileLine.substr(separatorPos + 1, std::string::npos); #if CHHASHFILEVSALTED_DEBUG printf("Hash:Salt format\n"); printf("Hash: %s\n", hashValue.c_str()); printf("Salt: %s\n", saltValue.c_str()); #endif } // Deal with the hash: It should be ASCII-hex, so convert it. HashVectorEntry.hash = this->convertAsciiToBinary(hashValue); // Deal with the salt properly. if (this->SaltIsLiteral) { // Salt is literal - copy it into the salt vector with a std::copy operation. HashVectorEntry.salt.reserve(saltValue.length()); std::copy(saltValue.begin(), saltValue.end(), std::back_inserter(HashVectorEntry.salt)); } else { // Salt is ascii-hex - convert it from a string to a vector. HashVectorEntry.salt = this->convertAsciiToBinary(saltValue); } #if CHHASHFILEVSALTED_DEBUG printf("Loaded hash value: 0x"); for (int i = 0; i < HashVectorEntry.hash.size(); i++) { printf("%02x", HashVectorEntry.hash[i]); } printf("\n"); printf("Loaded salt value: 0x"); for (int i = 0; i < HashVectorEntry.salt.size(); i++) { printf("%02x", HashVectorEntry.salt[i]); } printf("\n"); #endif this->Hashes.push_back(HashVectorEntry); fileLineCount++; } this->SortHashes(); // Set total hashes and hashes remaining to size of hash vector. this->TotalHashes = this->Hashes.size(); this->TotalHashesRemaining = this->TotalHashes; hashFile.close(); this->ExtractUncrackedSalts(); return 1; }
int CHHashFileVSSHA::OpenHashFile(std::string filename) { std::ifstream hashFile; std::string fileLine; std::string userData, hashData; std::vector<uint8_t> rawVector, hashVector; HashSalted HashVectorEntry; uint32_t fileLineCount = 0; std::string whitespaces (" \t\f\v\n\r"); size_t found; HashVectorEntry.passwordFound = 0; HashVectorEntry.passwordOutputToFile = 0; HashVectorEntry.passwordPrinted = 0; this->HashFileMutex.lock(); hashFile.open(filename.c_str(), std::ios_base::in); if (!hashFile.good()) { std::cout << "ERROR: Cannot open hashfile " << filename <<"\n"; exit(1); } while (std::getline(hashFile, fileLine)) { // Be nice to users and 1-index the lines fileLineCount++; HashVectorEntry.hash.clear(); HashVectorEntry.salt.clear(); HashVectorEntry.originalSalt.clear(); HashVectorEntry.userData.clear(); found=fileLine.find_last_not_of(whitespaces); if (found!=std::string::npos) fileLine.erase(found+1); else fileLine.clear(); // Look for the separator character. If found, there's a username to // split out. found = fileLine.find(this->InputDelineator, 0); userData.clear(); hashData.clear(); if (found != std::string::npos) { // Username found - split it out. userData = fileLine.substr(0, found); hashData = fileLine.substr(found + 1, fileLine.length()); } else { // No username - simply copy the hash. hashData = fileLine; } // SSHA can be variable length, so do not check line length. // Check for the '{SSHA}' prefix - if not found, continue. if ((hashData[0] != '{') || (hashData[1] != 'S') || (hashData[2] != 'S') || (hashData[3] != 'H') || (hashData[4] != 'A') || (hashData[5] != '}')) { printf("Prefix not found: Line %d\n", fileLineCount); continue; } // If it's a valid line, do the work. if (hashData.length() > 0) { // Load the base64 part of the hash - past the {SSHA} prefix. hashVector = std::vector<uint8_t>(hashData.begin() + 6, hashData.end()); HashVectorEntry.userData = userData; rawVector = this->base64Decode(hashVector); if (rawVector.size() <= 20) { printf("Hash data length error: Line %d\n", fileLineCount); continue; } // The first 20 bytes are the SHA1 hash HashVectorEntry.hash.assign(rawVector.begin(), rawVector.begin() + 20); // The remaining bytes are the salt. HashVectorEntry.originalSalt.assign(rawVector.begin() + 20, rawVector.end()); HashVectorEntry.salt = HashVectorEntry.originalSalt; this->Hashes.push_back(HashVectorEntry); } } this->SortHashes(); // Set total hashes and hashes remaining to size of hash vector. this->TotalHashes = this->Hashes.size(); this->TotalHashesRemaining = this->TotalHashes; this->clearCaches(); hashFile.close(); this->HashFileMutex.unlock(); return 1; }
WCardFilter * WCFilterFactory::Construct(string src) { size_t x = 0; string whitespaces(" \t\f\v\n\r"); x = src.find_first_not_of(whitespaces); if (x != string::npos) src = src.substr(x); size_t srcLength = src.size(); if (!srcLength) return NEW WCFilterNULL(); //Empty string. for (size_t i = 0; i < srcLength; i++) { unsigned char c = src[i]; if (isspace(c)) continue; if (c == '(') { //Parenthesis size_t endp = findNext(src, i); if (endp != string::npos) { WCFilterGROUP * g = NEW WCFilterGROUP(Construct(src.substr(i + 1, endp - 1))); if ( endp < (srcLength - 1) ) { if (src[endp + 1] == '|') return NEW WCFilterOR(g, Construct(src.substr(endp + 2))); else if (src[endp + 1] == '&') return NEW WCFilterAND(g, Construct(src.substr(endp + 2))); } return g; } else return NEW WCFilterNULL(); } else if (c == '{') { //Negation size_t endp = findNext(src, i, '{', '}'); if (endp != string::npos) { WCFilterNOT * g = NEW WCFilterNOT(Construct(src.substr(i + 1, endp - 1))); if (endp < (srcLength - 1) ) { if (src[endp + 1] == '|') return NEW WCFilterOR(g, Construct(src.substr(endp + 2))); else if (src[endp + 1] == '&') return NEW WCFilterAND(g, Construct(src.substr(endp + 2))); } return g; } else return NEW WCFilterNULL(); } else if (c == '&') { //And return NEW WCFilterAND(Construct(src.substr(0, i)), Construct(src.substr(i + 1))); } else if (c == '|') { //Or return NEW WCFilterOR(Construct(src.substr(0, i)), Construct(src.substr(i + 1))); } } return Leaf(src); }