More fixes

This commit is contained in:
momo5502
2019-09-24 11:46:47 +02:00
parent 91aa9cc0b8
commit 84cba76ae3
37 changed files with 3327 additions and 3280 deletions

View File

@ -12,7 +12,7 @@ FARPROC loader::load(const utils::nt::module& module) const
const auto buffer = binary_loader::load(this->mode_);
if (buffer.empty()) return nullptr;
utils::nt::module source(HMODULE(buffer.data()));
const utils::nt::module source(HMODULE(buffer.data()));
if (!source) return nullptr;
this->load_sections(module, source);
@ -58,8 +58,8 @@ FARPROC loader::load(const utils::nt::module& module) const
.get_optional_header()->DataDirectory[
IMAGE_DIRECTORY_ENTRY_IMPORT];
std::memmove(module.get_nt_headers(), source.get_nt_headers(),
sizeof(IMAGE_NT_HEADERS) + (source.get_nt_headers()->FileHeader.NumberOfSections * (sizeof(
IMAGE_SECTION_HEADER))));
sizeof(IMAGE_NT_HEADERS) + source.get_nt_headers()->FileHeader.NumberOfSections * sizeof(
IMAGE_SECTION_HEADER));
return FARPROC(module.get_ptr() + source.get_relative_entry_point());
}

View File

@ -1,26 +1,26 @@
#pragma once
class module
{
public:
virtual ~module()
{
}
virtual void post_start()
{
}
virtual void post_load()
{
}
virtual void pre_destroy()
{
}
virtual void* load_import(const std::string& module, const std::string& function)
{
return nullptr;
}
};
#pragma once
class module
{
public:
virtual ~module()
{
}
virtual void post_start()
{
}
virtual void post_load()
{
}
virtual void pre_destroy()
{
}
virtual void* load_import(const std::string& module, const std::string& function)
{
return nullptr;
}
};

View File

@ -27,7 +27,7 @@ bool module_loader::post_start()
module_->post_start();
}
}
catch(premature_shutdown_trigger&)
catch (premature_shutdown_trigger&)
{
return false;
}
@ -75,7 +75,7 @@ void* module_loader::load_import(const std::string& module, const std::string& f
for (const auto& module_ : *modules_)
{
const auto module_function_ptr = module_->load_import(module, function);
if(module_function_ptr)
if (module_function_ptr)
{
function_ptr = module_function_ptr;
}

View File

@ -1,61 +1,61 @@
#pragma once
#include "module.hpp"
class module_loader final
{
public:
class premature_shutdown_trigger final : public std::exception
{
const char* what() const noexcept override
#pragma once
#include "module.hpp"
class module_loader final
{
public:
class premature_shutdown_trigger final : public std::exception
{
const char* what() const noexcept override
{
return "Premature shutdown requested";
}
};
template <typename T>
class installer final
{
static_assert(std::is_base_of<module, T>::value, "Module has invalid base class");
public:
installer()
{
register_module(std::make_unique<T>());
}
};
template<typename T>
static T* get()
{
for(const auto& module_ : *modules_)
{
if(typeid(*module_.get()) == typeid(T))
{
return reinterpret_cast<T*>(module_.get());
}
}
return nullptr;
}
static void register_module(std::unique_ptr<module>&& module);
static bool post_start();
static bool post_load();
static void pre_destroy();
static void* load_import(const std::string& module, const std::string& function);
static void trigger_premature_shutdown();
private:
static std::vector<std::unique_ptr<module>>* modules_;
static void destroy_modules();
};
#define REGISTER_MODULE(name) \
namespace \
{ \
static module_loader::installer<name> $_##name; \
}
}
};
template <typename T>
class installer final
{
static_assert(std::is_base_of<module, T>::value, "Module has invalid base class");
public:
installer()
{
register_module(std::make_unique<T>());
}
};
template <typename T>
static T* get()
{
for (const auto& module_ : *modules_)
{
if (typeid(*module_.get()) == typeid(T))
{
return reinterpret_cast<T*>(module_.get());
}
}
return nullptr;
}
static void register_module(std::unique_ptr<module>&& module);
static bool post_start();
static bool post_load();
static void pre_destroy();
static void* load_import(const std::string& module, const std::string& function);
static void trigger_premature_shutdown();
private:
static std::vector<std::unique_ptr<module>>* modules_;
static void destroy_modules();
};
#define REGISTER_MODULE(name) \
namespace \
{ \
static module_loader::installer<name> $_##name; \
}