BlackBone
Windows memory hacking library
 All Classes Functions
Utils.h
1 #pragma once
2 
3 #include "../Include/Winheaders.h"
4 #include <string>
5 
6 namespace blackbone
7 {
8 
9 class Utils
10 {
11 public:
17  BLACKBONE_API static std::wstring UTF8ToWstring( const std::string& str );
18 
24  BLACKBONE_API static std::string WstringToUTF8( const std::wstring& str );
25 
32  BLACKBONE_API static std::wstring AnsiToWstring( const std::string& input, DWORD locale = CP_ACP );
33 
40  BLACKBONE_API static std::string WstringToAnsi( const std::wstring& input, DWORD locale = CP_ACP );
41 
48  BLACKBONE_API static std::wstring FormatString( const wchar_t* fmt, ... );
49 
55  BLACKBONE_API static std::wstring StripPath( const std::wstring& path );
56 
62  BLACKBONE_API static std::wstring GetParent( const std::wstring& path );
63 
68  BLACKBONE_API static std::wstring GetExeDirectory();
69 
75  BLACKBONE_API static std::wstring ToLower( const std::wstring& str );
76 
82  BLACKBONE_API static std::wstring RandomANString( int length = 0 );
83 
89  BLACKBONE_API static std::wstring GetErrorDescription( NTSTATUS code );
90 
96  BLACKBONE_API static bool FileExists( const std::wstring& path );
97 };
98 
99 
104 {
105 public:
106  BLACKBONE_API CriticalSection()
107  {
108  InitializeCriticalSection( &_native );
109  }
110 
111  BLACKBONE_API ~CriticalSection()
112  {
113  DeleteCriticalSection( &_native );
114  }
115 
116  BLACKBONE_API void lock()
117  {
118  EnterCriticalSection( &_native );
119  }
120 
121  BLACKBONE_API void unlock()
122  {
123  LeaveCriticalSection( &_native );
124  }
125 
126 private:
127  CRITICAL_SECTION _native;
128 };
129 
130 
134 class CSLock
135 {
136 public:
137  BLACKBONE_API CSLock( CriticalSection& cs )
138  : _cs( cs )
139  {
140  cs.lock();
141  }
142 
143  BLACKBONE_API ~CSLock()
144  {
145  _cs.unlock();
146  }
147 
148 private:
149  CSLock( const CSLock& ) = delete;
150  CSLock& operator = ( const CSLock& ) = delete;
151 
152 private:
153  CriticalSection& _cs;
154 };
155 
156 }
static BLACKBONE_API std::wstring ToLower(const std::wstring &str)
Cast string characters to lower case
Definition: Utils.cpp:162
std::lock_guard alternative
Definition: Utils.h:134
static BLACKBONE_API std::wstring AnsiToWstring(const std::string &input, DWORD locale=CP_ACP)
Convert ANSI string to wide char one
Definition: Utils.cpp:37
Definition: Utils.h:9
static BLACKBONE_API bool FileExists(const std::wstring &path)
Check if file exists
Definition: Utils.cpp:202
static BLACKBONE_API std::wstring GetParent(const std::wstring &path)
Get parent directory
Definition: Utils.cpp:101
static BLACKBONE_API std::wstring FormatString(const wchar_t *fmt,...)
Format string
Definition: Utils.cpp:63
static BLACKBONE_API std::wstring GetErrorDescription(NTSTATUS code)
Get system error description
Definition: Utils.cpp:175
static BLACKBONE_API std::string WstringToAnsi(const std::wstring &input, DWORD locale=CP_ACP)
Convert wide char string to ANSI one
Definition: Utils.cpp:50
static BLACKBONE_API std::string WstringToUTF8(const std::wstring &str)
Convert wide string to UTF-8
Definition: Utils.cpp:26
std::mutex alternative
Definition: Utils.h:103
static BLACKBONE_API std::wstring UTF8ToWstring(const std::string &str)
Convert UTF-8 string to wide char one
Definition: Utils.cpp:16
static BLACKBONE_API std::wstring RandomANString(int length=0)
Generate random alpha-numeric string
Definition: Utils.cpp:139
static BLACKBONE_API std::wstring GetExeDirectory()
Get current process exe file directory
Definition: Utils.cpp:120
static BLACKBONE_API std::wstring StripPath(const std::wstring &path)
Get filename from full-qualified path
Definition: Utils.cpp:81
Definition: AsmHelper32.cpp:6