GeoResource::GeoResource(int xsz, int ysz, int bsz, GDALDataType datatype, string filename, dictionary options) : _Filename(filename) { // format, driver, and file extension string format = Options::DefaultFormat(); //if (format == "GTiff") options["COMPRESS"] = "LZW"; GDALDriver *driver = GetGDALDriverManager()->GetDriverByName(format.c_str()); // TODO check for null driver and create method // Check extension string ext = driver->GetMetadataItem(GDAL_DMD_EXTENSION); if (ext != "" && _Filename.extension().string() != ('.'+ext)) _Filename = boost::filesystem::path(_Filename.string() + '.' + ext); // add options char **papszOptions = NULL; if (options.size()) { for (dictionary::const_iterator imap=options.begin(); imap!=options.end(); imap++) papszOptions = CSLSetNameValue(papszOptions,imap->first.c_str(),imap->second.c_str()); } // create file //BOOST_LOG_TRIVIAL(info) << Basename() << ": create new file " << xsz << " x " << ysz << " x " << bsz << std::endl; if (Options::Verbose() > 4) std::cout << Basename() << ": create new file " << xsz << " x " << ysz << " x " << bsz << std::endl; _GDALDataset.reset( driver->Create(_Filename.string().c_str(), xsz,ysz,bsz,datatype, papszOptions) ); if (_GDALDataset.get() == NULL) { //BOOST_LOG_TRIVIAL(fatal) << "Error creating " << _Filename.string() << CPLGetLastErrorMsg() << std::endl; std::cout << "Error creating " << _Filename.string() << CPLGetLastErrorMsg() << std::endl; } }
/* * Given a word, add it to the dictionary, increment its count * and add the line number on which it was found. */ void processWord(string& word, dictionary& dict, int lineNumber) { if (word.size() > 0) { dictionary::iterator itr = dict.find(word); if (itr == dict.end()) { dict[word] = pair<int, vector<int> >(1, vector<int>(1, lineNumber)); } else { pair<int, vector<int> > value = itr->second; ++(value.first); value.second.push_back(lineNumber); // Update the dictionary reference dict[word] = value; } } }
void display(std::ostream & out, unsigned indent) const { svector<symbol> names; dictionary<info>::iterator it = m_info.begin(); dictionary<info>::iterator end = m_info.end(); for (; it != end; ++it) { names.push_back(it->m_key); } std::sort(names.begin(), names.end(), lt()); svector<symbol>::iterator it2 = names.begin(); svector<symbol>::iterator end2 = names.end(); for (; it2 != end2; ++it2) { for (unsigned i = 0; i < indent; i++) out << " "; out << *it2; info d; d.second = 0; m_info.find(*it2, d); SASSERT(d.second); out << " (" << d.first << ") " << d.second << "\n"; } }
/* * Given a dictionary of words, their frequency and line number of occurence, * print it in alphabetical order, in the format: * word {3:1,2,3} */ void print(dictionary& dict) { // Sort all the words in the dictionary vector<string> words; for(dictionary::iterator itr = dict.begin(); itr != dict.end(); ++itr) words.push_back(itr->first); sort(words.begin(), words.end()); // Go through the sorted list of words and print out the concordance. for (vector<string>::iterator i = words.begin(); i != words.end(); ++i) { cout << *i << "\t{"; pair<int, vector<int> > value = dict[*i]; cout << value.first << ":"; string comma = ""; for (vector<int>::iterator j = value.second.begin(); j != value.second.end(); ++j) { cout << comma << *j; comma = ","; } cout << "}" << endl; } }
void display(std::ostream & out, unsigned indent, bool smt2_style, bool include_descr) const { svector<symbol> names; dictionary<info>::iterator it = m_info.begin(); dictionary<info>::iterator end = m_info.end(); for (; it != end; ++it) { names.push_back(it->m_key); } std::sort(names.begin(), names.end(), lt()); svector<symbol>::iterator it2 = names.begin(); svector<symbol>::iterator end2 = names.end(); for (; it2 != end2; ++it2) { for (unsigned i = 0; i < indent; i++) out << " "; if (smt2_style) out << ':'; char const * s = it2->bare_str(); unsigned n = static_cast<unsigned>(strlen(s)); for (unsigned i = 0; i < n; i++) { if (smt2_style && s[i] == '_') out << '-'; else if (!smt2_style && s[i] == '-') out << '_'; else if (s[i] >= 'A' && s[i] <= 'Z') out << (s[i] - 'A' + 'a'); else out << s[i]; } info d; m_info.find(*it2, d); SASSERT(d.m_descr); out << " (" << d.m_kind << ")"; if (include_descr) out << " " << d.m_descr; if (d.m_default != 0) out << " (default: " << d.m_default << ")"; out << "\n"; } }
crack_index network_crack_http(const string target_ip,const unsigned int target_port,dictionary crack_dictionary,const string crack_express,const string crack_term) { string resolve_string(crack_express); split_result split; crack_index result; unsigned int username_point=find_string(resolve_string,"%username%"); if (-1==username_point) { dictionary crack_dictionary_; resolve_dictionary_add_username(crack_dictionary_,""); resolve_dictionary_add_password(crack_dictionary_, resolve_dictionary_get_password_list(crack_dictionary, resolve_dictionary_get_user_list(crack_dictionary)[0])); crack_dictionary=crack_dictionary_; } unsigned int password_point=find_string(resolve_string,"%password%"); if (-1==password_point) { dictionary crack_dictionary_; username_list name_list; name_list=resolve_dictionary_get_user_list(crack_dictionary); crack_dictionary=crack_dictionary_; for (dictionary::const_iterator username_iterator=crack_dictionary.begin(); username_iterator!=crack_dictionary.end(); ++username_iterator) resolve_dictionary_add_username(crack_dictionary,username_iterator->first); resolve_dictionary_add_password(crack_dictionary,""); } unsigned int length_point=find_string(resolve_string,"%length%"); unsigned int handle=scan_tcp_connect(target_ip.c_str(),target_port); if (-1!=handle) { for (dictionary::const_iterator username_iterator=crack_dictionary.begin(); username_iterator!=crack_dictionary.end(); ++username_iterator) { for (password_list::const_iterator password_iterator=username_iterator->second.begin(); password_iterator!=username_iterator->second.end(); ++password_iterator) { string packet(resolve_string); if (-1!=username_point) replace_string(packet,"%username%",username_iterator->first); if (-1!=password_point) replace_string(packet,"%password%",*password_iterator); packet=resolve_express(packet); if (-1!=length_point) { string http_body; split_result result_body(split_string(packet,"\r\n\r\n")); if (!result_body.second.empty()) { unsigned int length=result_body.second.length()-4; replace_string(packet,"%length%",number_to_string(length)); } } CRACK: scan_tcp_send(handle,packet.c_str(),packet.length()); char recv_buffer[NETWORK_CRACK_RECV_BUFFER_LENGTH]={0}; unsigned int recv_length=scan_tcp_recv(handle,recv_buffer,NETWORK_CRACK_RECV_BUFFER_LENGTH); if (-1!=recv_length && recv_length) { if (-1!=find_string(recv_buffer,crack_term)) { result.first=username_iterator->first; result.second=*password_iterator; scan_tcp_disconnect(handle); return result; } } else { scan_tcp_disconnect(handle); Sleep(50); handle=scan_tcp_connect(target_ip.c_str(),target_port); Sleep(50); goto CRACK; } } } scan_tcp_disconnect(handle); } return result; }