Reformat code
This commit is contained in:
@ -36,7 +36,7 @@ namespace binary_loader
|
||||
return {};
|
||||
}
|
||||
|
||||
std::string load_base(bool verify = true)
|
||||
std::string load_base(const bool verify = true)
|
||||
{
|
||||
std::string data;
|
||||
if (!utils::io::read_file("iw5mp_server.exe", &data))
|
||||
@ -87,7 +87,8 @@ namespace binary_loader
|
||||
|
||||
std::string build_binary(const std::string& base, const std::string& diff)
|
||||
{
|
||||
const auto* size = reinterpret_cast<const unsigned long long*>(diff.data() + diff.size() - sizeof(unsigned long long));
|
||||
const auto* size = reinterpret_cast<const unsigned long long*>(diff.data() + diff.size() - sizeof(unsigned long
|
||||
long));
|
||||
|
||||
std::string binary;
|
||||
binary.resize(size_t(*size));
|
||||
|
@ -5,7 +5,6 @@
|
||||
|
||||
loader::loader(const launcher::mode mode) : mode_(mode)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
FARPROC loader::load(const utils::nt::module& module) const
|
||||
@ -22,19 +21,22 @@ FARPROC loader::load(const utils::nt::module& module) const
|
||||
if (source.get_optional_header()->DataDirectory[IMAGE_DIRECTORY_ENTRY_TLS].Size)
|
||||
{
|
||||
const IMAGE_TLS_DIRECTORY* target_tls = reinterpret_cast<PIMAGE_TLS_DIRECTORY>(module.get_ptr() + module
|
||||
.get_optional_header()
|
||||
->DataDirectory
|
||||
.get_optional_header()
|
||||
->
|
||||
DataDirectory
|
||||
[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress);
|
||||
const IMAGE_TLS_DIRECTORY* source_tls = reinterpret_cast<PIMAGE_TLS_DIRECTORY>(module.get_ptr() + source
|
||||
.get_optional_header()
|
||||
->DataDirectory
|
||||
.get_optional_header()
|
||||
->
|
||||
DataDirectory
|
||||
[IMAGE_DIRECTORY_ENTRY_TLS].VirtualAddress);
|
||||
|
||||
*reinterpret_cast<DWORD*>(source_tls->AddressOfIndex) = 0;
|
||||
|
||||
DWORD old_protect;
|
||||
VirtualProtect(PVOID(target_tls->StartAddressOfRawData),
|
||||
source_tls->EndAddressOfRawData - source_tls->StartAddressOfRawData, PAGE_READWRITE, &old_protect);
|
||||
source_tls->EndAddressOfRawData - source_tls->StartAddressOfRawData, PAGE_READWRITE,
|
||||
&old_protect);
|
||||
|
||||
const auto tls_base = *reinterpret_cast<LPVOID*>(__readfsdword(0x2C));
|
||||
std::memmove(tls_base, PVOID(source_tls->StartAddressOfRawData),
|
||||
@ -142,7 +144,8 @@ void loader::load_imports(const utils::nt::module& target, const utils::nt::modu
|
||||
|
||||
if (!function)
|
||||
{
|
||||
throw std::runtime_error(utils::string::va("Unable to load import '%s' from module '%s'", function_name.data(), name.data()));
|
||||
throw std::runtime_error(utils::string::va("Unable to load import '%s' from module '%s'",
|
||||
function_name.data(), name.data()));
|
||||
}
|
||||
|
||||
*address_table_entry = reinterpret_cast<uintptr_t>(function);
|
||||
|
@ -5,7 +5,7 @@
|
||||
class loader final
|
||||
{
|
||||
public:
|
||||
loader(launcher::mode mode);
|
||||
explicit loader(launcher::mode mode);
|
||||
|
||||
FARPROC load(const utils::nt::module& module) const;
|
||||
|
||||
@ -15,8 +15,8 @@ private:
|
||||
launcher::mode mode_;
|
||||
std::function<FARPROC(const std::string&, const std::string&)> import_resolver_;
|
||||
|
||||
static void load_section(const utils::nt::module& target, const utils::nt::module& source, IMAGE_SECTION_HEADER* section);
|
||||
static void load_section(const utils::nt::module& target, const utils::nt::module& source,
|
||||
IMAGE_SECTION_HEADER* section);
|
||||
void load_sections(const utils::nt::module& target, const utils::nt::module& source) const;
|
||||
void load_imports(const utils::nt::module& target, const utils::nt::module& source) const;
|
||||
|
||||
};
|
||||
|
@ -1,10 +1,17 @@
|
||||
#pragma once
|
||||
#include "launcher/launcher.hpp"
|
||||
|
||||
class module
|
||||
{
|
||||
public:
|
||||
virtual ~module() {};
|
||||
virtual void post_load() {}
|
||||
virtual void pre_destroy() {}
|
||||
virtual ~module()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void post_load()
|
||||
{
|
||||
}
|
||||
|
||||
virtual void pre_destroy()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
@ -5,7 +5,7 @@ class module_loader final
|
||||
{
|
||||
public:
|
||||
template <typename T>
|
||||
class installer
|
||||
class installer final
|
||||
{
|
||||
static_assert(std::is_base_of<module, T>::value, "Module has invalid base class");
|
||||
|
||||
|
Reference in New Issue
Block a user