Fixed tags for mmsource-central
mmsource-1.00-RC1 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:41:34 2006 UTC
mmsource-1.00-RC2 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:35:20 2006 UTC
mmsource-1.00 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:30:40 2006 UTC
mmsource-1.1 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:25:09 2006 UTC
mmsource-1.1.1 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:22:23 2006 UTC
mmsource-1.1.2 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:14:00 2006 UTC
mmsource-1.2 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:10:47 2006 UTC
mmsource-1.2.1 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 08:01:35 2006 UTC
mmsource-1.2.2 - Not tagged originally, but eventually done by Scott Ehlert <
[email protected]> on Wed Jul 19 07:57:26 2006 UTC
mmsource-1.2.3 - Not tagged originally, but eventually done by David Anderson <
[email protected]> on Wed Jul 12 17:33:59 2006 UTC
mmsource-1.3 - Originally tagged by Scott Ehlert <
[email protected]> on Thu Aug 17 03:19:55 2006 UTC
mmsource-1.3a - Originally tagged by Scott Ehlert <
[email protected]> on Wed Sep 6 07:17:37 2006 UTC
mmsource-1.3d - Originally tagged by Scott Ehlert <
[email protected]> on Fri Feb 2 05:30:56 2007 UTC
mmsource-1.4 - Originally tagged by Scott Ehlert <
[email protected]> on Sat Apr 7 05:00:28 2007 UTC
mmsource-1.6.0 - Originally tagged by David Anderson <
[email protected]> on Mon Feb 18 23:31:29 2008 UTC
mmsource-1.6.1 - Originally tagged by David Anderson <
[email protected]> on Mon Feb 25 17:15:44 2008 UTC
mmsource-1.6.2 - Originally tagged by David Anderson <
[email protected]> on Sat Jul 26 05:04:35 2008 UTC
1 /* ======== SourceHook ========
2 * Copyright (C) 2004-2008 Metamod:Source Development Team
3 * No warranties of any kind
7 * Author(s): Pavol "PM OnoTo" Marko, Scott "Damaged Soul" Ehlert
8 * Contributors: lancevorgin, XAD, theqizmo
9 * ============================
12 #ifndef __SHINT_MEMORY_H__
13 #define __SHINT_MEMORY_H__
16 // Unprotect now sets to readwrite
17 // The vtable doesn't need to be executable anyway
19 # if /********/ defined _WIN32
21 # define SH_MEM_READ 1
22 # define SH_MEM_WRITE 2
23 # define SH_MEM_EXEC 4
24 # elif /******/ defined __linux__
25 # include <sys/mman.h>
29 // http://www.die.net/doc/linux/man/man2/mprotect.2.html
32 # define PAGESIZE 4096
34 # define SH_MEM_READ PROT_READ
35 # define SH_MEM_WRITE PROT_WRITE
36 # define SH_MEM_EXEC PROT_EXEC
38 // We need to align addr down to pagesize on linux
39 // We assume PAGESIZE is a power of two
40 # define SH_LALIGN(x) (void*)((intptr_t)(x) & ~(PAGESIZE-1))
41 # define SH_LALDIF(x) ((intptr_t)(x) % PAGESIZE)
43 # error Unsupported OS/Compiler
50 inline bool SetMemAccess(void *addr, size_t len, int access)
53 return mprotect(SH_LALIGN(addr), len + SH_LALDIF(addr), access)==0 ? true : false;
60 prot = PAGE_READONLY; break;
61 case SH_MEM_READ | SH_MEM_WRITE:
62 prot = PAGE_READWRITE; break;
63 case SH_MEM_READ | SH_MEM_EXEC:
64 prot = PAGE_EXECUTE_READ; break;
66 case SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC:
67 prot = PAGE_EXECUTE_READWRITE; break;
69 return VirtualProtect(addr, len, prot, &tmp) ? true : false;
77 jmp_buf g_BadReadJmpBuf;
79 static void BadReadHandler(int sig)
82 longjmp(g_BadReadJmpBuf, 1);
88 * @brief Checks whether the specified memory region is (still) accessible
90 * @param addr The lower boundary
91 * @param len Length of the region to be checked
95 bool ModuleInMemory(char *addr, size_t len)
98 // On linux, first check /proc/self/maps
99 long lower = reinterpret_cast<long>(addr);
100 long upper = lower + len;
102 FILE *pF = fopen("/proc/self/maps", "r");
105 // Linux /proc/self/maps -> parse
107 // lower upper prot stuff path
108 // 08048000-0804c000 r-xp 00000000 03:03 1010107 /bin/cat
110 while (fscanf(pF, "%lx-%lx", &rlower, &rupper) != EOF)
112 // Check whether we're IN THERE!
113 if (lower >= rlower && upper <= rupper)
118 // Read to end of line
120 while ((c = fgetc(pF)) != '\n')
131 pF = fopen("/proc/curproc/map", "r");
134 // FreeBSD /proc/curproc/map -> parse
135 // 0x804800 0x805500 13 15 0xc6e18960 r-x 21 0x0 COW NC vnode
137 while (fscanf(pF, "0x%lx 0x%lx", &rlower, &rupper) != EOF)
139 // Check whether we're IN THERE!
140 if (lower >= rlower && upper <= rupper)
145 // Read to end of line
147 while ((c = fgetc(pF)) != '\n')
159 // Both of the above failed, try to actually read and trap sigsegv (implemented by Damaged Soul)
160 void(*prevHandler)(int sig);
161 g_BadReadCalled = true;
163 if (setjmp(g_BadReadJmpBuf))
166 prevHandler = signal(SIGSEGV, BadReadHandler);
168 volatile const char *p = reinterpret_cast<const char*>(addr);
171 for (size_t i = 0; i < len; i++)
174 g_BadReadCalled = false;
176 signal(SIGSEGV, prevHandler);
180 // On Win32, simply use IsBadReadPtr
181 return !IsBadReadPtr(addr, len);