-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pointer.h
49 lines (48 loc) · 874 Bytes
/
Pointer.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
#include "stdafx.h"
#include <vector>
#include <array>
template<class T = DWORD, class S = DWORD> struct Pointer
{
private:
std::vector<S> params;
S variable;
bool MoreThanOne;
public:
template<class... Args>
Pointer(Args... args)
{
std::array<S, sizeof...(args)> list = { args... };
for (auto i : list)
params.push_back(i);
if (params.size() > 1)
MoreThanOne = true;
else
MoreThanOne = false;
}
T ResolvePointer()
{
variable = params[0];
if (!MoreThanOne)
return (T)variable;
try
{
auto it = params.begin();
++it;
for (; it != params.end(); ++it)
{
if (*reinterpret_cast<S*>(variable) == NULL)
return static_cast<T>(NULL);
variable = *reinterpret_cast<S*>(variable)+*it;
}
}
catch (...)
{
return static_cast<T>(NULL);
}
return (T)variable;
}
T operator()()
{
return ResolvePointer();
}
};