Ark Server API (ASE) - 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
14
15 // get base of .data section
17 const auto first_section = IMAGE_FIRST_SECTION(nt_headers);
19
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
29 {
30 Log::GetLog()->error("Failed to get the base of the .data section.");
31 throw;
32 }
33
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 {
52 return reinterpret_cast<DWORD64>(base) + static_cast<DWORD64>(offsets_dump_[name]);
53 }
54
56 {
57 return reinterpret_cast<LPVOID>(module_base_ + static_cast<DWORD64>(offsets_dump_[name]));
58 }
59
61 {
62 return reinterpret_cast<LPVOID>(data_base_ + static_cast<DWORD64>(offsets_dump_[name]));
63 }
64
66 {
68 }
69
71 {
73 }
74
76 {
77 const auto bf = bitfields_dump_[name];
78 auto cf = BitField();
82 cf.offset = reinterpret_cast<DWORD64>(base) + static_cast<DWORD64>(bf.offset);
83
84 return cf;
85 }
86} // namespace API
Definition IBaseApi.h:9