示例#1
0
	ParticleGroup& ParticleGroup::operator=(const ParticleGroup& system)
	{
		ErrorFlags flags(ErrorFlag_ThrowException, true);

		Renderable::operator=(system);

		m_controllers = system.m_controllers;
		m_declaration = system.m_declaration;
		m_generators = system.m_generators;
		m_maxParticleCount = system.m_maxParticleCount;
		m_particleCount = system.m_particleCount;
		m_particleSize = system.m_particleSize;
		m_renderer = system.m_renderer;

		// The copy can not (or should not) happen during the update, there is no use to copy
		m_dyingParticles.clear();
		m_processing = false;

		m_buffer.clear(); // To avoid a copy due to resize() which will be pointless
		ResizeBuffer();

		// We only copy alive particles
		std::memcpy(m_buffer.data(), system.m_buffer.data(), system.m_particleCount * m_particleSize);

		return *this;
	}
示例#2
0
XnStatus MockGenerator::SetNextData(const void *pData, XnUInt32 nSize)
{
	XnStatus nRetVal = XN_STATUS_OK;

	//Make sure the node is in Generating state so it would be recorded properly
	SetGenerating(TRUE);

	DataInfo& nextData = m_data[m_nNextDataIdx];

	if (!m_bAggregateData)
	{
		nextData.nDataSize = 0;
	}

	nRetVal = ResizeBuffer(m_nNextDataIdx, nextData.nDataSize + nSize);
	XN_IS_STATUS_OK(nRetVal);

	xnOSMemCopy((XnUChar*)nextData.pData + nextData.nDataSize, pData, nSize);
	nextData.nDataSize += nSize;

	nRetVal = SetNewDataAvailable();
	XN_IS_STATUS_OK(nRetVal);

	return XN_STATUS_OK;
}
示例#3
0
bool MyBoundResults::RefetchField(MYSQL_STMT *stmt, 
				  unsigned int id,
				  size_t initSize,
				  enum_field_types type)
{
	ResultBind *rbind = &m_pull[id];

	/* Make sure there is a buffer to pull into */
	ResizeBuffer(rbind, initSize);

	/* Update the bind with the buffer size */
	m_bind[id].buffer = rbind->blob;
	m_bind[id].buffer_length = (unsigned long)rbind->length;
	m_bUpdatedBinds = true;

	MYSQL_BIND bind;

	/* Initialize bind info */
	memset(&bind, 0, sizeof(MYSQL_BIND));
	bind.buffer = rbind->blob;
	bind.buffer_type = type;
	bind.buffer_length = (unsigned long)rbind->length;
	bind.length = &(rbind->my_length);
	bind.is_null = &(rbind->my_null);

	/* Attempt to fetch */
	return (mysql_stmt_fetch_column(stmt, &bind, id, 0) == 0);
}
void FSlateElementIndexBuffer::FillBuffer( const TArray<SlateIndex>& InIndices, bool bShrinkToFit  )
{
	check( IsInRenderingThread() );

	if( InIndices.Num() )
	{
		uint32 NumIndices = InIndices.Num();

		uint32 RequiredBufferSize = NumIndices*sizeof(SlateIndex);

		// resize if needed
		if( RequiredBufferSize > GetBufferSize() || bShrinkToFit )
		{
			// Use array resize techniques for the vertex buffer
			ResizeBuffer( InIndices.GetAllocatedSize() );
		}

		BufferUsageSize += RequiredBufferSize;

		void* IndicesPtr = RHILockIndexBuffer( IndexBufferRHI, 0, RequiredBufferSize, RLM_WriteOnly );

		FMemory::Memcpy( IndicesPtr, InIndices.GetData(), RequiredBufferSize );

		RHIUnlockIndexBuffer(IndexBufferRHI);
	}
}
ULONG
GetTraceEventInfo(
    __in PEVENT_RECORD Event,
    __inout PPROCESSING_CONTEXT LogContext,
    __out PTRACE_EVENT_INFO* EventInfo
)

/*++

Routine Description:

    This routine retrieves the TRACE_EVENT_INFO structure for the
    passed EVENT_RECORD Event. This structure contains the meta-
    information about the event.

Arguments:

    Event - Supplies the structure representing an event.

    EventInfo - Receives the event meta-information.

Return Value:

    ERROR_SUCCESS - Success.

    Win32 error code - TdhGetEventInformation() failed.

--*/

