ReactOS  0.4.13-dev-982-g9853eab
shimlib.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  tagHOOKAPI
 
struct  tagSHIMREG
 

Macros

#define SHIM_REASON_INIT   100
 
#define SHIM_REASON_DEINIT   101
 
#define SHIM_REASON_DLL_LOAD   102 /* Arg: PLDR_DATA_TABLE_ENTRY */
 
#define SHIM_REASON_DLL_UNLOAD   103 /* Arg: PLDR_DATA_TABLE_ENTRY */
 
#define SHIM_NOTIFY_ATTACH   1
 
#define SHIM_NOTIFY_DETACH   2
 
#define SHIM_NOTIFY_DLL_LOAD   3 /* Arg: PLDR_DATA_TABLE_ENTRY */
 
#define SHIM_NOTIFY_DLL_UNLOAD   4 /* Arg: PLDR_DATA_TABLE_ENTRY */
 
#define SHIM_MSG(fmt, ...)   do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_MSG, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
 
#define SHIM_FAIL(fmt, ...)   do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_FAIL, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
 
#define SHIM_WARN(fmt, ...)   do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
 
#define SHIM_INFO(fmt, ...)   do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
 

Typedefs

typedef struct tagHOOKAPI HOOKAPI
 
typedef struct tagHOOKAPIPHOOKAPI
 
typedef enum _SEI_LOG_LEVEL SEI_LOG_LEVEL
 
typedef PHOOKAPI(WINAPI_PVGetHookAPIs) (DWORD, PCSTR, PDWORD)
 
typedef BOOL(WINAPI_PVNotify) (DWORD, PVOID)
 
typedef struct tagSHIMREG SHIMREG
 
typedef struct tagSHIMREGPSHIMREG
 

Enumerations

enum  _SEI_LOG_LEVEL { SEI_MSG = 1, SEI_FAIL = 2, SEI_WARN = 3, SEI_INFO = 4 }
 

Functions

PVOID ShimLib_ShimMalloc (SIZE_T dwSize)
 
VOID ShimLib_ShimFree (PVOID pData)
 
PCSTR ShimLib_StringDuplicateA (PCSTR szString)
 
PCSTR ShimLib_StringNDuplicateA (PCSTR szString, SIZE_T stringLength)
 
BOOL ShimLib_StrAEqualsWNC (PCSTR szString, PCWSTR wszString)
 
HINSTANCE ShimLib_Instance (VOID)
 
VOID ShimLib_Init (HINSTANCE hInstance)
 
VOID ShimLib_Deinit (VOID)
 
PHOOKAPI WINAPI ShimLib_GetHookAPIs (LPCSTR szCommandLine, LPCWSTR wszShimName, PDWORD pdwHookCount)
 
BOOL WINAPI ShimLib_NotifyShims (DWORD fdwReason, PVOID ptr)
 
BOOL WINAPIV SeiDbgPrint (SEI_LOG_LEVEL Level, PCSTR Function, PCSTR Format,...)
 

Variables

ULONG g_ShimEngDebugLevel
 

Macro Definition Documentation

◆ SHIM_FAIL

#define SHIM_FAIL (   fmt,
  ... 
)    do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_FAIL, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)

Definition at line 76 of file shimlib.h.

◆ SHIM_INFO

#define SHIM_INFO (   fmt,
  ... 
)    do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)

Definition at line 78 of file shimlib.h.

◆ SHIM_MSG

#define SHIM_MSG (   fmt,
  ... 
)    do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_MSG, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)

Definition at line 75 of file shimlib.h.

◆ SHIM_NOTIFY_ATTACH

#define SHIM_NOTIFY_ATTACH   1

Definition at line 50 of file shimlib.h.

◆ SHIM_NOTIFY_DETACH

#define SHIM_NOTIFY_DETACH   2

Definition at line 51 of file shimlib.h.

◆ SHIM_NOTIFY_DLL_LOAD

#define SHIM_NOTIFY_DLL_LOAD   3 /* Arg: PLDR_DATA_TABLE_ENTRY */

Definition at line 52 of file shimlib.h.

◆ SHIM_NOTIFY_DLL_UNLOAD

#define SHIM_NOTIFY_DLL_UNLOAD   4 /* Arg: PLDR_DATA_TABLE_ENTRY */

