-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandle.h
54 lines (43 loc) · 809 Bytes
/
handle.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#define _HANDLE_FUNC [[nodiscard]] inline
typedef unsigned long long DWORD64;
typedef unsigned long DWORD;
class handle
{
public:
handle() : address(0) {}
handle(DWORD64 _addr) : address(_addr) {}
_HANDLE_FUNC bool is_valid() const
{
return address;
}
_HANDLE_FUNC handle at(int _offset) const
{
return is_valid() ? address + _offset : 0;
}
template<typename t>
_HANDLE_FUNC t *get() const
{
return reinterpret_cast<t*>(address);
}
template<typename t>
_HANDLE_FUNC t value() const
{
return is_valid() ? *get<t>() : 0;
}
_HANDLE_FUNC DWORD64 addr() const
{
return address;
}
_HANDLE_FUNC handle into() const
{
if (is_valid())
{
auto handle = at(1);
return handle.at(handle.value<DWORD>()).at(4);
}
return 0;
}
private:
DWORD64 address;
};