{
    ULONG Status = ERROR_SUCCESS;
    PPROCESSING_DATA_CONTEXT DataContext= &LogContext->DataContext;
    ULONG BufferSize = DataContext->EventInfoBufferSize;

    do {
        if (Status == ERROR_INSUFFICIENT_BUFFER) {
            Status = ResizeBuffer(&DataContext->EventInfoBuffer,
                                  &DataContext->EventInfoBufferSize,
                                  BufferSize);
            if (DataContext->EventInfoBuffer == NULL) {
                return ERROR_OUTOFMEMORY;
            }
            DataContext->EventInfoBufferSize = BufferSize;
        }

        Status = TdhGetEventInformation(Event,
                                        0,
                                        NULL,
                                        (PTRACE_EVENT_INFO)DataContext->EventInfoBuffer,
                                        &BufferSize);

    } while (Status == ERROR_INSUFFICIENT_BUFFER);

    if (Status == ERROR_SUCCESS) {
        *EventInfo = (PTRACE_EVENT_INFO)DataContext->EventInfoBuffer;
    }

    return Status;
}
示例#6
0
inline void C2DRoundRect::SetNumSegmentsPerCorner( int num_segs_per_corner )
{
	if( num_segs_per_corner != m_NumSegmentsPerCorner )
	{
		// need reallocation
		m_NumSegmentsPerCorner = num_segs_per_corner;
		ResizeBuffer();
	}
}
示例#7
0
文件: NoRSX.cpp 项目: wargio/NoRSX
void NoRSX::RescaleFlip(){
	waitFlip();
	ResizeBuffer();
	flip(context, currentBuffer);
	currentBuffer = !currentBuffer;
	setRenderTarget(context, &buffers[currentBuffer]);
	sysUtilCheckCallback();
	return;
}
示例#8
0
	ParticleGroup::ParticleGroup(unsigned int maxParticleCount, ParticleDeclarationConstRef declaration) :
	m_maxParticleCount(maxParticleCount),
	m_particleCount(0),
	m_declaration(std::move(declaration)),
	m_processing(false)
	{
		// In case of error, the constructor can only throw an exception
		ErrorFlags flags(ErrorFlag_ThrowException, true);

		m_particleSize = m_declaration->GetStride(); // The size of each particle

		ResizeBuffer();
	}
示例#9
0
bool String::PrepareBuffer(unsigned long newSize,bool preserve)
{
	if(m_BufferSize == newSize)
		return true;

	if(newSize < m_BufferSize)
		if(m_BufferSize - newSize < STRING_ALLOCATION_SIZE)
			return true;

	newSize = newSize - newSize % STRING_ALLOCATION_SIZE + STRING_ALLOCATION_SIZE;

	return ResizeBuffer(newSize,preserve);
}
示例#10
0
static inline void log_formatter_createPrefix(char** buffer, size_t* bufferSize,
		const char* section, int level)
{
	//log_formatter_createPrefix_xorgStyle(buffer, bufferSize, section, level);
	//log_formatter_createPrefix_testing(buffer, bufferSize, section, level);
	log_formatter_createPrefix_default(buffer, bufferSize, section, level);

	// check if the buffer was large enough, if not resize it and try again
	const bool bufferTooSmall = ((strlen(*buffer) + 1) >= *bufferSize);
	if (bufferTooSmall) {
		ResizeBuffer(buffer, bufferSize);
		log_formatter_createPrefix(buffer, bufferSize, section, level); // recursive
	}
}
BOOL
ISAPI_STRING::CopyToOffset(
    CHAR *  szString,
    DWORD   cchString,
    DWORD   dwOffset
    )
/*++

Purpose:

    Copies a string into the ISAPI_STRING's data, starting at the
    specified offset.

Arguments:

    szString  - The string to copy
    cchString - The number of characters to copy
    dwOffset  - The offset at which to copy

Returns:

    TRUE on success, FALSE on failure

--*/
{
    DWORD   cbData;

    //
    // Ensure that we have enough storage available
    //

    cbData = cchString + sizeof(CHAR);

    if ( ResizeBuffer( cbData + dwOffset ) == FALSE )
    {
        return FALSE;
    }

    //
    // Copy the data and ensure proper termination
    //

    CopyMemory( QueryStr() + dwOffset, szString, cbData );

    SetLen( QueryCCH() + cbData - sizeof(CHAR) );

    return TRUE;
}
BOOL
ISAPI_STRINGW::CopyToOffset(
    WCHAR * szStringW,
    DWORD   cchStringW,
    DWORD   cchOffset
    )
