Fixed "meta unload" segfault.

Added fake responces to server queries.
Added dynamic link ents. (except android).
This commit is contained in:
Dmitry 2019-07-31 14:05:36 +03:00 committed by jeefo
commit 535f298621
16 changed files with 763 additions and 246 deletions

View file

@ -46,8 +46,8 @@ public:
}
public:
inline bool load (const String &file) noexcept {
#ifdef CR_WINDOWS
bool load (const String &file) noexcept {
#if defined (CR_WINDOWS)
m_handle = LoadLibraryA (file.chars ());
#else
m_handle = dlopen (file.chars (), RTLD_NOW);
@ -55,15 +55,39 @@ public:
return m_handle != nullptr;
}
bool locate (void *address) {
#if defined (CR_WINDOWS)
MEMORY_BASIC_INFORMATION mbi;
if (!VirtualQuery (address, &mbi, sizeof (mbi))) {
return false;
}
if (mbi.State != MEM_COMMIT) {
return false;
}
m_handle = reinterpret_cast <void *> (mbi.AllocationBase);
#else
Dl_info dli;
memset (&dli, 0, sizeof (dli));
if (dladdr (address, &dli)) {
return load (dli.dli_fname);
}
#endif
return m_handle != nullptr;
}
void unload () noexcept {
if (!*this) {
return;
}
#ifdef CR_WINDOWS
#if defined (CR_WINDOWS)
FreeLibrary (static_cast <HMODULE> (m_handle));
#else
dlclose (m_handle);
#endif
m_handle = nullptr;
}
template <typename R> R resolve (const char *function) const {
@ -72,7 +96,7 @@ public:
}
return reinterpret_cast <R> (
#ifdef CR_WINDOWS
#if defined (CR_WINDOWS)
GetProcAddress (static_cast <HMODULE> (m_handle), function)
#else
dlsym (m_handle, function)
@ -80,6 +104,10 @@ public:
);
}
void *handle () const {
return m_handle;
}
public:
explicit operator bool () const {
return m_handle != nullptr;