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
4
namespace
API
5
{
6
Offsets
::
Offsets
()
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
37
Offsets
&
Offsets
::
Get
()
38
{
39
static
Offsets
instance
;
40
return
instance
;
41
}
42
43
void
Offsets
::
Init
(
std
::
unordered_map
<
std
::
string
,
intptr_t
>&&
offsets_dump
,
44
std
::
unordered_map
<
std
::
string
,
BitField
>&&
bitfields_dump
)
45
{
46
offsets_dump_
.
swap
(
offsets_dump
);
47
bitfields_dump_
.
swap
(
bitfields_dump
);
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
55
LPVOID
Offsets
::
GetAddress
(
const
std
::
string
&
name
)
56
{
57
return
reinterpret_cast
<
LPVOID
>(
module_base_
+
static_cast
<
DWORD64
>(
offsets_dump_
[
name
]));
58
}
59
60
LPVOID
Offsets
::
GetDataAddress
(
const
std
::
string
&
name
)
61
{
62
return
reinterpret_cast
<
LPVOID
>(
data_base_
+
static_cast
<
DWORD64
>(
offsets_dump_
[
name
]));
63
}
64
65
BitField
Offsets
::
GetBitField
(
const
void
*
base
,
const
std
::
string
&
name
)
66
{
67
return
GetBitFieldInternal
(
base
,
name
);
68
}
69
70
BitField
Offsets
::
GetBitField
(
LPVOID
base
,
const
std
::
string
&
name
)
71
{
72
return
GetBitFieldInternal
(
base
,
name
);
73
}
74
75
BitField
Offsets
::
GetBitFieldInternal
(
const
void
*
base
,
const
std
::
string
&
name
)
76
{
77
const
auto
bf
=
bitfields_dump_
[
name
];
78
auto
cf
=
BitField
();
79
cf
.
bit_position
=
bf
.
bit_position
;
80
cf
.
length
=
bf
.
length
;
81
cf
.
num_bits
=
bf
.
num_bits
;
82
cf
.
offset
=
reinterpret_cast
<
DWORD64
>(
base
) +
static_cast
<
DWORD64
>(
bf
.
offset
);
83
84
return
cf
;
85
}
86
}
// namespace API
API
Definition
IBaseApi.h:9
Downloads
ArkServerAPI_NEW
ASE
AseApi-main
version
Core
Private
Offsets.cpp
Generated by
1.10.0