/*++

Purpose:

    Copies a Unicode string into the ISAPI_STRINGW's data, starting at the
    specified offset, in characters.

Arguments:

    szStringW  - The Unicode string to copy
    cchStringW - The number of characters to copy
    cchOffset  - The offset, in chracters, at which to copy

Returns:

    TRUE on success, FALSE on failure

--*/
{
    DWORD   cbData;

    //
    // Ensure that we have enough storage available
    //

    cbData = ( cchStringW + 1 ) * sizeof(WCHAR);

    if ( ResizeBuffer( cbData + cchOffset * sizeof(WCHAR) ) == FALSE )
    {
        return FALSE;
    }

    //
    // Copy the data and ensure proper termination
    //

    CopyMemory( QueryStr() + cchOffset, szStringW, cbData );

    SetLen( QueryCCH() + cchStringW );

    return TRUE;
}
示例#13
0
XnStatus MockGenerator::SetNextData(const void *pData, XnUInt32 nSize)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = ResizeBuffer(m_nNextDataIdx, nSize);
	XN_IS_STATUS_OK(nRetVal);

	DataInfo& nextData = m_data[m_nNextDataIdx];
	xnOSMemCopy(nextData.pData, pData, nSize);
	nextData.nDataSize = nSize;

	m_bNewDataAvailable = TRUE;
	nRetVal = m_newDataAvailableEvent.Raise();
	XN_IS_STATUS_OK(nRetVal);
	return XN_STATUS_OK;
}
示例#14
0
XnStatus MockGenerator::OnStateReady()
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = MockProductionNode::OnStateReady();
	XN_IS_STATUS_OK(nRetVal);
	
	// allocate current buffer (so the app won't get a NULL pointer)
	XnUInt32 nNeededSize = GetRequiredBufferSize();

	nRetVal = ResizeBuffer(m_nCurrentDataIdx, nNeededSize);
	XN_IS_STATUS_OK(nRetVal);

	xnOSMemSet(m_data[m_nCurrentDataIdx].pData, 0, nNeededSize);

	return (XN_STATUS_OK);
}
示例#15
0
	ParticleGroup::ParticleGroup(const ParticleGroup& system) :
	Renderable(system),
	m_maxParticleCount(system.m_maxParticleCount),
	m_particleCount(system.m_particleCount),
	m_particleSize(system.m_particleSize),
	m_controllers(system.m_controllers),
	m_generators(system.m_generators),
	m_declaration(system.m_declaration),
	m_renderer(system.m_renderer),
	m_processing(false)
	{
		ErrorFlags flags(ErrorFlag_ThrowException, true);

		ResizeBuffer();

		// We only copy alive particles
		std::memcpy(m_buffer.data(), system.m_buffer.data(), system.m_particleCount*m_particleSize);
	}
示例#16
0
 virtual void Flush()
 {
   while (const int res = LameApi->lame_encode_flush(Context.get(), &Encoded[0], Encoded.size()))
   {
     if (res > 0)
     {
       Stream->ApplyData(Binary::DataAdapter(&Encoded[0], res));
       break;
     }
     else if (-1 == res)//buffer too small
     {
       ResizeBuffer();
     }
     else
     {
       CheckLameCall(res, THIS_LINE);
     }
   }
   Dbg("Stream flushed");
 }
