fixed inheritance not being used in the base menu style when removing clients from the watch list
3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #include "MemoryUtils.h"
22 MemoryUtils g_MemUtils;
25 MemoryUtils::MemoryUtils()
27 #ifdef PLATFORM_WINDOWS
32 m_PageSize = info.dwPageSize;
34 #elif defined PLATFORM_POSIX
36 m_PageSize = sysconf(_SC_PAGE_SIZE);
42 void MemoryUtils::OnSourceModAllInitialized()
44 g_ShareSys.AddInterface(NULL, this);
47 void *MemoryUtils::FindPattern(const void *libPtr, const char *pattern, size_t len)
53 memset(&lib, 0, sizeof(DynLibInfo));
55 if (!GetLibraryInfo(libPtr, lib))
60 ptr = reinterpret_cast<char *>(lib.baseAddress);
61 end = ptr + lib.memorySize;
66 for (register size_t i = 0; i < len; i++)
68 if (pattern[i] != '\x2A' && pattern[i] != ptr[i])
84 bool MemoryUtils::GetLibraryInfo(const void *libPtr, DynLibInfo &lib)
86 unsigned long baseAddr;
93 #ifdef PLATFORM_WINDOWS
95 MEMORY_BASIC_INFORMATION info;
96 IMAGE_DOS_HEADER *dos;
98 IMAGE_FILE_HEADER *file;
99 IMAGE_OPTIONAL_HEADER *opt;
101 if (!VirtualQuery(libPtr, &info, sizeof(MEMORY_BASIC_INFORMATION)))
106 baseAddr = reinterpret_cast<unsigned long>(info.AllocationBase);
108 /* All this is for our insane sanity checks :o */
109 dos = reinterpret_cast<IMAGE_DOS_HEADER *>(baseAddr);
110 pe = reinterpret_cast<IMAGE_NT_HEADERS *>(baseAddr + dos->e_lfanew);
111 file = &pe->FileHeader;
112 opt = &pe->OptionalHeader;
114 /* Check PE magic and signature */
115 if (dos->e_magic != IMAGE_DOS_SIGNATURE || pe->Signature != IMAGE_NT_SIGNATURE || opt->Magic != IMAGE_NT_OPTIONAL_HDR32_MAGIC)
120 /* Check architecture, which is 32-bit/x86 right now
121 * Should change this for 64-bit if Valve gets their act together
123 if (file->Machine != IMAGE_FILE_MACHINE_I386)
128 /* For our purposes, this must be a dynamic library */
129 if ((file->Characteristics & IMAGE_FILE_DLL) == 0)
134 /* Finally, we can do this */
135 lib.memorySize = opt->SizeOfImage;
137 #elif defined PLATFORM_LINUX
144 if (!dladdr(libPtr, &info))
149 if (!info.dli_fbase || !info.dli_fname)
154 /* This is for our insane sanity checks :o */
155 baseAddr = reinterpret_cast<unsigned long>(info.dli_fbase);
156 file = reinterpret_cast<Elf32_Ehdr *>(baseAddr);
158 /* Check ELF magic */
159 if (memcmp(ELFMAG, file->e_ident, SELFMAG) != 0)
164 /* Check ELF version */
165 if (file->e_ident[EI_VERSION] != EV_CURRENT)
170 /* Check ELF architecture, which is 32-bit/x86 right now
171 * Should change this for 64-bit if Valve gets their act together
173 if (file->e_ident[EI_CLASS] != ELFCLASS32 || file->e_machine != EM_386 || file->e_ident[EI_DATA] != ELFDATA2LSB)
178 /* For our purposes, this must be a dynamic library/shared object */
179 if (file->e_type != ET_DYN)
184 phdrCount = file->e_phnum;
185 phdr = reinterpret_cast<Elf32_Phdr *>(baseAddr + file->e_phoff);
187 /* Add up the memory sizes of segments marked as PT_LOAD as those are the only ones that should be in memory */
188 for (uint16_t i = 0; i < phdrCount; i++)
190 Elf32_Phdr &hdr = phdr[i];
192 if (hdr.p_type == PT_LOAD)
194 lib.memorySize += hdr.p_memsz;
200 lib.baseAddress = reinterpret_cast<void *>(baseAddr);