00001 #ifndef IG_HOOK_IG_HOOK_H
00002 # define IG_HOOK_IG_HOOK_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 class IgHook
00013 {
00014 public:
00015 enum Status
00016 {
00017 Success = 0,
00018 ErrBadOptions,
00019 ErrLibraryNotFound,
00020 ErrSymbolNotFoundInLibrary,
00021 ErrSymbolNotFoundInSelf,
00022 ErrPrologueNotRecognised,
00023 ErrPrologueTooLarge,
00024 ErrMemoryProtection,
00025 ErrAllocateTrampoline,
00026 ErrOther
00027 };
00028
00029 struct Data
00030 {
00031 int options;
00032 const char *function;
00033 const char *version;
00034 const char *library;
00035 void *replacement;
00036 void *chain;
00037 void *original;
00038 void *trampoline;
00039 };
00040
00041 template <typename Func>
00042 struct SafeData
00043 {
00044 int options;
00045 const char *function;
00046 const char *version;
00047 const char *library;
00048 Func *replacement;
00049 Func *chain;
00050 Func *original;
00051 void *trampoline;
00052 };
00053
00054 template <typename Func>
00055 union TypedData
00056 {
00057 SafeData<Func> typed;
00058 Data raw;
00059 };
00060
00061 static Status hook (Data &data);
00062 static Status hook (const char *function,
00063 const char *version,
00064 const char *library,
00065 void *replacement,
00066 int options = 0,
00067 void **chain = 0,
00068 void **original = 0,
00069 void **trampoline = 0);
00070 };
00071
00072
00073
00074
00075 inline IgHook::Status
00076 IgHook::hook (Data &data)
00077 {
00078 return hook (data.function, data.version, data.library, data.replacement,
00079 data.options, &data.chain, &data.original, &data.trampoline);
00080 }
00081
00082 #endif // IG_HOOK_IG_HOOK_H