Ark Server API (ASA) - Wiki
Loading...
Searching...
No Matches
Offsets.cpp
Go to the documentation of this file.
1#include "Offsets.h"
2#include "Logger/Logger.h"
3
4namespace API
5{
7 {
8 module_base_ = data_base_ = reinterpret_cast<DWORD64>(GetModuleHandle(nullptr));
9
10 const auto dos_header = reinterpret_cast<PIMAGE_DOS_HEADER>(module_base_);
11 const auto nt_headers = reinterpret_cast<PIMAGE_NT_HEADERS>(module_base_ + dos_header->e_lfanew);
12
13 module_base_ += nt_headers->OptionalHeader.BaseOfCode;
14
15 // get base of .data section
16 const auto section_count = nt_headers->FileHeader.NumberOfSections;
17 const auto first_section = IMAGE_FIRST_SECTION(nt_headers);
18 const auto end_section = first_section + section_count;
19
20 const auto data_section_header = std::find_if(first_section, end_section, [](_IMAGE_SECTION_HEADER hdr)
21 {
22 auto name = std::string(reinterpret_cast<char*>(hdr.Name), 8);
23 name.erase(std::remove(name.begin(), name.end(), '\0'), name.end());
24
25 return name == ".data";
26 });
27
28 if (data_section_header == end_section)
29 {
30 Log::GetLog()->error("Failed to get the base of the .data section.");
31 throw;
32 }
33
34 data_base_ += data_section_header->VirtualAddress;
35 }
36
38 {
39 static Offsets instance;
40 return instance;
41 }
42
45 {
48 }
49
50 DWORD64 Offsets::GetAddress(const void* base, const std::string& name)
51 {
53 {
54 Log::GetLog()->critical("Failed to get the offset of {}.", name);
55 Log::GetLog()->flush();
56 Sleep(10000);
57 throw;
58 }
59
60 return reinterpret_cast<DWORD64>(base) + static_cast<DWORD64>(offsets_dump_[name]);
61 }
62
64 {
66 {
67 Log::GetLog()->critical("Failed to get the offset of {}.", name);
68 Log::GetLog()->flush();
69 Sleep(10000);
70 throw;
71 }
72
73 return reinterpret_cast<LPVOID>(module_base_ + static_cast<DWORD64>(offsets_dump_[name]));
74 }
75
77 {
79 {
80 Log::GetLog()->critical("Failed to get the offset of {}.", name);
81 Log::GetLog()->flush();
82 Sleep(10000);
83 throw;
84 }
85
86 return reinterpret_cast<LPVOID>(data_base_ + static_cast<DWORD64>(offsets_dump_[name]));
87 }
88
90 {
92 }
93
95 {
97 }
98
100 {
102 {
103 Log::GetLog()->critical("Failed to get the bitfield address of {}.", name);
104 Log::GetLog()->flush();
105 Sleep(10000);
106 throw;
107 }
108
109 const auto bf = bitfields_dump_[name];
110 auto cf = BitField();
112 cf.length = bf.length;
114 cf.offset = reinterpret_cast<DWORD64>(base) + static_cast<DWORD64>(bf.offset);
115
116 return cf;
117 }
118} // namespace API
DWORD64 module_base_
Definition Offsets.h:36
DWORD64 data_base_
Definition Offsets.h:37
static Offsets & Get()
Definition Offsets.cpp:37
Definition IBaseApi.h:9
Definition json.hpp:4518