Unit HookType |
*****************************************************} { MemProof } { Hook functions prototypes } { } { Copyright (c) 1998 Atanas Stoyanov } { } { 6/2/98 - Modifications by Stefan Hoffmeister } { 5/10/98- Initial release } { } {*******************************************************} {$A+,B-,C+,D-,E-,F-,G+,H+,I+,J+,K-,L+,M-,N+,O-,P+,Q-,R-,S-,T-,U-,V+,W+,X+,Y+,Z1} // ****** What follows are important compiler switches // ****** expanded in their long form so that one can // ****** actually read and understand them // ****** DO NOT CHANGE ANY SETTING BELOW {$DEBUGINFO OFF} {$ENDIF DEBUG} {$STACKFRAMES ON} {$TYPEDADDRESS ON} {$OPTIMIZATION OFF
Classes |
Functions |
AddLastWin32Error - Adds the Last error returned by windows as an error entry.
ClearFlag - clears a particular flag Flags is one of the HF_xx constants.
IsFlagSet - 128 returns true is a particular flag bit is set Flags is one of the HF_xx constants.
IsPointerOverrunOK - will check if the ovewrrun stamp is still ok (the memory has not been overran by a bad write
will check if the overrun stamp is still ok (the memory has not been overran by a bad write
SetFlag - sets a particular flag Flags is one of the HF_xx constants.
StampForOverrunTest - will stamp the address - Size of the stamp variable with a specific value
will stamp the address - Size of the stamp variable with a specific value
Types |
PExportedFunctions
TAddError
TAllocateResource
TExportedFunctions
TFreeResource
TFreeResourcesWithTag
TNewHookDLL
TNewHookFunction
TNewHookGroup
TNewHookItem
TRegisterDLLs
TRegisterFunctions
TRegisterGroups
TRegisterItems
TSetResourceTag
Constants |
HDS_NORMAL
HF_RESERVED2
HF_RESERVED3
HF_RESERVED4
HF_RESERVED5
HF_RESERVED6
HF_RESERVED7
HF_STRESS
HF_TESTFOROVERRUN
HGS_NORMAL
HGS_SIZEITEM
HGS_TRACEITEM
HIS_HIDDEN
HIS_NORMAL
OverrunStampBytes
Variables |
Functions |
Adds the Last error returned by windows as an error entry. Called form Windows API hooks when they detect error
clears a particular flag Flags is one of the HF_xx constants.
returns true is a particular flag bit is set Flags is one of the HF_xx constants.
will check if the overrun stamp is still ok (the memory has not been overran by a bad write
sets a particular flag Flags is one of the HF_xx constants.
will stamp the address - Size of the stamp variable with a specific value
Types |
PExportedFunctions = ^TExportedFunctions
TAddError = procedure( ErrorGroup : Integer; ErrorNo : Integer; ErrorText : PChar; Tag : Integer)Add error. Called when an error is detected in some of the APIs
TAllocateResource = procedure ( SomeText : PChar; Resource : Pointer; ResourceSize : Integer; ResourceGroup : Integer; ResourceSubType : Integer; Tag : Integer)AllocateResource is called when a resource is being allocated. For resources where the size is unknown, call with ResourceSize = 0. This will avoid size checking
TExportedFunctions = record
AAddError : TAddError;
AAllocateResource : TAllocateResource;
AFreeResource : TFreeResource;
AFreeResourcesWithTag : TFreeResourcesWithTag;
ASetResourceTag : TSetResourceTag;
end;
TFreeResource = procedure ( Resource : Pointer; ResourceSize : Integer; ResourceGroup : Integer)FreeResource is called when a resource is being freed. It will check if the whole size is being freed For resources where the size is unknown, call with ResourceSize = 0. This will avoid size checking
TFreeResourcesWithTag = procedure ( ResourceTag : Integer; ResourceGroup : Integer; IncludeSubItems : Boolean)FreeResourceWithtag is called when all the resources with a specific tage are being freed.
TNewHookDLL = function ( Instance : THandle; DLLName : PChar; DLLDescription : PChar; Style : Integer) : Integerinstance is the HInstance of the calling dll. installs a new dll to be hooked upon. Returns a unique identifier to be used as Dll_ID Style : Integer is a set HDS_xx constants If error will return -1
TNewHookFunction = procedure( Item_ID : Integer; FunctionName : PChar;//Function to be hooked NewFunction : Pointer; POldAddress : Pointer)Hooks a function. Item_ID is returned by previous call to NewHookItem The function name is the name of exported function If the function is imported by ordinal, one can use it ex FunctionName = '2' -N.B. do NOT use Pchar(2) New Function is the address of the hook function to be called POldFunction is the address of a variable that will hold the address of the original hook funciton If error will return -1
TNewHookGroup = function( Dll_ID : Integer; GroupDescription : PChar; Style : Integer) : Integerinstalls a new group of functions to be hooked. groups of functions share the same Free procedure, even tough they are Style : Integer is a set HGS_xx constants different items Returns a unique ID to be used as Group_ID If error will return -1
TNewHookItem = function ( Group_ID : Integer; ItemDescription : PChar; var PStress : PInteger; Style : Integer; BitmapID : Integer) : Integerinstalls a new item to be hooked. Items are the smallest unit that will be hooked. Items are part of groups PStress is a pointer to the Stress variable, Style : Integer is a set of HIS_xx constants BitmapID : Resource ID of the bitmap glyph for this item. Used in the UI to identify this item. Returns a unique ID to be used as Item_ID If error will return -1
TRegisterDLLs = function ( RegisterFunction : TNewHookDLL) : Integerfollow the types of the four functions that each dll should export function that will be called first to register the hooked dlls
TRegisterFunctions = function ( RegisterFunction : TNewHookFunction; Functions : PExportedFunctions) : IntegerTRegisterFunctions
TRegisterGroups = function( RegisterFunction : TNewHookGroup) : Integerfunction that will be called to register the hooked groups/categories
TRegisterItems = function (RegisterFunction : TNewHookItem) : Integerfunction that will be called to register the hooked functions
TSetResourceTag = procedure( Resource : Pointer; ResourceTag : Integer; ResourceGroup : Integer)Sets the tag of a previously allocated resource
Constants |
Variables |