Esempio n. 1
0
void
ssa_parser_c::decode_chars(unsigned char c1,
                           unsigned char c2,
                           unsigned char c3,
                           unsigned char c4,
                           memory_cptr &buffer,
                           size_t bytes_to_add,
                           size_t &allocated) {
    unsigned char bytes[3];

    uint32_t value = ((c1 - 33) << 18) + ((c2 - 33) << 12) + ((c3 - 33) << 6) + (c4 - 33);
    bytes[2]       =  value & 0x0000ff;
    bytes[1]       = (value & 0x00ff00) >>  8;
    bytes[0]       = (value & 0xff0000) >> 16;

    if ((buffer->get_size() + bytes_to_add) > allocated) {
        int old_size  = buffer->get_size();
        allocated    += 1024;
        buffer->resize(allocated);
        buffer->set_size(old_size);
    }

    memcpy(buffer->get_buffer() + buffer->get_size(), bytes, bytes_to_add);
    buffer->set_size(buffer->get_size() + bytes_to_add);
}
Esempio n. 2
0
void
header_removal_compressor_c::compress(memory_cptr &buffer) {
  if (!m_bytes.is_set() || (0 == m_bytes->get_size()))
    return;

  size_t size = m_bytes->get_size();
  if (buffer->get_size() < size)
    throw mtx::compression_x(boost::format(Y("Header removal compression not possible because the buffer contained %1% bytes "
                                             "which is less than the size of the headers that should be removed, %2%.")) % buffer->get_size() % size);

  unsigned char *buffer_ptr = buffer->get_buffer();
  unsigned char *bytes_ptr  = m_bytes->get_buffer();

  if (memcmp(buffer_ptr, bytes_ptr, size)) {
    std::string b_buffer, b_bytes;
    size_t i;

    for (i = 0; size > i; ++i) {
      b_buffer += (boost::format(" %|1$02x|") % static_cast<unsigned int>(buffer_ptr[i])).str();
      b_bytes  += (boost::format(" %|1$02x|") % static_cast<unsigned int>(bytes_ptr[i])).str();
    }
    throw mtx::compression_x(boost::format(Y("Header removal compression not possible because the buffer did not start with the bytes that should be removed. "
                                             "Wanted bytes:%1%; found:%2%.")) % b_bytes % b_buffer);
  }

  size_t new_size = buffer->get_size() - size;

  if (buffer->is_free()) {
    memmove(buffer_ptr, buffer_ptr + size, new_size);
    buffer->set_size(new_size);
  } else
    buffer = clone_memory(buffer_ptr + size, new_size);
}
Esempio n. 3
0
uint32_t
mm_io_c::read(memory_cptr &buffer,
              size_t size,
              int offset) {
  if (-1 == offset)
    offset = buffer->get_size();

  if (buffer->get_size() <= (size + static_cast<size_t>(offset)))
    buffer->resize(size + offset);

  if (read(buffer->get_buffer() + offset, size) != size)
    throw mtx::mm_io::end_of_file_x();

  buffer->set_size(size + offset);

  return size;
}