inline BufferType * installPrefixBuffer( std::basic_ostream< CharType > & stream ) { BufferType * sbuf( new BufferType( stream.rdbuf() ) ); BufferManagerType::instance()->insert( stream, sbuf ); stream.rdbuf( sbuf ); return sbuf; }
int tcpdemux::process_ip4(const be13::packet_info &pi) { /* make sure that the packet is at least as long as the min IP header */ if (pi.ip_datalen < sizeof(struct be13::ip4)) { DEBUG(6) ("received truncated IP datagram!"); return -1; // couldn't process } const struct be13::ip4 *ip_header = (struct be13::ip4 *) pi.ip_data; DEBUG(100)("process_ip4. caplen=%d vlan=%d ip_p=%d",(int)pi.pcap_hdr->caplen,(int)pi.vlan(),(int)ip_header->ip_p); if(debug>200){ sbuf_t sbuf(pos0_t(),(const uint8_t *)pi.ip_data,pi.ip_datalen,pi.ip_datalen,false); sbuf.hex_dump(std::cerr); } /* for now we're only looking for TCP; throw away everything else */ if (ip_header->ip_p != IPPROTO_TCP) { DEBUG(50) ("got non-TCP frame -- IP proto %d", ip_header->ip_p); return -1; // couldn't process } /* check and see if we got everything. NOTE: we must use * ip_total_len after this, because we may have captured bytes * beyond the end of the packet (e.g. ethernet padding). */ size_t ip_len = ntohs(ip_header->ip_len); if (pi.ip_datalen < ip_len) { DEBUG(6) ("warning: captured only %ld bytes of %ld-byte IP datagram", (long) pi.ip_datalen, (long) ip_len); } /* XXX - throw away everything but fragment 0; this version doesn't * know how to do fragment reassembly. */ if (ntohs(ip_header->ip_off) & 0x1fff) { DEBUG(2) ("warning: throwing away IP fragment from X to X"); return -1; } /* figure out where the IP header ends */ size_t ip_header_len = ip_header->ip_hl * 4; /* make sure there's some data */ if (ip_header_len > ip_len) { DEBUG(6) ("received truncated IP datagram!"); return -1; } /* do TCP processing, faking an ipv6 address */ uint16_t ip_payload_len = ip_len - ip_header_len; ipaddr src(ip_header->ip_src.addr); ipaddr dst(ip_header->ip_dst.addr); return process_tcp(src, dst, AF_INET, pi.ip_data + ip_header_len, ip_payload_len, pi); }
bool TrackMapsCoordinates::loadTrackDataFile() { QString fName = F1LTCore::trackDataFile(); if (!fName.isNull()) { QFile f(fName); if (f.open(QIODevice::ReadOnly)) { QDataStream stream(&f); char *cbuf; stream >> cbuf; QString sbuf(cbuf); delete [] cbuf; if (sbuf != "F1LT_TD") return false; int size; stream >> size; for (int i = 0; i < size; ++i) { TrackCoordinates trackCoordinates; int coordSize; stream >> cbuf; trackCoordinates.name = QString(cbuf); delete [] cbuf; stream >> trackCoordinates.year; stream >> trackCoordinates.indexes[0]; stream >> trackCoordinates.indexes[1]; stream >> trackCoordinates.indexes[2]; stream >> coordSize; for (int j = 0; j < coordSize; ++j) { QPoint p; stream >> p; trackCoordinates.coordinates.append(p); } ltTrackCoordinates.append(trackCoordinates); // for (int j = 0; j < ltEvents.size(); ++j) // { // if (ltEvents[j].eventShortName.toLower() == trackCoordinates.name.toLower()) // { // ltEvents[j].trackCoordinates = trackCoordinates; // break; // } // } } return true; }
void Server::updateGame(int ticks) { if (paused == 0) { ball[0].move(ticks); if (state == RUNNING) { Buffer sbuf(BALLPOSITION); const Vec3f& pos = ball[0].getPosition(); sbuf.pushDouble(pos.x); sbuf.pushDouble(pos.y); sbuf.pushDouble(pos.z); sendPacket(sbuf, false); } } }
void scan_sceadan(const class scanner_params &sp,const recursion_control_block &rcb) { assert(sp.sp_version==scanner_params::CURRENT_SP_VERSION); if(sp.phase==scanner_params::PHASE_STARTUP){ assert(sp.info->si_version==scanner_info::CURRENT_SI_VERSION); sp.info->name = "bulk"; sp.info->author = "Simson Garfinkel"; sp.info->description = "perform bulk data scan"; sp.info->flags = (scanner_info::SCANNER_DISABLED | scanner_info::SCANNER_WANTS_NGRAMS | scanner_info::SCANNER_NO_ALL); sp.info->feature_names.insert("bulk"); sp.info->feature_names.insert("bulk"); sp.info->get_config("bulk_block_size",&opt_bulk_block_size,"Block size (in bytes) for bulk data analysis"); debug = sp.info->config->debug; histogram::precalc_entropy_array(opt_bulk_block_size); return; } feature_recorder *bulk_fr = sp.fs.get_name("bulk"); if(!bulk_fr) return; // all of the remianing steps need bulk_fr if(sp.phase==scanner_params::PHASE_INIT){ bulk_fr->set_flag(feature_recorder::FLAG_NO_CONTEXT | feature_recorder::FLAG_NO_STOPLIST | feature_recorder::FLAG_NO_ALERTLIST | feature_recorder::FLAG_NO_FEATURES ); } // classify a buffer if(sp.phase==scanner_params::PHASE_SCAN){ //if(sp.sbuf.pos0.isRecursive()){ /* Record the fact that a recursive call was made, which tells us about the data */ // bulk_fr->write(sp.sbuf.pos0,"",""); // tag that we found recursive data, not sure what kind //} if(sp.sbuf.pagesize < opt_bulk_block_size) return; // can't analyze something that small // Loop through the sbuf in opt_bulk_block_size sized chunks // for each one, examine the entropy and scan for bitlocker (unfortunately hardcoded) // This needs to have a general plug-in architecture for(size_t base=0;base+opt_bulk_block_size<=sp.sbuf.pagesize;base+=opt_bulk_block_size){ sbuf_t sbuf(sp.sbuf,base,opt_bulk_block_size); sector_classifier sc(bulk_fr,sbuf); sc.run(); } } if(sp.phase==scanner_params::PHASE_SHUTDOWN){ } }
int main(int argc,char **argv) { scanner_t *fn; if(argc!=2){ fprintf(stderr,"usage: %s scanner.so\n",argv[0]); exit(1); } #ifdef HAVE_DLOPEN const char *fname = argv[1]; char *name = strdup(fname); char *cc = strrchr(name,'.'); if(cc){ cc[0] = 0; } else { fprintf(stderr,"%s: cannot strip extension\n",name); exit(1); } if(!dlopen_preflight(fname)){ err(1,"dlopen_preflight - cannot open %s: %s",fname,dlerror()); } void *lib=dlopen(fname, RTLD_LAZY); if(lib==0) errx(1,"dlopen: %s\n",dlerror()); fn=(scanner_t *)dlsym(lib, name); if(fn==0) errx(1,"dlsym: %s\n",dlerror()); #else #ifdef HAVE_LOADLIBRARY /* Use Win32 LoadLibrary function */ /* See http://msdn.microsoft.com/en-us/library/ms686944(v=vs.85).aspx */ const char *fname = "hello.DLL"; HINSTANCE hinstLib = LoadLibrary(TEXT(fname)); if(hinstLib==0) errx(1,"LoadLibrary(%s) failed",fname); MYPROC fn = (MYPROC)GetProcAddress(hinstLib,"hello"); if(fn==0) errx(1,"GetProcAddress(%s) failed","hello"); #endif #endif uint8_t buf[100]; pos0_t p0(""); sbuf_t sbuf(p0,buf,sizeof(buf),sizeof(buf),false); feature_recorder_set fs(0); scanner_params sp(scanner_params::startup,sbuf,fs); recursion_control_block rcb(0,"STAND",true); scanner_info si; sp.info = &si; (*fn)(sp,rcb); std::cout << "Loaded scanner '" << si.name << "' by " << si.author << "\n"; dlclose(lib); return 0; }
void exclusive_scan(const vex::vector<T> &src, vex::vector<T> &dst) { auto queue = src.queue_list(); std::vector<T> tail; /* If there is more than one partition, we need to take a copy the last * element in each partition (except the last) as otherwise information * about it is lost. * * This must be captured here rather than later, in case the input and * output alias. */ if (queue.size() > 1) { tail.resize(queue.size() - 1); for (unsigned d = 0; d < tail.size(); ++d) { if (src.part_size(d)) tail[d] = src[src.part_start(d + 1) - 1]; } } // Scan partitions separately. for(unsigned d = 0; d < queue.size(); ++d) { if (src.part_size(d)) { boost::compute::command_queue q( queue[d]() ); boost::compute::buffer sbuf( src(d).raw() ); boost::compute::buffer dbuf( dst(d).raw() ); boost::compute::detail::scan( boost::compute::make_buffer_iterator<T>(sbuf, 0), boost::compute::make_buffer_iterator<T>(sbuf, src.part_size(d)), boost::compute::make_buffer_iterator<T>(dbuf, 0), true, q ); } } // If there are more than one partition, // update all of them except for the first. if (queue.size() > 1) { T sum{}; for(unsigned d = 0; d < tail.size(); ++d) { if (src.part_size(d)) { sum += tail[d]; sum += dst[src.part_start(d + 1) - 1]; // Wrap partition into vector for ease of use: vex::vector<T> part(queue[d + 1], dst(d + 1)); part += sum; } } } }
bool ReplicaExchange::do_exchange(double myscore0, double myscore1, int findex) { double myscore=myscore0-myscore1; double fscore; int myindex=index_[myrank_]; int frank=get_rank(findex); MPI_Sendrecv(&myscore,1,MPI_DOUBLE,frank,myrank_, &fscore,1,MPI_DOUBLE,frank,frank, MPI_COMM_WORLD, &status_); bool do_accept=get_acceptance(myscore,fscore); boost::scoped_array<int> sdel(new int[nproc_ - 1]); boost::scoped_array<int> rdel(new int[nproc_ - 1]); for(int i=0;i<nproc_-1;++i) {sdel[i]=0;} if(do_accept){ std::map<std::string,Floats>::iterator it; for (it = parameters_.begin(); it != parameters_.end(); it++){ Floats param = get_friend_parameter((*it).first,findex); set_my_parameter((*it).first,param); } //update the increment vector only to those replicas that upgraded to //a higher temperature to avoid double // calculations (excluding the transition 0 -> nrep-1) int delindex=findex-myindex; if (delindex==1){ //std::cout << myindex << " " << findex << " " << std::endl; sdel[myindex]=1; } //update the indexes myindex=findex; } MPI_Barrier(MPI_COMM_WORLD); //get the increment vector from all replicas and copy it to the //exchange array MPI_Allreduce(sdel.get(),rdel.get(),nproc_-1,MPI_INT,MPI_SUM,MPI_COMM_WORLD); for(int i=0;i<nproc_-1;++i) {exarray_[i]=rdel[i];} // in any case, update index vector boost::scoped_array<int> sbuf(new int[nproc_]); boost::scoped_array<int> rbuf(new int[nproc_]); for(int i=0;i<nproc_;++i) {sbuf[i]=0;} sbuf[myrank_]=myindex; MPI_Allreduce(sbuf.get(),rbuf.get(),nproc_,MPI_INT,MPI_SUM,MPI_COMM_WORLD); for(int i=0;i<nproc_;++i){index_[i]=rbuf[i];} return do_accept; }
void gxsURL::ProcessFTPType(const gxString &url, char &ftp_type) // Determine the FTP type. { const char *gxsFTP_TYPE_STRING = ";type="; gxString sbuf(url); int offset = sbuf.Find(gxsFTP_TYPE_STRING); if(offset == -1) { ftp_type = '\0'; return; } offset += strlen(gxsFTP_TYPE_STRING); ftp_type = sbuf[offset]; }
int gxsURL::ParseDirectory(const gxString &url, gxString &path, gxString &dir, gxString &file) // Build the directory and filename components of the path. { gxString sbuf(url); const char *gxsHOSTNAME_ID = "://"; path.Clear(); dir.Clear(); file.Clear(); // 09/11/2006: Set the default protocol if not set SetDefaultProto(sbuf); // Identify where the host name starts in a URL int offset = sbuf.Find(gxsHOSTNAME_ID); // A URL Host Name was not found if(offset == -1) return 0; sbuf.DeleteAt(0, (offset+strlen(gxsHOSTNAME_ID))); sbuf.TrimLeadingSpaces(); gxString dir_buf = sbuf; dir_buf.DeleteAfterIncluding("?"); dir_buf.DeleteAfterIncluding("#"); // 03/30/2009: Account for JS session IDs // Example: /switchsite.ds;jsessionid=54D3A5C9DC8A767DF64B3A377FB3EA8B dir_buf.DeleteAfterIncluding(";"); offset = dir_buf.Find("/"); // Scan to the end of the host name if(offset != -1) { // Remove everything before the host name sbuf.DeleteAt(0, offset); } else { path = "/"; dir = "/"; return 0; // No path specified in the url } // Remove everything following a trailing space offset = sbuf.Find(" "); if(offset != -1) { sbuf.DeleteAt(offset, (sbuf.length() - offset)); } path = sbuf; return HasFile(path, dir, file); }
int gxsURL::ParseHostName(const gxString &url, gxString &host, int remove_port_number) // Parse the hostname from a url. If the "remove_port_number // variable is true the port number will be removed from the // host name if a port number was specified. Returns true if // a valid hostname was found in the string containing the // URL. { gxString sbuf(url); const char *gxsHOSTNAME_ID = "://"; host.Clear(); // 09/11/2006: Set the default protocol if not set SetDefaultProto(sbuf); // Identify where the host name starts in a URL int offset = sbuf.Find(gxsHOSTNAME_ID); // A URL Host Name was not found if(offset == -1) return 0; sbuf.DeleteAt(0, (offset+strlen(gxsHOSTNAME_ID))); sbuf.TrimLeadingSpaces(); offset = sbuf.Find("/"); // Scan to the end of the host name if(offset != -1) { // Remove everything after the host name sbuf.DeleteAt(offset, (sbuf.length() - offset)); } else { // Remove everything following a trailing space offset = sbuf.Find(" "); if(offset != -1) { sbuf.DeleteAt(offset, (sbuf.length() - offset)); } } if(remove_port_number) { // Look for a port number and remove it if it is found offset = sbuf.Find(":"); if(offset != -1) { sbuf.DeleteAt(offset, (sbuf.length() - offset)); } } // Return false if no hostname exists after the hostname ID if(sbuf.length() == 0) return 0; host = sbuf; return 1; }
void Server::movePaddle(double x, double y, unsigned int time) { if (state == UNINITIALIZED) return; // we move it ourselves.. the client will report it to the server Player* player = peer[localid].player; player->move(x, y, time); if (state == RUNNING) { Vec2f pos = player->getPosition(); Buffer sbuf(PADDLEPOSITION); sbuf.pushId(localid); sbuf.pushDouble(pos.y); sbuf.pushDouble(pos.x); sendPacket(sbuf, false); } }
void Server::handle_request(int incoming_socket) const { struct timeval tv_start_network; gettimeofday(&tv_start_network, NULL); // Open as file, so we can do fgets, etc. FILE *conn = fdopen(incoming_socket, "r+"); if (conn == NULL) { throw "Unable to handle incoming connection"; } char buf[10240]; // Get the arguments Id_t searcher_userid = 0; Id_t searcher_school = 0; Id_t searcher_location = 0; Params_t params; // General search parameters std::vector<Id_t> interests; bool perform_search = false; while (fgets(buf, sizeof(buf), conn)) { std::stringstream sbuf(buf); std::string key; std::string value; sbuf >> key; key = Utility::downcase(key); if ((key == "end") || (key == "quit") || (key == "exit")) { break; } else if (key == "help") { help(conn); } else if (key == "stats") { stats(conn); fclose(conn); return; } else if (key == "terminate") { exit(0); } else if (key == "reload") { fclose(conn); Load::reload_online_and_new(data); return; } else if (key == "searcher_userid") { sbuf >> searcher_userid; global_stats->incrSearchReq(key); perform_search = true; } else if (key == "searcher_school") {
bool XMLTree::readConfigString(std::string s) { is_file = false; std::string sbuf(s); std::size_t nn=0; while(isspace(s[nn])) ++nn; if (s[nn] != '<') { DEBUG(0,LEVEL_ERROR,"expected '<' while reading config file, found %c\n",s[nn]); return false; } ++nn; tree->xmlparse(sbuf,nn); return true; }
QPUserId::QPUserId(const char *regcode) { QString code = regcode; QRegExp rx("[^ABCDEFGHJKLMNPQRSTUVWXYZ23456789]"); qint32 nbits = 64, sn = 0, ocnt = 0, mask = 0x80, charIdx = 0, pos = 0; quint32 temp = 0; QByteArray s(8, 0); code = code.toUpper(); code.replace(rx, ""); while(nbits--) { if (ocnt == 0) { sn = codeAsc.indexOf(code.at(charIdx++)); ocnt = 5; } if (sn & 0x10) { temp = (quint32)(s[pos] & 0xff); temp |= mask; temp &= 0xff; s[pos] = (quint8)temp; } sn <<= 1; sn &= 0xffff; --ocnt; mask >>= 1; mask &= 0xffff; if (mask == 0) { mask = 0x80; ++pos; s[pos] = 0; } } QDataStream sbuf(s); sbuf.device()->reset(); sbuf >> mCrc; mCrc = qToBigEndian(mCrc); sbuf >> mCounter; mCounter = qToBigEndian(mCounter); }
String Path::GetTruePath(RCString p) { #if UCFG_USE_POSIX char buf[PATH_MAX]; for (const char *psz = p;; psz = buf) { int len = ::readlink(psz, buf, sizeof(buf)-1); if (len == -1) { if (errno == EINVAL) return psz; CCheck(-1); } buf[len] = 0; } #elif UCFG_WIN32_FULL TCHAR buf[_MAX_PATH]; DWORD len = ::GetLongPathName(p, buf, _countof(buf)-1); Win32Check(len != 0); buf[len] = 0; typedef DWORD (WINAPI *PFN_GetFinalPathNameByHandle)(HANDLE hFile, LPTSTR lpszFilePath, DWORD cchFilePath, DWORD dwFlags); DlProcWrap<PFN_GetFinalPathNameByHandle> pfn("KERNEL32.DLL", EXT_WINAPI_WA_NAME(GetFinalPathNameByHandle)); if (!pfn) return buf; TCHAR buf2[_MAX_PATH]; File file; file.Attach(::CreateFile(buf, 0, 0, 0, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0)); len = pfn(Handle(file), buf2, _countof(buf2)-1, 0); Win32Check(len != 0); buf2[len] = 0; #if UCFG_USE_REGEX wcmatch m; if (regex_search(buf2, m, s_reDosName)) return m[1]; #else String sbuf(buf2); //!!! incoplete check, better to use Regex int idx = sbuf.Find(':'); if (idx != -1) return sbuf.Mid(idx-1); #endif return buf2; #else return p; #endif }
void Server::startGame() { output.removeMessage(Interface::WAITING_FOR_OPPONENT); resetScore(); // it could be we are serving at this moment output.removeMessage(Interface::YOU_SERVE); player[0]->detachBall(0.0); // create new players delete player[0]; delete player[1]; player.clear(); for (std::map<grapple_user, Peer>::iterator i = peer.begin(); i != peer.end(); ++i) { Side side = (i->first == localid ? FRONT : BACK); i->second.player = new Player(this, i->second.name, side, field.getLength()/2.0f); player.push_back(i->second.player); i->second.player->run(); } // now we are up & .. state = RUNNING; sendSimplePacket(READY); // reset ball in a cool way output.addMessage(Interface::FLASH_GAME_STARTED); ballouttimer = addTimer(10, BALLOUT, this); // tell pause state if (paused) sendSimplePacket(PAUSE_REQUEST); else sendSimplePacket(RESUME_REQUEST); // tell our initial position Vec2f pos = peer[localid].player->getPosition(); Buffer sbuf(PADDLEPOSITION); sbuf.pushId(localid); sbuf.pushDouble(pos.y); sbuf.pushDouble(pos.x); sendPacket(sbuf, false); }
static void process_open_path(const image_process &p,std::string path,scanner_params::PrintOptions &po, const size_t process_path_bufsize) { /* Check for "/r" in path which means print raw */ if(path.size()>2 && path.substr(path.size()-2,2)=="/r"){ path = path.substr(0,path.size()-2); } std::string prefix = get_and_remove_token(path); int64_t offset = stoi64(prefix); /* Get the offset into the buffer process */ u_char *buf = (u_char *)calloc(process_path_bufsize,1); if(!buf){ std::cerr << "Cannot allocate " << process_path_bufsize << " buffer\n"; return; } int count = p.pread(buf,process_path_bufsize,offset); if(count<0){ std::cerr << p.image_fname() << ": " << strerror(errno) << " (Read Error)\n"; return; } /* make up a bogus feature recorder set and with a disabled feature recorder. * Then we call the path printer, which throws an exception after the printing * to prevent further printing. * * The printer is called when a PRINT token is found in the * forensic path, so that has to be added. */ feature_recorder_set fs(feature_recorder_set::SET_DISABLED,feature_recorder_set::null_hasher, feature_recorder_set::NO_INPUT,feature_recorder_set::NO_OUTDIR); pos0_t pos0(path+"-PRINT"); // insert the PRINT token sbuf_t sbuf(pos0,buf,count,count,true); // sbuf system will free scanner_params sp(scanner_params::PHASE_SCAN,sbuf,fs,po); try { process_path_printer(sp); } catch (path_printer_finished &e) { } }
void inclusive_scan(const vex::vector<T> &src, vex::vector<T> &dst) { auto queue = src.queue_list(); // Scan partitions separately. for(unsigned d = 0; d < queue.size(); ++d) { if (src.part_size(d)) { boost::compute::command_queue q( queue[d]() ); boost::compute::buffer sbuf( src(d)() ); boost::compute::buffer dbuf( dst(d)() ); boost::compute::detail::scan( boost::compute::make_buffer_iterator<T>(sbuf, 0), boost::compute::make_buffer_iterator<T>(sbuf, src.part_size(d)), boost::compute::make_buffer_iterator<T>(dbuf, 0), false, q ); } } // If there are more than one partition, // update all of them except for the first. if (queue.size() > 1) { std::vector<T> tail(queue.size() - 1, T()); for(unsigned d = 0; d < tail.size(); ++d) { if (src.part_size(d)) tail[d] = dst[src.part_start(d + 1) - 1]; } std::partial_sum(tail.begin(), tail.end(), tail.begin()); for(unsigned d = 1; d < queue.size(); ++d) { if (src.part_size(d)) { // Wrap partition into vector for ease of use: vex::vector<T> part(queue[d], dst(d)); part += tail[d - 1]; } } } }
int gxsURL::CleanUserName(const gxString &url, gxString &clean_url) // Removes the username and password string from a url and // passes back a clean url in the "clean_url" variable. Returns // false if the url does not contain a username or password. { gxString sbuf(url); clean_url.Clear(); const char *gxsHOSTNAME_ID = "://"; // 09/10/2006: Must account for dynamic pages and targets // Example: http://username:[email protected]/leaving.php?http://www.datareel.com sbuf.DeleteAfterIncluding("?"); sbuf.DeleteAfterIncluding("#"); // 03/30/2009: Account for JS session IDs // Example: /switchsite.ds;jsessionid=54D3A5C9DC8A767DF64B3A377FB3EA8B sbuf.DeleteAfterIncluding(";"); // Identify where the host name starts and the protocol ends int hp_offset = sbuf.Find(gxsHOSTNAME_ID); // A URL hostname and protocol was not found if(hp_offset == -1) return 0; // Offset the hostname and protocol passed the gxsHOSTNAME_ID string hp_offset += strlen(gxsHOSTNAME_ID); // Is there an `@' character preceeding the hostname int up_offset = sbuf.Find("@", hp_offset); // This URL does not contain a username or password if(up_offset == -1) { clean_url = url; return 0; } unsigned name_len = up_offset - hp_offset; // Length of the username info sbuf.DeleteAt(hp_offset, (name_len + 1)); // Account for the '@' character clean_url = sbuf; return 1; }
static void send_trace_log (std::map<MonoMethod*, CallInfo> const &dict) { MemWriter sbuf(0x100000); MemWriter writer(0x100000); std::map<MonoMethod*, CallInfo>::const_iterator p; for (p = dict.begin (); p != dict.end (); p++) { MonoMethod *method = p->first; CallInfo call_info = p->second; char const *m = get_method_image_name (method); char *n = mono_method_full_name (method, 0); char str[256]; sbuf.sprintf ("[%s] %s [%08X]|%d|%d\n", m, n, mono_method_get_token (method), call_info.times, call_info.order); g_free (n); } if (!compress_data (sbuf.getBuffPtr (), sbuf.getBuffSize (), &writer)) { LOGD ("compress_data err!"); return; } /*Fixme : 这里写在使用protocolbuf之前, 因此非常不河蟹的出现了不使用pb的封包*/ ecmd_send (XMONO_ID_TRACE_REPORT, writer.getBuffPtr (), writer.getBuffSize ()); return; }
void seek_and_read_getn(concurrency::streams::istream stream, const std::vector<uint8_t>& content_to_compare) { size_t content_len = content_to_compare.size(); size_t pos1 = 0; size_t pos2 = content_len / 4; size_t pos3 = content_len / 2; size_t pos4 = content_len - content_len / 4; std::vector<uint8_t> buffer; buffer.resize(content_len); concurrency::streams::container_buffer<std::vector<uint8_t>> sbuf(buffer, std::ios_base::out); sbuf.seekpos(pos3, std::ios_base::out); CHECK_EQUAL(pos3, stream.seek((int)pos3, std::ios_base::beg)); CHECK_EQUAL(pos4 - pos3, stream.read(sbuf, pos4 - pos3).get()); sbuf.seekpos(pos1, std::ios_base::out); CHECK_EQUAL(pos1, stream.seek((int)(pos1 - pos4), std::ios_base::cur)); CHECK_EQUAL(pos2 - pos1, stream.read(sbuf, pos2 - pos1).get()); sbuf.seekpos(pos2, std::ios_base::out); CHECK_EQUAL(pos2, stream.seek((int)(pos2 - content_len), std::ios_base::end)); CHECK_EQUAL(pos3 - pos2, stream.read(sbuf, pos3 - pos2).get()); sbuf.seekpos(pos4, std::ios_base::out); CHECK_EQUAL(pos4, stream.seek((int)(pos4 - pos3), std::ios_base::cur)); CHECK_EQUAL(content_len - pos4, stream.read(sbuf, content_len - pos4).get()); CHECK_ARRAY_EQUAL(content_to_compare.data(), sbuf.collection().data(), (int)content_len); CHECK_EQUAL((concurrency::streams::istream::pos_type)concurrency::streams::istream::traits::eof(), stream.seek(-1, std::ios_base::beg)); CHECK_EQUAL((concurrency::streams::istream::pos_type)0, stream.seek(0, std::ios_base::beg)); CHECK_EQUAL((concurrency::streams::istream::pos_type)content_len, stream.seek(0, std::ios_base::end)); CHECK_EQUAL((concurrency::streams::istream::pos_type)concurrency::streams::istream::traits::eof(), stream.seek(1, std::ios_base::end)); CHECK_EQUAL((concurrency::streams::istream::pos_type)content_len, stream.seek(content_len, std::ios_base::beg)); CHECK_EQUAL((concurrency::streams::istream::pos_type)concurrency::streams::istream::traits::eof(), stream.seek(content_len + 1, std::ios_base::beg)); }
void RenderType(TCHAR *buf, int len, Type *type) { stringprint sbuf(buf, len); Type *restore = 0; Type *tptr; for(tptr = type; tptr; tptr = tptr->link) { if(tptr->ty == typeTYPEDEF) { tptr = tptr->link; restore = BreakLink(type, tptr); break; } } type = InvertType(type); RecurseRenderType(sbuf, type); type = InvertType(type); if(restore) RestoreLink(restore, tptr); }
// // Utility method for setting the rcok // motion in the X axis // void rockingTransformMatrix::setRockInX( double rock, const MString& scene, const MString& mesh) { if(scene=="" || mesh=="") return; double delta = rock - SHelper::safeConvertToInt(rock); std::string sbuf(scene.asChar()); SHelper::changeFrameNumber(sbuf, SHelper::safeConvertToInt(rock)); ZXMLDoc doc; XYZ a, b, c; float size; if(XMLUtil::findByNameAndType(sbuf.c_str(), mesh.asChar(), "transform", doc)) { doc.getFloat3AttribByName("X", fm[0][0], fm[0][1], fm[0][2]); doc.getFloat3AttribByName("Y", fm[1][0], fm[1][1], fm[1][2]); doc.getFloat3AttribByName("Z", fm[2][0], fm[2][1], fm[2][2]); doc.getFloat3AttribByName("W", fm[3][0], fm[3][1], fm[3][2]); doc.free(); } else if(XMLUtil::findByNameAndType(sbuf.c_str(), mesh.asChar(), "camera", doc)) { doc.getFloat3AttribByName("X", fm[0][0], fm[0][1], fm[0][2]); doc.getFloat3AttribByName("Y", fm[1][0], fm[1][1], fm[1][2]); doc.getFloat3AttribByName("Z", fm[2][0], fm[2][1], fm[2][2]); doc.getFloat3AttribByName("W", fm[3][0], fm[3][1], fm[3][2]); doc.free(); } else MGlobal::displayWarning(MString("cannot load ")+sbuf.c_str()); if(delta >0) { SHelper::changeFrameNumber(sbuf, SHelper::safeConvertToInt(rock+1.0)); char found = 0; if(XMLUtil::findByNameAndType(sbuf.c_str(), mesh.asChar(), "transform", doc)) { found = 1; doc.getFloat3AttribByName("X", fm1[0][0], fm1[0][1], fm1[0][2]); doc.getFloat3AttribByName("Y", fm1[1][0], fm1[1][1], fm1[1][2]); doc.getFloat3AttribByName("Z", fm1[2][0], fm1[2][1], fm1[2][2]); doc.getFloat3AttribByName("W", fm1[3][0], fm1[3][1], fm1[3][2]); doc.free(); } else if(XMLUtil::findByNameAndType(sbuf.c_str(), mesh.asChar(), "camera", doc)) { found = 1; doc.getFloat3AttribByName("X", fm1[0][0], fm1[0][1], fm1[0][2]); doc.getFloat3AttribByName("Y", fm1[1][0], fm1[1][1], fm1[1][2]); doc.getFloat3AttribByName("Z", fm1[2][0], fm1[2][1], fm1[2][2]); doc.getFloat3AttribByName("W", fm1[3][0], fm1[3][1], fm1[3][2]); doc.free(); } if(found) { a.x = fm[0][0]; a.y = fm[0][1]; a.z = fm[0][2]; size = a.length(); b.x = fm1[0][0]; b.y = fm1[0][1]; b.z = fm1[0][2]; c = a + (b-a)*delta; c.normalize(); c *= size; fm[0][0] =c.x; fm[0][1] =c.y; fm[0][2] =c.z; a.x = fm[1][0]; a.y = fm[1][1]; a.z = fm[1][2]; size = a.length(); b.x = fm1[1][0]; b.y = fm1[1][1]; b.z = fm1[1][2]; c = a + (b-a)*delta; c.normalize(); c *= size; fm[1][0] =c.x; fm[1][1] =c.y; fm[1][2] =c.z; a.x = fm[2][0]; a.y = fm[2][1]; a.z = fm[2][2]; size = a.length(); b.x = fm1[2][0]; b.y = fm1[2][1]; b.z = fm1[2][2]; c = a + (b-a)*delta; c.normalize(); c *= size; fm[2][0] =c.x; fm[2][1] =c.y; fm[2][2] =c.z; a.x = fm[3][0]; a.y = fm[3][1]; a.z = fm[3][2]; b.x = fm1[3][0]; b.y = fm1[3][1]; b.z = fm1[3][2]; c = a + (b-a)*delta; fm[3][0] =c.x; fm[3][1] =c.y; fm[3][2] =c.z; } } //rockXValue = rock; }
int main(int argc,char **argv) { if(argc!=2){ fprintf(stderr,"usage: %s scanner.so\n",argv[0]); fprintf(stderr,"type 'make plugins' to make available plugins\n"); exit(1); } /* Strip extension and path */ std::string fname = argv[1]; scanner_t *fn=0; std::string name = fname; size_t dot = name.rfind('.'); if(dot==std::string::npos){ fprintf(stderr,"%s: cannot strip extension\n",name.c_str()); exit(1); } name = name.substr(0,dot); /* Strip dir */ size_t slash = name.rfind('.'); if(slash!=std::string::npos){ name = name.substr(slash+1); } #ifdef HAVE_DLOPEN if(fname.find('.')==std::string::npos){ fname = "./" + fname; // fedora requires a complete path name } #ifdef HAVE_DLOPEN_PREFLIGHT if(!dlopen_preflight(fname.c_str())){ fprintf(stderr,"dlopen_preflight - cannot open %s: %s",fname.c_str(),dlerror()); exit(1); } #endif void *lib=dlopen(fname.c_str(), RTLD_LAZY); if(lib==0){ fprintf(stderr,"fname=%s\n",fname.c_str()); fprintf(stderr,"dlopen: %s\n",dlerror()); exit(1); } fn=(scanner_t *)dlsym(lib, name.c_str()); if(fn==0){ fprintf(stderr,"dlsym: %s\n",dlerror()); exit(1); } #endif #ifdef HAVE_LOADLIBRARY /* Use Win32 LoadLibrary function */ /* See http://msdn.microsoft.com/en-us/library/ms686944(v=vs.85).aspx */ HINSTANCE hinstLib = LoadLibrary(TEXT(fname.c_str())); if(hinstLib==0){ fprintf(stderr,"LoadLibrary(%s) failed",fname.c_str()); exit(1); } MYPROC fn = (MYPROC)GetProcAddress(hinstLib,name.c_str()); if(fn==0){ fprintf(stderr,"GetProcAddress(%s) failed",name.c_str()); exit(1); } #endif feature_recorder_set fs(0,my_hasher,feature_recorder_set::NO_INPUT,feature_recorder_set::NO_OUTDIR); uint8_t buf[100]; pos0_t p0(""); sbuf_t sbuf(p0,buf,sizeof(buf),sizeof(buf),false); scanner_params sp(scanner_params::PHASE_STARTUP,sbuf,fs); recursion_control_block rcb(0,"STAND"); scanner_info si; sp.info = &si; (*fn)(sp,rcb); std::cout << "Loaded scanner '" << si.name << "' by " << si.author << "\n"; #ifdef HAVE_DLOPEN dlclose(lib); #endif return 0; }
void FormatData(TCHAR *buf, int len, char *data, int datalen, bool fHex, bool fSigned, bool fBigEndian, TYPE ty) { stringprint sbuf(buf, len); }
void Framework::sendSimplePacket(PacketType t) { Buffer sbuf(t); /* up till now, all simple packets are state control and therefor need to be sent reliable. */ sendPacket(sbuf, true); }
void scan_bulk(const class scanner_params &sp,const recursion_control_block &rcb) { assert(sp.sp_version==scanner_params::CURRENT_SP_VERSION); // startup if(sp.phase==scanner_params::PHASE_STARTUP){ assert(sp.info->si_version==scanner_info::CURRENT_SI_VERSION); sp.info->name = "bulk"; sp.info->author = "Simson Garfinkel"; sp.info->description = "perform bulk data scan"; sp.info->flags = scanner_info::SCANNER_DISABLED | scanner_info::SCANNER_WANTS_NGRAMS | scanner_info::SCANNER_NO_ALL; sp.info->feature_names.insert("bulk"); sp.info->feature_names.insert("bulk_tags"); sp.info->get_config("bulk_block_size",&opt_bulk_block_size,"Block size (in bytes) for bulk data analysis"); debug = sp.info->config->debug; histogram::precalc_entropy_array(opt_bulk_block_size); sp.info->get_config("DFRWS2012",&dfrws_challenge,"True if running DFRWS2012 challenge code"); return; } // classify a buffer if(sp.phase==scanner_params::PHASE_SCAN){ feature_recorder *bulk = sp.fs.get_name("bulk"); feature_recorder *bulk_tags = sp.fs.get_name("bulk_tags"); if(sp.sbuf.pos0.isRecursive()){ /* Record the fact that a recursive call was made, which tells us about the data */ bulk_tags->write_tag(sp.sbuf,""); // tag that we found recursive data, not sure what kind } if(sp.sbuf.pagesize < opt_bulk_block_size) return; // can't analyze something that small // Loop through the sbuf in opt_bulk_block_size sized chunks // for each one, examine the entropy and scan for bitlocker (unfortunately hardcoded) // This needs to have a general plug-in architecture for(size_t base=0;base+opt_bulk_block_size<=sp.sbuf.pagesize;base+=opt_bulk_block_size){ sbuf_t sbuf(sp.sbuf,base,opt_bulk_block_size); bulk_ngram_entropy(sbuf,bulk,bulk_tags); bulk_bitlocker(sbuf,bulk,bulk_tags); } } // shutdown --- combine the results if we are in DFRWS mode if(sp.phase==scanner_params::PHASE_SHUTDOWN){ if(dfrws_challenge){ feature_recorder *bulk = sp.fs.get_name("bulk"); // First process the bulk_tags and lift_tags bulk_process_feature_file(bulk->outdir + "/bulk_tags.txt"); bulk_process_feature_file(bulk->outdir + "/lift_tags.txt"); // Process the remaining feature files dig d(bulk->outdir); for(dig::const_iterator it = d.begin(); it!=d.end(); ++it){ if(ends_with(*it,_TEXT("_tags.txt"))==false){ bulk_process_feature_file(*it); } } dfrws2012_bulk_process_dump(); } return; // no cleanup } }
void Server::doNetworking() { grapple_message *message; while (grapple_server_messages_waiting(server)) { message = grapple_server_message_pull(server); switch (message->type) { case GRAPPLE_MSG_NEW_USER: peer[message->NEW_USER.id] = Peer(grapple_server_client_address_get(server, message->NEW_USER.id)); std::cerr << "client connected from " << peer[message->NEW_USER.id].name << std::endl; break; case GRAPPLE_MSG_USER_NAME: peer[message->USER_NAME.id].name = message->USER_NAME.name; break; case GRAPPLE_MSG_USER_MSG: { grapple_user id = message->USER_MSG.id; Buffer buf((char*)message->USER_MSG.data, message->USER_MSG.length); switch (buf.getType()) { case READY: peer[id].ready = true; if (peer.size() > 1) { bool ready = true; for (std::map<grapple_user, Peer>::iterator i = peer.begin(); i != peer.end(); ++i) { if (!(*i).second.ready) { ready = false; break; } } if (ready) startGame(); } break; case PADDLEMOVE: { unsigned int time = buf.popInt(); peer[id].player->move(buf.popDouble(), buf.popDouble(), time); Vec2f pos = peer[id].player->getPosition(); Buffer sbuf(PADDLEPOSITION); sbuf.pushId(id); sbuf.pushDouble(pos.y); sbuf.pushDouble(pos.x); sendPacket(sbuf, false); } break; case SERVE_BALL: peer[id].player->detachBall(ballspeed); break; case PAUSE_REQUEST: togglePause(true, true); std::cout << "Player " << peer[id].name << " paused the game." << std::endl; break; case RESUME_REQUEST: togglePause(false, true); std::cout << "Player " << peer[id].name << " resumed the game." << std::endl; break; } break; } case GRAPPLE_MSG_USER_DISCONNECTED: std::cout << "Player " << peer[message->USER_DISCONNECTED.id].name << " disconnected!" << std::endl; shutdown(); break; } grapple_message_dispose(message); } while (grapple_client_messages_waiting(loopback)) { message=grapple_client_message_pull(loopback); switch (message->type) { case GRAPPLE_MSG_NEW_USER_ME: { localid = message->NEW_USER.id; peer[localid].player = new Player(this, peer[localid].name, FRONT, field.getLength()/2.0f); player.push_back(peer[localid].player); peer[localid].player->attachBall(&ball[0]); output.addMessage(Interface::YOU_SERVE); peer[localid].ready = true; state = WAITING; } break; } grapple_message_dispose(message); } }
bool TrackRecords::loadTrackRecords(QString fileName) { QFile f(fileName); if (f.open(QIODevice::ReadOnly)) { QDataStream stream(&f); char *tab; stream >> tab; QString sbuf(tab); delete [] tab; if (QString(sbuf) != "F1LT2_TR") { f.close(); return false; } trackRecords.clear(); int size; stream >> size; for (int i = 0; i < size; ++i) { Track track; stream >> track.name; int verSize; stream >> verSize; for (int j = 0; j < verSize; ++j) { TrackVersion tv; stream >> tv.year; stream >> tv.map; QString time; for (int k = 0; k < 2; ++k) { stream >> time; tv.trackRecords[k].time = LapTime(time); stream >> tv.trackRecords[k].driver; stream >> tv.trackRecords[k].team; stream >> tv.trackRecords[k].year; } int tsSize; stream >> tsSize; for (int k = 0; k < tsSize; ++k) { TrackWeekendRecords ts; stream >> ts.year; for (int w = 0; w < 4; ++w) { stream >> time; ts.sessionRecords[w].time = LapTime(time); stream >> ts.sessionRecords[w].driver; stream >> ts.sessionRecords[w].team; stream >> ts.sessionRecords[w].session; } int dsSize; stream >> dsSize; for (int w = 0; w < dsSize; ++w) { DriverWeekendRecords ds; stream >> ds.driver; stream >> ds.team; for (int x = 0; x < 5; ++x) { for (int y = 0; y < 4; ++y) { stream >> time; ds.sessionRecords[x][y].time = LapTime(time); stream >> ds.sessionRecords[x][y].session; } } ts.driverRecords.append(ds); } tv.trackWeekendRecords.append(ts); } track.trackVersions.append(tv); } qSort(track.trackVersions); trackRecords.append(track); } }