Fixed "meta unload" segfault.
Added fake responces to server queries. Added dynamic link ents. (except android).
This commit is contained in:
parent
4f664f0162
commit
535f298621
16 changed files with 763 additions and 246 deletions
|
|
@ -205,7 +205,7 @@ public:
|
|||
if (index + count > m_capacity) {
|
||||
return false;
|
||||
}
|
||||
for (size_t i = m_length; i < m_length + count; i++) {
|
||||
for (size_t i = index; i < index + count; i++) {
|
||||
alloc.destruct (&m_data[i]);
|
||||
}
|
||||
m_length -= count;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
#include <crlib/cr-random.h>
|
||||
#include <crlib/cr-ulz.h>
|
||||
#include <crlib/cr-color.h>
|
||||
#include <crlib/cr-hook.h>
|
||||
|
||||
CR_NAMESPACE_BEGIN
|
||||
|
||||
|
|
|
|||
132
include/crlib/cr-hook.h
Normal file
132
include/crlib/cr-hook.h
Normal file
|
|
@ -0,0 +1,132 @@
|
|||
//
|
||||
// Yet Another POD-Bot, based on PODBot by Markus Klinge ("CountFloyd").
|
||||
// Copyright (c) YaPB Development Team.
|
||||
//
|
||||
// This software is licensed under the BSD-style license.
|
||||
// Additional exceptions apply. For full license details, see LICENSE.txt or visit:
|
||||
// https://yapb.ru/license
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <crlib/cr-basic.h>
|
||||
|
||||
#if !defined (CR_WINDOWS)
|
||||
# include <sys/mman.h>
|
||||
#endif
|
||||
|
||||
CR_NAMESPACE_BEGIN
|
||||
|
||||
class SimpleHook : DenyCopying {
|
||||
private:
|
||||
enum : uint32 {
|
||||
CodeLength = 12
|
||||
};
|
||||
|
||||
private:
|
||||
bool m_patched;
|
||||
|
||||
uint32 m_pageSize;
|
||||
uint32 m_origFunc;
|
||||
uint32 m_hookFunc;
|
||||
|
||||
uint8 m_origBytes[CodeLength];
|
||||
uint8 m_hookBytes[CodeLength];
|
||||
|
||||
private:
|
||||
void setPageSize () {
|
||||
#if defined (CR_WINDOWS)
|
||||
SYSTEM_INFO sysinfo;
|
||||
GetSystemInfo (&sysinfo);
|
||||
|
||||
m_pageSize = sysinfo.dwPageSize;
|
||||
#else
|
||||
m_pageSize = sysconf (_SC_PAGESIZE);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline void *align (void *address) {
|
||||
return reinterpret_cast <void *> ((reinterpret_cast <long> (address) & ~(m_pageSize - 1)));
|
||||
}
|
||||
|
||||
bool unprotect () {
|
||||
auto orig = reinterpret_cast <void *> (m_origFunc);
|
||||
|
||||
#if defined (CR_WINDOWS)
|
||||
DWORD oldProt;
|
||||
|
||||
FlushInstructionCache (GetCurrentProcess (), orig, m_pageSize);
|
||||
return VirtualProtect (orig, m_pageSize, PAGE_EXECUTE_READWRITE, &oldProt);
|
||||
#else
|
||||
auto aligned = align (orig);
|
||||
return !mprotect (aligned, m_pageSize, PROT_READ | PROT_WRITE | PROT_EXEC);
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
SimpleHook () : m_patched (false), m_origFunc (0), m_hookFunc (0), m_pageSize (0) {
|
||||
setPageSize ();
|
||||
}
|
||||
|
||||
~SimpleHook () {
|
||||
disable ();
|
||||
}
|
||||
|
||||
public:
|
||||
bool patch (void *address, void *replacement) {
|
||||
uint8 *ptr = reinterpret_cast <uint8 *> (address);
|
||||
|
||||
while (*reinterpret_cast <uint16 *> (ptr) == 0x25ff) {
|
||||
ptr = **reinterpret_cast <uint8 * **> ((ptr + 2));
|
||||
}
|
||||
m_origFunc = reinterpret_cast <uint32> (ptr);
|
||||
|
||||
if (!m_origFunc) {
|
||||
return false;
|
||||
}
|
||||
m_hookFunc = reinterpret_cast <uint32> (replacement);
|
||||
|
||||
m_hookBytes[0] = 0x68;
|
||||
m_hookBytes[5] = 0xc3;
|
||||
|
||||
*reinterpret_cast <uint32 *> (&m_hookBytes[1]) = m_hookFunc;
|
||||
|
||||
if (unprotect ()) {
|
||||
memcpy (m_origBytes, reinterpret_cast <void *> (m_origFunc), CodeLength);
|
||||
return enable ();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enable () {
|
||||
if (m_patched) {
|
||||
return false;
|
||||
}
|
||||
m_patched = true;
|
||||
|
||||
if (unprotect ()) {
|
||||
memcpy (reinterpret_cast <void *> (m_origFunc), m_hookBytes, CodeLength);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool disable () {
|
||||
if (!m_patched) {
|
||||
return false;
|
||||
}
|
||||
m_patched = false;
|
||||
|
||||
if (unprotect ()) {
|
||||
memcpy (reinterpret_cast <void *> (m_origFunc), m_origBytes, CodeLength);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool enabled () const {
|
||||
return m_patched;
|
||||
}
|
||||
};
|
||||
|
||||
CR_NAMESPACE_END
|
||||
|
|
@ -20,14 +20,13 @@
|
|||
# include <netinet/in.h>
|
||||
# include <sys/socket.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/uio.h>
|
||||
# include <arpa/inet.h>
|
||||
# include <unistd.h>
|
||||
# include <errno.h>
|
||||
# include <netdb.h>
|
||||
# include <fcntl.h>
|
||||
#elif defined (CR_WINDOWS)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <winsock2.h>
|
||||
#endif
|
||||
|
||||
|
|
@ -138,6 +137,30 @@ public:
|
|||
template <typename U> int32 recv (U *buffer, int32 length) {
|
||||
return ::recv (m_socket, reinterpret_cast <char *> (buffer), length, 0);
|
||||
}
|
||||
|
||||
public:
|
||||
static int32 CR_STDCALL sendto (int socket, const void *message, size_t length, int flags, const struct sockaddr *dest, int32 destLength) {
|
||||
#if defined (CR_WINDOWS)
|
||||
WSABUF buffer = { length, const_cast <char *> (reinterpret_cast <const char *> (message)) };
|
||||
DWORD sendLength = 0;
|
||||
|
||||
if (WSASendTo (socket, &buffer, 1, &sendLength, flags, dest, destLength, NULL, NULL) == SOCKET_ERROR) {
|
||||
errno = WSAGetLastError ();
|
||||
return -1;
|
||||
}
|
||||
return static_cast <int32> (sendLength);
|
||||
#else
|
||||
iovec iov = { const_cast <void *> (message), length };
|
||||
msghdr msg = { 0, };
|
||||
|
||||
msg.msg_name = reinterpret_cast <void *> (const_cast <struct sockaddr *> (dest));
|
||||
msg.msg_namelen = destLength;
|
||||
msg.msg_iov = &iov;
|
||||
msg.msg_iovlen = 1;
|
||||
|
||||
return sendmsg (socket, &msg, flags);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
|
|
|||
|
|
@ -169,5 +169,4 @@ public:
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
CR_NAMESPACE_END
|
||||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -34,11 +34,13 @@ CR_NAMESPACE_BEGIN
|
|||
# define CR_CXX_CLANG
|
||||
#endif
|
||||
|
||||
// configure export macros
|
||||
// configure macroses
|
||||
#if defined(CR_WINDOWS)
|
||||
# define CR_EXPORT extern "C" __declspec (dllexport)
|
||||
# define CR_STDCALL __stdcall
|
||||
#elif defined(CR_LINUX) || defined(CR_OSX)
|
||||
# define CR_EXPORT extern "C" __attribute__((visibility("default")))
|
||||
# define CR_STDCALL
|
||||
#else
|
||||
# error "Can't configure export macros. Compiler unrecognized."
|
||||
#endif
|
||||
|
|
@ -56,11 +58,14 @@ CR_NAMESPACE_BEGIN
|
|||
CR_NAMESPACE_END
|
||||
|
||||
#if defined(CR_WINDOWS)
|
||||
# define WIN32_LEAN_AND_MEAN
|
||||
# include <windows.h>
|
||||
# include <direct.h>
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <strings.h>
|
||||
# include <sys/stat.h>
|
||||
# include <sys/time.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
|
@ -154,6 +159,25 @@ struct Platform : public Singleton <Platform> {
|
|||
#endif
|
||||
}
|
||||
|
||||
float seconds () {
|
||||
#if defined(CR_WINDOWS)
|
||||
LARGE_INTEGER count, freq;
|
||||
|
||||
count.QuadPart = 0;
|
||||
freq.QuadPart = 0;
|
||||
|
||||
QueryPerformanceFrequency (&freq);
|
||||
QueryPerformanceCounter (&count);
|
||||
|
||||
return static_cast <float> (count.QuadPart) / static_cast <float> (freq.QuadPart);
|
||||
#else
|
||||
timeval tv;
|
||||
gettimeofday (&tv, NULL);
|
||||
|
||||
return static_cast <float> (tv.tv_sec) + (static_cast <float> (tv.tv_usec)) / 1000000.0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void abort (const char *msg = "OUT OF MEMORY!") noexcept {
|
||||
fprintf (stderr, "%s\n", msg);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue