HyperDbg Debugger
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1
13#pragma once
14
16// Definitions //
18
19#define AssertReturn return;
20
21#define AssertReturnFalse return FALSE;
22
23#define AssertReturnOne return 1;
24
25#define ASSERT_MESSAGE_DRIVER_NOT_LOADED "handle of the driver not found, probably the driver is not loaded. Did you use 'load' command?\n"
26
27#define ASSERT_MESSAGE_BUILD_SIGNATURE_DOESNT_MATCH "the handshaking process was successful; however, there is a mismatch between " \
28 "the version/build of the debuggee and the debugger. please use the same " \
29 "version/build for both the debuggee and debugger\n"
30
31#define ASSERT_MESSAGE_CANNOT_SPECIFY_PID "err, since HyperDbg won't context-switch to keep the system in a halted state, " \
32 "you cannot specify 'pid' for this command in the debugger mode. You can switch to the target process " \
33 "memory layout using the '.process' or the '.thread' command. After that, you can use " \
34 "this command without specifying the process ID. Alternatively, you can modify the current " \
35 "CR3 register to achieve the same functionality\n"
36
37#define AssertReturnStmt(expr, stmt, rc) \
38 do \
39 { \
40 if (expr) \
41 { \
42 /* likely */ \
43 } \
44 else \
45 { \
46 stmt; \
47 rc; \
48 } \
49 } while (0)
50
51#define AssertShowMessageReturnStmt(expr, message, rc) \
52 do \
53 { \
54 if (expr) \
55 { \
56 /* likely */ \
57 } \
58 else \
59 { \
60 ShowMessages(message); \
61 rc; \
62 } \
63 } while (0)
64
69#define PAGE_SIZE 0x1000
70
75#define PAGE_ALIGN(Va) ((PVOID)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
76
81#define CPUID_ADDR_WIDTH 0x80000008
82
84// Assembly Functions //
86
87#ifdef __cplusplus
88extern "C" {
89#endif
90
91extern bool
93
94#ifdef __cplusplus
95}
96#endif
97
99// Spinlocks //
101
102void
103SpinlockLock(volatile LONG * Lock);
104
105void
106SpinlockLockWithCustomWait(volatile LONG * Lock, unsigned MaximumWait);
107
108void
109SpinlockUnlock(volatile LONG * Lock);
110
112// Functions //
114
115VOID
116PrintBits(const UINT32 size, const void * ptr);
117
118BOOL
119Replace(std::string & str, const std::string & from, const std::string & to);
120
121VOID
122ReplaceAll(string & str, const string & from, const string & to);
123
124const vector<string>
125Split(const string & s, const char & c);
126
128IsNumber(const string & str);
129
130UINT32
132
133vector<string>
134SplitIp(const string & str, char delim);
135
137IsHexNotation(const string & s);
138
139vector<char>
140HexToBytes(const string & hex);
141
143ConvertStringToUInt64(string TextToConvert, PUINT64 Result);
144
146ConvertStringToUInt32(string TextToConvert, PUINT32 Result);
147
149HasEnding(string const & fullString, string const & ending);
150
152ValidateIP(const string & ip);
153
154BOOL
155SetPrivilege(HANDLE Token, // access token handle
156 LPCTSTR Privilege, // name of privilege to enable/disable
157 BOOL EnablePrivilege // to enable or disable privilege
158);
159
160void
161Trim(std::string & s);
162
163std::string
164RemoveSpaces(std::string str);
165
167IsFileExistA(const char * FileName);
168
170IsFileExistW(const wchar_t * FileName);
171
172VOID
173GetConfigFilePath(PWCHAR ConfigPath);
174
175VOID
176StringToWString(std::wstring & ws, const std::string & s);
177
178VOID
179SplitPathAndArgs(std::vector<std::string> & Qargs, const std::string & Command);
180
181size_t
182FindCaseInsensitive(std::string Input, std::string ToSearch, size_t Pos);
183
184size_t
185FindCaseInsensitiveW(std::wstring Input, std::wstring ToSearch, size_t Pos);
186
187char *
188ConvertStringVectorToCharPointerArray(const std::string & s);
189
190std::vector<std::string>
191ListDirectory(const std::string & Directory, const std::string & Extension);
192
194IsEmptyString(char * Text);
195
196VOID
197CommonCpuidInstruction(UINT32 Func, UINT32 SubFunc, int * CpuInfo);
198
201
202UINT32
204
206CheckAccessValidityAndSafety(UINT64 TargetAddress, UINT32 Size);
207
int BOOL
Definition BasicTypes.h:23
UCHAR BOOLEAN
Definition BasicTypes.h:39
#define VOID
Definition BasicTypes.h:33
unsigned int * PUINT32
Definition BasicTypes.h:48
unsigned __int64 UINT64
Definition BasicTypes.h:21
unsigned __int64 * PUINT64
Definition BasicTypes.h:21
unsigned int UINT32
Definition BasicTypes.h:48
void SpinlockLock(volatile LONG *Lock)
Tries to get the lock and won't return until successfully get the lock.
Definition Spinlock.c:52
VOID StringToWString(std::wstring &ws, const std::string &s)
convert std::string to std::wstring
Definition common.cpp:729
VOID CommonCpuidInstruction(UINT32 Func, UINT32 SubFunc, int *CpuInfo)
Get cpuid results.
Definition Common.c:85
VOID GetConfigFilePath(PWCHAR ConfigPath)
Get config path.
Definition common.cpp:671
BOOLEAN CheckCpuSupportRtm()
Check whether the processor supports RTM or not.
Definition common.cpp:903
BOOLEAN IsNumber(const string &str)
check if given string is a numeric string or not
Definition common.cpp:145
const vector< string > Split(const string &s, const char &c)
general split command
Definition common.cpp:117
BOOLEAN VmxSupportDetection()
Detect whether the VMX is supported or not.
Definition common.cpp:505
void SpinlockLockWithCustomWait(volatile LONG *Lock, unsigned MaximumWait)
Tries to get the lock and won't return until successfully get the lock.
Definition Spinlock.c:125
size_t FindCaseInsensitive(std::string Input, std::string ToSearch, size_t Pos)
Find case insensitive sub string in a given substring.
Definition common.cpp:817
BOOLEAN ValidateIP(const string &ip)
Function to validate an IP address.
Definition common.cpp:469
void SpinlockUnlock(volatile LONG *Lock)
Release the lock.
Definition Spinlock.c:158
BOOL Replace(std::string &str, const std::string &from, const std::string &to)
general replace all function
Definition common.cpp:73
BOOLEAN ConvertStringToUInt64(string TextToConvert, PUINT64 Result)
check and convert string to a 64 bit unsigned integer and also check for special notations like 0x,...
Definition common.cpp:240
BOOLEAN IsHexNotation(const string &s)
check whether the string is hex or not
Definition common.cpp:162
BOOLEAN ConvertStringToUInt32(string TextToConvert, PUINT32 Result)
check and convert string to a 32 bit unsigned it and also check for special notations like 0x etc.
Definition common.cpp:347
VOID ReplaceAll(string &str, const string &from, const string &to)
general replace all function
Definition common.cpp:91
std::vector< std::string > ListDirectory(const std::string &Directory, const std::string &Extension)
Create a list of special files in a directory.
Definition common.cpp:699
BOOL SetPrivilege(HANDLE Token, LPCTSTR Privilege, BOOL EnablePrivilege)
SetPrivilege enables/disables process token privilege.
Definition common.cpp:522
size_t FindCaseInsensitiveW(std::wstring Input, std::wstring ToSearch, size_t Pos)
Find case insensitive sub string in a given substring (unicode)
Definition common.cpp:836
BOOLEAN IsFileExistA(const char *FileName)
check if a file exist or not (ASCII)
Definition common.cpp:619
VOID SplitPathAndArgs(std::vector< std::string > &Qargs, const std::string &Command)
Split path and arguments and handle strings between quotes.
Definition common.cpp:744
char * ConvertStringVectorToCharPointerArray(const std::string &s)
Convert vector<string> to char*.
Definition common.cpp:858
UINT32 Getx86VirtualAddressWidth()
Get virtual address width for x86 processors.
Definition common.cpp:885
vector< char > HexToBytes(const string &hex)
converts hex to bytes
Definition common.cpp:216
BOOLEAN IsEmptyString(char *Text)
Is empty character.
Definition common.cpp:644
vector< string > SplitIp(const string &str, char delim)
UINT32 Log2Ceil(UINT32 n)
Function to compute log2Ceil.
Definition common.cpp:1216
BOOLEAN CheckAccessValidityAndSafety(UINT64 TargetAddress, UINT32 Size)
Check the safety to access the memory.
Definition AddressCheck.c:156
BOOLEAN HasEnding(string const &fullString, string const &ending)
checks whether the string ends with a special string or not
Definition common.cpp:448
void Trim(std::string &s)
trim from both ends and start of a string (in place)
Definition common.cpp:594
BOOLEAN IsFileExistW(const wchar_t *FileName)
check if a file exist or not (wide-char)
Definition common.cpp:632
VOID PrintBits(const UINT32 size, const void *ptr)
print bits and bytes for d* commands
Definition common.cpp:47
bool AsmVmxSupportDetection()
std::string RemoveSpaces(std::string str)
Remove all the spaces in a string.
Definition common.cpp:606