00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "CATInjectionPropagate.h"
00014 #ifdef CAT_CONFIG_WIN32
00015 #include "CATString.h"
00016 #include "CATDLLInjector.h"
00017
00018
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
00065 CATHOOK_CALLORIGINAL_WINAPI(hookInst, 10);
00066
00067
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