BlackBone
Windows memory hacking library
 All Classes Functions
Trace.hpp
1 #pragma once
2 
3 #include <cstdio>
4 #include <cstdlib>
5 #include <algorithm>
6 #include <DbgHelp.h>
7 
8 namespace blackbone
9 {
10 #ifndef BLACBONE_NO_TRACE
11 
12 template<typename Ch>
13 inline void DoTraceV( const Ch* fmt, va_list va_args );
14 
15 template<>
16 inline void DoTraceV<char>( const char* fmt, va_list va_args )
17 {
18  char buf[2048], userbuf[1024];
19  vsprintf_s( userbuf, fmt, va_args );
20  sprintf_s( buf, "BlackBone: %ls\r\n", userbuf );
21  OutputDebugStringA( buf );
22 
23 #ifdef CONSOLE_TRACE
24  printf( buf );
25 #endif
26 }
27 
28 template<>
29 inline void DoTraceV<wchar_t>( const wchar_t* fmt, va_list va_args )
30 {
31  wchar_t buf[2048], userbuf[1024];
32  vswprintf_s( userbuf, fmt, va_args );
33  swprintf_s( buf, L"BlackBone: %ls\r\n", userbuf );
34  OutputDebugStringW( buf );
35 
36 #ifdef CONSOLE_TRACE
37  wprintf( buf );
38 #endif
39 }
40 
41 template<typename Ch>
42 inline void DoTrace( const Ch* fmt, ... )
43 {
44  va_list va_args;
45  va_start( va_args, fmt );
46  DoTraceV( fmt, va_args );
47  va_end( va_args );
48 }
49 
50 #define BLACBONE_TRACE(fmt, ...) DoTrace(fmt, ##__VA_ARGS__)
51 
52 #else
53 #define BLACBONE_TRACE(...)
54 #endif
55 
56 }
Definition: AsmHelper32.cpp:6