Skip to content

Instantly share code, notes, and snippets.

View ArunTS96's full-sized avatar
💭
Crunching tons of code and food from the comfort of home

T.s. Arun ArunTS96

💭
Crunching tons of code and food from the comfort of home
  • Zoho
  • Chennai
View GitHub Profile
@ArunTS96
ArunTS96 / Where.cpp
Last active May 1, 2020 15:43
Where.exe source code. This will return full path to file from filename by checking through system directory, windows directory and path variable. Windows.
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();
}
@ArunTS96
ArunTS96 / SplitStringsToVector.cpp
Created May 1, 2020 14:57
Split std::basic_string to std::vector for any character as delimeter
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>
@ArunTS96
ArunTS96 / GetEnvAsMap.cpp
Created May 1, 2020 14:55
Get Environment variables as std::map windows
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;
@ArunTS96
ArunTS96 / OpenEventWrapper.cpp
Created April 17, 2020 10:30
C++ wrapper around windows Events.
#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())
@ArunTS96
ArunTS96 / InstanceMaintainer.cpp
Created April 9, 2020 15:28
Limiting your code to run only 'n' instance. c++. win32.
#include <Windows.h>
#include <string>
#include <iostream>
#define USE_MUTEX
class InstanceMaintainer
{
private:
HANDLE h_ = nullptr;
static InstanceMaintainer* instance_;
#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)(