void EventComponent::write(std::fstream& stream) { for(int i = 0; i < MAX_EVENT; i++) { stream.write((char*)&event[i].activation, sizeof(event[i].activation)); stream.write((char*)&event[i].activator, sizeof(event[i].activator)); int size = event[i].receiverName.size(); stream.write((char*)&size, sizeof(size)); stream.write(event[i].receiverName.c_str(), size * sizeof(char)); size = event[i].msg.getName().size(); stream.write((char*)&size, sizeof(size)); stream.write(event[i].msg.getName().c_str(), size * sizeof(char)); stream.write((char*)&event[i].arg0, sizeof(event[i].arg0)); stream.write((char*)&event[i].arg1, sizeof(event[i].arg1)); stream.write((char*)&event[i].arg2, sizeof(event[i].arg2)); stream.write((char*)&event[i].arg3, sizeof(event[i].arg3)); } }
void WriteSector(char* buffer, size_t sec) { sec += partitionOffset; if (sec > partitionLength) return; if ((sec * 512) > fsize) { std::cout << "WOAH BRO THIS SECTOR IS WRONG: " << sec << std::endl; return; } f.seekp(sec * 512, std::ios::beg); f.write(buffer, 512); }
void PEObject::WriteHeader(std::fstream &stream) { unsigned zero = 0; for (int i =0; i < name.size() && i < 8; i++) stream.write(&name[i], 1); for (int i = name.size(); i < 8; i++) stream.write((char *)&zero, 1); unsigned msize = ObjectAlign(objectAlign, size); stream.write((char *)&msize, 4); stream.write((char *)&virtual_addr, 4); msize = ObjectAlign(fileAlign, initSize); stream.write((char *)&msize, 4); stream.write((char *)&raw_addr, 4); stream.write((char *)&zero, 4); stream.write((char *)&zero, 4); stream.write((char *)&zero, 4); int flg = (flags ^ WINF_NEG_FLAGS) & WINF_IMAGE_FLAGS; /* get characteristice for section */ stream.write((char *)&flg, 4); }
void LuaHistoryFile::SaveLuaTable(lua_State* luaState, int nIndex, size_t nBufferLen, std::fstream& fileStream) { vector<string> vecStrings; if(lua_istable(luaState,nIndex)) { int nStrCnt = lua_objlen(luaState,nIndex); const char* cszWrite = NULL; for(int ix = 1; ix <= nStrCnt; ++ix) { lua_rawgeti(luaState, nIndex , ix); if(lua_isstring(luaState, -1)) { cszWrite = luaL_checkstring(luaState, -1); wstring wstrWrite; UTF8_to_Unicode(cszWrite, strlen(cszWrite), wstrWrite); string astrWrite; wstrWrite += WCHAR('\n'); Unicode_to_ANSI(wstrWrite.c_str(), wstrWrite.size(),astrWrite); vecStrings.push_back(astrWrite); } lua_pop(luaState,1); } } char szStrCnt[100]; itoa(vecStrings.size(), szStrCnt, 100); int nStrCntLen = strlen(szStrCnt); szStrCnt[nStrCntLen] = '\n'; fileStream.write(szStrCnt, nStrCntLen + 1); for(size_t ix = 0; ix < vecStrings.size(); ++ix) { const char* buf = vecStrings[ix].c_str(); size_t buflen = vecStrings[ix].size(); fileStream.write(buf, buflen); } }
/// Writes to file stream. void Tile::WriteTo(std::fstream & file) { // Write version file.write((char*)&tileVersion, sizeof(int)); // Fetch type index. this->typeIndex = -1; if (type) typeIndex = type->type; // Write type index file.write((char*)&typeIndex, sizeof(int)); // Write position. position.WriteTo(file); // Write stuff bound to the tile. int stuff = 0; if (event) stuff |= 0x001; file.write((char*)&stuff, sizeof(int)); // Write the path to the source of the event. if (event) event->source.WriteTo(file); // Write description of additional details to file. description.WriteTo(file); }
void Transaction::Store(std::fstream &stream) { m_Date.Store(stream); StoreString(m_Description, stream); StoreString(m_Payee, stream); StoreString(m_Category, stream); m_Amount.Store(stream); stream.write((char *) &m_Type, sizeof(unsigned char)); std::bitset<8> localset; localset[0] = m_Cleared; localset[1] = m_Split; localset[2] = m_Reconciled; localset[3] = m_Flagged; localset[4] = m_HasFITID; unsigned char cBitset = static_cast<unsigned char>(localset.to_ulong()); stream.write((char *) &cBitset, sizeof(unsigned char)); if (m_HasFITID) { StoreString(m_FITID, stream); } unsigned char numSplits = static_cast<unsigned char>(m_aSplits.size()); stream.write((char *) &numSplits, sizeof(unsigned char)); std::vector<SplitTransaction>::iterator it = m_aSplits.begin(); std::vector<SplitTransaction>::iterator itEnd = m_aSplits.end(); for (; it != itEnd; ++it) { (*it).Store(stream); } }
int User::writeUNPW(std::fstream &fout){ if (!fout.is_open()){ fout.open("UNPW.bin", std::ios::out, std::ios::binary); } auto fpos = fout.cur; fout.seekp(0, fout.beg); encode(username); encode(password); fout.write((char*)&username, sizeof(str)); fout.write((char*)&password, sizeof(str)); decode(username); decode(password); fout.seekp(0, fpos); return 0; }
Database::Database(char* file) { backing.open(file, std::ios::in|std::ios::out|std::ios::binary); if (backing.eof()) { char ver = FIDBVER; backing.write(&ver, 1); } else { char usedver = '\0'; backing.read(&usedver, 1); if (usedver != FIDBVER) { std::cerr << "Version " << usedver << " in file differs from " << FIDBVER << " in library!" << std::endl; return; } } indexstore = _ReadIndex(1); //Index is always on second byte }
void Database::_GetLock(uint64_t blockpos, bool readonly) { char blocklock = 1; backing.seekg(blockpos); backing.read(&blocklock, 1); while (blocklock == 1) { std::this_thread::sleep_for(std::chrono::milliseconds(50)); //Thanks StackOverflow! backing.seekg(blockpos); backing.read(&blocklock, 1); } if (readonly) { blocklock = 1; backing.seekp(blockpos); backing.write(&blocklock, 1); } }
exp bool RawWrite(const char* fname, size_t offsetIn, size_t offset, size_t len) { std::ifstream in(fname, std::ios::in | std::ios::binary); if (!in.is_open()) return false; // Seek to proper offsets in.seekg(offsetIn, std::ios::beg); f.seekp(offset + partitionOffset * 512, std::ios::beg); // Read data char* buffer = new char[len]; in.read(buffer, len); f.write(buffer, len); delete[] buffer; in.close(); return true; }
bool patch(std::fstream &file, char* buffer, size_t size) { std::vector<size_t> advapi; find_all(buffer, "ADVAPI32", size, 8, advapi); std::vector<int> functionlist; bool fullcheck = false; bool supported = true; if (!advapi.empty()) { if (fullcheck) for (int i = 0; i < 806; i++) { size_t func_len = strlen(Advapi_Function[i]); if (find_single(buffer, Advapi_Function[i], size, func_len)) { functionlist.push_back(i); supported = supported && Advapi_Support[i]; } }; if (supported) { for (size_t pos : advapi) { file.seekg(pos, std::ios::beg); file.write("REGEMU32", 8); } } wprintf(L"ADVAPI32 found (%d) and patched. ", advapi.size()); } else { wprintf(L"ADVAPI32 not found. "); } return !advapi.empty(); }
//****************************************************************************************************************************************************** //****************************************************************************************************************************************************** int WriteFile(std::fstream& fileHandle, BOOL* fieldSelections, int extractionMode, double* modeParameters, int numModeParameters, int numRecs, const mxArray *prhs[], int prhsIndex) { EventRec buf; memset(&buf, 0, mRecordSize ); int index = 0; for( int i = 0; i < numRecs; i++ ) { index = 0; if( fieldSelections[IndexTimestamp] ) { buf.qwTimeStamp = (unsigned __int64)(mInputFields[index][i]); index++; } if( !mGeneralOps.ValidRecToExtract(i, buf.qwTimeStamp, extractionMode, modeParameters, numModeParameters) ) { continue; } if( fieldSelections[IndexEventId] ) { buf.nevent_id = (short)(mInputFields[index][i]); index++; } if( fieldSelections[IndexTtl] ) { buf.nttl = (short)(mInputFields[index][i]); index++; } if( fieldSelections[IndexExtras] ) { for( int j = 0; j < EVENT_NUM_EXTRAS; j++) { buf.dnExtra[j] = (__int32)(mInputFields[index][(i*EVENT_NUM_EXTRAS)+j]); } index++; } if( fieldSelections[IndexEventString] ) { memset( buf.EventString, 0, sizeof(char)*NLX_EventRecStringSize); mxGetString( mxGetCell( prhs[prhsIndex], i ), buf.EventString, NLX_EventRecStringSize ); } fileHandle.write( (const char*)&buf, mRecordSize ); } return(Nlx2MatOK); }
void push_back(uint8_t x) { m_write_buf[m_widx] = x; if (m_sync) { m_read_buf[m_widx] = x; } ++m_widx; if (m_widx == m_buffer_size) { if (!m_sync) { // if not sync, write block to disk if (!m_stream.is_open()) { m_stream.open(m_file_name, std::ios::in | std::ios::out | std::ios::binary | std::ios::trunc); } m_stream.seekp(m_buffer_size * (m_wb++), std::ios::beg); m_stream.write((char*)m_write_buf, m_buffer_size); ++m_disk_buffered_blocks; } m_sync = 0; m_widx = 0; } }
void ssolver::Statedef::checkpoint(std::fstream & cp_file) { cp_file.write((char*)&pTime, sizeof(double)); cp_file.write((char*)&pNSteps, sizeof(uint)); SpecdefPVecCI s_end = pSpecdefs.end(); for (SpecdefPVecCI s = pSpecdefs.begin(); s != s_end; ++s) { (*s)->checkpoint(cp_file); } CompdefPVecCI c_end = pCompdefs.end(); for (CompdefPVecCI c = pCompdefs.begin(); c != c_end; ++c) { (*c)->checkpoint(cp_file); } PatchdefPVecCI p_end = pPatchdefs.end(); for (PatchdefPVecCI p = pPatchdefs.begin(); p != p_end; ++p) { (*p)->checkpoint(cp_file); } DiffBoundarydefPVecCI db_end = pDiffBoundarydefs.end(); for (DiffBoundarydefPVecCI db = pDiffBoundarydefs.begin(); db != db_end; ++db) { (*db)->checkpoint(cp_file); } ReacdefPVecCI r_end = pReacdefs.end(); for (ReacdefPVecCI r = pReacdefs.begin(); r != r_end; ++r) { (*r)->checkpoint(cp_file); } SReacdefPVecCI sr_end = pSReacdefs.end(); for (SReacdefPVecCI sr = pSReacdefs.begin(); sr != sr_end; ++sr) { (*sr)->checkpoint(cp_file); } DiffdefPVecCI d_end = pDiffdefs.end(); for (DiffdefPVecCI d = pDiffdefs.begin(); d != d_end; ++d) { (*d)->checkpoint(cp_file); } }
// WriteLn // Writes the formatted output to the file stream, returning the number of // bytes written. int WriteLn(std::fstream& stream, const char* fmt, ...) { char buf[MAX_BUFFER_LEN]; int nLength; t_Str szMsg; memset(buf, 0, MAX_BUFFER_LEN); va_list args; va_start (args, fmt); nLength = vsnprintf(buf, MAX_BUFFER_LEN, fmt, args); va_end (args); if ( buf[nLength] != '\n' && buf[nLength] != '\r' ) buf[nLength++] = '\n'; stream.write(buf, nLength); return nLength; }
bool unpatch(std::fstream &file, char* buffer, size_t size) { std::vector<size_t> regemu; find_all(buffer, "REGEMU32", size, 8, regemu); if (!regemu.empty()) { for (size_t pos : regemu) { file.seekg(pos, std::ios::beg); file.write("ADVAPI32", 8); } wprintf(L"REGEMU32 found (%d) and unpatched. ", regemu.size()); } else { wprintf(L"REGEMU32 not found. "); } return !regemu.empty(); }
void CBOLoader::_writeOctreeByMat(OctreeByMatScene *aScene, std::fstream &f) { /* Write the bounding box */ BoundingBox& aBoundingVolume = (BoundingBox &)aScene->getBoundingVolume(); std::vector<vec3> &points = aBoundingVolume.getNonTransformedPoints(); float flo[6]; flo[0] = points[0].x; flo[1] = points[0].y; flo[2] = points[0].z; flo[3] = points[1].x; flo[4] = points[1].y; flo[5] = points[1].z; f.write(reinterpret_cast<char*> (flo), 6 * sizeof(float)); OctreeByMat *o = aScene->m_pGeometry; _writeString(o->getName(),f); std::shared_ptr<OctreeByMatNode> &n = o->m_pOctreeRootNode; _writeOctreeByMatNode(n,f); }
//****************************************************************************************************************************************************** //****************************************************************************************************************************************************** int WriteFile(std::fstream & fileHandle, BOOL* fieldSelections, int extractionMode, double* modeParameters, int numModeParameters, int numRecs) { CRRec buf; memset(&buf, 0, mRecordSize ); int index = 0; for( int i = 0; i < numRecs; i++ ) { index = 0; if( fieldSelections[IndexTimestamp] ) { buf.qwTimeStamp = (unsigned __int64)(mInputFields[index][i]); index++; } if( !mGeneralOps.ValidRecToExtract(i, buf.qwTimeStamp, extractionMode, modeParameters, numModeParameters) ) { continue; } if( fieldSelections[IndexChannelNumbers] ) { buf.dwChannelNum = (unsigned __int32)(mInputFields[index][i]); index++; } if( fieldSelections[IndexSampleFrequency] ) { buf.dwSampleFreq = (unsigned __int32)(mInputFields[index][i]); index++; } if( fieldSelections[IndexNumberValidSamples] ) { buf.dwNumValidSamples = (unsigned __int32)(mInputFields[index][i]); index++; } if( fieldSelections[IndexSamples] ) { for( int j = 0; j < MAX_CSC_SAMPLES; j++) { buf.snSamples[j] = (signed __int16)(mInputFields[index][(i*MAX_CSC_SAMPLES)+j]); } } fileHandle.write( (const char*)&buf, mRecordSize ); } return(Nlx2MatOK2); }
int GeneralOperations::ProcessHeader(const mxArray *prhs[], int nrhs, int prhsIndex, std::fstream &fileHandle) { char header[NlxHeaderSize]; memset(header, 0, sizeof(char)*NlxHeaderSize); int headerIndex = 0; char buffer[500]; int numChars = 0; int numCells = mxGetM(prhs[prhsIndex]); CString temp; //copy cell to char array for( int i = 0; i < numCells; i++ ) { memset(buffer, 0, sizeof(char)*500); mxGetString( mxGetCell( prhs[prhsIndex], i ), buffer, 500); temp = buffer; numChars = temp.GetLength(); if( (headerIndex + numChars + 2) > NlxHeaderSize ) { break; } memcpy(&header[headerIndex], buffer, sizeof(char)*numChars); headerIndex += numChars; header[headerIndex] = '\r'; headerIndex++; header[headerIndex] = '\n'; headerIndex++; } //char errStr[20]; //sprintf(errStr,"Head %d %d", sizeof(char),NlxHeaderSize); //mexWarnMsgTxt(errStr); fileHandle.write( header, sizeof(char)*NlxHeaderSize ); return(Nlx2MatOK); }
void CBOLoader::_writeOctreeByMatNode(std::shared_ptr<OctreeByMatNode> &n, std::fstream &f) { unsigned int siz; BoundingBox& aBoundingVolume = (BoundingBox &)n->m_BoundingVolume; std::vector<vec3>& points = aBoundingVolume.getNonTransformedPoints(); float flo[6]; flo[0] = points[0].x; flo[1] = points[0].y; flo[2] = points[0].z; flo[3] = points[1].x; flo[4] = points[1].y; flo[5] = points[1].z; f.write(reinterpret_cast<char*> (flo), 6 * sizeof(float)); aBoundingVolume = (BoundingBox &)n->m_TightBoundingVolume; points = aBoundingVolume.getNonTransformedPoints(); flo[0] = points[0].x; flo[1] = points[0].y; flo[2] = points[0].z; flo[3] = points[1].x; flo[4] = points[1].y; flo[5] = points[1].z; f.write(reinterpret_cast<char*> (flo), 6 * sizeof(float)); siz = (unsigned int)n->m_pLocalMeshes.size(); f.write (reinterpret_cast<char *> (&siz), sizeof(siz)); for (auto so: n->m_pLocalMeshes) { _writeString(so.first, f); _writeOctreeByMatSceneObject(so.second, f); } f.write (reinterpret_cast<char *> (&n->m_ChildCount), sizeof(n->m_ChildCount)); f.write (reinterpret_cast<char *> (&n->m_NodeId), sizeof(n->m_NodeId)); f.write (reinterpret_cast<char *> (&n->m_NodeDepth), sizeof(n->m_NodeDepth)); for (int i = 0; i < 8; ++i) if (n->m_pChilds[i] != NULL) _writeOctreeByMatNode(n->m_pChilds[i],f); }
void DiaBinarySaver::saveEllipse(const DiaEntity* pEntity, std::fstream& fstream) const { const DiaEllipse* pEllipse = dynamic_cast<const DiaEllipse*>(pEntity); block.f_int = DiaEntity::Ellipse; fstream.write(block.f_char, sizeof(block)); block.f_int = pEllipse->id(); fstream.write(block.f_char, sizeof(block)); block.f_int = pEllipse->getX1r(); fstream.write(block.f_char, sizeof(block)); block.f_int = pEllipse->getY1r(); fstream.write(block.f_char, sizeof(block)); block.f_int = pEllipse->getX2r(); fstream.write(block.f_char, sizeof(block)); block.f_int = pEllipse->getY2r(); fstream.write(block.f_char, sizeof(block)); }
void DiaBinarySaver::saveRectangle(const DiaEntity* pEntity, std::fstream& fstream) const { const DiaRectangle* pRect = dynamic_cast<const DiaRectangle*>(pEntity); block.f_int = DiaEntity::Rectangle; fstream.write(block.f_char, sizeof(block)); block.f_int = pRect->id(); fstream.write(block.f_char, sizeof(block)); block.f_int = pRect->getX1r(); fstream.write(block.f_char, sizeof(block)); block.f_int = pRect->getY1r(); fstream.write(block.f_char, sizeof(block)); block.f_int = pRect->getX2r(); fstream.write(block.f_char, sizeof(block)); block.f_int = pRect->getY2r(); fstream.write(block.f_char, sizeof(block)); }
void File::Write(std::fstream &file, byte_t *data, size_t len) { file.write((char *) data, len); }
void G3D::writeVertices(std::fstream & fs, const float * const vertices, const GeometryInfo & info) { fs.write((char*)vertices, info.numberVertices * info.vertexSize); }
void G3D::writeIndices(std::fstream & fs, const uint32_t * const indices, const GeometryInfo & info) { fs.write((char*)indices, info.numberIndices * info.indexSize); }
void ssolver::Diffdef::checkpoint(std::fstream & cp_file) { cp_file.write((char*)&pDcst, sizeof(double)); }
void JumperComponent::write(std::fstream& stream) { stream.write((char*)&maxJumpHeight, sizeof(maxJumpHeight)); }
bool MapFileHeader::Write(std::fstream& file){ file.write((char*) &version, sizeof(int)); file.write((char*) &dateCreated, sizeof(long)); file.write((char*) mapName, MAX_PATH); return true; }
void ssolver::Chandef::checkpoint(std::fstream & cp_file) { cp_file.write((char*)&pNChanStates, sizeof(uint)); cp_file.write((char*)pChanStates, sizeof(uint) * pNChanStates); }
/** * Virtual function to write the data * * @param os Outputstream to write the data to */ void Table::WriteData(std::fstream &os) { for (int rec = 0; rec < Records(); rec++) { os.write(p_recbufs[rec], RecordSize()); } }