예제 #1
0
    unsigned int AndroidFile::Read(void * buffer, unsigned int size)
    {
        unsigned int realSize = size > GetBytesLeft() ? GetBytesLeft() : size;
        memcpy(buffer, mData + mPosition, realSize);

        return realSize;
    }
예제 #2
0
uint64_t
StringExtractor::GetHexWithFixedSize (uint32_t byte_size, bool little_endian, uint64_t fail_value)
{
    if (byte_size <= 8 && GetBytesLeft() >= byte_size * 2)
    {
        uint64_t result = 0;
        uint32_t i;
        if (little_endian)
        {
            // Little Endian
            uint32_t shift_amount;
            for (i = 0, shift_amount = 0;
                 i < byte_size && m_index != UINT32_MAX;
                 ++i, shift_amount += 8)
            {
                result |= ((uint64_t)GetHexU8() << shift_amount);
            }
        }
        else
        {
            // Big Endian
            for (i = 0; i < byte_size && m_index != UINT32_MAX; ++i)
            {
                result <<= 8;
                result |= GetHexU8();
            }
        }
    }
    m_index = UINT32_MAX;
    return fail_value;
}
예제 #3
0
	Array<byte> ImageReader::convertData( ) const {
		auto image = this->getImage( );

		// Bail if invalid
		if ( !image.IsOk( ) ) {
			return Array<byte>( );
		}

		// Write the png to memory
		wxMemoryOutputStream stream;
		if ( !image.SaveFile( stream, wxBITMAP_TYPE_PNG ) ) {
			return Array<byte>( );
		}

		// Reset the position of the stream
		auto buffer = stream.GetOutputStreamBuffer( );
		buffer->Seek( 0, wxFromStart );

		// Read the data from the stream and into a buffer
		Array<byte> data( buffer->GetBytesLeft( ) );
		buffer->Read( data.GetPointer( ), data.GetSize( ) );

		// Return the PNG data
		return data;
	}
