Document of interface IDirectCodeHook

This interface is for raw mode hooking.
You usually should use ICodeHook's raw mode hooking feature instead of use this interface directly.
To get the interface, call ICodeHook.GetDirectCodeHook;

Delphi syntax:
IDirectCodeHook = interface(IErrorCodeHook)
	function Hook(ATarget, AHook: Pointer; APreviousMethod: Pointer): LongBool; stdcall;
	function Unhook(ATarget: Pointer; APreviousMethod: Pointer): LongBool; stdcall;
	function AllocatePreviousMethodMemory: Pointer; stdcall;
	procedure FreePreviousMethodMemory(APreviousMethod: Pointer); stdcall;
end;
C++ syntax:
class IDirectCodeHook: public ICodeHookError {
public:
	virtual BOOL _stdcall Hook(Pointer Target, Pointer Hook, Pointer OldFunc) = 0;
	virtual BOOL _stdcall Unhook(Pointer Target, Pointer AOldFunc) = 0;
	virtual void * _stdcall AllocatePreviousMethodMemory() = 0;
	virtual void FreePreviousMethodMemory(Pointer OldFunc) = 0;
};
Function:

Hook


Low level hook a method.
Delphi syntax:
function Hook(ATarget, AHook: Pointer; APreviousMethod: Pointer): LongBool; stdcall;

C++ syntax:
virtual BOOL calltype Hook(Pointer Target, Pointer Hook, Pointer OldFunc) = 0;


Params
ATarget
Address of the target function.
AHook
Address of the hook function.
APreviousMethod
Pointer to a memory block to store the previous method information. You may use IDirectCodeHook.AllocatePreviousMethodMemory to allocate memory.
Return value
Return TRUE on success, otherwise, return FALSE.
Remarks
Don't use this function, instead, use ICodeHook.Hook.
Function:

Unhook


Low level unhook a method.
Delphi syntax:
function Unhook(ATarget: Pointer; APreviousMethod: Pointer): LongBool; stdcall;

C++ syntax:
virtual BOOL calltype Unhook(Pointer Target, Pointer AOldFunc) = 0;


Params
ATarget
Address of the target function.
APreviousMethod
Address of the previous function.
Return value
Return TRUE on success, otherwise, return FALSE.
Remarks
Don't use this function, instead, use ICodeHook.Unhook.
Function:

AllocatePreviousMethodMemory


Allocate a block of memory to store previous method information.
Delphi syntax:
function AllocatePreviousMethodMemory: Pointer; stdcall;

C++ syntax:
virtual void * calltype AllocatePreviousMethodMemory() = 0;


Params
This function has no parameters.
Return value
Return the memory pointer.
Remarks
You can pass the return value to IDirectCodeHook.Hook and IDirectCodeHook.Unhook.
Function:

FreePreviousMethodMemory


Free the memory block.
Delphi syntax:
procedure FreePreviousMethodMemory(APreviousMethod: Pointer); stdcall;

C++ syntax:
virtual void FreePreviousMethodMemory(Pointer OldFunc) = 0;


Params
APreviousMethod
Pointer that returned by IDirectCodeHook.AllocatePreviousMethodMemory
Return value
This function doesn't return value.