CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/exploits/CVE-2010-0232/common/common.h
Views: 11784
1
#ifndef _ESCALATE_COMMON_H
2
#define _ESCALATE_COMMON_H
3
4
/*! @brief When defined, debug output is enabled on Windows builds. */
5
//#define DEBUGTRACE 1
6
7
#ifdef DEBUGTRACE
8
#include <stdio.h>
9
#include <stdarg.h>
10
#include <string.h>
11
#define dprintf(...) real_dprintf(__VA_ARGS__)
12
#else
13
#define dprintf(...) do{}while(0);
14
#endif
15
16
/*! @brief Sets `dwResult` to the return value of `GetLastError()`, prints debug output, then does `break;` */
17
#define BREAK_ON_ERROR( str ) { dwResult = GetLastError(); dprintf( "%s. error=%d", str, dwResult ); break; }
18
/*! @brief Sets `dwResult` to `error`, prints debug output, then `break;` */
19
#define BREAK_WITH_ERROR( str, err ) { dwResult = err; dprintf( "%s. error=%d", str, dwResult ); break; }
20
/*! @brief Sets `dwResult` to the return value of `WASGetLastError()`, prints debug output, then does `break;` */
21
#define BREAK_ON_WSAERROR( str ) { dwResult = WSAGetLastError(); dprintf( "%s. error=%d", str, dwResult ); break; }
22
/*! @brief Sets `dwResult` to the return value of `GetLastError()`, prints debug output, then does `continue;` */
23
#define CONTINUE_ON_ERROR( str ) { dwResult = GetLastError(); dprintf( "%s. error=%d", str, dwResult ); continue; }
24
25
/*! @brief Close a service handle if not already closed and set the handle to NULL. */
26
#define CLOSE_SERVICE_HANDLE( h ) if( h ) { CloseServiceHandle( h ); h = NULL; }
27
/*! @brief Close a handle if not already closed and set the handle to NULL. */
28
#define CLOSE_HANDLE( h ) if( h ) { DWORD dwHandleFlags; if(GetHandleInformation( h , &dwHandleFlags)) CloseHandle( h ); h = NULL; }
29
30
#ifdef DEBUGTRACE
31
/*!
32
* @brief Output a debug string to the debug console.
33
* @details The function emits debug strings via `OutputDebugStringA`, hence all messages can be viewed
34
* using Visual Studio's _Output_ window, _DebugView_ from _SysInternals_, or _Windbg_.
35
*/
36
static void real_dprintf(char *format, ...) {
37
va_list args;
38
char buffer[1024];
39
va_start(args,format);
40
vsnprintf_s(buffer, sizeof(buffer), sizeof(buffer)-3, format,args);
41
strcat_s(buffer, sizeof(buffer), "\r\n");
42
OutputDebugStringA(buffer);
43
}
44
#endif
45
46
#endif
47