// Returns the usable size for a chunk, meaning the amount of bytes from the // beginning of the user data to the end of the backend allocated chunk. static INLINE uptr getUsableSize(const void *Ptr, UnpackedHeader *Header) { const uptr ClassId = Header->ClassId; if (ClassId) return PrimaryT::ClassIdToSize(ClassId) - getHeaderSize() - (Header->Offset << MinAlignmentLog); return SecondaryT::GetActuallyAllocatedSize( getBackendPtr(Ptr, Header)) - getHeaderSize(); }
// Returns the size the user requested when allocating the chunk. static INLINE uptr getSize(const void *Ptr, UnpackedHeader *Header) { const uptr SizeOrUnusedBytes = Header->SizeOrUnusedBytes; if (Header->ClassId) return SizeOrUnusedBytes; return SecondaryT::GetActuallyAllocatedSize( getBackendPtr(Ptr, Header)) - getHeaderSize() - SizeOrUnusedBytes; }
/* ** Classifies the header of the given message into an event ** Returns -1 if the message header is not recognized or error occurs ** ** Arguments: ** evt - event to be set to the classified header ** msg - the message with the header to be classified */ int classifyMessage(event * evt, char * msg){ int size = getHeaderSize(msg); if(size == -1){ return -1; } char * header = malloc((size + 1) * sizeof(char)); if(header == NULL){ perror("malloc"); return -1; } memcpy(header, msg, size); *(header + size * sizeof(char)) = '\0'; if(strcmp(header, "PREPARED") == 0){ *evt = PREPARED; } else if(strcmp(header, "STARTED") == 0){ *evt = STARTED; } else if(strcmp(header, "FINISHED") == 0){ *evt = FINISHED; } else if(strcmp(header, "ERROR") == 0){ *evt = ERROR; } else{ fprintf(stderr, "Header in received message not recognized:\n Header: %s\nMessage: %s\n", header, msg); free(header); return -1; } free(header); return 0; }
void resized() override { auto bounds = getLocalBounds(); auto headerBounds = bounds.removeFromTop (getHeaderSize()); if (customHeaderComponent != nullptr) customHeaderComponent->setBounds (headerBounds); component->setBounds (bounds); }
int MidiFile::setHeaderSize() { _fileHeader._size = getHeaderSize(); fprintf(stderr, "size %lu\n", _fileHeader._size); if (_fileHeader._size != 6) fprintf(stderr, "%s %lu\n", "Error, bad size", _fileHeader._size); assert(_fileHeader._size == 6); return 0; }
//<"LSCH"><CeHeader><CacheKey><ResponseHeader><ResponseBody> int DirHashCacheEntry::loadCeHeader() { int fd = getFdStore(); if ( fd == -1 ) { errno = EBADF; return -1; } if ( nio_lseek( fd, getStartOffset(), SEEK_SET ) == -1 ) return -1; char achBuf[4 + sizeof( CeHeader ) ]; if ( (size_t)nio_read( fd, achBuf, 4 + sizeof( CeHeader ) ) < 4 + sizeof( CeHeader ) ) return -1; // if ( *( uint32_t *)achBuf != CE_ID ) // return -1; if (memcmp(achBuf, CE_ID, 4) != 0) return -1; memmove( &getHeader(), &achBuf[4], sizeof( CeHeader ) ); int len = getHeader().m_keyLen; if ( len > 0 ) { char * p = getKey().prealloc( len+1 ); if ( !p ) return -1; if ( nio_read( fd, p, len ) < len ) return -1; *(p+len) = 0; } char tmpBUf[4096]; #ifdef CACHE_RESP_HEADER if (getHeader().m_valPart1Len < 4096 ) //< 4K { if ( nio_read( fd, tmpBUf, getHeader().m_valPart1Len ) < getHeader().m_valPart1Len ) return -1; m_sRespHeader.append(tmpBUf, getHeader().m_valPart1Len); } #endif //load part3 to buffer int part3offset = getHeaderSize() + getContentTotalLen(); if ( nio_lseek( fd, part3offset, SEEK_SET ) != -1 ) { while((len = nio_read( fd, tmpBUf, 4096 )) > 0) m_sPart3Buf.append(tmpBUf, len); } return 0; }
ZipLocalFileHeader::ZipLocalFileHeader(std::istream& inp, bool assumeHeaderRead, ParseCallback& callback): _forceZip64(false), _rawHeader(), _startPos(inp.tellg()), _endPos(-1), _fileName(), _lastModifiedAt(), _extraField(), _crc32(0), _compressedSize(0), _uncompressedSize(0) { poco_assert_dbg( (EXTRA_FIELD_POS+EXTRA_FIELD_LENGTH) == FULLHEADER_SIZE); if (assumeHeaderRead) _startPos -= ZipCommon::HEADER_SIZE; parse(inp, assumeHeaderRead); bool ok = callback.handleZipEntry(inp, *this); if (ok) { if (searchCRCAndSizesAfterData()) { char header[ZipCommon::HEADER_SIZE]={'\x00', '\x00', '\x00', '\x00'}; inp.read(header, ZipCommon::HEADER_SIZE); if (std::memcmp(header, ZipDataInfo64::HEADER, sizeof(header)) == 0) { ZipDataInfo64 nfo(inp, true); setCRC(nfo.getCRC32()); setCompressedSize(nfo.getCompressedSize()); setUncompressedSize(nfo.getUncompressedSize()); } else { ZipDataInfo nfo(inp, true); setCRC(nfo.getCRC32()); setCompressedSize(nfo.getCompressedSize()); setUncompressedSize(nfo.getUncompressedSize()); } } } else { poco_assert_dbg(!searchCRCAndSizesAfterData()); ZipUtil::sync(inp); } _endPos = _startPos + getHeaderSize() + _compressedSize; // exclude the data block! }
/** * Scrubs an image of all secret messages so you can hide your tracks! * * @param image the image to scrub */ void Steg::scrub(const std::string &image) { std::vector<char> scrubbedBytes; read(scrubbedBytes, image); auto throwOut = getHeaderSize(scrubbedBytes); for (int i = throwOut; i < scrubbedBytes.size(); i++) { // set all low-order bits to 1 setBit(scrubbedBytes.at(i), 0, 1); } write(scrubbedBytes, image); }
bool ResourceFileWriter::write() { ofstream outputFile(myFilePath.c_str(), ios::out | ios::binary); if(!outputFile.is_open()) // make sure the file is open { return false; } int headerSize = getHeaderSize(); // calculate how many bytes the header will be // write the header information writeNumber(outputFile, magicWord); writeNumber(outputFile, headerSize); writeNumber(outputFile, myEntries.size()); // write the file table int currentOffset = headerSize; for(map<string, ResourceFileEntry *>::iterator i = myEntries.begin(); i != myEntries.end(); i++) { ResourceFileEntry * entry = (*i).second; entry->setOffset(currentOffset); outputFile << entry->name() << '\0'; writeNumber(outputFile, entry->fileSize()); writeNumber(outputFile, currentOffset); currentOffset += entry->fileSize(); } // input all source files ifstream inputFile; for(map<string, ResourceFileEntry *>::iterator i = myEntries.begin(); i != myEntries.end(); i++) { ResourceFileEntry * entry = (*i).second; inputFile.open(entry->filePath().c_str(), ios::in | ios::binary); outputFile << inputFile.rdbuf(); inputFile.close(); } outputFile.close(); return true; }
void JpegPayload::marshallHeader() { int header_size = getHeaderSize(); BOOST_VERIFY(header_size >= 0); m_header_buf = new unsigned char[header_size]; marshallMainHeader(); if (m_restart_marker_header_is_existed) { marshallRestartMarkerHeader(); } if (m_quantization_table_header_is_existed) { marshallQuantizationTableHeader(); } }
/** * Prints the IS parsing as browser to the std output */ int tcp_pocessServerResponse(int socket) { int max = 2000; char *buffer = malloc(max); FILE *fp = NULL; int filetype; int nbytes = max; while ((nbytes = read(socket, buffer, max)) != 0) { if (nbytes == TCP_ERROR && errno == EINTR) { tcp_pocessServerResponse(socket); } char *headerSize = getHeaderSize(buffer, &nbytes); if ( headerSize != 0) { filetype = getFileType(buffer); buffer = headerSize; } switch (filetype) { case text: printWbePage(buffer, nbytes); break; case image: fp = saveImage(nbytes, fp, buffer); break; default: break; } buffer = malloc(max); } free(buffer); if(fp != NULL){ fclose(fp); } return EXIT_SUCCESS; }
void app_recv() { static comBuf * buffer; static uint8_t headerSize; static uint8_t from_seqNo = 0; static uint16_t originator = 0; while (1) { /* receive data frames from base */ buffer = net_recv(CTP_LISTENING_PORT); #ifdef KEEP_CTP_HEADER /* parse ctp header */ ctp_dl_data_header_t * dh = (ctp_dl_data_header_t *) buffer->data; if((is_base && (dh->type != AM_CTP_DATA)) || ((!is_base) && (dh->type != AM_CTP_DL_DATA)) ) { printf("\nReceived a frame type %C, not %s", dh->type, is_base?"CTP_DATA":"CTP_DL_DATA"); } else { originator = (dh->originHigh << 8) | (dh->originLow & 0xff); from_seqNo = dh->originSeqNo; } headerSize = getHeaderSize(dh->type); memcpy(buffer->data, &(buffer->data[headerSize]), buffer->size-headerSize); buffer->size -= headerSize; #endif /* parse app layer header. Header format (app_type, seqNo) */ app_header_t * appHeader = (app_header_t *) buffer->data; if(appHeader->type == APP_ACK) { printf(header_info, "APP_ACK", buffer->size, appHeader->seqNo, originator); } else if(appHeader->type == APP_DATA) { printf(header_info, "APP_DATA", buffer->size, appHeader->seqNo, originator); } else { printf(header_info1, buffer->size, appHeader->type, originator); } com_free_buf(buffer); } }
/** * Extracts a payload from a vector of bytes. The low-order bit of each byte * forms part of a character. One lower-order bit from 8 bytes forms a * character. * * @param payload the payload extracted from the bytes * @param modifiedBytes the bytes that have payload data in them */ bool Steg::extractPayload(std::string &payload, const std::vector<char> &modifiedBytes) { auto dataStart = getHeaderSize(modifiedBytes); std::vector<char> payloadBytes; for (int i = dataStart; i < modifiedBytes.size(); i += 8) { char c = char(0); for (int j = 0; j < 8; j++) { // set the j'th bit in char c equal to the lowest-order bit at i + j // of the modified bytes. This effectively looks at the next 8 // bytes, and reconstructs a character from their lowest-order bits. setBit(c, j, getBit(modifiedBytes.at(i + j), 0)); } if (isAscii(c)) { payloadBytes.push_back(c); } else { // a non-ascii character was found, so the operation is aborted return false; } // stop at a null char if (payloadBytes.back() == '\0') { break; } } // construct a string from the characters payload = std::string(payloadBytes.begin(), payloadBytes.end()); return true; }
/** * Attaches a secret payload to the bytes of a BMP file. * * @param modifiedBytes the bytes that have been modified to store the payload * @param originalBytes the bytes of the original BMP file * @param payload the secret message that will be stored in the modifiedBytes */ void Steg::equipPayload(std::vector<char> &modifiedBytes, const std::vector<char> &originalBytes, const std::string payload) { modifiedBytes = originalBytes; std::vector<unsigned short> expansion; expandPayload(expansion, payload); int throwOut = getHeaderSize(originalBytes); if (modifiedBytes.size() - throwOut < expansion.size()) { throw std::runtime_error("Image is not big enough to hold this data!"); } int i = throwOut; for (unsigned short val : expansion) { // set the lowest-order bit of this byte to the value of val setBit(modifiedBytes.at(i++), 0, val); } }
void resized() { component->setBounds (getLocalBounds().withTop (getHeaderSize())); }
static INLINE const AtomicPackedHeader *getConstAtomicHeader(const void *Ptr) { return reinterpret_cast<const AtomicPackedHeader *>( reinterpret_cast<uptr>(Ptr) - getHeaderSize()); }
/** * Analyzes the a BMP file to allow the user to plan their message length * appropriately. * * @param image the name of the image to analyze */ void Steg::analyze(const std::string &image) { std::vector<char> bytes; read(bytes, image); const unsigned int dWord = bytes.at(0) << 24 | bytes.at(1) << 16 | bytes.at(2) << 8 | bytes.at(3); auto header = getHeaderSize(bytes); unsigned short imageType = 0; switch (header) { case 10: imageType = 1; break; case 16: imageType = 2; break; case 54: imageType = 3; break; case 122: imageType = 4; break; default: imageType = -1; break; } std::cout << " Analyzing \"" << image << "\"" << std::endl; std::cout << " Image size : " << bytes.size() << " bytes\n"; std::cout << " Header size: " << header << " bytes" << std::endl; std::cout << " BMP type : " << imageType << std::endl; std::cout << " Max payload: " << ((bytes.size() - getHeaderSize(bytes)) / 8) - 1 << " characters\n"; bool encrypted = true; std::string payload; if (!extractPayload(payload, bytes)) { encrypted = false; } std::cout << " This image "; if (encrypted) { std::cout << "may be "; } else { std::cout << "is probably not "; } std::cout << "encrypted.\n"; }
// We can't use the offset member of the chunk itself, as we would double // fetch it without any warranty that it wouldn't have been tampered. To // prevent this, we work with a local copy of the header. static INLINE void *getBackendPtr(const void *Ptr, UnpackedHeader *Header) { return reinterpret_cast<void *>(reinterpret_cast<uptr>(Ptr) - getHeaderSize() - (Header->Offset << MinAlignmentLog)); }
JNIEXPORT jint JNICALL Java_org_theonionphone_protocol_SrtpProtocol_getHeaderSize (JNIEnv *env, jobject obj) { return getHeaderSize(); }
/** * Read the program meta data and the image data from a file, with * image validation. * * @param handle The input file handle. * * @return A BufferClass instance containing the program data, or OREF_NULL * if the file is not a valid image. */ BufferClass *ProgramMetaData::read(RexxString *fileName, FILE *handle) { bool badVersion = false; size_t headerSize = getHeaderSize(); size_t readSize; // now read the control info readSize = fread((char *)this, 1, headerSize, handle); // if we could read the header, validate all of the meta information if (readSize < headerSize || !validate(badVersion)) { // if this failed because we couldn't read in the required header, or // because of the version signature, we need to raise an error now. if (readSize < headerSize || badVersion) { fclose(handle); reportException(Error_Program_unreadable_version, fileName); } // if it didn't validate, it might be because we have a unix-style "hash bang" line at the // beginning of the file. The first read in bit has a "#!", then we need to read // beyond the first linend and try again. if (fileTag[0] == '#' && fileTag[1] == '!') { // back to the start (ok, just past the hash bang) fseek(handle, 2, SEEK_SET); while (true) { if (fread(fileTag, 1, 1, handle) <= 0) { fclose(handle); return OREF_NULL; } // if we hit a newline, this is our stopping point. // NB: this works with both \n and \r\n sequences. if (fileTag[0] == '\n') { break; } // ok, try to read the control information one more time. // if this doesn't work, no point in being pushy about it. readSize = fread((char *)this, 1, headerSize, handle); // if we could read the header, validate all of the meta information if (readSize < headerSize || !validate(badVersion)) { fclose(handle); /* close the file */ // if because we couldn't read in the required header, or // because of a bad version sig, we can close now if (readSize < headerSize || badVersion) { reportException(Error_Program_unreadable_version, fileName); } return OREF_NULL; } } } } BufferClass *buffer = new_buffer(imageSize); ProtectedObject p(buffer); readSize = fread(buffer->getData(), 1, imageSize, handle); if (readSize < imageSize) { fclose(handle); reportException(Error_Program_unreadable_version, fileName); return OREF_NULL; } return buffer; }
unsigned int Node::getFreeSize()const{ if(size>usedSize+getHeaderSize()) return (size-usedSize-getHeaderSize()); return 0; }
void descomprimir(FILE *fpin, FILE *fpout, struct nodo *raiz, struct header *h, int verbose) { BYTE buf_lec[BUF_SZ], buf_esc[BUF_SZ], b; int pos_buf_lec, pos_pos=0, nbits, cont=0; struct nodo *tmp=raiz; float completado=0.0F, inc; struct stat statbuf; if (verbose) { fstat(fileno(fpin), &statbuf); inc = (BUF_SZ*100.0F) / statbuf.st_size; if (inc > 100.0F) inc=100.0F; printf("Expanding... 0%%"); } fseek(fpin, getHeaderSize(h), SEEK_SET); for (;;) { pos_buf_lec=0; nbits=fread(buf_lec, 1, BUF_SZ, fpin); if (ferror(fpin)) { perror("fread: descomprimir()"); exit(1); } nbits<<=3; // nbits*=8; if (feof(fpin)) { nbits-=h->padding_bits; if (h->deterr != DONT_USE_ERR_DET) nbits-=16; } while (nbits != 0) { /* * Esta comprobacion es necesaria por si se * comprimio un fichero en el que todos los * caracteres son el mismo, ya que el arbol * solo tendra un nodo, la raiz */ if (tmp->hizq != NULL) { readBits(buf_lec, &pos_buf_lec, &pos_pos, &b, 1); if (b == 0) tmp=tmp->hizq; else tmp=tmp->hdch; } if (tmp->hizq == NULL) // Hoja { buf_esc[cont]=tmp->c; cont++; if (cont == BUF_SZ) { cont=0; fwrite(buf_esc, 1, BUF_SZ, fpout); if (ferror(fpout)) { perror("fwrite: descomprimir()"); exit(1); } } tmp=raiz; } nbits--; } if (verbose) { if ((int)completado == 100) printf("\b\b"); else if ((int)completado >= 10) printf("\b"); completado+=inc; if ((int)completado > 100) completado=100.0F; printf("\b\b%d%%", (int)completado); } if (feof(fpin)) { fwrite(buf_esc, 1, cont, fpout); if (ferror(fpout)) { perror("fwrite: descomprimir()"); exit(1); } if (verbose) { if ((int)completado < 100) printf("\b\b\b100%%"); printf("\n"); } break; // Salimos del for(;;) } } }
/** * Write the metadata to a file. * * @param handle The handle of the output file. * @param program The program buffer data (also written out). */ void ProgramMetaData::write(FILE *handle, BufferClass *program) { fwrite(this, 1, getHeaderSize(), handle); /* and finally the flattened method */ fwrite(program->getData(), 1, program->getDataLength(), handle); }