Esempio n. 1
0
void
DetectorNCC::Write(std::ofstream &s, bool binary)
{
  assert(binary);

  int t = IOBinary::DETECTOR_NCC;
  s.write((char*)&t, sizeof(t));

  IOBinary::WriteMat(s, _refs);

  t = _patch.size();
  s.write((char*)&t, sizeof(t));
  for(size_t i=0; i< _patch.size(); i++)
    _patch[i].Write(s, true);
}
Esempio n. 2
0
void MemoryMap::SaveState(std::ofstream& ofs)
{
    ofs.write((char*)_ram, sizeof(_ram));
    _ppu->SaveState(ofs);
    _apu->SaveState(ofs);
    _mapper->SaveState(ofs);
}
Esempio n. 3
0
void cineon_writer_t::write_pixels( std::ofstream& out, const image::const_image_view_t& view) const
{
    std::vector<boost::uint32_t> buffer( view.width());

    for( int y = 0; y < view.height(); ++y)
    {
		image::const_image_view_t::x_iterator src_it( view.row_begin( y));
	
		for( int x = 0; x < view.width(); ++x)
		{
			boost::uint32_t pix = 0;
	
			float r = boost::gil::get_color( *src_it, boost::gil::red_t());
			float g = boost::gil::get_color( *src_it, boost::gil::green_t());
			float b = boost::gil::get_color( *src_it, boost::gil::blue_t());
	
			boost::uint32_t ri = adobe::clamp( r, 0.0f, 1.0f) * 1023;
			boost::uint32_t gi = adobe::clamp( g, 0.0f, 1.0f) * 1023;
			boost::uint32_t bi = adobe::clamp( b, 0.0f, 1.0f) * 1023;
			pix = ( ri << 22) | ( gi << 12) | ( bi << 2);
	
			buffer[x] = IECore::asBigEndian( pix);
			++src_it;
		}
	
		// write vector
		out.write( reinterpret_cast<char *>( &buffer[0]), view.width() * sizeof( boost::uint32_t));
		
		if ( out.fail())
			throw exception( "error while writting image");
    }
}
Esempio n. 4
0
void Permutator::CreatePath(Node* n, std::ofstream& gvFile)
{
	std::stringstream stream;
	std::string pathAttribute = "[ penwidth = 5];\n";
	
	stream << std::hex << n->GetOffset();
	std::string stateName = "\"0x" + stream.str() + "\"";
	stream.str(std::string());

	for (unsigned int i = 0; i < n->GetChildren().size(); ++i)
	{
		stream << std::hex << n->GetChildren().at(i)->GetOffset();
		std::string childName = "\"0x" + stream.str() + "\"";
		std::string pathValue = stateName + " -> " + childName + " " + pathAttribute;
		try
		{
			gvFile.write(pathValue.c_str(), pathValue.length());
		}
		catch (std::fstream::failure e)
		{
			std::cerr << "CreatePath: Error while writing paths to graphviz output file: " << e.what() << std::endl;
			return;
		}
		
		CreatePath(n->GetChildren().at(i), gvFile);
		stream.str(std::string());
	}

	return;
}
void FeatureConnector::writeCoords(std::ofstream& output_file, const std::vector<geos::geom::Coordinate>* coords, bool singleton) {
    quint32 crdCount = (quint32)coords->size();
    if(!singleton) {
        output_file.write((char *)&crdCount,4);
    }
    std::vector<double> crds(crdCount * 3);
    quint32 count = 0;
    for(const geos::geom::Coordinate& crd : *coords) {
        crds[count] = crd.x;
        crds[count+1] = crd.y;
        crds[count+2] = 0;
        count +=3;
    }
    output_file.write((char *)&crds[0], crdCount * 8 * 3);

}
Esempio n. 6
0
void write_rat_header(std::ofstream& file, const std::vector<uint32_t>& sizes,
                      const uint32_t var, const uint32_t type,
                      const std::string& info)
{
    using tools::endian_reverse_inplace;
    using std::string;

    auto write = [&file](uint32_t x) {
        endian_reverse_inplace(x);
        file.write(reinterpret_cast<const char*>(&x), sizeof(x));
    };

    const uint32_t dim = sizes.size();

    write(dim);
    for (auto sz : sizes) {
        write(sz);
    }
    write(var);
    write(type);

    write(0);
    write(0);
    write(0);
    write(0);

    string _info = string(80, ' ');
    boost::copy(string(info, 0, 80), _info.begin());

    file << _info;
}
Esempio n. 7
0
 void readsome(const boost::system::error_code& ec, std::size_t bytes_transferred)
 {
     if (ec == error::eof) {
         file.close();
         if (!file) {
             ERROR "Cannot write to file " << filename;
             onerror();
         } else if (filesize == 0) {
             ERROR "Empty segment " << file_url.to_string();
             onerror();
         } else {
             downloading = false;
             complete = true;
             auto download_duration = duration_cast<milliseconds>(steady_clock::now() - download_start).count();
             INFO "Completed segment " << file_url.to_string() << " (" << std::setprecision(1) << std::fixed <<
                 (filesize / 1024.0 / 1024.0) << " MB) in " << download_duration <<
                 " ms (" << (filesize * 8000 / 1024.0 / 1024.0 / download_duration) << "Mbps)";
         }
     } else if (ec) {
         ERROR "Error reading URL " << file_url.to_string() << ": " << ec.message();
         onerror();
     } else {
         file.write(&buffer[0], bytes_transferred);
         filesize += bytes_transferred;
         segment_stream.async_read_some(boost::asio::buffer(buffer), std::bind(&Segment::readsome, this, _1, _2));
     }
 }
