-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.cpp
More file actions
80 lines (77 loc) · 4.8 KB
/
Copy pathutils.cpp
File metadata and controls
80 lines (77 loc) · 4.8 KB
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
#include "include/utils.h"
std::wstring Utils::s2ws(const std::string& str)
{
int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed);
return wstrTo;
}
Utils::EncodedVectorEntry Utils::encode_module_vector(const uintptr_t base, uintptr_t size)
{
EncodedVectorEntry calculatedvector = { 0, 0, 0 };
const uint64_t actualbase = base >> 12;
const uint64_t actualsize = size >> 12;
calculatedvector.key1 = ((actualbase & 0x400000) << 0x26) |
((actualbase & 0x300000) << 0x24) |
((actualbase & 0x80000) << 0x1a) |
((actualbase & 0x40000) << 0x19) |
((actualbase & 0x3f000) << 0x16) |
((actualbase & 0xc00) << 0x14) |
((actualbase & 0x200) << 0xd) |
((actualbase & 0x1c0) << 0x9) |
((actualbase & 0x20) << 0x7) |
((actualbase & 0x18) << 0x6) |
((actualbase & 0x7) << 0x1) |
((actualsize & 0x100) << 0x35) |
((actualsize & 0x80) << 0x2e) |
((actualsize & 0x40) << 0x2a) |
((actualsize & 0x20) << 0x29) |
((actualsize & 0x10) << 0x25) |
((actualsize & 0x8) << 0x12) |
((actualsize & 0x6) << 0x11) |
((actualsize & 0x1) << 0x4);
calculatedvector.key2 = ((actualbase & 0x800000000000) << 0x7) |
((actualbase & 0x400000000000) << 0x5) |
((actualbase & 0x300000000000) << 0x2) |
((actualbase & 0xf0000000000) << 0x1) |
((actualbase & 0x8000000000) >> 0x1) |
((actualbase & 0x4000000000) >> 0x3) |
((actualbase & 0x2000000000) >> 0x4) |
((actualbase & 0x1e00000000) >> 0x9) |
((actualbase & 0x100000000) >> 0xa) |
((actualbase & 0x80000000) >> 0xc) |
((actualbase & 0x70000000) >> 0x13) |
((actualbase & 0x8000000) >> 0x14) |
((actualbase & 0x4000000) >> 0x15) |
((actualbase & 0x2000000) >> 0x16) |
((actualbase & 0x1800000) >> 0x17) |
((actualsize & 0x10000) << 0x2b) |
((actualsize & 0x8000) << 0x26) |
((actualsize & 0x4000) << 0x23) |
((actualsize & 0x2000) << 0x1b) |
((actualsize & 0x1000) << 0x16) |
((actualsize & 0x800) << 0x13) |
((actualsize & 0x400) << 0x7) |
((actualsize & 0x200) >> 0x3);
calculatedvector.key3 = ((actualsize & 0x80000) >> 0x8) |
((actualsize & 0x40000) >> 0x9) |
((actualsize & 0x20000) >> 0xd);
EncodedVectorEntry finalvector;
// take the bits needed for base/size from calculatedvector
finalvector.key1 = calculatedvector.key1;
finalvector.key2 = calculatedvector.key2;
finalvector.key3 = (int32_t)(calculatedvector.key3);;
return finalvector;
}
std::pair<uint64_t, uint64_t> Utils::decode_module_vector(const EncodedVectorEntry* vectorEntry)
{
std::pair<uint64_t, uint64_t> result;
const int64_t key1 = vectorEntry->key1;
const int64_t key2 = vectorEntry->key2;
const int32_t key3 = vectorEntry->key3;
uint64_t actualbase = ((((key3 & 0x0) | ((key2 >> 0x7) & 0x800000000000)) | (((((((key2 >> 0x5) & 0x400000000000) | ((key2 >> 0x2) & 0x300000000000)) | ((key2 >> 0x1) & 0xf0000000000)) | (((key2 * 0x2) & 0xffffffffffffffff) & 0x8000000000)) | (((key2 * 0x8) & 0xffffffffffffffff) & 0x4000000000)) | (((key2 * 0x10) & 0xffffffffffffffff) & 0x2000000000))) | (((((((((key2 & 0xf000000) * 0x200) & 0xffffffffffffffff) | (((key2 & 0x400000) * 0x400) & 0xffffffffffffffff)) | (((((((key2 * 0x1000) & 0xffffffffffffffff) & 0x80000000) | (((key2 * 0x80000) & 0xffffffffffffffff) & 0x70000000)) | (((key2 * 0x100000) & 0xffffffffffffffff) & 0x8000000)) | (((key2 & 0x20) * 0x200000) & 0xffffffffffffffff)) | (((key2 & 0x8) * 0x400000) & 0xffffffffffffffff))) | (((key2 & 0x3) * 0x800000) & 0xffffffffffffffff)) | ((((((key1 >> 0x26) & 0x400000) | ((key1 >> 0x24) & 0x300000)) | ((key1 >> 0x1a) & 0x80000)) | ((key1 >> 0x19) & 0x40000)) | ((key1 >> 0x16) & 0x3f000))) | ((key1 >> 0x14) & 0xc00)) | ((((((key1 >> 0xd) & 0x200) | ((key1 >> 0x9) & 0x1c0)) | ((key1 >> 0x7) & 0x20)) | ((key1 >> 0x6) & 0x18)) | ((key1 >> 0x1) & 0x7))));
uint64_t actualsize = (((((((key3 * 0x100) & 0xffffffff) & 0x80000) | (((key3 * 0x200) & 0xffffffff) & 0x40000)) | (((((((key3 & 0x10) * 0x2000) & 0xffffffff) | ((key2 >> 0x2b) & 0x10000)) | ((key2 >> 0x26) & 0x8000)) | ((key2 >> 0x23) & 0x4000)) | ((key2 >> 0x1b) & 0x2000))) | ((((((key2 >> 0x16) & 0x1000) | ((key2 >> 0x13) & 0x800)) | ((key2 >> 0x7) & 0x400)) | (((key2 & 0x40) * 0x8) & 0xffffffffffffffff)) | (((key1 >> 0x35) & 0x100) | ((key1 >> 0x2e) & 0x80)))) | (((key1 >> 0x2a) & 0x40) | ((((((key1 >> 0x29) & 0x20) | ((key1 >> 0x25) & 0x10)) | ((key1 >> 0x12) & 0x8)) | ((key1 >> 0x11) & 0x6)) | ((key1 >> 0x4) & 0x1))));
result.first = actualbase << 12;
result.second = actualsize << 12;
return result;
}