core/MemoryUtils.h
author Nicholas Hastings <skamonkey@gmail.com>
Mon Feb 08 19:57:20 2010 -0800 (2010-02-08)
changeset 2914 bf5f9aa53abe
parent 2863 d740d9cdf53a
child 2992 affc67b319f4
permissions -rw-r--r--
Fixed FindEntityByClassname crash in Synergy (bug 4235, r=dvander).
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2000 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  */
    29 
    30 #ifndef _INCLUDE_SOURCEMOD_MEMORYUTILS_H_
    31 #define _INCLUDE_SOURCEMOD_MEMORYUTILS_H_
    32 
    33 #include <IMemoryUtils.h>
    34 #include "sm_globals.h"
    35 #ifdef PLATFORM_LINUX
    36 #include <sh_vector.h>
    37 #include "sm_symtable.h"
    38 
    39 using namespace SourceHook;
    40 #endif
    41 
    42 using namespace SourceMod;
    43 
    44 struct DynLibInfo
    45 {
    46 	void *baseAddress;
    47 	size_t memorySize;
    48 };
    49 
    50 #ifdef PLATFORM_LINUX
    51 typedef uint32_t Elf32_Addr;
    52 
    53 struct LibSymbolTable
    54 {
    55 	SymbolTable table;
    56 	Elf32_Addr lib_base;
    57 	uint32_t last_pos;
    58 };
    59 #endif
    60 
    61 class MemoryUtils : 
    62 	public IMemoryUtils,
    63 	public SMGlobalClass
    64 {
    65 public:
    66 	~MemoryUtils();
    67 public: // SMGlobalClass
    68 	void OnSourceModAllInitialized();
    69 public: // IMemoryUtils
    70 	void *FindPattern(const void *libPtr, const char *pattern, size_t len);
    71 	void *ResolveSymbol(void *handle, const char *symbol);
    72 public:
    73 	bool GetLibraryInfo(const void *libPtr, DynLibInfo &lib);
    74 #ifdef PLATFORM_LINUX
    75 private:
    76 	CVector<LibSymbolTable *> m_SymTables;
    77 #endif
    78 };
    79 
    80 extern MemoryUtils g_MemUtils;
    81 
    82 #endif // _INCLUDE_SOURCEMOD_MEMORYUTILS_H_