This is a wrapper interface of ICodeHook.
It makes more easier to use hooking.
To get the interface, call ICodeHook.GetCodeHookHelper;
Delphi syntax:
ICodeHookHelper = interface(IErrorCodeHook) procedure SetCallingConvention(ATargetCC: Integer; AHookCC: Integer); stdcall; function HookWithGlobalMethod(ATargetObject: Pointer; ATarget: Pointer; AHook: Pointer; AParamCount: Integer; AFlags: Cardinal): TCodeHookHandle; stdcall; function HookWithObjectMethod(ATargetObject: Pointer; AHookObject: Pointer; ATarget: Pointer; AHook: Pointer; AParamCount: Integer; AFlags: Cardinal): TCodeHookHandle; stdcall; function HookWithGlobalMethodExtra(ATargetObject: Pointer; ATarget: Pointer; AHook: Pointer; AParamCount: Integer; AExtraParams: PCardinal; AExtraParamCount: Integer; AFlags: Cardinal): TCodeHookHandle; stdcall; function HookWithObjectMethodExtra(ATargetObject: Pointer; AHookObject: Pointer; ATarget: Pointer; AHook: Pointer; AParamCount: Integer; AExtraParams: PCardinal; AExtraParamCount: Integer; AFlags: Cardinal): TCodeHookHandle; stdcall; function UnhookTarget(ATarget: Pointer): LongBool; stdcall; procedure UnhookAll; stdcall; end;C++ syntax:
class ICodeHookHelper: public ICodeHookError {
public:
virtual void _stdcall SetCallingConvention(int TargetCC, int HookCC) = 0;
virtual TCodeHookHandle _stdcall HookWithGlobalMethod(Pointer TargetObject, Pointer Target,
Pointer Hook, int ParamCount, UINT Flags) = 0;
virtual TCodeHookHandle _stdcall HookWithObjectMethod(Pointer TargetObject, Pointer AObject,
Pointer Target, Pointer Hook, int ParamCount, UINT Flags) = 0;
virtual TCodeHookHandle _stdcall HookWithGlobalMethodExtra(Pointer SelfPointer, Pointer Target,
Pointer Hook, int ParamCount,
PUINT ExtraParams, int ExtraParamCount,
UINT Flags) = 0;
virtual TCodeHookHandle _stdcall HookWithObjectMethodExtra(Pointer SelfPointer, Pointer AObject,
Pointer Target, Pointer Hook, int ParamCount,
PUINT ExtraParams, int ExtraParamCount,
UINT Flags) = 0;
virtual BOOL _stdcall UnhookTarget(Pointer Target) = 0;
virtual void _stdcall UnhookAll() = 0;
};
Function:
Set the calling convention of target and hook function.
Delphi syntax:
C++ syntax:
Params
SetCallingConvention
Set the calling convention of target and hook function.
Delphi syntax:
procedure SetCallingConvention(ATargetCC: Integer; AHookCC: Integer); stdcall;
C++ syntax:
virtual void calltype SetCallingConvention(int TargetCC, int HookCC) = 0;
Params
- ATargetCC
- The target calling convention
- AHookCC
- The hook calling convention
- This function doesn't return value.
- This function is used to set the default calling convention before hooking.
In a program, the target and hook calling conventions are usually fixed.
To you only need to set the calling conventions once.
Function:
Hook a method with a global (not class member) method as hook.
Delphi syntax:
C++ syntax:
Params
HookWithGlobalMethod
Hook a method with a global (not class member) method as hook.
Delphi syntax:
function HookWithGlobalMethod(ATargetObject: Pointer; ATarget: Pointer; AHook: Pointer;
AParamCount: Integer; AFlags: Cardinal): TCodeHookHandle; stdcall;
C++ syntax:
virtual TCodeHookHandle calltype HookWithGlobalMethod(Pointer TargetObject, Pointer Target, Pointer Hook, int ParamCount, UINT Flags) = 0;
Params
- ATargetObject
- Address of the "this" or "self" pointer of the target.
If the target is a global function, set this parameter to NULL. - ATarget
- Address of the target function.
- AHook
- Address of the hook function.
- AParamCount
- The param count of the target function.
- AFlags
- For future use. Now pass it with 0.
- A handle that represents the code hook information.
Function:
Hook a method with an object (class member) method as hook.
Delphi syntax:
C++ syntax:
Params
HookWithObjectMethod
Hook a method with an object (class member) method as hook.
Delphi syntax:
function HookWithObjectMethod(ATargetObject: Pointer; AHookObject: Pointer;
ATarget: Pointer; AHook: Pointer;
AParamCount: Integer; AFlags: Cardinal): TCodeHookHandle; stdcall;
C++ syntax:
virtual TCodeHookHandle calltype HookWithObjectMethod(Pointer TargetObject, Pointer AObject, Pointer Target, Pointer Hook, int ParamCount, UINT Flags) = 0;
Params
- ATargetObject
- Address of the "this" or "self" pointer of the target.
If the target is a global function, set this parameter to NULL. - AHookObject
- Address of the "this" or "self" pointer of the hook.
If the hook is a global function, use HookWithGlobalMethod instead. - ATarget
- Address of the target function.
- AHook
- Address of the hook function.
- AParamCount
- The param count of the target function.
- AFlags
- For future use. Now pass it with 0.
- A handle that represents the code hook information.
Function:
Hook a method with a global (not class member) method with extra parameters as hook.
Delphi syntax:
C++ syntax:
Params
HookWithGlobalMethodExtra
Hook a method with a global (not class member) method with extra parameters as hook.
Delphi syntax:
function HookWithGlobalMethodExtra(ATargetObject: Pointer; ATarget: Pointer; AHook: Pointer;
AParamCount: Integer;
AExtraParams: PCardinal; AExtraParamCount: Integer;
AFlags: Cardinal): TCodeHookHandle; stdcall;
C++ syntax:
virtual TCodeHookHandle calltype HookWithGlobalMethodExtra(Pointer SelfPointer, Pointer Target, Pointer Hook, int ParamCount, PUINT ExtraParams, int ExtraParamCount, UINT Flags) = 0;
Params
- ATargetObject
- Address of the "this" or "self" pointer of the target.
If the target is a global function, set this parameter to NULL. - ATarget
- Address of the target function.
- AHook
- Address of the hook function.
- AParamCount
- The param count of the target function.
- AExtraParams
- The pointer to the extra parameters.
- AExtraParamCount
- The extra parameter count.
- AFlags
- For future use. Now pass it with 0.
- A handle that represents the code hook information.
Function:
Hook a method with an object (class member) method with extra parameters as hook.
Delphi syntax:
C++ syntax:
Params
HookWithObjectMethodExtra
Hook a method with an object (class member) method with extra parameters as hook.
Delphi syntax:
function HookWithObjectMethodExtra(ATargetObject: Pointer; AHookObject: Pointer;
ATarget: Pointer; AHook: Pointer;
AParamCount: Integer;
AExtraParams: PCardinal; AExtraParamCount: Integer;
AFlags: Cardinal): TCodeHookHandle; stdcall;
C++ syntax:
virtual TCodeHookHandle calltype HookWithObjectMethodExtra(Pointer SelfPointer, Pointer AObject, Pointer Target, Pointer Hook, int ParamCount, PUINT ExtraParams, int ExtraParamCount, UINT Flags) = 0;
Params
- ATargetObject
- Address of the "this" or "self" pointer of the target.
If the target is a global function, set this parameter to NULL. - AHookObject
- Address of the "this" or "self" pointer of the hook.
If the hook is a global function, use AllocateGlobalHook instead. - ATarget
- Address of the target function.
- AHook
- Address of the hook function.
- AParamCount
- The param count of the target function.
- AExtraParams
- The pointer to the extra parameters.
- AExtraParamCount
- The extra parameter count.
- AFlags
- For future use. Now pass it with 0.
- A handle that represents the code hook information.
Function:
Unhook a target function.
Delphi syntax:
C++ syntax:
Params
UnhookTarget
Unhook a target function.
Delphi syntax:
function UnhookTarget(ATarget: Pointer): LongBool; stdcall;
C++ syntax:
virtual BOOL calltype UnhookTarget(Pointer Target) = 0;
Params
- ATarget
- Address of the target function.
- Return TRUE on success, otherwise, return FALSE.
Function:
Unhook all hooked target functions.
Delphi syntax:
C++ syntax:
Params
UnhookAll
Unhook all hooked target functions.
Delphi syntax:
procedure UnhookAll; stdcall;
C++ syntax:
virtual void calltype UnhookAll() = 0;
Params
- This function has no parameters.
- This function doesn't return value.