From 20d28e80a5c861a9d5f449ea911ab75b4f37ad0d Mon Sep 17 00:00:00 2001 From: Jef Date: Tue, 24 Sep 2024 14:54:57 +0200 Subject: Initial community commit --- Src/wbm/WbmSvcMgr.cpp | 20 ++++ Src/wbm/WbmSvcMgr.h | 17 +++ Src/wbm/main.cpp | 168 +++++++++++++++++++++++++++++ Src/wbm/wbm.sln | 30 ++++++ Src/wbm/wbm.vcxproj | 257 ++++++++++++++++++++++++++++++++++++++++++++ Src/wbm/wbm.vcxproj.filters | 27 +++++ 6 files changed, 519 insertions(+) create mode 100644 Src/wbm/WbmSvcMgr.cpp create mode 100644 Src/wbm/WbmSvcMgr.h create mode 100644 Src/wbm/main.cpp create mode 100644 Src/wbm/wbm.sln create mode 100644 Src/wbm/wbm.vcxproj create mode 100644 Src/wbm/wbm.vcxproj.filters (limited to 'Src/wbm') diff --git a/Src/wbm/WbmSvcMgr.cpp b/Src/wbm/WbmSvcMgr.cpp new file mode 100644 index 00000000..4496d0f9 --- /dev/null +++ b/Src/wbm/WbmSvcMgr.cpp @@ -0,0 +1,20 @@ +#include "WbmSvcMgr.h" +#include +int Add(HANDLE manifest, GUID service_guid, uint32_t service_type, const char *service_name, const char *service_test_string); +int WbmSvcMgr::service_register(waServiceFactory *svc) +{ + GUID service_guid = svc->getGuid(); + uint32_t service_type = svc->getServiceType(); + const char *service_name = svc->getServiceName(); + const char *service_test_string = (const char *)svc->getTestString(); + printf("Found service: %s\n", service_name); + Add(manifest, service_guid, service_type, service_name, service_test_string); + + return 1; +} + +#define CBCLASS WbmSvcMgr +START_DISPATCH; +CB(API_SERVICE_SERVICE_REGISTER, service_register); +END_DISPATCH; +#undef CBCLASS \ No newline at end of file diff --git a/Src/wbm/WbmSvcMgr.h b/Src/wbm/WbmSvcMgr.h new file mode 100644 index 00000000..5fd523c2 --- /dev/null +++ b/Src/wbm/WbmSvcMgr.h @@ -0,0 +1,17 @@ +#pragma once +#include +#include + +class WbmSvcMgr : public api_service +{ +public: + WbmSvcMgr(HANDLE _manifest) + { + manifest=_manifest; + } + int service_register(waServiceFactory *svc); +protected: + RECVS_DISPATCH; +private: + HANDLE manifest; +}; \ No newline at end of file diff --git a/Src/wbm/main.cpp b/Src/wbm/main.cpp new file mode 100644 index 00000000..7a63f2fe --- /dev/null +++ b/Src/wbm/main.cpp @@ -0,0 +1,168 @@ +#include +#include +#include +#include +#include +#include +#include +#include "../Agave/Component/ifc_wa5component.h" +#include "WbmSvcMgr.h" + +/* layout (binary) +0xdeadbeef - 32 bits +service guid - 128 bits +service fourcc - 32 bits +length of service name - 16bits +service name - see previous +length of test string - 16 bits +test string - see previous +repeat as necessary +*/ + +static uint32_t magic_word = 0xdeadbeefUL; +int Add(HANDLE manifest, GUID service_guid, uint32_t service_type, const char *service_name, const char *service_test_string) +{ + DWORD bytesWritten=0; + WriteFile(manifest, &magic_word, sizeof(magic_word), &bytesWritten, NULL); + WriteFile(manifest, &service_guid, sizeof(service_guid), &bytesWritten, NULL); + WriteFile(manifest, &service_type, sizeof(service_type), &bytesWritten, NULL); + uint16_t service_name_length = 0; + if (service_name) + service_name_length = (uint16_t)strlen(service_name); + WriteFile(manifest, &service_name_length, sizeof(service_name_length), &bytesWritten, NULL); + if (service_name_length) + WriteFile(manifest, service_name, service_name_length, &bytesWritten, NULL); + uint16_t service_test_string_length = 0; + if (service_test_string) + service_test_string_length = (uint16_t)strlen(service_test_string); + WriteFile(manifest, &service_test_string_length, sizeof(service_test_string_length), &bytesWritten, NULL); + if (service_test_string_length) + WriteFile(manifest, service_test_string, service_test_string_length, &bytesWritten, NULL); + return 0; +} + +static GUID MakeGUID(const char *source) +{ + if (!strchr(source, '{') || !strchr(source, '}')) + return INVALID_GUID; + + GUID guid; + int Data1, Data2, Data3; + int Data4[8]; + + // {1B3CA60C-DA98-4826-B4A9-D79748A5FD73} + int n = sscanf( source, " { %08x - %04x - %04x - %02x%02x - %02x%02x%02x%02x%02x%02x } ", + &Data1, &Data2, &Data3, Data4 + 0, Data4 + 1, + Data4 + 2, Data4 + 3, Data4 + 4, Data4 + 5, Data4 + 6, Data4 + 7 ); + + if (n != 11) return INVALID_GUID; + + // Cross assign all the values + guid.Data1 = Data1; + guid.Data2 = Data2; + guid.Data3 = Data3; + guid.Data4[0] = Data4[0]; + guid.Data4[1] = Data4[1]; + guid.Data4[2] = Data4[2]; + guid.Data4[3] = Data4[3]; + guid.Data4[4] = Data4[4]; + guid.Data4[5] = Data4[5]; + guid.Data4[6] = Data4[6]; + guid.Data4[7] = Data4[7]; + + return guid; +} + +static ifc_wa5component *LoadWasabiComponent(const char *filename, api_service *svcmgr) +{ + ifc_wa5component * comp = 0; + HMODULE wacLib = LoadLibraryA(filename); + if (wacLib) + { + GETCOMPONENT_FUNC f = (GETCOMPONENT_FUNC)GetProcAddress(wacLib, "GetWinamp5SystemComponent"); + if (f) + { + comp = f(); + if (comp) + { + comp->hModule = wacLib; + comp->RegisterServices(svcmgr); + } + } + } + return comp; +} + +void UnloadWasabiComponent(ifc_wa5component *comp, api_service *svcmgr) +{ + comp->DeregisterServices(svcmgr); + + FreeLibrary(comp->hModule); +} + +int main(int argc, char *argv[]) +{ + if (argc < 3) + return 1; + + const char *command=argv[1]; + const char *filename=argv[2]; + + if (!_stricmp(command, "create")) + { + const char *guid = argv[3]; + const char *type = argv[4]; + const char *name = argv[5]; + const char *test_string = (argc>6)?argv[5]:NULL; + GUID service_guid = MakeGUID(guid); + + FOURCC service_type = MK4CC(type[0], type[1], type[2], type[3]); + + + HANDLE manifest = CreateFileA(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); + if (manifest != INVALID_HANDLE_VALUE) + { + Add(manifest, service_guid, service_type, name, test_string); + CloseHandle(manifest); + } + } + else if (!_stricmp(command, "add")) + { + const char *guid = argv[3]; + const char *type = argv[4]; + const char *name = argv[5]; + const char *test_string = (argc>6)?argv[5]:NULL; + GUID service_guid = MakeGUID(guid); + + FOURCC service_type = MK4CC(type[0], type[1], type[2], type[3]); + + HANDLE manifest = CreateFileA(filename, GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0); + if (manifest != INVALID_HANDLE_VALUE) + { + SetFilePointer(manifest, 0, 0, FILE_END); + Add(manifest, service_guid, service_type, name, test_string); + CloseHandle(manifest); + } + } + else if (!_stricmp(command, "auto") && argc >= 4) + { + const char *w5s_filename = argv[3]; + HANDLE manifest = CreateFileA(filename, GENERIC_WRITE, 0, 0, CREATE_ALWAYS, 0, 0); + if (manifest != INVALID_HANDLE_VALUE) + { + WbmSvcMgr svcmgr(manifest); + ifc_wa5component *comp = LoadWasabiComponent(w5s_filename, &svcmgr); + if (comp) + { + UnloadWasabiComponent(comp, &svcmgr); + } + else + printf("failed to load %s\n", w5s_filename); + CloseHandle(manifest); + } + else + printf("failed to create %s\n", filename); + + } + return 0; +} \ No newline at end of file diff --git a/Src/wbm/wbm.sln b/Src/wbm/wbm.sln new file mode 100644 index 00000000..25e2881d --- /dev/null +++ b/Src/wbm/wbm.sln @@ -0,0 +1,30 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29424.173 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "wbm", "wbm.vcxproj", "{7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Debug|x64 = Debug|x64 + Release|Win32 = Release|Win32 + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Debug|Win32.ActiveCfg = Debug|Win32 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Debug|Win32.Build.0 = Debug|Win32 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Debug|x64.ActiveCfg = Debug|x64 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Debug|x64.Build.0 = Debug|x64 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Release|Win32.ActiveCfg = Release|Win32 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Release|Win32.Build.0 = Release|Win32 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Release|x64.ActiveCfg = Release|x64 + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {9D2EA7DB-DF43-4944-9E6F-8CF2B012DA49} + EndGlobalSection +EndGlobal diff --git a/Src/wbm/wbm.vcxproj b/Src/wbm/wbm.vcxproj new file mode 100644 index 00000000..ca373ed4 --- /dev/null +++ b/Src/wbm/wbm.vcxproj @@ -0,0 +1,257 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {7B0D8017-8DC4-4DD0-94D7-2BA54E6800FD} + wbm + 10.0.19041.0 + + + + Application + v142 + Unicode + + + Application + v142 + Unicode + + + Application + v142 + Unicode + + + Application + v142 + Unicode + + + + + + + + + + + + + + + + + + + false + $(PlatformShortName)_$(Configuration)\ + $(PlatformShortName)_$(Configuration)\ + $(IncludePath) + $(LibraryPath) + + + false + $(PlatformShortName)_$(Configuration)\ + $(PlatformShortName)_$(Configuration)\ + + + false + $(PlatformShortName)_$(Configuration)\ + $(PlatformShortName)_$(Configuration)\ + $(IncludePath) + $(LibraryPath) + + + false + $(PlatformShortName)_$(Configuration)\ + $(PlatformShortName)_$(Configuration)\ + + + false + + + + + false + Debug + x86-windows-static-md + + + + + false + x86-windows-static-md + + + + + false + x86-windows-static-md + Debug + + + + + false + x86-windows-static-md + + + + Disabled + ../Wasabi;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + false + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + ProgramDatabase + $(IntDir)$(TargetName).pdb + + + Rpcrt4.lib;%(AdditionalDependencies) + true + $(OutDir)$(TargetName)$(TargetExt) + $(IntDir)$(TargetName).pdb + Console + false + MachineX86 + false + %(AdditionalLibraryDirectories) + + + xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\ +xcopy /Y /D $(IntDir)$(TargetName).pdb ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\ + Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\' + + + + + Disabled + ../Wasabi;%(AdditionalIncludeDirectories) + WIN64;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + false + true + EnableFastChecks + MultiThreadedDebugDLL + Level3 + ProgramDatabase + $(IntDir)$(TargetName).pdb + + + Rpcrt4.lib;%(AdditionalDependencies) + true + $(OutDir)$(TargetName)$(TargetExt) + $(IntDir)$(TargetName).pdb + Console + false + false + %(AdditionalLibraryDirectories) + + + xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\ +xcopy /Y /D $(IntDir)$(TargetName).pdb ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\ + Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\' + + + + + MinSpace + Size + true + ../Wasabi;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + true + MultiThreadedDLL + false + true + Level3 + None + $(IntDir)$(TargetName).pdb + + + Rpcrt4.lib;%(AdditionalDependencies) + $(OutDir)$(TargetName)$(TargetExt) + $(IntDir)$(TargetName).pdb + Console + true + true + false + MachineX86 + false + false + %(AdditionalLibraryDirectories) + + + xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\ + Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\' + + + + + MinSpace + Size + true + ../Wasabi;%(AdditionalIncludeDirectories) + WIN64;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions) + true + true + MultiThreadedDLL + false + true + Level3 + None + $(IntDir)$(TargetName).pdb + + + Rpcrt4.lib;%(AdditionalDependencies) + $(OutDir)$(TargetName)$(TargetExt) + $(IntDir)$(TargetName).pdb + Console + true + true + false + false + false + %(AdditionalLibraryDirectories) + + + xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\ + Post build event: 'xcopy /Y /D $(OutDir)$(TargetName)$(TargetExt) ..\..\Build\Winamp_$(PlatformShortName)_$(Configuration)\' + + + + + + + + + + + + {3e0bfa8a-b86a-42e9-a33f-ec294f823f7f} + + + + + + \ No newline at end of file diff --git a/Src/wbm/wbm.vcxproj.filters b/Src/wbm/wbm.vcxproj.filters new file mode 100644 index 00000000..835f1c7c --- /dev/null +++ b/Src/wbm/wbm.vcxproj.filters @@ -0,0 +1,27 @@ + + + + + Source Files + + + Source Files + + + + + {e669cb2f-4834-4b8d-96bc-4b1edce71719} + + + {45b6b1bd-1ee8-4a27-a2f5-ec11788419e8} + + + {62a5586a-c0a8-49a4-8fca-4d46dff6117d} + + + + + Header Files + + + \ No newline at end of file -- cgit