From ce6b706251cef1c929afeb6f398b52a14a47ff54 Mon Sep 17 00:00:00 2001 From: TheTank20 Date: Wed, 20 Dec 2023 19:52:26 -0500 Subject: [PATCH] rewrite to GCC instead of MSVC --- .github/workflows/windows.yml | 36 ++++++----------------- .gitignore | 2 ++ .idea/.gitignore | 8 +++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 +++++ .idea/vcs.xml | 6 ++++ .idea/xpmgr.iml | 2 ++ test.txt | 3 ++ xpmgr.cpp | 55 ++++++++++++++++++++++++----------- 9 files changed, 80 insertions(+), 44 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/xpmgr.iml create mode 100644 test.txt diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index bb2cfef..a4f717f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -10,47 +10,29 @@ jobs: build: runs-on: windows-latest steps: - - name: Install Windows XP Support for Visual Studio - run: | - Set-Location "C:\Program Files (x86)\Microsoft Visual Studio\Installer\" - $InstallPath = "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" - $componentsToAdd = @( - "Microsoft.VisualStudio.Component.WinXP" - ) - [string]$workloadArgs = $componentsToAdd | ForEach-Object {" --add " + $_} - $Arguments = ('/c', "vs_installer.exe", 'modify', '--installPath', "`"$InstallPath`"",$workloadArgs, '--quiet', '--norestart', '--nocache') - $process = Start-Process -FilePath cmd.exe -ArgumentList $Arguments -Wait -PassThru -WindowStyle Hidden - if ($process.ExitCode -eq 0) - { - Write-Host "components have been successfully added" - Get-ChildItem C:\ProgramData\Microsoft\VisualStudio\Packages\Microsoft.Windows.XPSupport.* - } - else - { - Write-Host "components were not installed" - exit 1 - } - - name: Checkout Source Tree uses: actions/checkout@v3 - - name: Setup MSBuild - uses: microsoft/setup-msbuild@v1 + - name: Setup folder directories + run: | + mkdir build + mkdir build\x86 + mkdir build\x64 - name: Build xpmgr (x86) - run: msbuild xpmgr.vcxproj /P:Configuration=Release /P:Platform=Win32 + run: g++ -m32 -o build\x86\xpmgr_x86 xpmgr.cpp -lole32 -luuid -loleaut32 - name: Build xpmgr (x64) - run: msbuild xpmgr.vcxproj /P:Configuration=Release /P:Platform=x64 + run: g++ -o build\x64\xpmgr_x64 xpmgr.cpp -lole32 -luuid -loleaut32 - name: Upload build artifact (x86) uses: actions/upload-artifact@v3.1.2 with: name: xpmgr (x86) - path: .\Win32\Release + path: .\build\x86 - name: Upload build artifact (x64) uses: actions/upload-artifact@v3.1.2 with: name: xpmgr (x64) - path: .\x64\Release + path: .\build\x64 diff --git a/.gitignore b/.gitignore index 9491a2f..07f703e 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,8 @@ bld/ [Oo]ut/ [Ll]og/ [Ll]ogs/ +[Bb]uild/ +cmake-build-debug/ # Visual Studio 2015/2017 cache/options directory .vs/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..79b3c94 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..06cbee3 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/xpmgr.iml b/.idea/xpmgr.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/xpmgr.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..8786c78 --- /dev/null +++ b/test.txt @@ -0,0 +1,3 @@ +14037188531115461057117122732036502128316172554233 + +115654-870803-633253-538651-586936-689612-768696 \ No newline at end of file diff --git a/xpmgr.cpp b/xpmgr.cpp index e953ee6..d9c9ac1 100644 --- a/xpmgr.cpp +++ b/xpmgr.cpp @@ -2,13 +2,10 @@ typedef struct IUnknown IUnknown; #include #include -#include +#include #include #include -#pragma comment(lib, "comsuppw.lib") -#pragma comment(lib, "kernel32.lib") - // Check windows #if _WIN32 || _WIN64 #if _WIN64 @@ -286,7 +283,7 @@ static BOOL O2003_LoadLicenseManager() } #pragma region Internals -bool RegistryKeyExists(HKEY rootKey, const wchar_t* keyPath) { +bool RegistryKeyExists(HKEY rootKey, const char* keyPath) { HKEY hKey; LSTATUS result = RegOpenKeyEx(rootKey, keyPath, 0, KEY_READ, &hKey); @@ -353,6 +350,31 @@ OLECHAR SizeToOLECHAR(size_t value) return oChar; } +BSTR ConvertToBSTR(const std::string& str) { + int size = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, NULL, 0); + BSTR bstr = SysAllocStringLen(NULL, size - 1); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, bstr, size); + return bstr; +} + +std::string ConvertToStdString(BSTR bstr) { + int size = WideCharToMultiByte(CP_UTF8, 0, bstr, -1, NULL, 0, NULL, NULL); + char* buffer = new char[size]; + WideCharToMultiByte(CP_UTF8, 0, bstr, -1, buffer, size, NULL, NULL); + + std::string result(buffer); + delete[] buffer; + + return result; +} + +BSTR ConvertCharToBSTR(const char* charString) { + int size = MultiByteToWideChar(CP_UTF8, 0, charString, -1, NULL, 0); + BSTR bstr = SysAllocStringLen(NULL, size - 1); + MultiByteToWideChar(CP_UTF8, 0, charString, -1, bstr, size); + return bstr; +} + bool IsProcessRunning(const wchar_t* processName) { HANDLE snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0); @@ -508,7 +530,7 @@ static BSTR XP_SetConfirmationID(BSTR confirmationID) { for (size_t i = 0; i < inputString.length(); i += 6) { std::string substring = inputString.substr(i, 6); const char* cstr = substring.c_str(); - if (0 != wcscmp(XP_VerifyCheckDigits(_com_util::ConvertStringToBSTR(cstr)), L"Successfully verified CID chunk")) { + if (0 != wcscmp(XP_VerifyCheckDigits(ConvertCharToBSTR(cstr)), L"Successfully verified CID chunk")) { return SysAllocString(L"An error occurred at XP_VerifyCheckDigits: Check for misspelling"); } } @@ -623,7 +645,7 @@ static BSTR O2003_SetConfirmationID(BSTR confirmationID) { for (size_t i = 0; i < inputString.length(); i += 6) { std::string substring = inputString.substr(i, 6); const char* cstr = substring.c_str(); - if (0 != wcscmp(XP_VerifyCheckDigits(_com_util::ConvertStringToBSTR(cstr)), L"Successfully verified CID chunk")) { + if (0 != wcscmp(XP_VerifyCheckDigits(ConvertToBSTR(cstr)), L"Successfully verified CID chunk")) { return SysAllocString(L"An error occurred at XP_VerifyCheckDigits: Check for misspelling"); } } @@ -683,7 +705,7 @@ int main(int argc, char* argv[]) if (cmdOptionExists(argv, argv + argc, "--Office2003")) { #ifdef ENVIRONMENT32 - if (RegistryKeyExists(HKEY_CLASSES_ROOT, L"CLSID\\{000C0114-0000-0000-C000-000000000046}")) { + if (RegistryKeyExists(HKEY_CLASSES_ROOT, "CLSID\\{000C0114-0000-0000-C000-000000000046}")) { specifiedProduct = "Office2003"; } else { @@ -749,18 +771,18 @@ int main(int argc, char* argv[]) if (cmdOptionExists(argv, argv + argc, "--GetInstallationID")) { if (specifiedProduct == "Office2003") { - std::cout << _com_util::ConvertBSTRToString(O2003_GetInstallationID()); + std::cout << ConvertToStdString(O2003_GetInstallationID()); return 0; } - std::cout << _com_util::ConvertBSTRToString(XP_GetInstallationID()); + std::cout << ConvertToStdString(XP_GetInstallationID()); return 0; } else if (cmdOptionExists(argv, argv + argc, "--SetConfirmationID")) { if (specifiedProduct == "Office2003") { - std::cout << _com_util::ConvertBSTRToString(O2003_SetConfirmationID(_com_util::ConvertStringToBSTR(getCmdOption(argv, argv + argc, "--SetConfirmationID")))); + std::cout << ConvertToStdString(O2003_SetConfirmationID(ConvertCharToBSTR(getCmdOption(argv, argv + argc, "--SetConfirmationID")))); return 0; } - std::cout << _com_util::ConvertBSTRToString(XP_SetConfirmationID(_com_util::ConvertStringToBSTR(getCmdOption(argv, argv + argc, "--SetConfirmationID")))); + std::cout << ConvertToStdString(XP_SetConfirmationID(ConvertCharToBSTR(getCmdOption(argv, argv + argc, "--SetConfirmationID")))); return 0; } @@ -769,7 +791,7 @@ int main(int argc, char* argv[]) std::cout << "An error occurred at specifiedProduct: This command is for Windows management only."; return 0; } - std::cout << _com_util::ConvertBSTRToString(XP_GetWPALeft()); + std::cout << ConvertToStdString(XP_GetWPALeft()); return 0; } else if (cmdOptionExists(argv, argv + argc, "--GetEvalLeft")) { @@ -777,7 +799,7 @@ int main(int argc, char* argv[]) std::cout << "An error occurred at specifiedProduct: This command is for Windows management only."; return 0; } - std::cout << _com_util::ConvertBSTRToString(XP_GetEvalLeft()); + std::cout << ConvertToStdString(XP_GetEvalLeft()); return 0; } @@ -786,7 +808,7 @@ int main(int argc, char* argv[]) std::cout << "An error occurred at specifiedProduct: This command is for Windows management only."; return 0; } - std::cout << _com_util::ConvertBSTRToString(XP_SetProductKey(convertCharArrayToLPCWSTR(getCmdOption(argv, argv + argc, "--SetProductKey")))); + std::cout << ConvertToStdString(XP_SetProductKey(convertCharArrayToLPCWSTR(getCmdOption(argv, argv + argc, "--SetProductKey")))); return 0; } else if (cmdOptionExists(argv, argv + argc, "--GetProductID")) { @@ -794,7 +816,7 @@ int main(int argc, char* argv[]) std::cout << "An error occurred at specifiedProduct: This command is for Windows management only."; return 0; } - std::cout << _com_util::ConvertBSTRToString(XP_GetProductID()); + std::cout << ConvertToStdString(XP_GetProductID()); return 0; } else { @@ -802,5 +824,4 @@ int main(int argc, char* argv[]) std::cout << text; return 0; } - return 0; } \ No newline at end of file