From 472613d973b5ba1454530a819ee99363a0ef4807 Mon Sep 17 00:00:00 2001 From: Twilight Suzuka Date: Mon, 13 Feb 2006 19:31:46 +0000 Subject: [PATCH] Fixed engine and dll bases screwing up. --- dlls/MemHack/MemHack.cpp | 4 +--- dlls/MemHack/MemMisc.cpp | 30 ++++++++++++++++++++---------- dlls/MemHack/MemMisc.h | 6 +++--- dlls/MemHack/MemMiscNatives.cpp | 6 ++++++ 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/dlls/MemHack/MemHack.cpp b/dlls/MemHack/MemHack.cpp index fee0a3de..eb3fd05d 100644 --- a/dlls/MemHack/MemHack.cpp +++ b/dlls/MemHack/MemHack.cpp @@ -13,6 +13,4 @@ void OnAmxxAttach() MF_AddNatives(read_natives); MF_AddNatives(write_natives); MF_AddNatives(misc_natives); -} - - +} \ No newline at end of file diff --git a/dlls/MemHack/MemMisc.cpp b/dlls/MemHack/MemMisc.cpp index 527c1b46..62465a19 100644 --- a/dlls/MemHack/MemMisc.cpp +++ b/dlls/MemHack/MemMisc.cpp @@ -1,24 +1,25 @@ #include "MemConst.h" // Game memory addresses -maddress gameDllAddress; -maddress gameEngAddress; +maddress gameDllAddress = NULL; +maddress gameEngAddress = NULL; -bool GetBaseAddress(void *pAddr, maddress &pBaseAddr) +bool GetBaseAddress(void *pAddr, maddress &pBaseAddr/*, size_t *memLength*/) { #ifdef WIN32 MEMORY_BASIC_INFORMATION mem; if (!VirtualQuery(pAddr, &mem, sizeof(mem))) return false; - if (pBaseAddr) - pBaseAddr = (maddress)mem.AllocationBase; - + pBaseAddr = (maddress)mem.AllocationBase; + IMAGE_DOS_HEADER *dos = (IMAGE_DOS_HEADER *)(mem.AllocationBase); - IMAGE_NT_HEADERS *pe = reinterpret_cast((unsigned long)dos + (unsigned long)dos->e_lfanew); + IMAGE_NT_HEADERS *pe = reinterpret_cast( (unsigned long)dos + (unsigned long)dos->e_lfanew ); if (pe->Signature != IMAGE_NT_SIGNATURE) return false; + //if (memLength) + //*memLength = (size_t)(pe->OptionalHeader.SizeOfImage); return true; #else Dl_info info; @@ -34,9 +35,9 @@ bool GetBaseAddress(void *pAddr, maddress &pBaseAddr) return false; if (pBaseAddr) - pBaseAddr = (maddress)info.dli_fbase; - if (memLength) - *memLength = buf.st_size; + *pBaseAddr = (unsigned char *)info.dli_fbase; + //if (memLength) + //*memLength = buf.st_size; return true; #endif @@ -75,6 +76,15 @@ int MemoryProtect(void *addr, size_t len, unsigned long newProt, unsigned long * return retVal; } +// Linux won't work till I fix it for MEMTYPE_DATA +#ifdef __linux__ + // Data section stuff + maddress dataSectionStart; + maddress dataSectionOffset; + + int pageSize = sysconf(_SC_PAGESIZE); +#endif + /* Gets real memory address */ maddress GetRealMemoryAddress(maddress baseaddress, maddress address, char memType) { diff --git a/dlls/MemHack/MemMisc.h b/dlls/MemHack/MemMisc.h index 751a11c5..73acc070 100644 --- a/dlls/MemHack/MemMisc.h +++ b/dlls/MemHack/MemMisc.h @@ -4,7 +4,7 @@ #include "MemConst.h" #define SAMPLE_DLLFUNC reinterpret_cast(gpGamedllFuncs->dllapi_table->pfnThink) -#define SAMPLE_ENGFUNC reinterpret_cast(*g_engfuncs.pfnChangeLevel) +#define SAMPLE_ENGFUNC reinterpret_cast(g_engfuncs.pfnChangeLevel) extern maddress gameDllAddress; extern maddress gameEngAddress; @@ -26,10 +26,10 @@ inline bool GetBaseAddresses( void ) { bool success = false; - success = GetBaseAddress(SAMPLE_DLLFUNC, gameDllAddress ); + success = GetBaseAddress(SAMPLE_DLLFUNC, gameDllAddress); if(success == false) return false; - success = GetBaseAddress(SAMPLE_ENGFUNC, gameEngAddress ); + success = GetBaseAddress(SAMPLE_ENGFUNC, gameEngAddress); if(success == false) return false; return true; diff --git a/dlls/MemHack/MemMiscNatives.cpp b/dlls/MemHack/MemMiscNatives.cpp index 982917b1..5cd2d4ed 100644 --- a/dlls/MemHack/MemMiscNatives.cpp +++ b/dlls/MemHack/MemMiscNatives.cpp @@ -20,8 +20,14 @@ static cell AMX_NATIVE_CALL memhack_get_realaddr(AMX *amx, cell *params) return (cell)GetRealMemoryAddress(NATIVE_MISC_ADDRESS,NATIVE_MISC_BASEADDRESS,NATIVE_MISC_FLAGS); } +static cell AMX_NATIVE_CALL memhack_return_addr(AMX *amx, cell *params) +{ + return (cell)PickBaseAddress(params[1]); +} + AMX_NATIVE_INFO misc_natives[] = { { "memhack_get_base", memhack_get_base }, { "memhack_get_realaddr", memhack_get_realaddr }, + { "memhack_return_addr", memhack_return_addr }, { NULL, NULL } };