tools/gdc-psyfork/MemoryUtils.h
author Ruben Gonzalez <drifter01620@gmail.com>
Thu May 22 09:49:27 2014 -0400 (2014-05-22)
changeset 4378 568f4497ef4a
parent 3574 b51285ca203f
permissions -rw-r--r--
Update CS:GO team score gamedata.
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2010 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 <string.h>
    35 #include <vector>
    36 #if defined PLATFORM_LINUX || defined PLATFORM_APPLE
    37 #include "sm_symtable.h"
    38 #include <unistd.h>
    39 
    40 #endif
    41 
    42 using namespace SourceMod;
    43 using std::vector;
    44 
    45 struct DynLibInfo
    46 {
    47 	void *baseAddress;
    48 	size_t memorySize;
    49 };
    50 
    51 #if defined PLATFORM_LINUX || defined PLATFORM_APPLE
    52 struct LibSymbolTable
    53 {
    54 	SymbolTable table;
    55 	AddrTable table2;
    56 	uintptr_t lib_base;
    57 	uint32_t last_pos;
    58 };
    59 #endif
    60 
    61 class MemoryUtils
    62 {
    63 public:
    64 	MemoryUtils();
    65 	~MemoryUtils();
    66 public: // IMemoryUtils
    67 	void *FindPattern(const void *libPtr, const char *pattern, size_t len, int &matches, bool &atFuncStart);
    68 	void *ResolveSymbol(void *handle, const char *symbol);
    69 	const char *ResolveAddr(void *handle, void *addr);
    70 public:
    71 	void *FindPatternInFile(int fd, const char *pattern, size_t len, int &matches, bool &atFuncStart);
    72 	bool GetLibraryInfo(const void *libPtr, DynLibInfo &lib);
    73 #if defined PLATFORM_LINUX || defined PLATFORM_APPLE
    74 private:
    75 	vector<LibSymbolTable *> m_SymTables;
    76 #ifdef PLATFORM_APPLE
    77 	struct dyld_all_image_infos *m_ImageList;
    78 #endif
    79 #endif
    80 };
    81 
    82 #endif // _INCLUDE_SOURCEMOD_MEMORYUTILS_H_