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)
16 typedef struct tagHOOKAPI
20 PVOID ReplacementFunction
;
21 PVOID OriginalFunction
;
26 PVOID
ShimLib_ShimMalloc(SIZE_T dwSize
);
27 VOID
ShimLib_ShimFree(PVOID pData
);
28 PCSTR
ShimLib_StringDuplicateA(PCSTR szString
);
29 PCSTR
ShimLib_StringNDuplicateA(PCSTR szString
, SIZE_T stringLength
);
30 BOOL
ShimLib_StrAEqualsWNC(PCSTR szString
, PCWSTR wszString
);
31 HINSTANCE
ShimLib_Instance(VOID
);
33 /* Forward events to generic handlers */
34 VOID
ShimLib_Init(HINSTANCE hInstance
);
35 VOID
ShimLib_Deinit(VOID
);
36 PHOOKAPI WINAPI
ShimLib_GetHookAPIs(LPCSTR szCommandLine
,LPCWSTR wszShimName
,PDWORD pdwHookCount
);
37 BOOL WINAPI
ShimLib_NotifyShims(DWORD fdwReason
, PVOID ptr
);
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.
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 */
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 */
57 typedef enum _SEI_LOG_LEVEL
{
64 BOOL WINAPIV
SeiDbgPrint(SEI_LOG_LEVEL Level
, PCSTR Function
, PCSTR Format
, ...);
65 extern ULONG g_ShimEngDebugLevel
;
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)
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)
81 typedef PHOOKAPI (WINAPI
* _PVGetHookAPIs
)(DWORD
, PCSTR
, PDWORD
);
82 typedef BOOL (WINAPI
* _PVNotify
)(DWORD
, PVOID
);
84 typedef struct tagSHIMREG
86 _PVGetHookAPIs GetHookAPIs
;
93 #define _SHMALLOC(x) __declspec(allocate(x))
94 #elif defined(__GNUC__)
95 #define _SHMALLOC(x) __attribute__ ((section (x) ))
97 #error Your compiler is not supported.