Definition at line 53 of file shimlib.h.

◆ SHIM_REASON_DEINIT

#define SHIM_REASON_DEINIT   101

Definition at line 46 of file shimlib.h.

◆ SHIM_REASON_DLL_LOAD

#define SHIM_REASON_DLL_LOAD   102 /* Arg: PLDR_DATA_TABLE_ENTRY */

Definition at line 47 of file shimlib.h.

◆ SHIM_REASON_DLL_UNLOAD

#define SHIM_REASON_DLL_UNLOAD   103 /* Arg: PLDR_DATA_TABLE_ENTRY */

Definition at line 48 of file shimlib.h.

◆ SHIM_REASON_INIT

#define SHIM_REASON_INIT   100

Definition at line 45 of file shimlib.h.

◆ SHIM_WARN

#define SHIM_WARN (   fmt,
  ... 
)    do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)

Definition at line 77 of file shimlib.h.

Typedef Documentation

◆ _PVGetHookAPIs

typedef PHOOKAPI(WINAPI* _PVGetHookAPIs) (DWORD, PCSTR, PDWORD)

Definition at line 81 of file shimlib.h.

◆ _PVNotify

typedef BOOL(WINAPI* _PVNotify) (DWORD, PVOID)

Definition at line 82 of file shimlib.h.

◆ HOOKAPI

◆ PHOOKAPI

◆ PSHIMREG

◆ SEI_LOG_LEVEL

◆ SHIMREG

Enumeration Type Documentation

◆ _SEI_LOG_LEVEL

Enumerator
SEI_MSG 
SEI_FAIL 
SEI_WARN 
SEI_INFO 

Definition at line 57 of file shimlib.h.

57  {
58  SEI_MSG = 1,
59  SEI_FAIL = 2,
60  SEI_WARN = 3,
61  SEI_INFO = 4,
enum _SEI_LOG_LEVEL SEI_LOG_LEVEL

Function Documentation

◆ SeiDbgPrint()

BOOL WINAPIV SeiDbgPrint ( SEI_LOG_LEVEL  Level,
PCSTR  Function,
PCSTR  Format,
  ... 
)

Outputs diagnostic info.

Parameters
[in]LevelThe level to log this message with, choose any of [SHIM_ERR, SHIM_WARN, SHIM_INFO].
[in]FunctionNameThe function this log should be attributed to.
[in]FormatThe format string.
...Variable arguments providing additional information.
Returns
Success: TRUE Failure: FALSE.

Definition at line 159 of file shimeng.c.

160 {
161  char Buffer[512];
162  char* Current = Buffer;
163  const char* LevelStr;
164  size_t Length = sizeof(Buffer);
165  va_list ArgList;
166  HRESULT hr;
167 
168  if (g_ShimEngDebugLevel == 0xffffffff)
170 
172  return FALSE;
173 
174  switch (Level)
175  {
176  case SEI_MSG:
177  LevelStr = "MSG ";
178  break;
179  case SEI_FAIL:
180  LevelStr = "FAIL";
181  break;
182  case SEI_WARN:
183  LevelStr = "WARN";
184  break;
185  case SEI_INFO:
186  LevelStr = "INFO";
187  break;
188  default:
189  LevelStr = "USER";
190  break;
191  }
192 
193  if (Function)
194  hr = StringCchPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, "[%s] [%s] ", LevelStr, Function);
195  else
196  hr = StringCchPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, "[%s] ", LevelStr);
197 
198  if (!SUCCEEDED(hr))
199  return FALSE;
200 
201  va_start(ArgList, Format);
202  hr = StringCchVPrintfExA(Current, Length, &Current, &Length, STRSAFE_NULL_ON_FAILURE, Format, ArgList);
203  va_end(ArgList);
204  if (!SUCCEEDED(hr))
205  return FALSE;
206 
207  DbgPrint("%s", Buffer);
208  return TRUE;
209 }
#define TRUE
Definition: types.h:120
HRESULT hr
Definition: shlfolder.c:183
#define DbgPrint
Definition: loader.c:25
STRSAFEAPI StringCchVPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat, va_list argList)
Definition: strsafe.h:650
ULONG g_ShimEngDebugLevel
Definition: shimeng.c:32
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
STRSAFEAPI StringCchPrintfExA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPSTR *ppszDestEnd, size_t *pcchRemaining, STRSAFE_DWORD dwFlags, STRSAFE_LPCSTR pszFormat,...)
Definition: strsafe.h:575
#define va_end(ap)
Definition: acmsvcex.h:90
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
char * va_list
Definition: acmsvcex.h:78
Definition: bufpool.h:45
LONG HRESULT
Definition: typedefs.h:77
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
#define va_start(ap, A)
Definition: acmsvcex.h:91
#define STRSAFE_NULL_ON_FAILURE
Definition: ntstrsafe.h:47
VOID SeiInitDebugSupport(VOID)
Definition: shimeng.c:127
IN BOOLEAN OUT PSTR Buffer
Definition: progress.h:34
#define SUCCEEDED(hr)
Definition: intsafe.h:57

