-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRemoteType.h
208 lines (180 loc) · 4.35 KB
/
RemoteType.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
#pragma once
#include "iostream"
#include <tchar.h>
#include <memory>
#include "windows.h"
BOOL RPM(
LPCVOID lpBaseAddress,
LPVOID lpBuffer,
size_t nSize,
size_t* lpNumberOfBytesRead
);
struct _RemoteType_Deleter
{
template <class T>
void operator() (T* p)
{
free(p);
}
};
template<typename T>
class RemoteType {
size_t addr;
public:
T* address()
{
return (T*)addr;
}
explicit RemoteType(size_t _addr) :addr(_addr) {
};
explicit RemoteType(void* _addr) :addr((size_t)_addr) {
};
explicit RemoteType(T* _addr) :addr((size_t)_addr) {
};
explicit RemoteType() :addr(0) {
};
template<typename V>
RemoteType(V) = delete;
template<typename U = std::remove_pointer<T>::type>
typename std::enable_if<std::is_pointer<T>::value, RemoteType<U>>::type operator[] (const int index)
{
T result;
size_t rb;
RPM((void*)(addr + sizeof(size_t)*index), &result, sizeof(T), &rb);
RemoteType<U> a((size_t)result);
return a;
};
template<typename U = T>
typename std::enable_if<
!std::is_pointer<U>::value, U>::type
operator[](const int index)
{
U result;
size_t rb;
RPM((void*)(addr + sizeof(U)*index), &result, sizeof(U), &rb);
return result;
};
template<typename U = T>
typename std::enable_if<!std::is_pointer<U>::value,
std::unique_ptr<U[], _RemoteType_Deleter> >::type
shareArray(int size) const
{
U* result = (U*)malloc(sizeof(T)*size);
size_t rb;
RPM((void*)addr,
result, sizeof(U)*size, &rb);
return std::unique_ptr<U[], _RemoteType_Deleter>(result);
}
template<typename U = std::remove_pointer<T>::type>
typename std::enable_if<std::is_pointer<T>::value,
std::unique_ptr<RemoteType<U>[], _RemoteType_Deleter> >::type
shareArray(int size) const
{
RemoteType<U>* result = (RemoteType<U>*)malloc(sizeof(T)*size);
size_t rb;
RPM((void*)addr,
result, sizeof(T)*size, &rb);
return std::unique_ptr<RemoteType<U>[], _RemoteType_Deleter>(result);
}
T get() const
{
T result;
size_t rb;
RPM((void*)addr, &result, sizeof(T), &rb);
return result;
}
std::unique_ptr<T,_RemoteType_Deleter> share() const
{
T* result = (T*)malloc(sizeof(T));
size_t rb;
RPM((void*)addr,
result, sizeof(T), &rb);
return std::unique_ptr<T, _RemoteType_Deleter>(result);
}
operator const T() const
{
return this->get();
};
template<typename U = std::remove_pointer<T>::type>
typename std::enable_if<std::is_pointer<T>::value, RemoteType<U>>::type
operator*() const
{
T result;
size_t rb;
RPM((void*)(addr), &result, sizeof(T), &rb);
RemoteType<U> a((size_t)result);
return a;
}
template<typename U = T>
typename std::enable_if<!std::is_pointer<T>::value, U>::type
operator*() const
{
return this->get();
}
template<typename U = T>
typename std::enable_if<std::is_class<U>::value, std::unique_ptr<U, _RemoteType_Deleter>>::type
operator->() const noexcept
{
U* result = (U*)malloc(sizeof(U));
size_t rb;
RPM((void*)(addr), result, sizeof(U), &rb);
return std::unique_ptr<U, _RemoteType_Deleter>(result);
}
template<typename U = std::remove_pointer<T>::type>
typename std::enable_if<std::is_pointer<T>::value, RemoteType<U>>::type
operator->() const noexcept
{
return this->operator*();
}
template<typename W>
RemoteType<W> cast()
{
return RemoteType<W>(addr);
}
};
template<typename T>
class ReflectPointer {
public:
size_t addr;
ReflectPointer(T _addr) :addr((size_t)_addr) {
static_assert(std::is_pointer<T>::value, "ReflectPointer must be a pointer.");
};
ReflectPointer() :addr(0) {
static_assert(std::is_pointer<T>::value, "ReflectPointer must be a pointer.");
};
T address()
{
return (T)addr;
}
template<typename U = std::remove_pointer<T>::type>
RemoteType<U> toRemoteType() const
{
return RemoteType<U>(addr);
}
template<typename W>
ReflectPointer<W> cast()
{
return ReflectPointer<W>((W)addr);
}
template<typename U = std::remove_pointer<T>::type>
RemoteType<U> operator->() const
{
return toRemoteType();
}
template<typename U = std::remove_pointer<T>::type>
U get() const
{
return toRemoteType().get();
}
template<typename U = std::remove_pointer<T>::type>
std::unique_ptr<U, _RemoteType_Deleter> share() const
{
return toRemoteType().share();
}
template<typename U = std::remove_pointer<T>::type>
typename std::enable_if<std::is_pointer<U>::value, ReflectPointer<U>>::type
operator*() const
{
return ReflectPointer<U>(this->get());
}
};