void FSlateElementIndexBuffer::PreFillBuffer(int32 RequiredIndexCount, bool bShrinkToMinSize)
{
	//SCOPE_CYCLE_COUNTER( STAT_SlatePreFullBufferRTTime );

	checkSlow(IsInRenderingThread());

	if (RequiredIndexCount > 0)
	{
		int32 RequiredBufferSize = RequiredIndexCount*sizeof(SlateIndex);

		// resize if needed
		if (RequiredBufferSize > GetBufferSize() || bShrinkToMinSize)
		{
			// Use array resize techniques for the vertex buffer
			ResizeBuffer(RequiredBufferSize);
		}

		BufferUsageSize = RequiredBufferSize;		
	}
}
示例#18
0
static inline void PrintfAppend(char** buffer, size_t* bufferSize, const char* fmt, va_list arguments)
{
    // dynamically adjust the buffer size until VSNPRINTF returns fine
    size_t bufferPos = strlen(*buffer);

    do {
        size_t freeBufferSize = (*bufferSize) - bufferPos;
        char* bufAppendPos = &((*buffer)[bufferPos]);

        // printf will move the internal pointer of va_list.
        // So we need to make a copy, if want to run it again.
        va_list arguments_;
        va_copy(arguments_, arguments);
        VSNPRINTF(bufAppendPos, freeBufferSize, fmt, arguments_);
        va_end(arguments_);
        const bool bufferTooSmall = ((strlen(*buffer) + 1) >= *bufferSize);
        if (!bufferTooSmall) break;

        ResizeBuffer(buffer, bufferSize, true);
    } while (true);
}
// REM This function is also called by Init() for initialization
bool CSVwrite::Reset()
{
    if( _output_ptr )
    {
        _error = true;
        _error_msg = "Not implemented";
        return false;
    }

    if( !_buffer )
    {
        if( !ResizeBuffer( 4096 ) )
            return false;
    }

    _flags = CSVwrite::none;
    _error = false;
    _error_msg = "";
    _is_first_field = true;

    return true;
}
示例#20
0
XnStatus MockGenerator::SetNextData(const void *pData, XnUInt32 nSize)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	DataInfo& nextData = m_data[m_nNextDataIdx];

	if (!m_bAggregateData)
	{
		nextData.nDataSize = 0;
	}

	nRetVal = ResizeBuffer(m_nNextDataIdx, nextData.nDataSize + nSize);
	XN_IS_STATUS_OK(nRetVal);

	xnOSMemCopy((XnUChar*)nextData.pData + nextData.nDataSize, pData, nSize);
	nextData.nDataSize += nSize;

	nRetVal = SetNewDataAvailable();
	XN_IS_STATUS_OK(nRetVal);

	return XN_STATUS_OK;
}
示例#21
0
 void ApplyData(Chunk::Ptr data) override
 {
   //work with 16-bit
   static_assert(Sample::BITS == 16, "Incompatible sound sample bits count");
   static_assert(Sample::CHANNELS == 2, "Incompatible sound channels count");
   data->ToS16();
   while (const int res = LameApi->lame_encode_buffer_interleaved(Context.get(),
     safe_ptr_cast<short int*>(&data->front()), data->size(), &Encoded[0], Encoded.size()))
   {
     if (res > 0) //encoded
     {
       Stream->ApplyData(Binary::DataAdapter(&Encoded[0], res));
       break;
     }
     else if (-1 == res)//buffer too small
     {
       ResizeBuffer();
     }
     else
     {
       CheckLameCall(res, THIS_LINE);
     }
   }
 }
示例#22
0
static inline void PrintfAppend(char** buffer, size_t* bufferSize, const char* fmt, va_list arguments)
{
	// dynamically adjust the buffer size until VSNPRINTF returns fine
	size_t bufferPos = strlen(*buffer);

	do {
		size_t freeBufferSize = (*bufferSize) - bufferPos;
		char* bufAppendPos = &((*buffer)[bufferPos]);

		// printf will move the internal pointer of va_list.
		// So we need to make a copy, if want to run it again.
		va_list arguments_;
		va_copy(arguments_, arguments); 
		int writtenChars = VSNPRINTF(bufAppendPos, freeBufferSize, fmt, arguments_);
		va_end(arguments_);
		// since writtenChars excludes the null terminator (if any was written),
		// writtenChars >= freeBufferSize always means buffer was too small
		// NOTE: earlier glibc versions and MSVC will return -1 when buffer is too small
		const bool bufferTooSmall = writtenChars >= freeBufferSize || writtenChars < 0;
		if (!bufferTooSmall) break;

		ResizeBuffer(buffer, bufferSize, true);
	} while (true);
}
示例#23
0
 virtual void ApplyData(const Chunk::Ptr& data)
 {
   //work with 16-bit
   BOOST_STATIC_ASSERT(Sample::BITS == 16);
   BOOST_STATIC_ASSERT(Sample::CHANNELS == 2);
   data->ToS16();
   while (const int res = LameApi->lame_encode_buffer_interleaved(Context.get(),
     safe_ptr_cast<short int*>(&data->front()), data->size(), &Encoded[0], Encoded.size()))
   {
     if (res > 0) //encoded
     {
       Stream->ApplyData(Binary::DataAdapter(&Encoded[0], res));
       break;
     }
     else if (-1 == res)//buffer too small
     {
       ResizeBuffer();
     }
     else
     {
       CheckLameCall(res, THIS_LINE);
     }
   }
 }
