1 #ifndef NCBI_WIN_HOOK__HPP
2 #define NCBI_WIN_HOOK__HPP
41 #if defined(NCBI_OS_MSWIN)
63 virtual const char* GetErrCodeString(
void)
const;
75 int my_stricmp(
const char* left,
const char* right);
87 PCSTR pszCalleeModName,
110 num += it->second.size();
119 HMODULE hmodOriginal,
120 DWORD dwFuncOrdinalNum,
125 PCSTR pszCalleeModName,
126 DWORD dwFuncOrdinalNum,
130 HMODULE hmodOriginal,
131 DWORD dwFuncOrdinalNum,
249 typedef void (*TFunct) (void);
254 bool Add(TFunct funct);
255 void Remove(TFunct funct);
263 static void WINAPI xs_ExitProcess(
UINT uExitCode);
Helper class for object allocation/deallocation.
#define ITERATE(Type, Var, Cont)
ITERATE macro to sequence through container elements.
EErrCode
Error types that an application can generate.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
#define NCBI_DBAPIDRIVER_EXPORT
BOOL UnHookImport(PCSTR pszCalleeModName, PCSTR pszFuncName)
Restore hooked up API function.
void WINAPI HackModuleOnLoad(HMODULE hmod, DWORD dwFlags)
Used when a DLL is newly loaded after hooking a function.
BOOL m_bSystemFuncsHooked
Determines whether all system functions has been successfuly hacked.
void UnHookAllFuncs(void)
void operator=(const CApiHookMgr &)
int my_stricmp(const char *left, const char *right)
map< void *, TFunctionList > TModuleList
vector< TFunct > TRegistry
static FARPROC WINAPI xs_GetProcAddressWindows(HMODULE hmod, PCSTR pszProcName)
Returns original address of the API function.
CHookedFunctions m_pHookedFunctions
Container keeps track of all hacked functions.
void x_GetFunctionNameByOrdinal(PCSTR pszCalleeModName, DWORD dwFuncOrdinalNum, PSTR pszFuncName) const
Return the name of the function by its ordinal value.
CRef< CHookedFunction > GetHookedFunction(HMODULE hmod, PCSTR pszFuncName) const
Return the address of an CHookedFunction object Protected version.
BOOL HookImport(PCSTR pszCalleeModName, PCSTR pszFuncName, PROC pfnHook)
Hook up an API.
static HMODULE WINAPI MyLoadLibraryExW(PCWSTR pszModuleName, HANDLE hFile, DWORD dwFlags)
Used to trap events when DLLs are loaded.
bool HaveHookedFunctions(void) const
Indicates whether there is hooked function.
static HMODULE WINAPI MyLoadLibraryW(PCWSTR pszModuleName)
Used to trap events when DLLs are loaded.
bool operator()(const string &x, const string &y) const
NCBI_EXCEPTION_DEFAULT(CWinHookException, CCoreException)
static FARPROC WINAPI MyGetProcAddress(HMODULE hmod, PCSTR pszProcName)
Returns address of replacement function if hooked function is requested.
void x_UnHookAllFuncs(void)
Unhook all functions and restore original ones.
map< string, TFunctionList, SNocaseCmp > TModuleNameList
TModuleNameList m_ModuleNameList
CRef< CHookedFunction > GetHookedFunction(PCSTR pszCalleeModName, PCSTR pszFuncName) const
Return the address of an CHookedFunction object.
map< string, CRef< CHookedFunction >, SNocaseCmp > TFunctionList
static HMODULE WINAPI MyLoadLibraryExA(PCSTR pszModuleName, HANDLE hFile, DWORD dwFlags)
Used to trap events when DLLs are loaded.
BOOL RemoveHook(const CRef< CHookedFunction > pHook)
Remove exising object pointer from the container.
BOOL x_RemoveHook(PCSTR pszCalleeModName, PCSTR pszFuncName)
Remove intercepted function from the container.
BOOL x_GetFunctionNameFromExportSection(HMODULE hmodOriginal, DWORD dwFuncOrdinalNum, PSTR pszFuncName) const
Return the name of the function from EAT by its ordinal value.
bool HaveHookedFunctions(void) const
BOOL x_HookSystemFuncs(void)
Hook all needed system functions in order to trap loading libraries.
static CApiHookMgr & GetInstance(void)
static HMODULE WINAPI MyLoadLibraryA(PCSTR pszModuleName)
Used to trap events when DLLs are loaded.
BOOL AddHook(const CRef< CHookedFunction > pHook)
Add a new object to the container.
BOOL x_AddHook(PCSTR pszCalleeModName, PCSTR pszFuncName, PROC pfnOrig, PROC pfnHook)
Add a newly intercepted function to the container.
#define HANDLE
An abstraction for a file handle.
Static variables safety - create on demand, destroy on application termination.