diff --git a/server/proxy/modules/bitmap-filter/CMakeLists.txt b/server/proxy/modules/bitmap-filter/CMakeLists.txt index a57180ffd..7dcb25fce 100644 --- a/server/proxy/modules/bitmap-filter/CMakeLists.txt +++ b/server/proxy/modules/bitmap-filter/CMakeLists.txt @@ -40,6 +40,7 @@ include(CXXCompilerFlags) set(SRCS bitmap-filter.cpp) addtargetwithresourcefile(${PROJECT_NAME} FALSE "${PROJECT_VERSION}" SRCS FALSE) +target_compile_definitions(${PROJECT_NAME} PRIVATE $<$:BUILD_SHARED_LIBS>) target_link_libraries(${PROJECT_NAME} winpr freerdp) installwithrpath(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR}) diff --git a/server/proxy/modules/bitmap-filter/bitmap-filter.cpp b/server/proxy/modules/bitmap-filter/bitmap-filter.cpp index e3777fb0a..a2fb77f95 100644 --- a/server/proxy/modules/bitmap-filter/bitmap-filter.cpp +++ b/server/proxy/modules/bitmap-filter/bitmap-filter.cpp @@ -445,16 +445,7 @@ static BOOL filter_server_session_end(proxyPlugin* plugin, proxyData* pdata, voi return TRUE; } -#ifdef __cplusplus -extern "C" -{ -#endif - FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata); -#ifdef __cplusplus -} -#endif - -BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) +static BOOL int_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) { proxyPlugin plugin = {}; @@ -477,3 +468,26 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda return plugins_manager->RegisterPlugin(plugins_manager, &plugin); } + +#ifdef __cplusplus +extern "C" +{ +#endif +#if defined(BUILD_SHARED_LIBS) + FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata); + + BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) + { + return int_proxy_module_entry_point(plugins_manager, userdata); + } +#else +FREERDP_API BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager, + void* userdata); +BOOL bitmap_filter_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) +{ + return int_proxy_module_entry_point(plugins_manager, userdata); +} +#endif +#ifdef __cplusplus +} +#endif diff --git a/server/proxy/modules/demo/CMakeLists.txt b/server/proxy/modules/demo/CMakeLists.txt index 18745deec..7deaf3cc1 100644 --- a/server/proxy/modules/demo/CMakeLists.txt +++ b/server/proxy/modules/demo/CMakeLists.txt @@ -40,6 +40,7 @@ include(CXXCompilerFlags) set(SRCS demo.cpp) addtargetwithresourcefile(${PROJECT_NAME} FALSE "${PROJECT_VERSION}" SRCS FALSE) +target_compile_definitions(${PROJECT_NAME} PRIVATE $<$:BUILD_SHARED_LIBS>) target_link_libraries(${PROJECT_NAME} winpr) installwithrpath(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR}) diff --git a/server/proxy/modules/demo/demo.cpp b/server/proxy/modules/demo/demo.cpp index 1b592d761..75a71a007 100644 --- a/server/proxy/modules/demo/demo.cpp +++ b/server/proxy/modules/demo/demo.cpp @@ -408,16 +408,7 @@ static BOOL demo_dyn_channel_intercept([[maybe_unused]] proxyPlugin* plugin, return TRUE; } -#ifdef __cplusplus -extern "C" -{ -#endif - FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata); -#ifdef __cplusplus -} -#endif - -BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) +static BOOL int_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) { struct demo_custom_data* custom = nullptr; proxyPlugin plugin = {}; @@ -467,3 +458,26 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda return plugins_manager->RegisterPlugin(plugins_manager, &plugin); } + +#ifdef __cplusplus +extern "C" +{ +#endif +#if defined(BUILD_SHARED_LIBS) + FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata); + + BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) + { + return int_proxy_module_entry_point(plugins_manager, userdata); + } +#else +FREERDP_API BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager, + void* userdata); +BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) +{ + return int_proxy_module_entry_point(plugins_manager, userdata); +} +#endif +#ifdef __cplusplus +} +#endif diff --git a/server/proxy/modules/dyn-channel-dump/CMakeLists.txt b/server/proxy/modules/dyn-channel-dump/CMakeLists.txt index 607d2544c..371813e8b 100644 --- a/server/proxy/modules/dyn-channel-dump/CMakeLists.txt +++ b/server/proxy/modules/dyn-channel-dump/CMakeLists.txt @@ -39,6 +39,7 @@ include(ProjectCXXStandard) set(SRCS dyn-channel-dump.cpp) addtargetwithresourcefile(${PROJECT_NAME} FALSE "${PROJECT_VERSION}" SRCS FALSE) +target_compile_definitions(${PROJECT_NAME} PRIVATE $<$:BUILD_SHARED_LIBS>) target_link_libraries(${PROJECT_NAME} PRIVATE winpr freerdp freerdp-client freerdp-server freerdp-server-proxy) installwithrpath(TARGETS ${PROJECT_NAME} DESTINATION ${FREERDP_PROXY_PLUGINDIR}) diff --git a/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp b/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp index 93a480f0d..ff407c55b 100644 --- a/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp +++ b/server/proxy/modules/dyn-channel-dump/dyn-channel-dump.cpp @@ -423,10 +423,7 @@ static BOOL dump_unload(proxyPlugin* plugin) return TRUE; } -extern "C" FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, - void* userdata); - -BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) +static BOOL int_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) { proxyPlugin plugin = {}; @@ -448,3 +445,26 @@ BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userda return plugins_manager->RegisterPlugin(plugins_manager, &plugin); } + +#ifdef __cplusplus +extern "C" +{ +#endif +#if defined(BUILD_SHARED_LIBS) + FREERDP_API BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata); + + BOOL proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) + { + return int_proxy_module_entry_point(plugins_manager, userdata); + } +#else +FREERDP_API BOOL demo_proxy_module_entry_point(proxyPluginsManager* plugins_manager, + void* userdata); +BOOL dyn_channel_dump_proxy_module_entry_point(proxyPluginsManager* plugins_manager, void* userdata) +{ + return int_proxy_module_entry_point(plugins_manager, userdata); +} +#endif +#ifdef __cplusplus +} +#endif diff --git a/server/proxy/pf_modules.c b/server/proxy/pf_modules.c index 2d43cb6f3..2879dc3bb 100644 --- a/server/proxy/pf_modules.c +++ b/server/proxy/pf_modules.c @@ -479,10 +479,53 @@ void pf_modules_list_loaded_plugins(proxyModule* module) ArrayList_ForEach(module->plugins, pf_modules_print_ArrayList_ForEachFkt); } -static BOOL pf_modules_load_module(const char* module_path, proxyModule* module, void* userdata) +static BOOL pf_modules_load_static_module(const char* module_name, proxyModule* module, + void* userdata) { WINPR_ASSERT(module); + HANDLE handle = LoadLibraryX(NULL); + + if (handle == NULL) + { + WLog_ERR(TAG, "failed loading static library: %s", module_name); + return FALSE; + } + + char name[256] = { 0 }; + (void)_snprintf(name, sizeof(name), "%s_%s", module_name, MODULE_ENTRY_POINT); + for (size_t x = 0; x < strnlen(name, sizeof(name)); x++) + { + if (name[x] == '-') + name[x] = '_'; + } + + proxyModuleEntryPoint pEntryPoint = GetProcAddressAs(handle, name, proxyModuleEntryPoint); + if (!pEntryPoint) + { + WLog_ERR(TAG, "GetProcAddress failed for static %s (module %s)", name, module_name); + goto error; + } + if (!ArrayList_Append(module->handles, handle)) + { + WLog_ERR(TAG, "ArrayList_Append failed!"); + goto error; + } + return pf_modules_add(module, pEntryPoint, userdata); + +error: + FreeLibrary(handle); + return FALSE; +} + +static BOOL pf_modules_load_module(const char* module_path, const char* module_name, + proxyModule* module, void* userdata) +{ + WINPR_ASSERT(module); + + if (pf_modules_load_static_module(module_name, module, userdata)) + return TRUE; + HANDLE handle = LoadLibraryX(module_path); if (handle == NULL) @@ -585,7 +628,6 @@ proxyModule* pf_modules_new(const char* root_dir, const char** modules, size_t c if (!winpr_PathMakePath(path, NULL)) { WLog_ERR(TAG, "error occurred while creating modules directory: %s", root_dir); - goto error; } } @@ -599,7 +641,7 @@ proxyModule* pf_modules_new(const char* root_dir, const char** modules, size_t c (void)_snprintf(name, sizeof(name), "proxy-%s-plugin%s", modules[i], FREERDP_SHARED_LIBRARY_SUFFIX); fullpath = GetCombinedPath(path, name); - pf_modules_load_module(fullpath, module, NULL); + pf_modules_load_module(fullpath, modules[i], module, NULL); free(fullpath); } } diff --git a/winpr/libwinpr/library/library.c b/winpr/libwinpr/library/library.c index 08292640e..0714696df 100644 --- a/winpr/libwinpr/library/library.c +++ b/winpr/libwinpr/library/library.c @@ -142,17 +142,15 @@ HMODULE LoadLibraryA(LPCSTR lpLibFileName) HMODULE LoadLibraryW(LPCWSTR lpLibFileName) { - if (!lpLibFileName) - return NULL; #if defined(_UWP) return LoadPackagedLibrary(lpLibFileName, 0); #else - HMODULE module = NULL; - char* name = ConvertWCharToUtf8Alloc(lpLibFileName, NULL); - if (!name) - return NULL; + char* name = NULL; - module = LoadLibraryA(name); + if (lpLibFileName) + name = ConvertWCharToUtf8Alloc(lpLibFileName, NULL); + + HMODULE module = LoadLibraryA(name); free(name); return module; #endif @@ -398,15 +396,14 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) HMODULE LoadLibraryX(LPCSTR lpLibFileName) { - if (!lpLibFileName) - return NULL; - #if defined(_WIN32) HMODULE hm = NULL; - WCHAR* wstr = ConvertUtf8ToWCharAlloc(lpLibFileName, NULL); + WCHAR* wstr = NULL; - if (wstr) - hm = LoadLibraryW(wstr); + if (lpLibFileName) + wstr = ConvertUtf8ToWCharAlloc(lpLibFileName, NULL); + + hm = LoadLibraryW(wstr); free(wstr); return hm; #else