• Main Page
  • Classes
  • Files
  • File List

HookDLL.h

00001 /*
00002  * synergy -- mouse and keyboard sharing utility
00003  * Copyright (C) 2012 Bolton Software Ltd.
00004  * Copyright (C) 2011 Chris Schoeneman
00005  * 
00006  * This package is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * found in the file COPYING that should have accompanied this file.
00009  * 
00010  * This package is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 /*--------------------------------------------------------------------------------------------------------
00020     Original comment:
00021 
00022     APIHIJACK.H - Based on DelayLoadProfileDLL.CPP, by Matt Pietrek for MSJ February 2000.
00023     http://msdn.microsoft.com/library/periodic/period00/hood0200.htm
00024     Adapted by Wade Brainerd, wadeb@wadeb.com
00025 --------------------------------------------------------------------------------------------------------*/
00026 
00027 #pragma once
00028 
00029 #define WIN32_LEAN_AND_MEAN
00030 #include <windows.h>
00031 
00032 #pragma warning(disable:4200)
00033 
00034 // Macro for convenient pointer addition.
00035 // Essentially treats the last two parameters as DWORDs.  The first
00036 // parameter is used to typecast the result to the appropriate pointer type.
00037 #define MakePtr(cast, ptr, addValue ) (cast)( (DWORD)(ptr)+(DWORD)(addValue))
00038 
00039 // Default Hook Stub Structure: Contains data about the original function, Name/Ordinal, Address 
00040 // and a Count field.  This is actually a block of assembly code.
00041 #pragma pack( push, 1 )
00042 struct DLPD_IAT_STUB
00043 {
00044     BYTE    instr_CALL;
00045     DWORD   data_call;
00046     BYTE    instr_JMP;
00047     DWORD   data_JMP;
00048     DWORD   count;
00049     DWORD   pszNameOrOrdinal;
00050 
00051     DLPD_IAT_STUB() : instr_CALL( 0xE8 ), instr_JMP( 0xE9 ), count( 0 ) {}
00052 };
00053 #pragma pack( pop )
00054 
00055 // Example DefaultHook procedure, called from the DLPD_IAT_STUB stubs.  
00056 // Increments "count" field of the stub.
00057 // See the implementation for more information.
00058 void __cdecl DefaultHook( PVOID dummy );
00059 
00060 struct SFunctionHook
00061 {
00062     char* Name;         // Function name, e.g. "DirectDrawCreateEx".
00063     void* HookFn;       // Address of your function.
00064     void* OrigFn;       // Stored by HookAPICalls, the address of the original function.
00065 };
00066 
00067 struct SDLLHook
00068 {
00069     // Name of the DLL, e.g. "DDRAW.DLL"
00070     char* Name;
00071 
00072     // Set true to call the default for all non-hooked functions before they are executed.
00073     bool UseDefault;
00074     void* DefaultFn;
00075 
00076     // Function hook array.  Terminated with a NULL Name field.
00077     SFunctionHook Functions[];
00078 };
00079 
00080 // Hook functions one or more DLLs.
00081 bool HookAPICalls( SDLLHook* hook );

Generated on Thu Jun 20 2013 00:00:05 for Synergy by  doxygen 1.7.1