sourcehook/sourcehook.cpp
author Pavol Marko <pavolmarko@gmail.com>
Sat Apr 16 16:55:53 2005 +0000 (2005-04-16)
changeset 6 4803fd7d28bb
parent 1 586787053c73
child 8 07e339563a28
permissions -rw-r--r--
Added possibility to specify your own g_SHPtr / g_Plug, removed all occurencies of The Word, fixed UnloadPlugin and CompleteShutdown
     1 /* ======== SourceHook ========
     2 * By PM
     3 * No warranties of any kind
     4 * ============================
     5 */
     6 
     7 /**
     8 *	@file sourcehook.cpp
     9 *	@brief Contains the implementation of the SourceHook API
    10 */
    11 
    12 #include <algorithm>
    13 #include "sourcehook_impl.h"
    14 
    15 #if SH_SYS == SH_SYS_WIN32
    16 # include <windows.h>
    17 #elif SH_SYS == SH_SYS_LINUX
    18 # include <sys/mman.h>
    19 # include <sys/limits.h>
    20 # include <unistd.h>
    21 # ifndef PAGESIZE
    22 #  define PAGESIZE 4096
    23 # endif
    24 #endif
    25 
    26 #if SH_RUNTIME_CODEGEN == 1
    27 # if SH_COMP == SH_COMP_GCC
    28 #  define SH_CCC_CODESIZE 15
    29 	//	 :TODO:
    30 	//void SH_CCC_MakeGate(void *origthisptr, unsigned char* &ptr, void *origvtable, int i)
    31 	//{
    32 	//}
    33 # elif SH_COMP == SH_COMP_MSVC
    34 #  define SH_CCC_CODESIZE 19
    35 	void SH_CCC_MakeGate(void *origthisptr, void *ccthisptr, unsigned char* ptr, void *origfunc)
    36 	{
    37 		// --Subtract old this pointer to get the offset
    38 		// 00417EDF 81 E9 A1 7B 33 01 sub         ecx,1337BA1h 
    39 		*ptr++ = 0x81;
    40 		*ptr++ = 0xE9;
    41 		*reinterpret_cast<void**>(ptr) = ccthisptr;
    42 		ptr += sizeof(void*);
    43 		// --Add it to the new this pointer
    44 		// 00417EE5 81 C1 37 13 37 13 add         ecx,13371337h 
    45 		*ptr++ = 0x81;
    46 		*ptr++ = 0xC1;
    47 		*reinterpret_cast<void**>(ptr) = origthisptr;
    48 		ptr += sizeof(void*);
    49 		// --Prepare address
    50 		// 00417EEB B8 EF BE AD DE   mov         eax,0DEADBEEFh 
    51 		*ptr++ = 0xB8;
    52 		*reinterpret_cast<void**>(ptr) = origfunc;
    53 		ptr += sizeof(void*);
    54 		// -- Do actual jump
    55 		// 00417EF0 FF E0            jmp         eax  
    56 		*ptr++ = 0xFF;
    57 		*ptr++ = 0xE0;
    58 	}
    59 # endif
    60 #endif
    61 
    62 
    63 namespace SourceHook
    64 {
    65 	CSourceHookImpl::CSourceHookImpl()
    66 	{
    67 		// Get page size
    68 #if SH_SYS == SH_SYS_WIN32
    69 		SYSTEM_INFO sysinfo;
    70 		GetSystemInfo(&sysinfo);
    71 		m_PageSize = sysinfo.dwPageSize;
    72 #elif SH_SYS == SH_SYS_LINUX
    73 		m_PageSize = PAGESIZE;
    74 #else
    75 # error Unsupported system
    76 #endif
    77 	}
    78 
    79 	CSourceHookImpl::~CSourceHookImpl()
    80 	{
    81 
    82 	}
    83 
    84 	bool CSourceHookImpl::IsPluginInUse(Plugin plug)
    85 	{
    86 		// Iterate through all hook managers which are in this plugin
    87 		// Iterate through their hooks
    88 		// If a hook from an other plugin is found, return true
    89 		// Return false otherwise
    90 
    91 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
    92 		{
    93 			if (iter->plug == plug && !iter->ifaces.empty())
    94 			{
    95 				for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end(); ++iter2)
    96 				{
    97 					std::list<HookManagerInfo::Iface::Hook>::iterator iter3;
    98 					for (iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
    99 						if (iter3->plug == plug)
   100 							return true;
   101 					for (iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   102 						if (iter3->plug == plug)
   103 							return true;
   104 				}
   105 			}
   106 		}
   107 		return false;
   108 	}
   109 
   110 	void CSourceHookImpl::UnloadPlugin(Plugin plug)
   111 	{
   112 		// 1) Manually remove all hooks by this plugin
   113 		std::list<RemoveHookInfo> hookstoremove;
   114 
   115 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
   116 		{
   117 			for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   118 				++iter2)
   119 			{
   120 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
   121 					if (iter3->plug == plug)
   122 						hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, false));
   123 
   124 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   125 					if (iter3->plug == plug)
   126 						hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, true));
   127 			}
   128 		}
   129 
   130 		for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
   131 			RemoveHook(rmiter->plug, rmiter->iface, rmiter->hpf, rmiter->handler, rmiter->post);
   132 
   133 		// 2) Other plugins may use hook managers in this plugin.
   134 		// Get a list of hook managers that are in this plugin and are used by other plugins
   135 		// Delete all hook managers that are in this plugin
   136 
   137 		HookManInfoList tmphookmans;
   138 		bool erase = false;
   139 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end();
   140 			erase ? iter=m_HookMans.erase(iter) : ++iter)
   141 		{
   142 			if (iter->plug == plug)
   143 			{
   144 				if (!iter->ifaces.empty())
   145 				{
   146 					// All hooks by this plugin are already removed
   147 					// So if there is an iface, it has to be used by an other plugin
   148 					tmphookmans.push_back(*iter);
   149 				}
   150 				erase = true;
   151 			}
   152 			else
   153 				erase = false;
   154 		}
   155 		
   156 		// For each hook manager:
   157 		for (HookManInfoList::iterator iter = tmphookmans.begin(); iter != tmphookmans.end(); ++iter)
   158 		{
   159 			// Find a suitable hook manager in an other plugin
   160 			HookManInfoList::iterator newHookMan = FindHookMan(m_HookMans.begin(), m_HookMans.end(),
   161 				iter->proto, iter->vtbl_offs, iter->vtbl_idx, iter->thisptr_offs);
   162 			if (newHookMan == m_HookMans.end())
   163 			{
   164 				// This should _never_ happen.
   165 				// If there is a hook from an other plugin, the plugin must have provided a hook manager as well.
   166 				SH_ASSERT(0);
   167 			}
   168 
   169 			// AddHook should make sure that every plugin only has _one_ hook manager for _one_ proto/vi/vo/thisptroffs
   170 			SH_ASSERT(newHookMan->plug != plug);
   171 
   172 			// The first hooker should be always used - so the new hook manager has to be empty
   173 			SH_ASSERT(newHookMan->ifaces.empty());
   174 
   175 			// Move the ifaces from the old hook manager to the new one
   176 			newHookMan->ifaces = iter->ifaces;
   177 
   178 			// Unregister the old one, register the new one
   179 			iter->func(HA_Unregister, NULL);
   180 			newHookMan->func(HA_Register, &(*newHookMan));
   181 		}
   182 	}
   183 
   184 	void CSourceHookImpl::CompleteShutdown()
   185 	{
   186 		std::list<RemoveHookInfo> hookstoremove;
   187 
   188 		for (HookManInfoList::iterator iter = m_HookMans.begin(); iter != m_HookMans.end(); ++iter)
   189 		{
   190 			for (std::list<HookManagerInfo::Iface>::iterator iter2 = iter->ifaces.begin(); iter2 != iter->ifaces.end();
   191 				++iter2)
   192 			{
   193 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_pre.begin(); iter3 != iter2->hooks_pre.end(); ++iter3)
   194 					hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, false));
   195 				
   196 				for (std::list<HookManagerInfo::Iface::Hook>::iterator iter3 = iter2->hooks_post.begin(); iter3 != iter2->hooks_post.end(); ++iter3)
   197 					hookstoremove.push_back(RemoveHookInfo(iter3->plug, iter2->ptr, iter->func, iter3->handler, true));
   198 			}
   199 		}
   200 
   201 		for (std::list<RemoveHookInfo>::iterator rmiter = hookstoremove.begin(); rmiter != hookstoremove.end(); ++rmiter)
   202 			RemoveHook(rmiter->plug, rmiter->iface, rmiter->hpf, rmiter->handler, rmiter->post);
   203 
   204 		m_HookMans.clear();
   205 	}
   206 
   207 	bool CSourceHookImpl::AddHook(Plugin plug, void *iface, int ifacesize, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post)
   208 	{
   209 		// 1) Get info about the hook manager
   210 		HookManagerInfo tmp;
   211 		if (myHookMan(HA_GetInfo, &tmp) != 0)
   212 			return false;
   213 
   214 		// Add the proposed hook manager to the _end_ of the list if the plugin doesn't have a hook manager with this proto/vo/vi registered
   215 		HookManInfoList::iterator hookmaniter;
   216 		for (hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   217 		{
   218 			if (hookmaniter->plug == plug && strcmp(hookmaniter->proto, tmp.proto) == 0 &&
   219 				hookmaniter->vtbl_offs == tmp.vtbl_offs && hookmaniter->vtbl_idx == tmp.vtbl_idx &&
   220 				hookmaniter->thisptr_offs == tmp.thisptr_offs)
   221 				break;
   222 		}
   223 		if (hookmaniter == m_HookMans.end())
   224 		{
   225 			// No such hook manager from this plugin yet, add it!
   226 			tmp.func = myHookMan;
   227 			tmp.plug = plug;
   228 			m_HookMans.push_back(tmp);
   229 		}
   230 
   231 		// Then, search for a suitable hook manager (from the beginning)
   232 		HookManInfoList::iterator hookman = FindHookMan(m_HookMans.begin(), m_HookMans.end(), tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   233 		SH_ASSERT(hookman != m_HookMans.end());
   234 
   235 		// Tell it to store the pointer if it's not already active
   236 		if (hookman->ifaces.empty())
   237 			hookman->func(HA_Register, &(*hookman));
   238 
   239 		std::list<HookManagerInfo::Iface>::iterator ifsiter = std::find(hookman->ifaces.begin(), hookman->ifaces.end(), iface);
   240 
   241 		if (ifsiter == hookman->ifaces.end())
   242 		{
   243 			HookManagerInfo::Iface ifs;
   244 			ifs.ptr = iface;
   245 			ifs.callclass = GetCallClass(iface, ifacesize);
   246 			void *vtableptr = *reinterpret_cast<void**>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs);
   247 			SetMemAccess(vtableptr, sizeof(void*) * hookman->vtbl_idx, SH_MEM_READ | SH_MEM_WRITE);
   248 			ifs.orig_entry = (*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs))[hookman->vtbl_idx];
   249 			(*reinterpret_cast<void***>(reinterpret_cast<char*>(iface) + hookman->vtbl_offs))[hookman->vtbl_idx] =
   250 				(*reinterpret_cast<void***>(reinterpret_cast<char*>(hookman->hookfunc_inst) + hookman->hookfunc_vtbl_offs))[hookman->hookfunc_vtbl_idx];
   251 			hookman->ifaces.push_back(ifs);
   252 			ifsiter = hookman->ifaces.end();
   253 			--ifsiter;
   254 		}
   255 		HookManagerInfo::Iface::Hook hookinfo;
   256 		hookinfo.handler = handler;
   257 		hookinfo.plug = plug;
   258 		if (post)
   259    			ifsiter->hooks_post.push_back(hookinfo);
   260 		else
   261 			ifsiter->hooks_pre.push_back(hookinfo);
   262 
   263 
   264 		// Now that it is done, check whether we have to update any callclasses
   265 		for (Impl_CallClassList::iterator cciter = m_CallClasses.begin(); cciter != m_CallClasses.end(); ++cciter)
   266 		{
   267 			if (cciter->iface == iface)
   268 			{
   269 				ApplyCallClassPatch(*cciter, tmp.vtbl_offs, tmp.vtbl_idx, ifsiter->orig_entry);
   270 
   271 				// We can assume that there is no more callclass with the same iface
   272 				break;
   273 			}
   274 		}
   275 
   276 		return true;
   277 	}
   278 
   279 	bool CSourceHookImpl::RemoveHook(Plugin plug, void *iface, HookManagerPubFunc myHookMan, ISHDelegate *handler, bool post)
   280 	{
   281 		HookManagerInfo tmp;
   282 		if (myHookMan(HA_GetInfo, &tmp) != 0)
   283 			return false;
   284 
   285 		// Find the hook manager and the hook
   286 		HookManInfoList::iterator hookman = FindHookMan(m_HookMans.begin(), m_HookMans.end(), 
   287 			tmp.proto, tmp.vtbl_offs, tmp.vtbl_idx, tmp.thisptr_offs);
   288 		if (hookman == m_HookMans.end())
   289 			return false;
   290 
   291 		for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookman->ifaces.begin(); ifaceiter != hookman->ifaces.end(); ++ifaceiter)
   292 		{
   293 			if (ifaceiter->ptr == iface)
   294 			{
   295 				std::list<HookManagerInfo::Iface::Hook> &hooks = post ? ifaceiter->hooks_post : ifaceiter->hooks_pre;
   296 				bool erase;
   297 				for (std::list<HookManagerInfo::Iface::Hook>::iterator hookiter = hooks.begin();
   298 					hookiter != hooks.end(); erase ? hookiter = hooks.erase(hookiter) : ++hookiter)
   299 				{
   300 					erase = hookiter->plug == plug && hookiter->handler->IsEqual(handler);
   301 					if (erase)
   302 						hookiter->handler->DeleteThis();			// Make the _plugin_ delete the handler object
   303 				}
   304 				if (ifaceiter->hooks_post.empty() && ifaceiter->hooks_pre.empty())
   305 				{
   306 					// Deactivate the hook
   307 					(*reinterpret_cast<void***>(reinterpret_cast<char*>(ifaceiter->ptr) +
   308 						hookman->vtbl_offs))[hookman->vtbl_idx]= ifaceiter->orig_entry;
   309 
   310 					// Release the callclass
   311 					ReleaseCallClass(ifaceiter->callclass);
   312 
   313 					// Remove the iface info
   314 					hookman->ifaces.erase(ifaceiter);
   315 
   316 					if (hookman->ifaces.empty())
   317 						hookman->func(HA_Unregister, NULL);
   318 				}
   319 				// :TODO: Better return value? Or none?
   320 				return true;
   321 			}
   322 		}
   323 		return false;
   324 	}
   325 
   326 	void *CSourceHookImpl::GetCallClass(void *iface, size_t size)
   327 	{
   328 		for (Impl_CallClassList::iterator cciter = m_CallClasses.begin(); cciter != m_CallClasses.end(); ++cciter)
   329 		{
   330 			if (cciter->iface == iface)
   331 			{
   332 				++cciter->refcounter;
   333 				return cciter->ptr;
   334 			}
   335 		}
   336 
   337 		// The layout of callclasses is:
   338 		//  Copy of the class; vtable entries pointing to gates
   339 		//  Pointer to the corresponding CallClass object
   340 		//  Copy of the class; vtable entries pointing to original functions
   341 
   342 		CallClass tmp;
   343 		char *ptr = new char[size * 2 + sizeof(void*)];
   344 		tmp.ptr = reinterpret_cast<void*>(ptr);
   345 		memcpy(reinterpret_cast<void*>(ptr), iface, size);
   346 		memcpy(reinterpret_cast<void*>(ptr + size + sizeof(void*)), iface, size);
   347 		tmp.iface = iface;
   348 		tmp.size = size;
   349 		tmp.refcounter = 1;
   350 
   351 		// Go through _all_ hooks and apply any needed patches
   352 		for (HookManInfoList::iterator hookman = m_HookMans.begin(); hookman != m_HookMans.end(); ++hookman)
   353 		{
   354 			for (std::list<HookManagerInfo::Iface>::iterator ifaceiter = hookman->ifaces.begin(); ifaceiter != hookman->ifaces.end(); ++ifaceiter)
   355 			{
   356 				if (ifaceiter->ptr == iface)
   357 				{
   358 					if (!ApplyCallClassPatch(tmp, hookman->vtbl_offs, hookman->vtbl_idx, ifaceiter->orig_entry))
   359 					{
   360 						FreeCallClass(tmp);
   361 						return NULL;
   362 					}
   363 				}
   364 			}
   365 		}
   366 		m_CallClasses.push_back(tmp);
   367 		// The object has to be followed by the pointer to the vtable info object
   368 		*reinterpret_cast<void**>(ptr + size) = &m_CallClasses.back();
   369 		return tmp.ptr;
   370 	}
   371 
   372 	void CSourceHookImpl::ReleaseCallClass(void *ptr)
   373 	{
   374 		Impl_CallClassList::iterator iter = std::find(m_CallClasses.begin(), m_CallClasses.end(), ptr);
   375 		if (iter == m_CallClasses.end())
   376 			return;
   377 		--iter->refcounter;
   378 		if (iter->refcounter < 1)
   379 		{
   380 			FreeCallClass(*iter);
   381 			m_CallClasses.erase(iter);
   382 		}
   383 	}
   384 
   385 	void CSourceHookImpl::FreeCallClass(CallClass &cc)
   386 	{
   387 		for (CallClass::VTableList::iterator vtbliter = cc.vtables.begin(); vtbliter != cc.vtables.end(); ++vtbliter)
   388 		{
   389 #if SH_RUNTIME_CODEGEN == 1
   390 			// Delete generated callgates
   391 			for (std::list<int>::iterator cgiter = vtbliter->patches.begin(); cgiter != vtbliter->patches.end(); ++cgiter)
   392 			{
   393 				char *cgptr = reinterpret_cast<char**>(vtbliter->ptr)[*cgiter];
   394 				delete [] cgptr;
   395 			}
   396 #endif
   397 			delete [] reinterpret_cast<char*>(vtbliter->ptr);
   398 		}
   399 		delete [] reinterpret_cast<char*>(cc.ptr);
   400 	}
   401 
   402 	bool CSourceHookImpl::ApplyCallClassPatch(CallClass &cc, int vtbl_offs, int vtbl_idx, void *orig_entry)
   403 	{
   404 		char *ptr = reinterpret_cast<char*>(cc.ptr);
   405 		void *vtable = *reinterpret_cast<void**>(ptr + vtbl_offs);
   406 
   407 		// Check whether we already know that vtable
   408 		CallClass::VTableList::iterator vtbliter = std::find(cc.vtables.begin(),
   409 			cc.vtables.end(), reinterpret_cast<void*>(vtable));
   410 		int actvtablesize=MAX_VTABLE_LEN;
   411 		if (vtbliter == cc.vtables.end())
   412 		{
   413 			CallClass::VTable newvtableinfo;
   414 			int pagesnum = (MAX_VTABLE_LEN % m_PageSize == 0) ? MAX_VTABLE_LEN / m_PageSize : MAX_VTABLE_LEN / m_PageSize + 1;
   415 			// Set all pages in the range to readwrite
   416 			// :TODO: Fix this!
   417 			char *pagebegin = reinterpret_cast<char*>(vtable) - (reinterpret_cast<int>(vtable) % m_PageSize);
   418 			for (int ipage = 0; ipage < pagesnum; ++ipage)
   419 			{
   420 				if (!SetMemAccess(reinterpret_cast<void*>(pagebegin + ipage * m_PageSize), 1,
   421 					SH_MEM_READ | SH_MEM_WRITE))
   422 				{
   423 					// We can't go here anymore
   424 					actvtablesize = static_cast<int>((pagebegin + ipage * m_PageSize) - reinterpret_cast<char*>(vtable));
   425 					break;
   426 				}
   427 			}
   428 			if (actvtablesize < 1)
   429 			{
   430 				// We can't access the vtable -> Quit
   431 				return false;
   432 			}
   433 			// Create a new vtable
   434 			newvtableinfo.ptr = reinterpret_cast<void*>(new char[actvtablesize]);
   435 			// Fill it with the information from the old vtable
   436 			memcpy(newvtableinfo.ptr, vtable, actvtablesize);
   437 			newvtableinfo.actsize = actvtablesize;
   438 			// Set the pointer in the object and add it to the list of already known vtables
   439 			*reinterpret_cast<void**>(ptr + vtbl_offs) = newvtableinfo.ptr;
   440 			cc.vtables.push_back(newvtableinfo);
   441 
   442 			vtbliter = cc.vtables.end();
   443 			--vtbliter;
   444 			// :TODO: When not codegen, patch the other vtable?
   445 		}
   446 
   447 		// Check whether we already have this patch
   448 		if (std::find(vtbliter->patches.begin(), vtbliter->patches.end(), vtbl_idx) == vtbliter->patches.end())
   449 		{
   450 			// No -> apply it
   451 
   452 			// Get a call gate
   453 			void *callgate = NULL;
   454 #if SH_RUNTIME_CODEGEN == 1
   455 			unsigned char *cggen = new unsigned char[SH_CCC_CODESIZE];
   456 			SH_CCC_MakeGate(cc.iface, cc.ptr, cggen, orig_entry);
   457 			callgate = (void*)cggen;
   458 			SetMemAccess(callgate, SH_CCC_CODESIZE, SH_MEM_READ | SH_MEM_WRITE | SH_MEM_EXEC);
   459 #else
   460 			// :TODO:
   461 #error Not supported yet!
   462 #endif
   463 			vtbliter->patches.push_back(vtbl_idx);
   464 			reinterpret_cast<void**>(vtbliter->ptr)[vtbl_idx] = callgate;
   465 		}
   466 		return true;
   467 	}
   468 
   469 
   470 	CSourceHookImpl::HookManInfoList::iterator CSourceHookImpl::FindHookMan(HookManInfoList::iterator begin,
   471 		HookManInfoList::iterator end, const char *proto, int vtblofs, int vtblidx, int thisptrofs)
   472 	{
   473 		for (HookManInfoList::iterator hookmaniter = m_HookMans.begin(); hookmaniter != m_HookMans.end(); ++hookmaniter)
   474 		{
   475 			if (strcmp(hookmaniter->proto, proto) == 0 && hookmaniter->vtbl_offs == vtblofs && hookmaniter->vtbl_idx == vtblidx &&
   476 				hookmaniter->thisptr_offs == thisptrofs)
   477 				break;
   478 		}
   479 		return hookmaniter;
   480 	}
   481 
   482 
   483 	void CSourceHookImpl::SetRes(META_RES res)
   484 	{
   485 		m_CurRes = res;
   486 	}
   487 
   488 	META_RES CSourceHookImpl::GetPrevRes()
   489 	{
   490 		return m_PrevRes;
   491 	}
   492 
   493 	META_RES CSourceHookImpl::GetStatus()
   494 	{
   495 		return m_Status;
   496 	}
   497 
   498 	const void *CSourceHookImpl::GetOrigRet()
   499 	{
   500 		return m_OrigRet;
   501 	}
   502 
   503 	const void *CSourceHookImpl::GetOverrideRet()
   504 	{
   505 		return m_OverrideRet;
   506 	}
   507 
   508 	META_RES &CSourceHookImpl::GetCurResRef()
   509 	{
   510 		return m_CurRes;
   511 	}
   512 
   513 	META_RES &CSourceHookImpl::GetPrevResRef()
   514 	{
   515 		return m_PrevRes;
   516 	}
   517 
   518 	META_RES &CSourceHookImpl::GetStatusRef()
   519 	{
   520 		return m_Status;
   521 	}
   522 
   523 	void CSourceHookImpl::SetOrigRet(const void *ptr)
   524 	{
   525 		m_OrigRet = ptr;
   526 	}
   527 
   528 	void CSourceHookImpl::SetOverrideRet(const void *ptr)
   529 	{
   530 		m_OverrideRet = ptr;
   531 	}
   532 
   533 	void CSourceHookImpl::SetIfacePtr(void *ptr)
   534 	{
   535 		m_IfacePtr = ptr;
   536 	}
   537 	void *CSourceHookImpl::GetIfacePtr()
   538 	{
   539 		return m_IfacePtr;
   540 	}
   541 }