-
Notifications
You must be signed in to change notification settings - Fork 0
/
offsets.cpp
68 lines (64 loc) · 1.7 KB
/
offsets.cpp
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
#include <Windows.h>
#include <fstream>
#include "json.hpp"
#include "offsets.hpp"
#include <sstream>
#include <iostream>
#include <sstream>
template <typename T>
void readValue(const nlohmann::json& src, T& dest)
{
if (!src.is_null())
{
if (src.is_string())
{
std::string value_str = src.get<std::string>();
if (value_str.substr(0, 2) == "0x") // hex prefix
{
dest = static_cast<T>(std::stoul(value_str.substr(2), nullptr, 16));
}
else
{
dest = static_cast<T>(std::stoul(value_str, nullptr, 10));
}
}
else
{
dest = src.get<T>();
}
}
}
template <>
void readValue<unsigned long long>(const nlohmann::json& src, unsigned long long& dest)
{
if (!src.is_null())
{
if (src.is_string())
{
std::string value_str = src.get<std::string>();
if (value_str.substr(0, 2) == "0x") // hex prefix
{
dest = std::stoull(value_str.substr(2), nullptr, 16);
}
else
{
dest = std::stoull(value_str, nullptr, 10);
}
}
else
{
dest = src.get<unsigned long long>();
}
}
}
void offsets::initialize()
{
std::ifstream input_file{ "offsets.json" };
if (!input_file.good())
throw std::invalid_argument("Invalid offsets.json file");
nlohmann::json json;
input_file >> json;
readValue(json["offsets"]["VM_XOR_BASE"], offsets::VM_XOR_BASE);
readValue(json["offsets"]["VM_PTR"], offsets::VM_PTR);
readValue(json["offsets"]["VM_XOR_KEY"], offsets::VM_XOR_KEY);
}