예제 #4
0
파일: stream.cpp 프로젝트: hgwells/tive
size_t wxStreamBuffer::GetDataLeft()
{
    /* Why is this done? RR. */
    if ( m_buffer_pos == m_buffer_end && m_flushable)
        FillBuffer();

    return GetBytesLeft();
}
예제 #5
0
size_t StringExtractor::GetHexByteString(std::string &str) {
  str.clear();
  str.reserve(GetBytesLeft() / 2);
  char ch;
  while ((ch = GetHexU8()) != '\0')
    str.append(1, ch);
  return str.size();
}
예제 #6
0
파일: stream.cpp 프로젝트: hgwells/tive
// copy up to size bytes from our buffer into the provided one
void wxStreamBuffer::GetFromBuffer(void *buffer, size_t size)
{
    // don't get more bytes than left in the buffer
    size_t left = GetBytesLeft();

    if ( size > left )
        size = left;

    memcpy(buffer, m_buffer_pos, size);
    m_buffer_pos += size;
}
예제 #7
0
//----------------------------------------------------------------------
// If a pair of valid hex digits exist at the head of the
// StringExtractor they are decoded into an unsigned byte and returned
// by this function
//
// If there is not a pair of valid hex digits at the head of the
// StringExtractor, it is left unchanged and -1 is returned
//----------------------------------------------------------------------
int StringExtractor::DecodeHexU8() {
  SkipSpaces();
  if (GetBytesLeft() < 2) {
    return -1;
  }
  const int hi_nibble = xdigit_to_sint(m_packet[m_index]);
  const int lo_nibble = xdigit_to_sint(m_packet[m_index + 1]);
  if (hi_nibble == -1 || lo_nibble == -1) {
    return -1;
  }
  m_index += 2;
  return (uint8_t)((hi_nibble << 4) + lo_nibble);
}
예제 #8
0
size_t
StringExtractorGDBRemote::GetEscapedBinaryData (std::string &str)
{
    str.clear();
    char ch;
    while (GetBytesLeft())
    {
        ch = GetChar();
        if (ch == 0x7d)
            ch = (GetChar() ^ 0x20);
        str.append(1,ch);
    }
    return str.size();
}
예제 #9
0
size_t
StringExtractorGDBRemote::GetEscapedBinaryData (std::string &str)
{
    // Just get the data bytes in the string as GDBRemoteCommunication::CheckForPacket()
    // already removes any 0x7d escaped characters. If any 0x7d characters are left in
    // the packet, then they are supposed to be there...
    str.clear();
    const size_t bytes_left = GetBytesLeft();
    if (bytes_left > 0)
    {
        str.assign(m_packet, m_index, bytes_left);
        m_index += bytes_left;
    }
    return str.size();
}
예제 #10
0
size_t StringExtractor::GetHexBytes(llvm::MutableArrayRef<uint8_t> dest,
                                    uint8_t fail_fill_value) {
  size_t bytes_extracted = 0;
  while (!dest.empty() && GetBytesLeft() > 0) {
    dest[0] = GetHexU8(fail_fill_value);
    if (!IsGood())
      break;
    ++bytes_extracted;
    dest = dest.drop_front();
  }

  if (!dest.empty())
    ::memset(dest.data(), fail_fill_value, dest.size());

  return bytes_extracted;
}
예제 #11
0
//----------------------------------------------------------------------
// Extract an unsigned character from two hex ASCII chars in the packet
// string
//----------------------------------------------------------------------
uint8_t
StringExtractor::GetHexU8 (uint8_t fail_value, bool set_eof_on_fail)
{
    if (GetBytesLeft() >= 2)
    {
        const uint8_t hi_nibble = g_hex_ascii_to_hex_integer[static_cast<uint8_t>(m_packet[m_index])];
        const uint8_t lo_nibble = g_hex_ascii_to_hex_integer[static_cast<uint8_t>(m_packet[m_index+1])];
        if (hi_nibble < 16 && lo_nibble < 16)
        {
            m_index += 2;
            return (hi_nibble << 4) + lo_nibble;
        }
    }
    if (set_eof_on_fail || m_index >= m_packet.size())
        m_index = UINT64_MAX;
    return fail_value;
}
예제 #12
0
size_t
StringExtractor::GetHexBytes (void *dst_void, size_t dst_len, uint8_t fail_fill_value)
{
    uint8_t *dst = (uint8_t*)dst_void;
    size_t bytes_extracted = 0;
    while (bytes_extracted < dst_len && GetBytesLeft ())
    {
        dst[bytes_extracted] = GetHexU8 (fail_fill_value);
        if (IsGood())
            ++bytes_extracted;
        else
            break;
    }

    for (size_t i = bytes_extracted; i < dst_len; ++i)
        dst[i] = fail_fill_value;

    return bytes_extracted;
}
예제 #13
0
// copy the contents of the provided buffer into this one
void wxStreamBuffer::PutToBuffer(const void *buffer, size_t size)
{
    size_t left = GetBytesLeft();

    if ( size > left )
    {
        if ( m_fixed )
        {
            // we can't realloc the buffer, so just copy what we can
            size = left;
        }
        else // !m_fixed
        {
            // realloc the buffer to have enough space for the data
            if ( m_buffer_pos + size > m_buffer_end )
            {
                size_t delta = m_buffer_pos - m_buffer_start;
                size_t new_size = delta + size;

                char *startOld = m_buffer_start;
                m_buffer_start = (char *)realloc(m_buffer_start, new_size);
                if ( !m_buffer_start )
                {
                    // don't leak memory if realloc() failed
                    m_buffer_start = startOld;

                    // what else can we do?
                    return;
                }

                // adjust the pointers invalidated by realloc()
                m_buffer_pos = m_buffer_start + delta;
                m_buffer_end = m_buffer_start + new_size;
            } // else: the buffer is big enough
        }
    }

    memcpy(m_buffer_pos, buffer, size);
    m_buffer_pos += size;
}
예제 #14
0
파일: stream.cpp 프로젝트: hgwells/tive
size_t wxStreamBuffer::Write(const void *buffer, size_t size)
{
    wxASSERT_MSG( buffer, _T("Warning: Null pointer is about to be send") );

    if (m_stream)
    {
        // lasterror is reset before all new IO calls
        m_stream->Reset();
    }

    size_t ret;

    if ( !HasBuffer() && m_fixed )
    {
        wxOutputStream *outStream = GetOutputStream();

        wxCHECK_MSG( outStream, 0, _T("should have a stream in wxStreamBuffer") );

        // no buffer, just forward the call to the stream
        ret = outStream->OnSysWrite(buffer, size);
    }
    else // we [may] have a buffer, use it
    {
        size_t orig_size = size;

        while ( size > 0 )
        {
            size_t left = GetBytesLeft();

            // if the buffer is too large to fit in the stream buffer, split
            // it in smaller parts
            //
            // NB: If stream buffer isn't fixed (as for wxMemoryOutputStream),
            //     we always go to the second case.
            //
            // FIXME: fine, but if it fails we should (re)try writing it by
            //        chunks as this will (hopefully) always work (VZ)

            if ( size > left && m_fixed )
            {
                PutToBuffer(buffer, left);
                size -= left;
                buffer = (char *)buffer + left;

                if ( !FlushBuffer() )
                {
                    SetError(wxSTREAM_WRITE_ERROR);

                    break;
                }

                m_buffer_pos = m_buffer_start;
            }
            else // we can do it in one gulp
            {
                PutToBuffer(buffer, size);
                size = 0;
            }
        }

        ret = orig_size - size;
    }

    if (m_stream)
    {
        // i am not entirely sure what we do this for
        m_stream->m_lastcount = ret;
    }

    return ret;
}