ReactOS  0.4.13-dev-698-g77671f0
shimlib.h
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Shim helper library
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: ReactOS Shim Engine common functions / structures
5  * COPYRIGHT: Copyright 2016-2019 Mark Jansen (mark.jansen@reactos.org)
6  */
7 
8 #pragma once
9 
10 
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14 
15 
16 typedef struct tagHOOKAPI
17 {
23 } HOOKAPI, *PHOOKAPI;
24 
25 
29 PCSTR ShimLib_StringNDuplicateA(PCSTR szString, SIZE_T stringLength);
30 BOOL ShimLib_StrAEqualsWNC(PCSTR szString, PCWSTR wszString);
32 
33 /* Forward events to generic handlers */
36 PHOOKAPI WINAPI ShimLib_GetHookAPIs(LPCSTR szCommandLine,LPCWSTR wszShimName,PDWORD pdwHookCount);
38 
39 
40 /* Shims should respond to SHIM_REASON_XXXX in the Notify routines.
41  SHIM_NOTIFY_ codes are sent by apphelp, and translated to SHIM_REASON_ by the shimlib routines.
42  The only exception being SHIM_NOTIFY_ATTACH, that is also set for one-time init.
43  */
44 
45 #define SHIM_REASON_INIT 100
46 #define SHIM_REASON_DEINIT 101
47 #define SHIM_REASON_DLL_LOAD 102 /* Arg: PLDR_DATA_TABLE_ENTRY */
48 #define SHIM_REASON_DLL_UNLOAD 103 /* Arg: PLDR_DATA_TABLE_ENTRY */
49 
50 #define SHIM_NOTIFY_ATTACH 1
51 #define SHIM_NOTIFY_DETACH 2
52 #define SHIM_NOTIFY_DLL_LOAD 3 /* Arg: PLDR_DATA_TABLE_ENTRY */
53 #define SHIM_NOTIFY_DLL_UNLOAD 4 /* Arg: PLDR_DATA_TABLE_ENTRY */
54 
55 
56 
57 typedef enum _SEI_LOG_LEVEL {
58  SEI_MSG = 1,
59  SEI_FAIL = 2,
60  SEI_WARN = 3,
61  SEI_INFO = 4,
63 
66 
67 #if defined(IN_APPHELP)
68 /* Apphelp shimeng logging uses the function name */
69 #define SHIMENG_MSG(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_MSG, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
70 #define SHIMENG_FAIL(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_FAIL, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
71 #define SHIMENG_WARN(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
72 #define SHIMENG_INFO(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
73 #else
74 /* Shims use the shim name */
75 #define SHIM_MSG(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_MSG, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
76 #define SHIM_FAIL(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_FAIL, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
77 #define SHIM_WARN(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
78 #define SHIM_INFO(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
79 #endif
80 
83 
84 typedef struct tagSHIMREG
85 {
89 } SHIMREG, *PSHIMREG;
90 
91 
92 #if defined(_MSC_VER)
93 #define _SHMALLOC(x) __declspec(allocate(x))
94 #elif defined(__GNUC__)
95 #define _SHMALLOC(x) __attribute__ ((section (x) ))
96 #else
97 #error Your compiler is not supported.
98 #endif
99 
100 #ifdef __cplusplus
101 } // extern "C"
102 #endif
103 
struct tagSHIMREG * PSHIMREG
VOID ShimLib_Deinit(VOID)
Definition: shimlib.c:39
const uint16_t * PCWSTR
Definition: typedefs.h:55
PCSTR ShimLib_StringNDuplicateA(PCSTR szString, SIZE_T stringLength)
Definition: shimlib.c:60
VOID ShimLib_Init(HINSTANCE hInstance)
Definition: shimlib.c:30
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
PCSTR LibraryName
Definition: shimlib.h:18
BOOL WINAPI ShimLib_NotifyShims(DWORD fdwReason, PVOID ptr)
Definition: shimlib.c:136
_PVGetHookAPIs GetHookAPIs
Definition: shimlib.h:86
struct tagSHIMREG SHIMREG
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR Level
Definition: wmitypes.h:55
_SEI_LOG_LEVEL
Definition: shimlib.h:57
#define BOOL
Definition: nt_native.h:43
VOID ShimLib_ShimFree(PVOID pData)
Definition: shimlib.c:50
#define DWORD
Definition: nt_native.h:44
HINSTANCE hInstance
Definition: charmap.c:20
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
unsigned int BOOL
Definition: ntddk_ex.h:94
PCSTR ShimLib_StringDuplicateA(PCSTR szString)
Definition: shimlib.c:67
static PVOID ptr
Definition: dispmode.c:27
_Reserved_ PVOID Reserved
Definition: winddi.h:3974
struct tagHOOKAPI * PHOOKAPI
ULONG g_ShimEngDebugLevel
Definition: shimeng.c:32
const char * LPCSTR
Definition: xmlstorage.h:183
void * PVOID
Definition: retypes.h:9
struct tagHOOKAPI HOOKAPI
BOOL(WINAPI * _PVNotify)(DWORD, PVOID)
Definition: shimlib.h:82
_PVNotify Notify
Definition: shimlib.h:87
BOOL WINAPIV SeiDbgPrint(SEI_LOG_LEVEL Level, PCSTR Function, PCSTR Format,...)
Definition: shimeng.c:159
#define WINAPI
Definition: msvc.h:8
PHOOKAPI WINAPI ShimLib_GetHookAPIs(LPCSTR szCommandLine, LPCWSTR wszShimName, PDWORD pdwHookCount)
unsigned long DWORD
Definition: ntddk_ex.h:95
PVOID OriginalFunction
Definition: shimlib.h:21
HINSTANCE ShimLib_Instance(VOID)
Definition: shimlib.c:55
#define WINAPIV
Definition: sdbpapi.h:64
BOOL ShimLib_StrAEqualsWNC(PCSTR szString, PCWSTR wszString)
Definition: shimlib.c:72
enum _SEI_LOG_LEVEL SEI_LOG_LEVEL
ULONG_PTR SIZE_T
Definition: typedefs.h:78
PVOID ReplacementFunction
Definition: shimlib.h:20
PVOID ShimLib_ShimMalloc(SIZE_T dwSize)
Definition: shimlib.c:45
PCSTR FunctionName
Definition: shimlib.h:19
DWORD * PDWORD
Definition: pedump.c:68
unsigned int ULONG
Definition: retypes.h:1
const char * PCSTR
Definition: typedefs.h:51
TW_UINT32 TW_UINT16 TW_UINT16 TW_MEMREF pData
Definition: twain.h:1827
PHOOKAPI(WINAPI * _PVGetHookAPIs)(DWORD, PCSTR, PDWORD)
Definition: shimlib.h:81
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:54
PCSTR ShimName
Definition: shimlib.h:88