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: Shimlib helper file, used to register shims setup with macro's from setup_shim.inl 5 * COPYRIGHT: Copyright 2016-2019 Mark Jansen (mark.jansen@reactos.org) 6 */ 7 8#ifndef SHIM_NS 9#error "A namespace should be provided in SHIM_NS before including this file!" 10#endif 11 12#ifndef SHIM_NUM_HOOKS 13#error "The number of hooks should be provided in SHIM_NUM_HOOKS before including this file!" 14#endif 15 16#ifndef SHIM_OBJ_NAME 17#error "setup_shim.inl should be included before this file!" 18#endif 19 20#if SHIM_NUM_HOOKS > 0 21#ifndef SHIM_SETUP_HOOKS 22#error "Please define a hook: #define SHIM_SETUP_HOOKS SHIM_HOOK(num, dll_name, function_name, your_function)" 23#endif 24#else 25#ifdef SHIM_SETUP_HOOKS 26#error "Hooks are defined, yet SHIM_NUM_HOOKS is <= 0 !" 27#endif 28#endif 29 30PHOOKAPI WINAPI SHIM_OBJ_NAME(GetHookAPIs)(DWORD fdwReason, PCSTR pszCmdLine, PDWORD pdwHookCount) 31{ 32 if (pszCmdLine) 33 { 34 SHIM_OBJ_NAME(g_szCommandLine) = ShimLib_StringDuplicateA(pszCmdLine); 35 } 36 else 37 { 38 SHIM_OBJ_NAME(g_szCommandLine) = ""; 39 } 40 SHIM_OBJ_NAME(g_pAPIHooks) = (PHOOKAPI)ShimLib_ShimMalloc(sizeof(HOOKAPI) * SHIM_NUM_HOOKS); 41 if (SHIM_NUM_HOOKS) 42 ZeroMemory(SHIM_OBJ_NAME(g_pAPIHooks), sizeof(HOOKAPI) * SHIM_NUM_HOOKS); 43 *pdwHookCount = SHIM_NUM_HOOKS; 44 45#ifdef SHIM_NOTIFY_FN 46 if (!SHIM_NOTIFY_FN(fdwReason, NULL)) 47 return NULL; 48#endif 49 50#if SHIM_NUM_HOOKS > 0 51 SHIM_SETUP_HOOKS 52#endif 53 return SHIM_OBJ_NAME(g_pAPIHooks); 54} 55 56 57#if defined(_MSC_VER) 58#pragma section(".shm$BBB",long,read) 59#endif 60 61_SHMALLOC(".shm$BBB") SHIMREG SHIM_OBJ_NAME(_shim_fn) = 62{ 63 SHIM_OBJ_NAME(GetHookAPIs), 64#ifdef SHIM_NOTIFY_FN 65 SHIM_NOTIFY_FN, 66#else 67 NULL, 68#endif 69 SHIM_STRINGIFY(SHIM_NS) 70}; 71 72#undef SHIM_SETUP_HOOKS 73#undef SHIM_NOTIFY_FN 74#undef SHIM_NUM_HOOKS 75#undef SHIM_NS 76