Add va function

This commit is contained in:
momo5502 2022-04-05 18:17:39 +02:00
parent 1f986d5588
commit 4f2b1e79a7
3 changed files with 24 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#include <ntddk.h>
#include <intrin.h>
#include <Ntstrsafe.h>
#pragma warning(push)
#pragma warning(disable: 4201)

View File

@ -11,4 +11,14 @@ namespace string
RtlInitUnicodeString(&unicode_string, string);
return unicode_string;
}
char* get_va_buffer()
{
constexpr auto va_buffer_count = 0x10;
static char buffers[va_buffer_count][VA_BUFFER_SIZE];
static volatile long current_buffer = 0;
const auto index = InterlockedIncrement(&current_buffer);
return buffers[index % va_buffer_count];
}
}

View File

@ -1,7 +1,20 @@
#pragma once
#include "type_traits.hpp"
#define VA_BUFFER_SIZE 0x1000
namespace string
{
_IRQL_requires_max_(DISPATCH_LEVEL)
UNICODE_STRING get_unicode_string(const wchar_t* string);
char* get_va_buffer();
template<typename ...Args>
const char* va(const char* message, Args&&... args)
{
auto* buffer = get_va_buffer();
RtlStringCchPrintfA(buffer, VA_BUFFER_SIZE, message, std::forward<Args>(args)...);
return buffer;
}
}