From 7343c99cfa74d7f31ff53e365787176c2d081a4e Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Fri, 29 Dec 2017 17:13:13 +0100 Subject: [PATCH] add debug print functionality --- GleeBug/GleeBug.vcxproj | 1 + GleeBug/GleeBug.vcxproj.filters | 3 +++ GleeBug/oprintf.h | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 GleeBug/oprintf.h diff --git a/GleeBug/GleeBug.vcxproj b/GleeBug/GleeBug.vcxproj index 4c08e2a..3fd2d7f 100644 --- a/GleeBug/GleeBug.vcxproj +++ b/GleeBug/GleeBug.vcxproj @@ -195,6 +195,7 @@ + diff --git a/GleeBug/GleeBug.vcxproj.filters b/GleeBug/GleeBug.vcxproj.filters index f7ffc42..d778bb0 100644 --- a/GleeBug/GleeBug.vcxproj.filters +++ b/GleeBug/GleeBug.vcxproj.filters @@ -190,6 +190,9 @@ Header Files\Zydis + + Header Files + diff --git a/GleeBug/oprintf.h b/GleeBug/oprintf.h new file mode 100644 index 0000000..0ad8d71 --- /dev/null +++ b/GleeBug/oprintf.h @@ -0,0 +1,31 @@ +#pragma once + +#include +#include +#include + +static inline void oprintf(const char* format, ...) +{ + va_list args; + va_start(args, format); + static char dprintf_msg[66000]; + *dprintf_msg = 0; + vsnprintf_s(dprintf_msg, sizeof(dprintf_msg), format, args); + if(GetConsoleWindow() == NULL) + AllocConsole(); + auto hOut = GetStdHandle(STD_OUTPUT_HANDLE); + DWORD w; + WriteFile(hOut, dprintf_msg, strlen(dprintf_msg), &w, nullptr); +} + +static inline void oputs(const char* text) +{ + oprintf("%s\n", text); +} + +static inline void oprintf_args(_In_z_ _Printf_format_string_ const char* Format, va_list Args) +{ + char buffer[16384]; + vsnprintf_s(buffer, _TRUNCATE, Format, Args); + oprintf("%s", buffer); +} \ No newline at end of file