Fixed hamsandwich vtable patching on Linux for newer GCC binaries.

This commit is contained in:
Scott Ehlert 2013-02-04 07:31:32 -06:00
parent ad960a64e2
commit 944f608f09

View File

@ -35,6 +35,8 @@
// This is just a simple container for data so I only have to add 1 extra // This is just a simple container for data so I only have to add 1 extra
// parameter to calls that get trampolined // parameter to calls that get trampolined
#define ALIGN(ar) ((intptr_t)ar & ~(sysconf(_SC_PAGESIZE)-1))
class Hook class Hook
{ {
public: public:
@ -66,7 +68,8 @@ public:
DWORD OldFlags; DWORD OldFlags;
VirtualProtect(&ivtable[entry],sizeof(int*),PAGE_READWRITE,&OldFlags); VirtualProtect(&ivtable[entry],sizeof(int*),PAGE_READWRITE,&OldFlags);
#elif defined __linux__ #elif defined __linux__
mprotect(&ivtable[entry],sizeof(int*),PROT_READ|PROT_WRITE); void *addr = (void *)ALIGN(&ivtable[entry]);
mprotect(addr,sysconf(_SC_PAGESIZE),PROT_READ|PROT_WRITE);
#endif #endif
ivtable[entry]=(int*)tramp; ivtable[entry]=(int*)tramp;
@ -84,8 +87,9 @@ public:
#if defined _WIN32 #if defined _WIN32
DWORD OldFlags; DWORD OldFlags;
VirtualProtect(&ivtable[entry],sizeof(int*),PAGE_READWRITE,&OldFlags); VirtualProtect(&ivtable[entry],sizeof(int*),PAGE_READWRITE,&OldFlags);
#elif defined __linux__ #elif defined __linux_
mprotect(&ivtable[entry],sizeof(int*),PROT_READ|PROT_WRITE); void *addr = (void *)ALIGN(&ivtable[entry]);
mprotect(addr,sysconf(_SC_PAGESIZE),PROT_READ|PROT_WRITE);
#endif #endif
ivtable[entry]=(int *)func; ivtable[entry]=(int *)func;