Referenced by SeiBuildShimRefArray(), and SeiInit().

◆ ShimLib_Deinit()

VOID ShimLib_Deinit ( VOID  )

Definition at line 39 of file shimlib.c.

40 {
41  // Is this a good idea?
43 }
BOOL WINAPI HeapDestroy(HANDLE hHeap)
Definition: heapmem.c:85
static HANDLE g_ShimLib_Heap
Definition: shimlib.c:27

Referenced by DllMain().

◆ ShimLib_GetHookAPIs()

PHOOKAPI WINAPI ShimLib_GetHookAPIs ( LPCSTR  szCommandLine,
LPCWSTR  wszShimName,
PDWORD  pdwHookCount 
)

◆ ShimLib_Init()

VOID ShimLib_Init ( HINSTANCE  hInstance)

Definition at line 30 of file shimlib.c.

31 {
33  g_ShimLib_Heap = HeapCreate(0, 0x10000, 0);
34 
37 }
HANDLE WINAPI HeapCreate(DWORD flOptions, SIZE_T dwInitialSize, SIZE_T dwMaximumSize)
Definition: heapmem.c:45
HINSTANCE hInstance
Definition: charmap.c:20
union _SLIST_HEADER * PSLIST_HEADER
PVOID ShimLib_ShimMalloc(SIZE_T dwSize)
Definition: shimlib.c:45
NTSYSAPI VOID NTAPI RtlInitializeSListHead(_Out_ PSLIST_HEADER ListHead)
Definition: slist.c:25
static PSLIST_HEADER g_UsedShims
Definition: shimlib.c:28
static HANDLE g_ShimLib_Heap
Definition: shimlib.c:27
static HINSTANCE g_ShimLib_hInstance
Definition: shimlib.c:26

Referenced by DllMain().

◆ ShimLib_Instance()

HINSTANCE ShimLib_Instance ( VOID  )

Definition at line 55 of file shimlib.c.

56 {
57  return g_ShimLib_hInstance;
58 }
static HINSTANCE g_ShimLib_hInstance
Definition: shimlib.c:26

Referenced by APIHook_FreeLibrary(), APIHook_GetProcAddress(), APIHook_LoadLibraryA(), APIHook_LoadLibraryExA(), APIHook_LoadLibraryExW(), and APIHook_LoadLibraryW().

◆ ShimLib_NotifyShims()

BOOL WINAPI ShimLib_NotifyShims ( DWORD  fdwReason,
PVOID  ptr 
)

Definition at line 136 of file shimlib.c.

