Game Accessibility Library logo SourceForge.net Logo
Game Accessibility Suite: CAT/CATInjectionPropagate.cpp Source File

CATInjectionPropagate.cpp

Go to the documentation of this file.
00001 /// \file  CATInjectionPropagate.cpp
00002 /// \brief Interception of new process creation with injected dll propagation.
00003 /// \ingroup CAT
00004 ///
00005 /// Copyright (c) 2008 by Michael Ellison.
00006 /// See COPYING.txt for the \ref gaslicense License (MIT License).
00007 ///
00008 // $Author: mikeellison $
00009 // $Date: 2008-01-27 01:25:54 -0600 (Sun, 27 Jan 2008) $
00010 // $Revision:   $
00011 // $NoKeywords: $
00012 
00013 #include "CATInjectionPropagate.h"
00014 #ifdef CAT_CONFIG_WIN32
00015 #include "CATString.h"
00016 #include "CATDLLInjector.h"
00017 
00018 // Kernel32 intercepts for time warp
00019 CATINTERCEPT_DLL_TABLE_ENTRY CATInjectionPropagate::kKernel32Funcs[] = 
00020 {
00021     {"CreateProcessW", CATInjectionPropagate::OnCreateProcessW, 5},    
00022     { 0, 0, 0}
00023 };
00024 
00025 CATInjectionPropagate::CATInjectionPropagate(const CATString& dllPath)
00026 {
00027     fDLLPath    = dllPath;
00028     fKernelDLL  = ::LoadLibrary(L"kernel32.dll");    
00029 }
00030 
00031 CATInjectionPropagate::~CATInjectionPropagate()
00032 {
00033     RestoreAll();
00034     if (fKernelDLL)
00035         FreeLibrary(fKernelDLL);
00036 }
00037 
00038 CATResult CATInjectionPropagate::HookFunctions()
00039 {
00040     CATResult result = CAT_SUCCESS;
00041 
00042     result = InterceptDLL(fKernelDLL,&kKernel32Funcs[0],0);
00043     if (CATFAILED(result))
00044         ::OutputDebugString(L"Failed hooking Kernel32.\n");
00045 
00046     return result;
00047 }
00048 
00049 CATHOOKFUNC void CATInjectionPropagate::OnCreateProcessW( 
00050                               CATHOOK*              hookInst,
00051                               LPCWSTR               lpApplicationName,
00052                               LPWSTR                lpCommandLine,
00053                               LPSECURITY_ATTRIBUTES lpProcessAttributes,
00054                               LPSECURITY_ATTRIBUTES lpThreadAttributes,
00055                               BOOL                  bInheritHandles,
00056                               DWORD                 dwCreationFlags,
00057                               LPVOID                lpEnvironment,
00058                               LPCWSTR               lpCurrentDirectory,
00059                               LPSTARTUPINFO         lpStartupInfo,
00060                               LPPROCESS_INFORMATION lpProcessInformation)
00061 {
00062     CATHOOK_PROLOGUE(10);
00063 
00064     // Go ahead and create the process as requested
00065     CATHOOK_CALLORIGINAL_WINAPI(hookInst, 10);
00066     
00067     // Toss the DLL into it :)
00068     ProcessFix(hookInst,lpProcessInformation);
00069 
00070     CATHOOK_EPILOGUE_WINAPI(10);
00071 }
00072 
00073 void CATInjectionPropagate::ProcessFix(CATHOOK*              hookInst,                               
00074                                        LPPROCESS_INFORMATION procInf)
00075 {
00076     if ((procInf) && (procInf->hProcess != 0))
00077     {
00078         CATDLLInjector::InjectIntoProcess(((CATInjectionPropagate*)hookInst->InterceptObj)->fDLLPath,procInf->dwProcessId);
00079     }
00080 }
00081 
00082 
00083 #endif // CAT_CONFIG_WIN32

Generated on Mon Feb 11 04:09:44 2008 for Game Accessibility Suite by doxygen 1.5.4