示例#24
0
bool StreamBuffer::ReserveMemory(size_t num_bytes, size_t alignment, bool allow_reuse /* = true */,
                                 bool allow_growth /* = true */,
                                 bool reallocate_if_full /* = false */)
{
  size_t required_bytes = num_bytes + alignment;

  // Check for sane allocations
  if (required_bytes > m_maximum_size)
  {
    PanicAlert("Attempting to allocate %u bytes from a %u byte stream buffer",
               static_cast<uint32_t>(num_bytes), static_cast<uint32_t>(m_maximum_size));

    return false;
  }

  // Is the GPU behind or up to date with our current offset?
  if (m_current_offset >= m_current_gpu_position)
  {
    size_t remaining_bytes = m_current_size - m_current_offset;
    if (required_bytes <= remaining_bytes)
    {
      // Place at the current position, after the GPU position.
      m_current_offset = Util::AlignBufferOffset(m_current_offset, alignment);
      m_last_allocation_size = num_bytes;
      return true;
    }

    // Check for space at the start of the buffer
    // We use < here because we don't want to have the case of m_current_offset ==
    // m_current_gpu_position. That would mean the code above would assume the
    // GPU has caught up to us, which it hasn't.
    if (allow_reuse && required_bytes < m_current_gpu_position)
    {
      // Reset offset to zero, since we're allocating behind the gpu now
      m_current_offset = 0;
      m_last_allocation_size = num_bytes;
      return true;
    }
  }

  // Is the GPU ahead of our current offset?
  if (m_current_offset < m_current_gpu_position)
  {
    // We have from m_current_offset..m_current_gpu_position space to use.
    size_t remaining_bytes = m_current_gpu_position - m_current_offset;
    if (required_bytes < remaining_bytes)
    {
      // Place at the current position, since this is still behind the GPU.
      m_current_offset = Util::AlignBufferOffset(m_current_offset, alignment);
      m_last_allocation_size = num_bytes;
      return true;
    }
  }

  // Try to grow the buffer up to the maximum size before waiting.
  // Double each time until the maximum size is reached.
  if (allow_growth && m_current_size < m_maximum_size)
  {
    size_t new_size = std::min(std::max(num_bytes, m_current_size * 2), m_maximum_size);
    if (ResizeBuffer(new_size))
    {
      // Allocating from the start of the buffer.
      m_last_allocation_size = new_size;
      return true;
    }
  }

  // Can we find a fence to wait on that will give us enough memory?
  if (allow_reuse && WaitForClearSpace(required_bytes))
  {
    _assert_(m_current_offset == m_current_gpu_position ||
             (m_current_offset + required_bytes) < m_current_gpu_position);
    m_current_offset = Util::AlignBufferOffset(m_current_offset, alignment);
    m_last_allocation_size = num_bytes;
    return true;
  }

  // If we are not allowed to execute in our current state (e.g. in the middle of a render pass),
  // as a last resort, reallocate the buffer. This will incur a performance hit and is not
  // encouraged.
  if (reallocate_if_full && ResizeBuffer(m_current_size))
  {
    m_last_allocation_size = num_bytes;
    return true;
  }

  // We tried everything we could, and still couldn't get anything. If we're not at a point
  // where the state is known and can be resumed, this is probably a fatal error.
  return false;
}
ULONG
CheckForMap(
    __in PEVENT_RECORD Event,
    __in PTRACE_EVENT_INFO EventInfo,
    __in PEVENT_PROPERTY_INFO Property,
    __inout PPROCESSING_CONTEXT LogContext,
    __out PEVENT_MAP_INFO* EventMapInfo
)

/*++

Routine Description:

    This routine checks if there is any map associated with the
    specified property from the passed event.

Arguments:

    Event - Supplies the structure representing an event.

    EventInfo - Supplies the event meta-information.

    Property - Supplies information about the simple property to be checked.

    EventMapInfo - Receives the resulting map information associated with the property.

Return Value:

    ERROR_SUCCESS - Success

    Win32 error code - TdhGetMapInformation() failed.

--*/

