From 8dbe52e6f3969619b20ceb1f446122f23781599b Mon Sep 17 00:00:00 2001 From: Ivailo Spasov Date: Mon, 21 Jan 2013 23:49:12 +0200 Subject: [PATCH] Fix for linux version of l4dtoolz Signed-off-by: Ivailo Spasov --- game_signature.h | 6 +++--- l4dtoolz_mm.cpp | 3 +++ signature.cpp | 35 ++++++++++++++++++++++------------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/game_signature.h b/game_signature.h index b08d702..d697d02 100644 --- a/game_signature.h +++ b/game_signature.h @@ -1,5 +1,5 @@ -#ifndef _INCLUDE_L4D1_SIGNATURE_LINUX_ -#define _INCLUDE_L4D1_SIGNATURE_LINUX_ +#ifndef _INCLUDE_GAME_SIGNATURE_ +#define _INCLUDE_GAME_SIGNATURE_ #ifdef WIN32 #ifdef L4D1 @@ -15,4 +15,4 @@ #endif #endif -#endif //_INCLUDE_L4D1_SIGNATURE_LINUX_ +#endif //_INCLUDE_GAME_SIGNATURE_ diff --git a/l4dtoolz_mm.cpp b/l4dtoolz_mm.cpp index c48c59f..53c15a8 100644 --- a/l4dtoolz_mm.cpp +++ b/l4dtoolz_mm.cpp @@ -150,6 +150,9 @@ bool l4dtoolz::Load(PluginId id, ISmmAPI *ismm, char *error, size_t maxlen, bool find_base(matchmaking_dll, &base_addr); + if(base_addr.addr == NULL) + find_base(matchmaking_dll_alt, &base_addr); + if(!lobby_match_ptr) { lobby_match_ptr = find_signature(lobby_match, &base_addr, 1); get_original_signature(lobby_match_ptr, lobby_match_new, lobby_match_org); diff --git a/signature.cpp b/signature.cpp index 165c597..857c6d4 100644 --- a/signature.cpp +++ b/signature.cpp @@ -17,7 +17,7 @@ #define SIGN_OFFSET_BYTE 1 -static int lock_region(const void *addr, unsigned int sign_len, int lock) +static int lock_region(const void *addr, unsigned int sign_len, unsigned int sign_off, int lock) { #ifndef WIN32 unsigned int all_adr; @@ -28,12 +28,13 @@ static int lock_region(const void *addr, unsigned int sign_len, int lock) p_size = sysconf(_SC_PAGESIZE); u_addr = (unsigned int)addr; - all_adr = (u_addr + sign_len) & ~(p_size-1); + all_adr = (u_addr + sign_off) & ~(p_size-1); all_size = u_addr - all_adr + sign_len; - if(lock) + if(lock) { mlock((void *)all_adr, all_size); - else + mprotect((void *)all_adr, all_size, PROT_READ|PROT_WRITE|PROT_EXEC); + } else munlock((void *)all_adr, all_size); #endif return 0; @@ -48,7 +49,12 @@ void *find_signature(const char* mask, struct base_addr_t *base_addr, int pure) if(base_addr == NULL) return NULL; - lock_region(pBasePtr, pEndPtr-pBasePtr, 1); +#ifndef WIN32 + unsigned int p_size = sysconf(_SC_PAGESIZE); + char* all_adr = (char*)((unsigned int)pBasePtr & ~(p_size-1)); + unsigned int size = pEndPtr - all_adr; + mlock(all_adr, size); +#endif while(pBasePtr < pEndPtr) { @@ -65,14 +71,18 @@ void *find_signature(const char* mask, struct base_addr_t *base_addr, int pure) tmp++; } if(i-1 == mask[0]) { - lock_region(pBasePtr, pEndPtr-pBasePtr, 0); +#ifndef WIN32 + munlock(all_adr, size); +#endif return pBasePtr; } pBasePtr++; } - lock_region(pBasePtr, pEndPtr-pBasePtr, 0); +#ifndef WIN32 + munlock(all_adr, size); +#endif return NULL; } @@ -171,14 +181,14 @@ int write_signature(const void* addr, const void* signature) CloseHandle(h_process); #else - lock_region(addr, sign_len, 1); + lock_region(addr, sign_len, sign_off, 1); memcpy((void *)(u_addr+sign_off), (void *)(u_addr_sign+SIGN_HEADER_LEN), sign_len); - lock_region(addr, sign_len, 0); + lock_region(addr, sign_len, sign_off, 0); #endif return 1; } - +#include int read_signature(const void *addr, void *signature) { unsigned int u_addr_sign; @@ -196,9 +206,9 @@ int read_signature(const void *addr, void *signature) ReadProcessMemory(h_process, (void *)(u_addr+sign_off), (void *)(u_addr_sign+SIGN_HEADER_LEN), sign_len, NULL); CloseHandle(h_process); #else - lock_region(addr, sign_len, 1); + lock_region(addr, sign_len, sign_off, 1); memcpy((void *)(u_addr_sign+SIGN_HEADER_LEN), (void *)(u_addr+sign_off), sign_len); - lock_region(addr, sign_len, 0); + lock_region(addr, sign_len, sign_off, 0); #endif return 0; } @@ -212,7 +222,6 @@ int get_original_signature(const void *offset, const void *new_sig, void *&org_s sign_len = ((unsigned char *)new_sig)[SIGN_LEN_BYTE]; org_sig = malloc(sign_len + SIGN_HEADER_LEN); - memset(org_sig, 0, sign_len + SIGN_HEADER_LEN); memcpy(org_sig, new_sig, SIGN_HEADER_LEN); return read_signature(offset, org_sig); }