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 
47  BLACKBONE_API static std::wstring StripPath( const std::wstring& path );
48 
54  BLACKBONE_API static std::wstring GetParent( const std::wstring& path );
55 
60  BLACKBONE_API static std::wstring GetExeDirectory();
61 
67  BLACKBONE_API static std::wstring ToLower( const std::wstring& str );
68 
74  BLACKBONE_API static std::wstring RandomANString( int length = 0 );
75 
81  BLACKBONE_API static std::wstring GetErrorDescription( NTSTATUS code );
82 
88  BLACKBONE_API static bool FileExists( const std::wstring& path );
89 };
90 
91 
96 {
97 public:
98  BLACKBONE_API CriticalSection()
99  {
100  InitializeCriticalSection( &_native );
101  }
102 
103  BLACKBONE_API ~CriticalSection()
104  {
105  DeleteCriticalSection( &_native );
106  }
107 
108  BLACKBONE_API void lock()
109  {
110  EnterCriticalSection( &_native );
111  }
112 
113  BLACKBONE_API void unlock()
114  {
115  LeaveCriticalSection( &_native );
116  }
117 
118 private:
119  CRITICAL_SECTION _native;
120 };
121 
122 
126 class CSLock
127 {
128 public:
129  BLACKBONE_API CSLock( CriticalSection& cs )
130  : _cs( cs )
131  {
132  cs.lock();
133  }
134 
135  BLACKBONE_API ~CSLock()
136  {
137  _cs.unlock();
138  }
139 
140 private:
141  CSLock( const CSLock& ) = delete;
142  CSLock& operator = ( const CSLock& ) = delete;
143 
144 private:
145  CriticalSection& _cs;
146 };
147 
148 }
static BLACKBONE_API std::wstring ToLower(const std::wstring &str)
Cast string characters to lower case
Definition: Utils.cpp:141
std::lock_guard alternative
Definition: Utils.h:126
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:181
static BLACKBONE_API std::wstring GetParent(const std::wstring &path)
Get parent directory
Definition: Utils.cpp:82
static BLACKBONE_API std::wstring GetErrorDescription(NTSTATUS code)
Get system error description
Definition: Utils.cpp:154
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:95
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:118
static BLACKBONE_API std::wstring GetExeDirectory()
Get current process exe file directory
Definition: Utils.cpp:101
static BLACKBONE_API std::wstring StripPath(const std::wstring &path)
Get filename from full-qualified path
Definition: Utils.cpp:62
Definition: AsmHelper32.cpp:6