{
    ULONG Status = ERROR_SUCCESS;
    PWSTR MapName = TEI_MAP_NAME(EventInfo, Property);
    PPROCESSING_DATA_CONTEXT DataContext = &LogContext->DataContext;
    ULONG MapSize = DataContext->MapInfoBufferSize;

    if (MapName != NULL) {

        //
        // This property has a map associated with it. Try to
        // extract the information about that map, using TDH.
        //

        do {
            if (Status == ERROR_INSUFFICIENT_BUFFER) {
                Status = ResizeBuffer(&DataContext->MapInfoBuffer,
                                      &DataContext->MapInfoBufferSize,
                                      MapSize);

                if (DataContext->MapInfoBuffer == NULL) {
                    return ERROR_OUTOFMEMORY;
                }

                DataContext->MapInfoBufferSize = MapSize;
            }
            Status = TdhGetEventMapInformation(Event,
                                               MapName,
                                               (PEVENT_MAP_INFO)DataContext->MapInfoBuffer,
                                               &MapSize);

        } while (Status == ERROR_INSUFFICIENT_BUFFER);

        if (Status == ERROR_SUCCESS) {
            *EventMapInfo = (PEVENT_MAP_INFO)DataContext->MapInfoBuffer;
        }

    } else {
        *EventMapInfo = NULL;
    }
    return Status;
}
ULONG
FormatProperty(
    __in PEVENT_RECORD Event,
    __in PTRACE_EVENT_INFO EventInfo,
    __in_opt PEVENT_MAP_INFO EventMapInfo,
    __in PEVENT_PROPERTY_INFO Property,
    __in USHORT PropertyLength,
    __in ULONG PropertyIndex,
    __inout PPROCESSING_CONTEXT LogContext
)

/*++

Routine Description:

    This routine prepares the formatting of the raw byte data contained
    in the property buffer. First, the offset from Event->UserData is calculated.
    Then the data in that offset is passed for concrete formatting in
    GetFormattedBuffer() or FormatMapToString(). These methods return the
    formatted  buffer and the amount of binary data consumed and use the amount
    of data consumed to advance the current data offset.

Arguments:

    Event - Supplies the structure representing an event.

    EventInfo - Supplies the event meta-information.

    Property - Supplies the property information about the simple property
               to be decoded.

    PropertyLength - Supplies the length of the simple property to be decoded.

    PropertyIndex - Supplies the index of the property to be decoded.

    LogContext - Supplies the structure that persists contextual information
                 across callbacks.

Return Value:

    ERROR_SUCCESS - Success

    Win32 error code - Formatting the property data failed.

--*/