Esempio n. 8
0
//! write sector to file
//!
//! @param file    file to write to
//!
//! @return success
//!
bool
Sector::writeToH8D(std::ofstream &file)
{

    uint16_t pos = 0;
  
    // look for the sync for the header 
    while ((buf_m[pos] != 0xfd) && (pos < bufSize_m))
    {
        pos++;
    }

    // skip past the header, since 0xfd could be the checksum
    pos += 5;

    // look for the data 
    while ((buf_m[pos++] != 0xfd) && (pos < bufSize_m))
    { }

    if ((bufSize_m - pos) < 256)
    {
        printf("Error data not found - sector: %d\n", sector_m);
        pos = bufSize_m - 256;
    }

    // write out the sector
    if (buf_m)
    {
        file.write((const char*) &buf_m[pos], 256);
    }

    return true;
}
void Bitmap::writePnm(std::ofstream &o) const {
    o << "P5" << std::endl;
    o << width << " " << height << std::endl;
    o << "255" << std::endl;
    o.write((const char *)buf, width * height);
    o.close();
}
Esempio n. 10
0
int main(int argc, char *argv[])
{
    PIN_InitSymbols();

    if( PIN_Init(argc, argv))
    {
        return usage();
    }

    traceFile.open(outputFile.Value().c_str());

    string trace_header = string("#\n"
                                 "# Shellcode detector\n"
                                 "#\n\nMAX_LEGIT_INSTRUCTION_LOG_SIZE : ") +
        KnobMaxLegitInsLogSize.ValueString() + "\n\n";

    for ( UINT32 i = 0; i < KnobModuleConcerned.NumberOfValues(); i++ )
    {
        LOG( "[+] ... " + KnobModuleConcerned.Value(i) + "\n" );
        modlist.insert( KnobModuleConcerned.Value(i) );
    }

    traceFile.write(trace_header.c_str(), trace_header.size());

    INS_AddInstrumentFunction(traceInst, 0);
    PIN_AddFiniFunction(fini, 0);

    // Never returns
    PIN_StartProgram();

    return 0;
}
Esempio n. 11
0
	static void gz_uncompress( gzFile in, std::ofstream &out ) {
		char buf[2048 * 1024];
		int len;
		size_t bytes = 0;

		for (
			len = gzread( in, buf, 2048 * 1024 );
			len;
			len = gzread( in, buf, 2048 * 1024 )
		) {
			if ( len < 0 ) {
				int err;
				gzerror( in, &err );

				// If an error occurred in the file system and not in the compression library, err is set to Z_ERRNO
				if ( err == Z_ERRNO ) {
					throwSystemError( errno, "Failed to read compressed file" );
				} else {
					throwGenericError( "Failed to read compressed file" );
				}
			} else {
				out.write( buf, len );
				bytes += len;
			}
		}

		LOG( Debug, verbose_info ) << "Uncompressed " << bytes << " bytes";
	}
