Cstrike: Fix ResolveSymbol misuse under linux/osx.

This commit is contained in:
Arkshine 2014-05-31 20:06:26 +02:00
parent f08a4f5a66
commit c96456503c
2 changed files with 22 additions and 27 deletions

View File

@ -151,8 +151,8 @@
#define CS_SYM_BOTARGS "BotArgs" #define CS_SYM_BOTARGS "BotArgs"
#elif defined __APPLE__ #elif defined __APPLE__
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 5 #define CS_DETOURCOPYBYTES_CLIENTCOMMAND 5
#define CS_SYM_USEBOTARGS "_UseBotArgs" #define CS_SYM_USEBOTARGS "UseBotArgs"
#define CS_SYM_BOTARGS "_BotArgs" #define CS_SYM_BOTARGS "BotArgs"
#else #else
#define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6 #define CS_DETOURCOPYBYTES_CLIENTCOMMAND 6
#define CS_CLICMD_OFFS_USEBOTARGS 2 #define CS_CLICMD_OFFS_USEBOTARGS 2

View File

@ -154,42 +154,37 @@ void CtrlDetours(bool set)
return; return;
} }
void *canBuyThisAddress = NULL;
void *buyItemAddress = NULL;
void *buyGunAmmoAddress = NULL;
#if defined(WIN32) #if defined(WIN32)
void *canBuyThisAddress = g_MemUtils.DecodeAndFindPattern(target, CS_SIG_CANBUYTHIS); canBuyThisAddress = g_MemUtils.DecodeAndFindPattern(target, CS_SIG_CANBUYTHIS);
void *buyItemAddress = g_MemUtils.DecodeAndFindPattern(target, CS_SIG_BUYITEM); buyItemAddress = g_MemUtils.DecodeAndFindPattern(target, CS_SIG_BUYITEM);
void *buyGunAmmoAddress = g_MemUtils.DecodeAndFindPattern(target, CS_SIG_BUYGUNAMMO); buyGunAmmoAddress = g_MemUtils.DecodeAndFindPattern(target, CS_SIG_BUYGUNAMMO);
g_UseBotArgs = *(int **)((unsigned char *)target + CS_CLICMD_OFFS_USEBOTARGS); g_UseBotArgs = *(int **)((unsigned char *)target + CS_CLICMD_OFFS_USEBOTARGS);
g_BotArgs = (const char **)*(const char **)((unsigned char *)target + CS_CLICMD_OFFS_BOTARGS); g_BotArgs = (const char **)*(const char **)((unsigned char *)target + CS_CLICMD_OFFS_BOTARGS);
#elif defined(__linux__) #elif defined(__linux__) || defined(__APPLE__)
void *canBuyThisAddress = g_MemUtils.ResolveSymbol(target, CS_SYM_CANBUYTHIS); Dl_info info;
void *buyItemAddress = g_MemUtils.ResolveSymbol(target, CS_SYM_BUYITEM); void *handle = NULL;
void *buyGunAmmoAddress = g_MemUtils.ResolveSymbol(target, CS_SYM_BUYGUNAMMO);
g_UseBotArgs = (int *)g_MemUtils.ResolveSymbol(target, CS_SYM_USEBOTARGS); if (dladdr(target, &info) == 0) || (handle = dlopen(info.dli_fname, RTLD_NOW)) == NULL)
g_BotArgs = (const char **)g_MemUtils.ResolveSymbol(target, CS_SYM_BOTARGS); {
return;
}
#elif defined(__APPLE__) canBuyThisAddress = g_MemUtils.ResolveSymbol(handle, CS_SYM_CANBUYTHIS);
buyItemAddress = g_MemUtils.ResolveSymbol(handle, CS_SYM_BUYITEM);
buyGunAmmoAddress = g_MemUtils.ResolveSymbol(handle, CS_SYM_BUYGUNAMMO);
struct nlist symbols[6]; g_UseBotArgs = (int *)g_MemUtils.ResolveSymbol(handle, CS_SYM_USEBOTARGS);
memset(symbols, 0, sizeof(symbols)); g_BotArgs = (const char **)g_MemUtils.ResolveSymbol(handle, CS_SYM_BOTARGS);
symbols[0].n_un.n_name = (char *)CS_SYM_CANBUYTHIS; dlclose(handle);
symbols[1].n_un.n_name = (char *)CS_SYM_BUYITEM;
symbols[2].n_un.n_name = (char *)CS_SYM_BUYGUNAMMO;
symbols[3].n_un.n_name = (char *)CS_SYM_USEBOTARGS;
symbols[4].n_un.n_name = (char *)CS_SYM_BOTARGS;
if (nlist(libName, symbols) != 0) { return; }
void *canBuyThisAddress = (void *)(base + symbols[0].n_value);
void *buyItemAddress = (void *)(base + symbols[1].n_value);
void *buyGunAmmoAddress = (void *)(base + symbols[2].n_value);
g_UseBotArgs = (int *)(base + symbols[3].n_value);
g_BotArgs = (const char **)(base + symbols[4].n_value);
#endif #endif
g_ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target); g_ClientCommandDetour = DETOUR_CREATE_STATIC_FIXED(C_ClientCommand, target);