forked from leftspace89/pPlat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemory.h
106 lines (94 loc) · 1.4 KB
/
Memory.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#pragma once
class Memory
{
public:
Memory();
~Memory();
template<typename type>
static type read(DWORD ptr)
{
type tmp;
SIZE_T numread;
ReadProcessMemory((HANDLE)-1, (LPVOID)ptr, &tmp, sizeof(type), &numread);
return tmp;
}
static bool isReadable(DWORD ptr)
{
DWORD tmp;
SIZE_T numread;
return ReadProcessMemory((HANDLE)-1, (LPVOID)ptr, &tmp, sizeof(DWORD), &numread);
}
};
template<typename type>
class lvar
{
public:
lvar(type &ptr)
{
var = ptr;
};
~lvar()
{
};
void set(type value) { *&var = value; }
type get() const { return var; }
auto operator==(type const p)
-> bool
{
return var == p;
}
auto operator<<=(type const p) // set operatoru
-> type
{
return var;
}
auto operator>>=(type const &p) // get operatoru
-> type
{
var = p;
return var;
}
//not: Delir kudur Rexy C++ get set ez s.q >> all
private:
type var;
};
class CriticalSection
{
public:
CriticalSection()
{
InitializeCriticalSection(&_native);
}
~CriticalSection()
{
DeleteCriticalSection(&_native);
}
void lock()
{
EnterCriticalSection(&_native);
}
void unlock()
{
LeaveCriticalSection(&_native);
}
private:
CRITICAL_SECTION _native;
};
class CSLock
{
public:
CSLock(CriticalSection& cs)
: _cs(cs)
{
cs.lock();
}
~CSLock()
{
_cs.unlock();
}
private:
CSLock(const CSLock&) = delete;
CSLock& operator = (const CSLock&) = delete;
private:
CriticalSection & _cs;
};