Esempio n. 12
0
bool compactIntArray::write(std::ofstream& fout)
{
    fout.write((char*)&size, sizeof(size));
    fout.write((char*)&wordsize, sizeof(wordsize));
    fout.write((char*)&innersize, sizeof(innersize));

    fout.write((char*)array, sizeof(*array) * innersize);
    if(fout.bad())
    {
        return false;
    }
    else
    {
        return true;
    }
}
Esempio n. 13
0
void writeBucketIndexSetVector(std::ofstream &file, const PVRTBucketIndexSetVector &indexsets)
{
	const size_t size = indexsets.size();
	file.write((const char*)&size, sizeof(size_t));
	for (unsigned int i=0; i < size; i++)
		writeBucketIndexSet(file, indexsets[i]);
}
void FeatureConnector::writeCoords(std::ofstream& output_file, const std::vector<Coordinate2d>& coords, bool singleton) {
    quint32 crdCount = coords.size();
    if(!singleton) {
        output_file.write((char *)&crdCount,4);
    }
    std::vector<double> crds(crdCount * 3);
    quint32 count = 0;
    for(const Coordinate2d& crd : coords) {
        crds[count] = crd.x();
        crds[count+1] = crd.y();
        crds[count+2] = 0;
        count +=3;
    }
    output_file.write((char *)&crds[0], crdCount * 8 * 3);

}
Esempio n. 15
0
	void CPanel::SavePanel(std::ofstream &fout)
	{
		//Bool - Active
		fout.write((const char*)(&this->m_bActive), sizeof(bool));
		//schar - Grid
		for (schar i = 0; i < kucMaxNumQSlots; ++i)
		{
			schar id = this->m_vGrid[i].GetID();
			fout.write((const char*)(&id), sizeof(schar));
		}
		//schar - Slots
		ulong size = this->m_vSlots.size();
		fout.write((const char*)(&size), sizeof(ulong));
		for (ulong i = 0; i < size; ++i)
			fout.write((const char*)(&this->m_vSlots[i]), sizeof(schar));
	}
Esempio n. 16
0
int  main(int argc, char *argv[])
{
    
    PIN_InitSymbols();

    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }
    

    TraceFile.open(KnobOutputFile.Value().c_str());

    TraceFile << hex;
    TraceFile.setf(ios::showbase);
    
    string trace_header = string("#\n"
                                 "# Call Trace Generated By Pin\n"
                                 "#\n");
    

    TraceFile.write(trace_header.c_str(),trace_header.size());
    
    TRACE_AddInstrumentFunction(Trace, 0);
    PIN_AddFiniFunction(Fini, 0);

    // Never returns

    PIN_StartProgram();
    
    return 0;
}
Esempio n. 17
0
static void
debugDumpData(std::ofstream &file,
              virt_ptr<const void> data,
              size_t size)
{
   file.write(reinterpret_cast<const char *>(data.get()), size);
}
Esempio n. 18
0
bool ActionRecord::saveToStream(std::ofstream& output) const
{
  output.write((const char*) &cAACT, 4);
  if (!saveSizeAndUnknownValues(output, getWriteSize())) return false;
  if (isDeleted()) return true;

  //write EDID
  output.write((const char*) &cEDID, 4);
  //EDID's length
  uint16_t subLength = editorID.length()+1;
  output.write((const char*) &subLength, 2);
  //write editor ID
  output.write(editorID.c_str(), subLength);

  return output.good();
}
Esempio n. 19
0
int main(int argc, char *argv[])
{
    string trace_header = string("#\n"
                                 "# Memory Access Trace Generated By Pin\n"
                                 "#\n");
    
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }
    
    TraceFile.open(KnobOutputFile.Value().c_str());
    TraceFile.write(trace_header.c_str(),trace_header.size());
    TraceFile.setf(ios::showbase);
    
    INS_AddInstrumentFunction(Instruction, 0);
    PIN_AddFiniFunction(Fini, 0);

    // Never returns

    PIN_StartProgram();
    
    RecordMemWrite(0);
    RecordWriteAddrSize(0, 0);
    
    return 0;
}
Esempio n. 20
0
void SaveFITS::writeFITSImageMatrix(const API::MatrixWorkspace_sptr img,
                                    std::ofstream &file) {
  const size_t sizeX = img->blocksize();
  const size_t sizeY = img->getNumberHistograms();

  int bitDepth = getProperty(PROP_BIT_DEPTH);
  const size_t bytespp = static_cast<size_t>(bitDepth) / 8;

  for (size_t row = 0; row < sizeY; ++row) {
    const auto &dataY = img->readY(row);
    for (size_t col = 0; col < sizeX; ++col) {
      int32_t pixelVal;
      if (8 == bitDepth) {
        pixelVal = static_cast<uint8_t>(dataY[col]);
      } else if (16 == bitDepth) {
        pixelVal = static_cast<uint16_t>(dataY[col]);
      } else if (32 == bitDepth) {
        pixelVal = static_cast<uint32_t>(dataY[col]);
      }

      // change endianness: to sequence of bytes in big-endian
      // this needs revisiting (similarly in LoadFITS)
      // See https://github.com/mantidproject/mantid/pull/15964
      std::array<uint8_t, g_maxBytesPP> bytesPixel;
      uint8_t *iter = reinterpret_cast<uint8_t *>(&pixelVal);
      std::reverse_copy(iter, iter + bytespp, bytesPixel.data());

      file.write(reinterpret_cast<const char *>(bytesPixel.data()), bytespp);
    }
  }
}
Esempio n. 21
0
/**
 * Writes the padding required to fill every header block. FITS
 * headers consist of subblocks of 36 entries/lines, with 80
 * characters per line. This method is to write as many "padding"
 * lines as required to have 36 lines in a block
 *
 * @param count how may bytes to write
 * @param file output stream to write to
 */
