Subversion Repositories spk

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
11 cycrow 1
/*--------------------------------------------------------------------------------------------------------
2
  APIHIJACK.H - Based on DelayLoadProfileDLL.CPP, by Matt Pietrek for MSJ February 2000.
3
  http://msdn.microsoft.com/library/periodic/period00/hood0200.htm
4
  Adapted by Wade Brainerd, wadeb@wadeb.com
5
--------------------------------------------------------------------------------------------------------*/
6
#ifndef APIHIJACK_H
7
#define APIHIJACK_H
8
 
9
#pragma warning(disable:4200)
10
 
11
// Macro for convenient pointer addition.
12
// Essentially treats the last two parameters as DWORDs.  The first
13
// parameter is used to typecast the result to the appropriate pointer type.
14
#define MakePtr(cast, ptr, addValue ) (cast)( (DWORD)(ptr)+(DWORD)(addValue))
15
 
16
// Default Hook Stub Structure: Contains data about the original function, Name/Ordinal, Address 
17
// and a Count field.  This is actually a block of assembly code.
18
#pragma pack( push, 1 )
19
struct DLPD_IAT_STUB
20
{
21
    BYTE    instr_CALL;
22
    DWORD   data_call;
23
    BYTE    instr_JMP;
24
    DWORD   data_JMP;
25
    DWORD   count;
26
    DWORD   pszNameOrOrdinal;
27
 
28
    DLPD_IAT_STUB() : instr_CALL( 0xE8 ), instr_JMP( 0xE9 ), count( 0 ) {}
29
};
30
#pragma pack( pop )
31
 
32
// Example DefaultHook procedure, called from the DLPD_IAT_STUB stubs.  
33
// Increments "count" field of the stub.
34
// See the implementation for more information.
35
void __cdecl DefaultHook( PVOID dummy );
36
 
37
struct SFunctionHook
38
{
39
    char* Name;         // Function name, e.g. "DirectDrawCreateEx".
40
    void* HookFn;       // Address of your function.
41
    void* OrigFn;       // Stored by HookAPICalls, the address of the original function.
42
};
43
 
44
struct SDLLHook
45
{
46
    // Name of the DLL, e.g. "DDRAW.DLL"
47
    char* Name;
48
 
49
    // Set true to call the default for all non-hooked functions before they are executed.
50
    bool UseDefault;
51
    void* DefaultFn;
52
 
53
    // Function hook array.  Terminated with a NULL Name field.
54
    SFunctionHook Functions[];
55
};
56
 
57
// Hook functions one or more DLLs.
58
bool HookAPICalls( SDLLHook* Hook );
59
 
60
#endif