137 {
139 
140  if (fdwReason < SHIM_REASON_INIT)
141  fdwReason += (SHIM_REASON_INIT - SHIM_NOTIFY_ATTACH);
142 
143  while (pEntry)
144  {
145  pUsedShim pUsed = CONTAINING_RECORD(pEntry, UsedShim, Entry);
146  _PVNotify Notify = pUsed->pShim->Notify;
147 #if (WINVER > _WIN32_WINNT_WS03)
148  if (pUsed->bInitCalled && fdwReason == SHIM_REASON_INIT)
149  Notify = NULL;
150 #endif
151  if (Notify)
152  Notify(fdwReason, ptr);
153 #if (WINVER > _WIN32_WINNT_WS03)
154  if (fdwReason == SHIM_REASON_INIT)
155  pUsed->bInitCalled = TRUE;
156 #endif
157 
158  pEntry = pEntry->Next;
159  }
160 
161  return TRUE;
162 }
BOOL WINAPI SHIM_OBJ_NAME() Notify(DWORD fdwReason, PVOID ptr)
#define TRUE
Definition: types.h:120
_Must_inspect_result_ NTSYSAPI PSLIST_ENTRY NTAPI RtlFirstEntrySList(_In_ const SLIST_HEADER *ListHead)
Definition: slist.c:51
static PVOID ptr
Definition: dispmode.c:27
smooth NULL
Definition: ftsmooth.c:416
#define SHIM_REASON_INIT
Definition: shimlib.h:45
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
#define SHIM_NOTIFY_ATTACH
Definition: shimlib.h:50
BOOL(WINAPI * _PVNotify)(DWORD, PVOID)
Definition: shimlib.h:82
_PVNotify Notify
Definition: shimlib.h:87
#define PSLIST_ENTRY
Definition: rtltypes.h:130
static PSLIST_HEADER g_UsedShims
Definition: shimlib.c:28
base of all file and directory entries
Definition: entries.h:82
PSHIMREG pShim
Definition: shimlib.c:18

Referenced by NotifyShims().

◆ ShimLib_ShimFree()

VOID ShimLib_ShimFree ( PVOID  pData)

Definition at line 50 of file shimlib.c.

51 {
53 }
static HANDLE g_ShimLib_Heap
Definition: shimlib.c:27
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by FreeLibrary(), and InitIgnoreFreeLibrary().

◆ ShimLib_ShimMalloc()

PVOID ShimLib_ShimMalloc ( SIZE_T  dwSize)

Definition at line 45 of file shimlib.c.

46 {
47  return HeapAlloc(g_ShimLib_Heap, 0, dwSize);
48 }
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static HANDLE g_ShimLib_Heap
Definition: shimlib.c:27
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54

Referenced by FreeLibrary(), InitIgnoreFreeLibrary(), ShimLib_GetHookAPIs(), ShimLib_Init(), and ShimLib_StringNDuplicateA().

◆ ShimLib_StrAEqualsWNC()

BOOL ShimLib_StrAEqualsWNC ( PCSTR  szString,
PCWSTR  wszString 
)

Definition at line 72 of file shimlib.c.

73 {
74  while (toupper(*szString) == towupper(*wszString))
75  {
76  if (!*szString)
77  return TRUE;
78 
79  szString++; wszString++;
80  }
81  return FALSE;
82 }
#define TRUE
Definition: types.h:120
int toupper(int c)
Definition: utclib.c:881
#define towupper(c)
Definition: wctype.h:99

Referenced by ShimLib_GetHookAPIs().

◆ ShimLib_StringDuplicateA()

PCSTR ShimLib_StringDuplicateA ( PCSTR  szString)

Definition at line 67 of file shimlib.c.

68 {
69  return ShimLib_StringNDuplicateA(szString, lstrlenA(szString) + 1);
70 }
PCSTR ShimLib_StringNDuplicateA(PCSTR szString, SIZE_T stringLengthIncludingNullTerm)
Definition: shimlib.c:60
int WINAPI lstrlenA(LPCSTR lpString)
Definition: lstring.c:145

Referenced by InitIgnoreFreeLibrary().

◆ ShimLib_StringNDuplicateA()

PCSTR ShimLib_StringNDuplicateA ( PCSTR  szString,
SIZE_T  stringLength 
)

Definition at line 60 of file shimlib.c.

61 {
62  PSTR NewString = ShimLib_ShimMalloc(stringLengthIncludingNullTerm);
63  StringCchCopyA(NewString, stringLengthIncludingNullTerm, szString);
64  return NewString;
65 }
PVOID ShimLib_ShimMalloc(SIZE_T dwSize)
Definition: shimlib.c:45
STRSAFEAPI StringCchCopyA(STRSAFE_LPSTR pszDest, size_t cchDest, STRSAFE_LPCSTR pszSrc)
Definition: strsafe.h:145
signed char * PSTR
Definition: retypes.h:7

Referenced by InitIgnoreFreeLibrary(), and ShimLib_StringDuplicateA().

Variable Documentation

◆ g_ShimEngDebugLevel

ULONG g_ShimEngDebugLevel

Definition at line 32 of file shimeng.c.

Referenced by SeiDbgPrint(), and SeiInitDebugSupport().