2 * PROJECT: ReactOS Shim helper library
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: ReactOS Shim Engine common functions / structures
5 * COPYRIGHT: Copyright 2016,2017 Mark Jansen (mark.jansen@reactos.org)
10 typedef struct tagHOOKAPI
14 PVOID ReplacementFunction
;
15 PVOID OriginalFunction
;
20 PVOID
ShimLib_ShimMalloc(SIZE_T
);
21 void ShimLib_ShimFree(PVOID
);
22 PCSTR
ShimLib_StringDuplicateA(PCSTR
);
23 BOOL
ShimLib_StrAEqualsW(PCSTR
, PCWSTR
);
26 /* Forward events to generic handlers */
27 void ShimLib_Init(HINSTANCE
);
28 void ShimLib_Deinit(void);
29 PHOOKAPI WINAPI
ShimLib_GetHookAPIs(LPCSTR
,LPCWSTR
,PDWORD
);
30 BOOL WINAPI
ShimLib_NotifyShims(DWORD fdwReason
, PVOID ptr
);
33 /* Shims should respond to SHIM_REASON_XXXX in the Notify routines.
34 SHIM_NOTIFY_ codes are sent by apphelp, and translated to SHIM_REASON_ by the shimlib routines.
35 The only exception being SHIM_NOTIFY_ATTACH, that is also set for one-time init.
38 #define SHIM_REASON_INIT 100
39 #define SHIM_REASON_DEINIT 101
40 #define SHIM_REASON_DLL_LOAD 102 /* Arg: PLDR_DATA_TABLE_ENTRY */
41 #define SHIM_REASON_DLL_UNLOAD 103 /* Arg: PLDR_DATA_TABLE_ENTRY */
43 #define SHIM_NOTIFY_ATTACH 1
44 #define SHIM_NOTIFY_DETACH 2
45 #define SHIM_NOTIFY_DLL_LOAD 3 /* Arg: PLDR_DATA_TABLE_ENTRY */
46 #define SHIM_NOTIFY_DLL_UNLOAD 4 /* Arg: PLDR_DATA_TABLE_ENTRY */
50 typedef enum _SEI_LOG_LEVEL
{
57 BOOL WINAPIV
SeiDbgPrint(SEI_LOG_LEVEL Level
, PCSTR Function
, PCSTR Format
, ...);
58 extern ULONG g_ShimEngDebugLevel
;
60 #if defined(IN_APPHELP)
61 /* Apphelp shimeng logging uses the function name */
62 #define SHIMENG_MSG(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_MSG, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
63 #define SHIMENG_FAIL(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_FAIL, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
64 #define SHIMENG_WARN(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
65 #define SHIMENG_INFO(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, __FUNCTION__, fmt, ##__VA_ARGS__ ); } while (0)
67 /* Shims use the shim name */
68 #define SHIM_MSG(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_MSG, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
69 #define SHIM_FAIL(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_FAIL, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
70 #define SHIM_WARN(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_WARN, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
71 #define SHIM_INFO(fmt, ...) do { if (g_ShimEngDebugLevel) SeiDbgPrint(SEI_INFO, SHIM_OBJ_NAME(g_szModuleName), fmt, ##__VA_ARGS__ ); } while (0)
74 typedef PHOOKAPI (WINAPI
* _PVGetHookAPIs
)(DWORD
, PCSTR
, PDWORD
);
75 typedef BOOL (WINAPI
* _PVNotify
)(DWORD
, PVOID
);
77 typedef struct tagSHIMREG
79 _PVGetHookAPIs GetHookAPIs
;
86 #define _SHMALLOC(x) __declspec(allocate(x))
87 #elif defined(__GNUC__)
88 #define _SHMALLOC(x) __attribute__ ((section (x) ))
90 #error Your compiler is not supported.