{
    ULONG Status = ERROR_SUCCESS;
    PPROCESSING_DATA_CONTEXT DataContext = &LogContext->DataContext;
    ULONG BufferSize = DataContext->BufferSize;
    USHORT PointerSize;
    ULONG DataLeft;
    FPTR_TDH_FORMATPROPERTY TdhFormatPropertyPtr = NULL;

    DataContext->BinDataLeft = Event->UserDataLength - DataContext->UserDataOffset;
    PBYTE Data = (PBYTE)Event->UserData + DataContext->UserDataOffset;

    //
    // If no more data, just fill the buffer with one non-printable UNICODE_NULL.
    //

    if (DataContext->BinDataLeft == 0) {
        Status = NullToBuffer(DataContext->Buffer, DataContext->BufferSize, &DataContext->BinDataConsumed);
        if (Status == ERROR_SUCCESS) {
            UpdateRenderItem(DataContext);
        }
        return Status;
    }

    //
    // Get the pointer size on the machine where the event was fired.
    // Will be needed later when decoding certain types of properies.
    //

    if ((Event->EventHeader.Flags & EVENT_HEADER_FLAG_64_BIT_HEADER) != 0) {
        PointerSize = sizeof(ULONGLONG);
    } else if ((Event->EventHeader.Flags & EVENT_HEADER_FLAG_32_BIT_HEADER) != 0) {
        PointerSize = sizeof(ULONG);
    } else {
        PointerSize = (USHORT)LogContext->PointerSize;
    }

    do {

        if (Status == ERROR_INSUFFICIENT_BUFFER) {

            Status = ResizeBuffer(&DataContext->Buffer,
                                  &DataContext->BufferSize,
                                  ((DataContext->BufferSize / MIN_PROP_BUFFERSIZE) + 1) * MIN_PROP_BUFFERSIZE);

            if (Status != ERROR_SUCCESS) {
                return Status;
            }
        }

        //
        // Check if the Windows 7 TDH API routine, TdhFormatProperty(), is avaliable.
        //

        if ((LogContext->TdhDllHandle != NULL)) {
            TdhFormatPropertyPtr = LogContext->FormatPropertyPtr;
        }

        if (TdhFormatPropertyPtr != NULL) {

            //
            // The decoding process is on Windows 7 or later. In Windows 7, the TDH API
            // is updated with several new functions. One of them is TdhFormatProperty, which
            // deals with all valid TDH InTypes and OutTypes, and formats them properly.
            // In order to get the sample to compile on both Vista and Windows 7, load the
            // TdhFormatProperty() dynamically.
            //

            Status = (*TdhFormatPropertyPtr)(EventInfo,
                                             EventMapInfo,
                                             PointerSize,
                                             Property->nonStructType.InType,
                                             Property->nonStructType.OutType,
                                             PropertyLength,
                                             DataContext->BinDataLeft,
                                             Data,
                                             &BufferSize,
                                             (PWSTR)DataContext->Buffer,
                                             &DataContext->BinDataConsumed);

        } else {

            //
            // The operating system is prior to Windows 7. The formatting for each
            // InType and OutType property must be handled manually.
            //

            if (EventMapInfo == NULL) {

                //
                // This property has no map associated with it.  Directly pass the buffer
                // referenced by the current offset for formatting to GetFormattedBuffer().
                // According to the in- and out-types of the property, proper formatting will
                // be performed.
                //

                Status = GetFormattedBuffer(Data,
                                            DataContext->BinDataLeft,
                                            PropertyLength,
                                            PointerSize,
                                            Property->nonStructType.InType,
                                            Property->nonStructType.OutType,
                                            DataContext->Buffer,
                                            DataContext->BufferSize,
                                            &DataContext->BinDataConsumed);
            } else {

                //
                // This property has map associated with it. The map key value is
                // in the Data buffer pointed by the property. It is a number pointing to
                // some resource. GetFormattedMapValue() will find and format both the key
                // and its resource value and will return the formatted value as result.
                //

                Status = GetFormattedMapValue(Data,
                                              DataContext->BinDataLeft,
                                              EventMapInfo,
                                              Property->nonStructType.InType,
                                              DataContext->Buffer,
                                              DataContext->BufferSize,
                                              &DataContext->BinDataConsumed);
            }
        }

    } while (Status == ERROR_INSUFFICIENT_BUFFER);

    if (Status == ERROR_EVT_INVALID_EVENT_DATA) {

        //
        // There can be cases when the string represented by the buffer Data, is
        // not aligned with the event payload (i.e. it is longer than the actual data left).
        // Just copy and format the last DataContext->BinDataLeft bytes from the payload.
        //

        if (Property->nonStructType.InType == TDH_INTYPE_UNICODESTRING) {
            DataLeft = DataContext->BinDataLeft;
            if (DataContext->BufferSize < DataLeft) {
                Status = ResizeBuffer(&DataContext->Buffer,
                                      &DataContext->BufferSize,
                                      ((DataContext->BufferSize / MIN_PROP_BUFFERSIZE) + 1) * MIN_PROP_BUFFERSIZE);

                if (Status != ERROR_SUCCESS) {
                    return Status;
                }
            }
            RtlCopyMemory(DataContext->Buffer, Data, DataLeft);
            DataContext->Buffer[DataLeft] = 0;
            DataContext->Buffer[DataLeft + 1] = 0;
            DataContext->BinDataConsumed = (USHORT)DataLeft;
            Status = ERROR_SUCCESS;

        } else if (Property->nonStructType.InType == TDH_INTYPE_ANSISTRING) {
            DataLeft = DataContext->BinDataLeft;
            BufferSize = (DataLeft + 1) * sizeof(WCHAR);
            if (DataContext->BufferSize < BufferSize) {

                Status = ResizeBuffer(&DataContext->Buffer,
                                      &DataContext->BufferSize,
                                      ((DataContext->BufferSize / MIN_PROP_BUFFERSIZE) + 1) * MIN_PROP_BUFFERSIZE);

                if (Status != ERROR_SUCCESS) {
                    return Status;
                }
            }

            DataContext->BinDataConsumed = (USHORT)MultiByteToWideChar(CP_ACP,
                                           0,
                                           (PSTR)Data,
                                           DataLeft,
                                           (PWSTR)DataContext->Buffer,
                                           DataLeft);

            DataLeft *= sizeof(WCHAR);
            DataContext->Buffer[DataLeft] = 0;
            DataContext->Buffer[DataLeft + 1] = 0;
            Status = ERROR_SUCCESS;

        } else if (EventMapInfo != NULL) {

            //
            // The integer key stored in Data was not matched as a valid map key entry.
            // Just try to print the formatted integer stored in Data.
            //

            Status = FormatProperty(Event,
                                    EventInfo,
                                    NULL,
                                    Property,
                                    PropertyLength,
                                    PropertyIndex,
                                    LogContext);

        }
    }

    if (Status == ERROR_SUCCESS) {
        DataContext->UserDataOffset += DataContext->BinDataConsumed;
        UpdateRenderItem(DataContext);
    }

    return Status;
}
ULONG
VPrintFToFile(
    __in BOOLEAN ForcePrint,
    __in PPROCESSING_CONTEXT LogContext,
    __in PWSTR FormatString,
    ...
)

