Exemplo n.º 1
0
static int _outputvws_safe(wchar_t* buf, int cnt, const wchar_t* fmt, va_list ap)
{
	int ret;

#if defined(_MSC_VER)
	if (NULL == buf || 0 == cnt)
		return _vscwprintf(fmt, ap);
	#if _MSC_VER >= 1500
	ret = _vsnwprintf_s(buf, cnt, _TRUNCATE, fmt, ap);
	#else
	ret = _vsnwprintf(buf, cnt, fmt, ap);
	#endif
#else
	ret = vsnwprintf(buf, cnt, fmt, ap);
#endif
	
	if (NULL != buf && cnt > 0){
		if (ret < 0)
			buf[cnt-1] = 0;
		else if (ret >= cnt)
			ret = -1;
	}

	return ret;
}
Exemplo n.º 2
0
/**
* CStringA::Format
* @date Modified Mar 02, 2006
*/
void CStringA::Format(const wchar_t* wszFormat, ...)
{
	// Get arguments
	va_list vaList;
	va_start(vaList, wszFormat);

	// Determine size of full string.
	int nSize = _vscwprintf(wszFormat, vaList);

	// Allocate buffer.
	wchar_t* wszBuffer = new wchar_t[nSize+1];
	memset(wszBuffer, 0, sizeof(wchar_t) * (nSize+1));

	// Save string.
	vswprintf(wszBuffer, wszFormat, vaList);
	CStringW str;
	str.m_strTheString = wszBuffer;

	// Cleanup buffer
	delete [] wszBuffer;

	// Cleanup args.
	va_end(vaList);

	// Use string conversion to save the final string
	(*this) = str;
}
Exemplo n.º 3
0
void log(const wchar_t* format, ...)
{
	if (!s_enableLogging)
	{
		return;
	}
	auto dir = settings::settingsDirectory();
	CreateDirectory(dir.c_str(), nullptr);
	auto file = CreateFile((dir + L"\\log.txt").c_str(), GENERIC_WRITE, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
	if (file == INVALID_HANDLE_VALUE)
	{
		return;
	}
	SetFilePointer(file, 0, nullptr, FILE_END);

	va_list args1, args2;
	va_start(args1, format);
	va_copy(args2, args1);
	int length = _vscwprintf(format, args1);
	if (length > 0)
	{
		size_t size = size_t(length + 3);
		wchar_t* buffer = new wchar_t[size];
		buffer[0] = 0;
		vswprintf_s(buffer, size, format, args2);
		wcscat_s(buffer, size, L"\r\n");
		DWORD written;
		WriteFile(file, buffer, (length + 2) * sizeof(wchar_t), &written, nullptr);
		delete[] buffer;
	}
	va_end(args1);
	va_end(args2);
	CloseHandle(file);
}
Exemplo n.º 4
0
wchar_t *vwcsdupf(const wchar_t *format, va_list l) {
	size_t len;
	wchar_t *s;
	va_list temp;
#if !defined(WIN32) && !defined(WIN64)
	size_t temp_len;
#endif

#if defined(WIN32) || defined(WIN64)
	va_copy(temp, l);
	len = _vscwprintf(format, l) + 1;
	va_end(temp);
	s = (wchar_t*)malloc(len * sizeof(wchar_t));
	vsnwprintf(s, len, format, l);
#else
	// TODO: faster
	len = BUFSIZE;
	s = NULL;
	do {
		len += BUFSIZE;
		if (realloc_free((void**)&s, len*sizeof(wchar_t)) != PALO_SUCCESS) {
			va_end(l);
			return NULL;
		}
		va_copy(temp, l);
		temp_len = vswprintf(s, len, format, temp);
		va_end(temp);
	} while (temp_len == -1);
	s = (wchar_t*)realloc((void*)s, (temp_len + 1) * sizeof(wchar_t));
	assert(s != NULL);
#endif

	return s;
}
Exemplo n.º 5
0
void kprintf(PCWCHAR format, ...)
{
#ifdef _WINDLL
	int varBuf;
	size_t tempSize;
#endif
	va_list args;
	va_start(args, format);
#ifndef _WINDLL
	vwprintf(format, args);
	fflush(stdout);
#else
	if(outputBuffer)
	{
		varBuf = _vscwprintf(format, args);
		if(varBuf > 0)
		{
			if((size_t) varBuf > (outputBufferElements - outputBufferElementsPosition - 1)) // NULL character
			{
				tempSize = (outputBufferElements + varBuf + 1) * 2; // * 2, just to be cool
				if(outputBuffer = (wchar_t *) LocalReAlloc(outputBuffer, tempSize * sizeof(wchar_t), LMEM_MOVEABLE))
					outputBufferElements = tempSize;
			}
			varBuf = vswprintf_s(outputBuffer + outputBufferElementsPosition, outputBufferElements - outputBufferElementsPosition, format, args);
			if(varBuf > 0)
				outputBufferElementsPosition += varBuf;
		}
	}
#endif
	if(logfile)
		vfwprintf(logfile, format, args);
	va_end(args);
	fflush(logfile);
}
Exemplo n.º 6
0
//-----------------------------------------------------------------
//printf形式で文字列データを作る
std::vector<wchar_t> CXmlWriter::FormatV(LPCWSTR lpszFormat, va_list args)
{
	int len = _vscwprintf(lpszFormat, args);
	std::vector<wchar_t> buf(len+1);
	len = vswprintf_s( &buf[0], len+1, lpszFormat, args );
	return buf;
}
Exemplo n.º 7
0
HRESULT StringCchAVPrintfW(_In_ HANDLE hHeap, _Outptr_result_nullonfailure_ LPWSTR *plpszDest, _Out_opt_ size_t *pcchDest, _In_ LPCWSTR lpszFormat, _In_ va_list argList)
{
	LPWSTR lpszDest;
	int cchDest;

	if (!hHeap || !plpszDest || !lpszFormat)
		return STRSAFE_E_INVALID_PARAMETER;

	*plpszDest = NULL;
	if (pcchDest)
		*pcchDest = 0;

	cchDest = _vscwprintf(lpszFormat, argList);
	if (cchDest < 0 || cchDest > STRSAFE_MAX_CCH)
		return STRSAFE_E_INVALID_PARAMETER;

	if ((cchDest+1) <= cchDest)
		return STRSAFE_E_INVALID_PARAMETER;

	cchDest += 1;
	lpszDest = (LPWSTR) HeapAlloc(hHeap, HEAP_ZERO_MEMORY, cchDest * sizeof(WCHAR));
	if (lpszDest) {
		cchDest = vswprintf_s(lpszDest, cchDest, lpszFormat, argList);
		if (cchDest >= 0) {
			*plpszDest = lpszDest;
			if (pcchDest)
				*pcchDest = cchDest;
			return S_OK;
		} else {
			HeapSafeFree(hHeap, 0, lpszDest);
		}
	}

	return STRSAFE_E_INSUFFICIENT_BUFFER;
}
Exemplo n.º 8
0
 int wchar_traits::Format( wchar_t** ppszDst, const wchar_t* pszFormat, va_list args )
 {
   int len = _vscwprintf( pszFormat, args ); // _vscprintf doesn't count terminating '\0'
   *ppszDst = (wchar_t*)cui::CuiMalloc((len+1)*sizeof(wchar_t));
   vswprintf(*ppszDst, pszFormat, args);
   return len;
 }
Exemplo n.º 9
0
VOID Console::FormatV( LPCWSTR wstrFormat, va_list pArgList )
{
    // Count the required length of the string
    DWORD dwStrLen = _vscwprintf( wstrFormat, pArgList ) + 1;    // +1 = null terminator
    WCHAR* strMessage = ( WCHAR* )_malloca( dwStrLen * sizeof( WCHAR ) );
    vswprintf_s( strMessage, dwStrLen, wstrFormat, pArgList );

    // Output the string to the console
    for( DWORD i = 0; i < wcslen( strMessage ); i++ )
    {
        Add( strMessage[i] );
    }

    // Output the string to the debug channel, if requested
    if( m_bOutputToDebugChannel )
    {
        OutputDebugStringW( strMessage );
    }

    // Render the new output
    Render();

    _freea( strMessage );

}
Exemplo n.º 10
0
    bool FormatArgsToWstring(wstring& wstr, LPCWSTR format, va_list args)
    {
        bool fRet = false;
        int nCount = 0;
        int nRet = 0;
        WCHAR* pBuffer = NULL;

        wstr.clear();

        nCount = _vscwprintf(format, args);
        if (!nCount)
            goto END;

        pBuffer = new WCHAR[nCount + 1];
        if (!pBuffer)
            goto END;

        memset(pBuffer, 0, sizeof(WCHAR) * (nCount + 1));
        nRet = vswprintf(pBuffer, nCount + 1, format, args);
        if (nRet <= 0)
            goto END;

        wstr = pBuffer;
        fRet = true;
    END:
        if (pBuffer)
            delete[] pBuffer;

        return fRet;
    }
Exemplo n.º 11
0
void _DBGPRINT( LPCWSTR kwszFunction, INT iLineNumber, LPCWSTR kwszDebugFormatString, ... )
{
    INT cbFormatString = 0;
    va_list args;
    PWCHAR wszDebugString = NULL;
    size_t st_Offset = 0;

    va_start( args, kwszDebugFormatString );

    cbFormatString = _scwprintf( L"[%s:%d] ", kwszFunction, iLineNumber ) * sizeof( WCHAR );
    cbFormatString += _vscwprintf( kwszDebugFormatString, args ) * sizeof( WCHAR ) + 2;

    /* Depending on the size of the format string, allocate space on the stack or the heap. */
    wszDebugString = (PWCHAR)_malloca( cbFormatString );

    /* Populate the buffer with the contents of the format string. */
    StringCbPrintfW( wszDebugString, cbFormatString, L"[%s:%d] ", kwszFunction, iLineNumber );
    StringCbLengthW( wszDebugString, cbFormatString, &st_Offset );
    StringCbVPrintfW( &wszDebugString[st_Offset / sizeof(WCHAR)], cbFormatString - st_Offset, kwszDebugFormatString, args );

    OutputDebugStringW( wszDebugString );

    _freea( wszDebugString );
    va_end( args );
}
Exemplo n.º 12
0
	void Log::PushLog( ELogType::Type type, const CHAR *pError, ... )
	{
		if ( type > m_logLevel )
			return;

		CHAR *tempMsg;
		SIZE_T len = 0;
		va_list arg_ptr;

		va_start( arg_ptr, pError );
		#if defined(PSX_UNICODE)
				len = _vscwprintf( pError, arg_ptr );
				tempMsg = new CHAR[len + 1];
				vswprintf( tempMsg, pError, arg_ptr );
		#else
				len = _vscprintf( pError, arg_ptr );
				tempMsg = new CHAR[len + 1];
				vsprintf( tempMsg, pError, arg_ptr );
		#endif /* defined(PSX_UNICODE) */

		// Display in output window
		OutputDebugString( tempMsg );
		OutputDebugString( PSX_String("\n") );

		PSX_SafeDeleteArray( tempMsg );
	}
Exemplo n.º 13
0
int InfoMessageBox(HWND hWnd, UINT uType, LPCWSTR lpTitle, LPCWSTR lpMessage, ...)
{
    int iRet = 0;
    LPWSTR lpMsgBuf = NULL;

    va_list args = NULL;
    va_start(args, lpMessage);

    if (lpMessage)
    {
        SIZE_T strLen = _vscwprintf(lpMessage, args);

        /* Create a buffer on the heap and zero it out (LPTR) */
        lpMsgBuf = (LPWSTR)LocalAlloc(LPTR, (strLen + 1) * sizeof(WCHAR));
        if (lpMsgBuf)
        {
            _vsnwprintf(lpMsgBuf, strLen, lpMessage, args);
        }
    }

    va_end(args);

    iRet = MessageBoxW(hWnd, (lpMessage && lpMsgBuf ? lpMsgBuf : L"Error displaying info message."), lpTitle, uType);

    if (lpMsgBuf) LocalFree(lpMsgBuf);

    /* Return the MessageBoxW information */
    return iRet;
}
Exemplo n.º 14
0
Arquivo: misc.c Projeto: LRN/mimerun
wchar_t *dup_wprintf (int *rlen, wchar_t *format, ...)
{
  va_list argptr;
  wchar_t *result = NULL;
  int len = 0;

  if (format == NULL)
    return NULL;

  va_start(argptr, format);

  len = _vscwprintf (format, argptr);
  if (len >= 0)
  {
    result = (wchar_t *) malloc (sizeof (wchar_t *) * (len + 1));
    if (result != NULL)
    {
      int len2 = vswprintf (result, format, argptr);
      if (len2 != len || len2 <= 0)
      {
        free (result);
        result = NULL;
      }
      else if (rlen != NULL)
        *rlen = len;
    }
  }
  va_end(argptr);
  return result;
}
Exemplo n.º 15
0
    void JavascriptError::SetErrorMessage(JavascriptError *pError, HRESULT hr, ScriptContext* scriptContext, va_list argList)
    {
        Assert(FAILED(hr));
        wchar_t * allocatedString = nullptr;

        if (FACILITY_CONTROL == HRESULT_FACILITY(hr) || FACILITY_JSCRIPT == HRESULT_FACILITY(hr))
        {
            if (argList != nullptr)
            {
                HRESULT hrAdjusted = GetAdjustedResourceStringHr(hr, /* isFormatString */ true);

                BSTR message = BstrGetResourceString(hrAdjusted);
                if (message != nullptr)
                {
                    size_t len = _vscwprintf(message, argList);
                    Assert(len > 0);
                    len = AllocSizeMath::Add(len, 1);
                    allocatedString = RecyclerNewArrayLeaf(scriptContext->GetRecycler(), wchar_t, len);

#pragma prefast(push)
#pragma prefast(disable:26014, "allocatedString allocated size more than msglen")
#pragma prefast(disable:26000, "allocatedString allocated size more than msglen")
                    len = vswprintf_s(allocatedString, len, message, argList);
                    Assert(len > 0);
#pragma prefast(pop)

                    SysFreeString(message);
                }
            }
Exemplo n.º 16
0
/*-----------------------------------------------------------------------------*/
std::wstring StringUtil::Format(const wchar_t* fmt, ...)
{
	va_list     arguments;
	std::wstring buffer = L"";

	assert(fmt);

	va_start(arguments, fmt);

	{
		int length = _vscwprintf(fmt, arguments);
		if (length >= 0)
		{

			std::unique_ptr<wchar_t[]> buf(new wchar_t[length + 1]);
#ifdef _WIN32
			int result = vswprintf_s(buf.get(), length + 1, fmt, arguments);
#else
			int result = vswprintf(buf.get(), length + 1, fmt, arguments);
#endif
			if (result >= 0)
			{
				buffer = buf.get();

			}
		}
	}

	va_end(arguments);

	return buffer;
}
Exemplo n.º 17
0
static void DbgPrint(LPCWSTR format, ...) {
  if (g_DebugMode) {
    const WCHAR *outputString;
    WCHAR *buffer = NULL;
    size_t length;
    va_list argp;

    va_start(argp, format);
    length = _vscwprintf(format, argp) + 1;
    buffer = _malloca(length * sizeof(WCHAR));
    if (buffer) {
      vswprintf_s(buffer, length, format, argp);
      outputString = buffer;
    } else {
      outputString = format;
    }
    if (g_UseStdErr)
      fputws(outputString, stderr);
    else
      OutputDebugStringW(outputString);
    if (buffer)
      _freea(buffer);
    va_end(argp);
  }
}
Exemplo n.º 18
0
// vsprintfのUNICODE(std::wstring)版
int unicode_format_va( std::wstring& str,LPCWSTR format,va_list va )
{
	int len=_vscwprintf( format,va );
	str.resize( len );
	_vsnwprintf_s( const_cast<wchar_t*>(str.c_str()),_TRUNCATE,str.size(),format,va );

	return len;
}
Exemplo n.º 19
0
std::wstring StringUtilities::Format(const wchar_t* format, ...) {
  va_list args;
  va_start(args, format);
  size_t buffer_size = _vscwprintf(format, args);
  std::vector<wchar_t> buffer(buffer_size + 1);
  _vsnwprintf_s(&buffer[0], buffer.size(), buffer_size + 1, format, args);
  va_end(args);
  std::wstring formatted = &buffer[0];
  return formatted;
}
Exemplo n.º 20
0
void log_p(const wchar_t* szText, ...){
	va_list args;
	va_start(args, szText);
	int len = _vscwprintf(szText, args ) + 1; // _vscprintf doesn't count terminating '\0' //!!!!!!!!!!!!!!!!
	wchar_t* buffer = new wchar_t[len * sizeof(wchar_t)];
	mir_vsntprintf(buffer, len, szText, args);
	va_end(args);
	log(buffer);
	delete[] buffer;
}
Exemplo n.º 21
0
void OutDebug(const wchar_t* psz_fmt, ...)
{
	va_list args;
	va_start(args, psz_fmt);
	int bufsize = _vscwprintf(psz_fmt, args) + 1;
	std::vector<wchar_t> msg(bufsize);
	_vsnwprintf_s(&msg[0], bufsize, bufsize - 1, psz_fmt, args);
	OutputDebugStringW(&msg[0]);
	va_end(args);
	
}
Exemplo n.º 22
0
void MFLogger::log_p(const wchar_t* szText, ...){
	va_list args;
	va_start(args, szText);
	int len = (PREFIX_SIZE + _vscwprintf(szText, args ) + 1); // _vscprintf doesn't count terminating '\0'
	wchar_t* buffer = new wchar_t[len * sizeof(wchar_t)];
	vswprintf_s(buffer + PREFIX_SIZE, len, szText, args);
	va_end(args);
	memcpy(buffer, m_prefix, PREFIX_SIZE * sizeof(m_prefix[0]));
	log_int(buffer);
	delete[] buffer;
}
Exemplo n.º 23
0
UnicodeString Format(const wchar_t * Format, va_list Args)
{
  UnicodeString Result;
  if (Format && *Format)
  {
    intptr_t Len = _vscwprintf(Format, Args);
    Result.SetLength(Len + 1);
    // vswprintf(Buf, Len + 1, Format, args);
    vswprintf(const_cast<wchar_t *>(Result.c_str()), Len + 1, Format, Args);
  }
  return Result.c_str();
}
Exemplo n.º 24
0
void kprintf(PCWCHAR format, ...)
{
#ifndef MIMIKATZ_W2000_SUPPORT
	int varBuf;
	size_t tempSize;
	wchar_t * tmpBuffer;
#endif
	va_list args;
	va_start(args, format);
#ifndef MIMIKATZ_W2000_SUPPORT
	if(outputBuffer)
	{
		varBuf = _vscwprintf(format, args);
		if(varBuf > 0)
		{
			if((size_t) varBuf > (outputBufferElements - outputBufferElementsPosition - 1)) // NULL character
			{
				tempSize = (outputBufferElements + varBuf + 1) * 2; // * 2, just to be cool
				if(tmpBuffer = (wchar_t *) LocalAlloc(LPTR, tempSize * sizeof(wchar_t)))
				{
					RtlCopyMemory(tmpBuffer, outputBuffer, outputBufferElementsPosition * sizeof(wchar_t));
					LocalFree(outputBuffer);
					outputBuffer = tmpBuffer;
					outputBufferElements = tempSize;
				}
				else wprintf(L"Erreur LocalAlloc: %u\n", GetLastError());
				//if(outputBuffer = (wchar_t *) LocalReAlloc(outputBuffer, tempSize * sizeof(wchar_t), LPTR))
				//	outputBufferElements = tempSize;
				//else wprintf(L"Erreur ReAlloc: %u\n", GetLastError());
			}
			varBuf = vswprintf_s(outputBuffer + outputBufferElementsPosition, outputBufferElements - outputBufferElementsPosition, format, args);
			if(varBuf > 0)
				outputBufferElementsPosition += varBuf;
		}
	}
#endif
#ifndef _POWERKATZ
#ifndef MIMIKATZ_W2000_SUPPORT
	else
#endif
	{
		vwprintf(format, args);
		fflush(stdout);
	}
#endif
	if(logfile)
	{
		vfwprintf(logfile, format, args);
		fflush(logfile);
	}
	va_end(args);
}
Exemplo n.º 25
0
void OutputStream::PutString(LPCWSTR fmt, ...)
{
    CStringW str;

    va_list args;
    va_start(args, fmt);
    int len = _vscwprintf(fmt, args) + 1;
    if(len > 0) vswprintf_s(str.GetBufferSetLength(len), len, fmt, args);
    va_end(args);

    LPCWSTR s = str;
    while(*s) PutChar(*s++);
}
Exemplo n.º 26
0
void Logger::Log_internal(const wchar_t *psz_fmt, va_list args)
{
	if(!mLog) open();

	if(mLog)
	{
		int bufsize = _vscwprintf(psz_fmt, args) + 1;
		std::vector<wchar_t> msg(bufsize);
		_vsnwprintf_s(&msg[0], bufsize, bufsize-1, psz_fmt, args);
		fwrite(&msg[0], sizeof(wchar_t), bufsize - 1, mLog);
		fflush(mLog);
	}
}
Exemplo n.º 27
0
	bool _format(cs::String& buf,LPCWSTR fms,...){
		va_list vaList;
		va_start(vaList,fms);
		int bufSize = _vscwprintf(fms,vaList);
		if(bufSize==-1){
			va_end(vaList);
			return 0;
		}
		buf.SetCubage(bufSize+3);
		int n = vswprintf_s(buf,bufSize+1,fms,vaList);
		va_end(vaList);
		return 1;
	}
Exemplo n.º 28
0
/** Real declaration of both verbose and verbose_step. */ 
static void __verbose(verbose_func func, wchar_t* message, ...)
{
	int lenbuf;
	wchar_t* buf;
	va_list args;
	if(!verbose_flag || !message) return;
	va_start(args, message);
	lenbuf = _vscwprintf(message, args);
	buf = walloc(lenbuf);
	vswprintf(buf, lenbuf+1, message, args);
	va_end(args);
	func(buf);
	xfree(buf);
}
Exemplo n.º 29
0
void Console::Print( const wchar_t *format, ... )
{
	va_list args;
	va_start(args, format);
	int length = _vscwprintf(format, args) + 1;
	wchar_t *message = (wchar_t*)calloc(length, sizeof(wchar_t));
	vswprintf_s(message, length, format, args);
	DWORD writtenChars;
	WriteConsoleW(m_outputHandle, message, length - 1, &writtenChars, NULL);
#ifdef _DEBUG
	OutputDebugStringW(message);
#endif
	free(message);
}
Exemplo n.º 30
0
    void JavascriptError::SetErrorMessage(JavascriptError *pError, HRESULT hr, ScriptContext* scriptContext, va_list argList)
    {
        Assert(FAILED(hr));
        char16 * allocatedString = nullptr;

        if (FACILITY_CONTROL == HRESULT_FACILITY(hr) || FACILITY_JSCRIPT == HRESULT_FACILITY(hr))
        {
            if (argList != nullptr)
            {
                HRESULT hrAdjusted = GetAdjustedResourceStringHr(hr, /* isFormatString */ true);

                BSTR message = BstrGetResourceString(hrAdjusted);
                if (message != nullptr)
                {
                    size_t len = _vscwprintf(message, argList);
                    Assert(len > 0);
                    len = AllocSizeMath::Add(len, 1);
                    allocatedString = RecyclerNewArrayLeaf(scriptContext->GetRecycler(), char16, len);

#pragma prefast(push)
#pragma prefast(disable:26014, "allocatedString allocated size more than msglen")
#pragma prefast(disable:26000, "allocatedString allocated size more than msglen")
                    len = vswprintf_s(allocatedString, len, message, argList);
                    Assert(len > 0);
#pragma prefast(pop)

                    SysFreeString(message);
                }
            }
            if (allocatedString == nullptr)
            {
                HRESULT hrAdjusted = GetAdjustedResourceStringHr(hr, /* isFormatString */ false);

                BSTR message = BstrGetResourceString(hrAdjusted);
                if (message == nullptr)
                {
                    message = BstrGetResourceString(IDS_UNKNOWN_RUNTIME_ERROR);
                }
                if (message != nullptr)
                {
                    uint32 len = SysStringLen(message) +1;
                    allocatedString = RecyclerNewArrayLeaf(scriptContext->GetRecycler(), char16, len);
                    wcscpy_s(allocatedString, len, message);
                    SysFreeString(message);
                }
            }
        }
        JavascriptError::SetErrorMessageProperties(pError, hr, allocatedString, scriptContext);
    }