void SaveFITS::writePaddingFITSHeaders(size_t count, std::ofstream &file) {
  static const std::vector<char> blanks(g_maxLenHdr, 32);

  for (size_t i = 0; i < count; ++i) {
    file.write(blanks.data(), g_maxLenHdr);
  }
}
Esempio n. 22
0
void CopyData ( std::ifstream &fin, std::ofstream &fout ) {
    char line[704];
    while (!fin.eof()) {
        fin.read(line, 704);
        fout.write(line, fin.gcount());
    }
}
Esempio n. 23
0
void
Alphabet::writeTo(std::ofstream& file) const
{
    for( std::map<usint, pair_type>::const_iterator itr = this->begin(); itr != this->end(); ++itr){
        usint c = itr->first;
        usint temp = this->countOf(c);
        if (temp != 0) {
            file.write((char*)&c, sizeof(c));//FIXME: possibly not portable wrt endianness
            file.write((char*)&temp, sizeof(temp));//FIXME: possibly not portable wrt endianness
        }
    }
    const usint zero = 0;
    //write a centinel map[0]=0 entry
    file.write((char*)&zero, sizeof(zero));//FIXME: possibly not portable wrt endianness
    file.write((char*)&zero, sizeof(zero));//FIXME: possibly not portable wrt endianness
}
Esempio n. 24
0
int  main(int argc, char *argv[])
{
    string trace_header = string("#\n"
                                 "# Compressed Instruction Trace Generated By Pin\n"
                                 "#\n");
    
    
    if( PIN_Init(argc,argv) )
    {
        return Usage();
    }
    

    TraceFile.open(KnobOutputFile.Value().c_str());
    TraceFile.write(trace_header.c_str(),trace_header.size());
    
        
    TRACE_AddInstrumentFunction(Trace, 0);
    PIN_AddFiniFunction(Fini, 0);

    // Never returns

    PIN_StartProgram();
    
    return 0;
}
bool Serializer::writeCharArray(std::ofstream &outfile, const char *write, int len) {
	outfile.write(write, len);
	if (!outfile.good())
		return false;

	return true;
}
Esempio n. 26
0
void binary_reader::stock_data::write( std::ofstream& out )
{
	if ( !out.write( stock_name_, sizeof(char)*(stock_size+1) ) )
		throw std::exception( "Error while writing data\n" );
	int year_, month_, day_;
	sscanf( date_time_, "%4d%2d%2d", &year_, &month_, &day_ );
	boost::uint32_t day_time_ = 372*(year_-1) + 31*(month_-1) + day_;
	if ( !out.write( reinterpret_cast<char*> (&day_time_), sizeof( boost::uint32_t ) ) )
		throw std::exception( "Error while writing data\n" );
	if ( !out.write( reinterpret_cast<char*> (&vwap_), sizeof(double) ) )
		throw std::exception( "Error while writing data\n" );
	if ( !out.write( reinterpret_cast<char*> (&volume_), sizeof( boost::uint32_t ) ) )
		throw std::exception( "Error while writing data\n" );
	if ( !out.write( reinterpret_cast<char*> (&f2_), sizeof(double) ) )
		throw std::exception( "Error while writing data\n" );
}
Esempio n. 27
0
int main(int argc, char *argv[])
{
    PIN_InitSymbols();

    if( PIN_Init(argc, argv))
    {
        return usage();
    }

    traceFile.open(outputFile.Value().c_str());

    string trace_header = string("#\n"
                                 "# Shellcode detector\n"
                                 "#\n");
    

    traceFile.write(trace_header.c_str(), trace_header.size());
    
    INS_AddInstrumentFunction(traceInst, 0);
    PIN_AddFiniFunction(fini, 0);

    // Never returns
    PIN_StartProgram();
    
    return 0;
}
Esempio n. 28
0
/*--------------------------------------------------------------------
						m_dump_keypoints_to_stream
----------------------------------------------------------------------*/
bool CStereoOdometryEstimator::m_dump_keypoints_to_stream(
				std::ofstream				& stream,
				const vector<cv::KeyPoint>	& keypoints,
				const cv::Mat				& descriptors )
{
	/* FORMAT
	- # of features in image
		- feat x coord
		- feat y coord
		- feat response
		- feat size
		- feat angle
		- feat octave
		- feat class_id
	- # of dimensions of descriptors (D): rows, cols and type
		feat descriptor d_0 ... d_{D-1}
	*/
	if( !stream.is_open() )
		return false;

	size_t num_kp = keypoints.size();
	stream.write( reinterpret_cast<char*>(&num_kp), sizeof(size_t));

	for( size_t f = 0; f < keypoints.size(); ++f )
	{
		stream.write( (char*)(&(keypoints[f].pt.x)), sizeof(float) );
		stream.write( (char*)(&(keypoints[f].pt.y)), sizeof(float) );
		stream.write( (char*)(&(keypoints[f].response)), sizeof(float) );
		stream.write( (char*)(&(keypoints[f].size)), sizeof(float) );
		stream.write( (char*)(&(keypoints[f].angle)), sizeof(float) );
		stream.write( (char*)(&(keypoints[f].octave)), sizeof(int) );
		stream.write( (char*)(&(keypoints[f].class_id)), sizeof(int) );
	} // end-for-keypoints

	int drows = descriptors.rows, dcols = descriptors.cols, dtype = descriptors.type();
	stream.write( (char*)&drows, sizeof(int) );
	stream.write( (char*)&dcols, sizeof(int) );
	stream.write( (char*)&dtype, sizeof(int) );

	for( cv::MatConstIterator_<uchar> it = descriptors.begin<uchar>(); it != descriptors.end<uchar>(); ++it )
	{
		uchar value = *it;
		stream.write( (char*)&value, sizeof(uchar) );
	}

	return true;
} // end-m_dump_keypoints_to_stream
Esempio n. 29
0
 inline void save(std::ofstream& ofs, const VecD& params){
   Real val = 0.0;
   
   for (int i = 0; i < params.rows(); ++i){
     val = params.coeff(i, 0);
     ofs.write((char*)&val, sizeof(Real));
   }
 }
Esempio n. 30
-1
void d2o_writer::impl::write(std::ofstream & file) const
{
    byte_buffer buffer;
    buffer.write_bytes<false>((const uint8_t *)"D2O", 3);
    buffer << 0;
    std::unordered_map<int, int> offsets;
    for (auto && it : _objects)
    {
        offsets.emplace(it.first, buffer.tellp());
        buffer << it.second.first;
        _classes.at(it.second.first).write(_owner, buffer, it.second.second);
    }

    int header = buffer.tellp();

    buffer << static_cast<int>(offsets.size() * 8);
    for (auto && it : offsets)
        buffer << it.first << it.second;
    buffer << static_cast<int>(_classes.size());
    for (auto && it : _classes)
        it.second.pack(buffer, it.first);

    buffer.seekp(3);
    buffer << header;
    file.write((const char *)&buffer[0], buffer.size());
}