/*++

Routine Description:

    This routine prints to standard output the variable number of arguments passed in.
    All the printing from the sample is rerouted here.

Arguments:

    ForcePrint - Supplies the flag that indicates whether the content should be printed
                 independently from the state of LogContext.

    LogContext - Supplies the structure that holds the output memory buffer and
                 the flag that indicates whether printing should be performed.

    FormatString - Supplies the format in which the arguments will be printed.

    ... - Variable list of arguments to be printed.

Return Value:

    ERROR_SUCCESS - Arguments were successfully printed.

    ERROR_INSUFFICIENT_BUFFER - The buffer was too small for storing the output.

--*/

{

    INT StrLen;
    PWSTR Buffer;
    va_list Arguments;
    ULONG BufferSize;
    ULONG Status = ERROR_SUCCESS;

    if ((ForcePrint == FALSE) && (LogContext->DumpXml == FALSE)) {
        return ERROR_SUCCESS;
    }

    va_start(Arguments, FormatString);
    StrLen = _vscwprintf(FormatString, Arguments) + 1;

    if (StrLen >= 0 ) {
        BufferSize = StrLen * sizeof(WCHAR);
        if (LogContext->PrintBufferSize < BufferSize) {
            Status = ResizeBuffer(&LogContext->PrintBuffer, &LogContext->PrintBufferSize, BufferSize);
            if (Status != ERROR_SUCCESS) {
                return Status;
            }
        }
        Buffer = (PWSTR)LogContext->PrintBuffer;
        vswprintf_s(Buffer, StrLen, FormatString, Arguments);
        wprintf(L"%s", Buffer);
    }

    va_end(Arguments);
    return ERROR_SUCCESS;
}
示例#28
0
文件: PrtUser.c 项目: thisiscam/P
static void PrtUserPrintInt32(_In_ PRT_INT32 i, _Inout_ char **buffer, _Inout_ PRT_UINT32 *bufferSize, _Inout_ PRT_UINT32 *numCharsWritten)
{
	PRT_UINT32 written = *numCharsWritten;
	ResizeBuffer(buffer, bufferSize, written, 32);
	*numCharsWritten += sprintf_s(*buffer + written, *bufferSize - written, "%d", i);
}
示例#29
0
文件: PrtUser.c 项目: thisiscam/P
static void PrtUserPrintString(_In_ PRT_STRING s, _Inout_ char **buffer, _Inout_ PRT_UINT32 *bufferSize, _Inout_ PRT_UINT32 *numCharsWritten)
{
	PRT_UINT32 written = *numCharsWritten;
	ResizeBuffer(buffer, bufferSize, written, (PRT_UINT32)strlen(s) + 1);
	*numCharsWritten += sprintf_s(*buffer + written, *bufferSize - written, "%s", s);
}
示例#30
0
String::~String(void)
{
	ResizeBuffer(NULL,false);
}