This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::wstring ProcessHandleToNameW(const HANDLE process) | |
{ | |
DWORD buffSize = page_size; | |
std::wstring ret(page_size, 0); | |
if (!QueryFullProcessImageNameW(process, 0, &ret[0], &buffSize)) | |
{ | |
STANDARD_GET_LAST_ERROR("QueryFullProcessImageNameW"); | |
ret.clear(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template <class Char, typename Out> | |
void Split(const std::basic_string<Char>& s, Char delim, Out result) { | |
std::basic_istringstream<Char, std::char_traits<Char>, std::allocator<Char>> iss(s); | |
std::basic_string<Char> item; | |
while (std::getline(iss, item, delim)) { | |
*result++ = item; | |
} | |
} | |
template <class Char> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::map<std::wstring, std::wstring> GetEnvAsMap() | |
{ | |
std::map<std::wstring, std::basic_string<wchar_t>> env; | |
auto free = [](wchar_t* p) { FreeEnvironmentStringsW(p); }; | |
const auto envBlock = std::unique_ptr<wchar_t, decltype(free)>{ | |
GetEnvironmentStringsW(), free }; | |
for (auto i = envBlock.get(); *i != L'\0'; ++i) { | |
std::wstring key; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define USERMSG(format,...) printf("[INFO]\t"##format##"\n", __VA_ARGS__) | |
#define ERRMSG(format,...) printf("[ERROR]\t"##format##"\n", __VA_ARGS__) | |
#define DEBUGMSG(format,...) printf("[DEBUG]\t"##format##"\n", __VA_ARGS__) | |
#define EMPTYMSG printf; | |
#define INSIDE_FUNCTION USERMSG("@@@@@ \t Inside %s() [%s](%d) \t @@@@@\n", __FUNCTION__, __FILE__, __LINE__) | |
#define DINSIDE_FUNCTION DEBUGMSG("@@@@@ \t Inside %s() [%s](%d) \t @@@@@\n", __FUNCTION__, __FILE__, __LINE__) | |
#define EXITING_FUNCTION DEBUGMSG("@@@@@ \t Exiting %s() [%s](%d) \t @@@@@\n", __FUNCTION__, __FILE__, __LINE__) | |
#define UEXITING_FUNCTION USERMSG("@@@@@ \t Exiting %s() [%s](%d) \t @@@@@\n", __FUNCTION__, __FILE__, __LINE__) | |
#define STANDARD_GET_LAST_ERROR(X) ERRMSG("Failed while using function name %s with error %lu\n", X, GetLastError()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <string> | |
#include <iostream> | |
#define USE_MUTEX | |
class InstanceMaintainer | |
{ | |
private: | |
HANDLE h_ = nullptr; | |
static InstanceMaintainer* instance_; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Windows.h> | |
#include <iostream> | |
#include <WtsApi32.h> | |
#include <string> | |
#include <stdio.h> | |
#include <NTSecAPI.h> | |
#pragma comment(lib, "Wtsapi32.lib") | |
typedef NTSYSAPI NTSTATUS (NTAPI *LP_NtCreateToken)( |