diff --git a/BUILD.gn b/BUILD.gn index af75c7d..6751d26 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -44,6 +44,7 @@ source_set("xp_activate32_sources") { "src/framework.h", "src/globals.h", "src/keygen.h", + "src/strings.h", "src/resource.h", "src/utils.h", "src/xp_activate32.h", @@ -51,6 +52,7 @@ source_set("xp_activate32_sources") { sources += [ "src/keygen.cc", + "src/strings.cc", "src/resource.rc", "src/utils.cc", "src/xp_activate32.cc", diff --git a/src/framework.h b/src/framework.h index 2eb5b3f..4b86960 100644 --- a/src/framework.h +++ b/src/framework.h @@ -40,11 +40,9 @@ #endif // not __MINGW32__ #include -#include #include #include #include - #include #include #include diff --git a/src/strings.cc b/src/strings.cc new file mode 100644 index 0000000..0f7413d --- /dev/null +++ b/src/strings.cc @@ -0,0 +1,46 @@ +#include "strings.h" + +std::wstring stringToWstring(const std::string& str) { + if (str.empty()) { + return std::wstring(); + } +// Windows: convert UTF-8 → UTF-16 +#ifdef _WIN32 + // Get length of string + int wide_len = MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, nullptr, 0); + if (wide_len == 0) { + throw std::runtime_error("MultiByteToWideChar failed!"); + } + + // Convert it! + std::wstring result(wide_len, L'\0'); + MultiByteToWideChar(CP_UTF8, 0, str.c_str(), -1, &result[0], wide_len); + + // Remove the null terminator added by Windows API ugh + if (!result.empty() && result.back() == L'\0') { + result.pop_back(); + } +// POSIX systems: convert UTF-8 → UTF-32 wchar_t +#else + // Set locale for multibyte conversion (thread-local) + std::mbstate_t state{}; + const char* src = str.c_str(); + // find required size + size_t len = std::mbsrtowcs(nullptr, &src, 0, &state); + if (len == static_cast(-1)) { + throw std::runtime_error("mbsrtowcs failed"); + } + + std::wstring result(len, L'\0'); + state = std::mbstate_t{}; + src = str.c_str(); + std::mbsrtowcs(result.data(), &src, len, &state); +#endif + return result; +} + +std::string WstringToString(const std::wstring& wstr) { + if (wstr.empty()) { + return std::string(); + } +} diff --git a/src/strings.h b/src/strings.h new file mode 100644 index 0000000..20c6c01 --- /dev/null +++ b/src/strings.h @@ -0,0 +1,13 @@ +#ifndef XP_ACTIVATE32_STRINGS_H_ +#define XP_ACTIVATE32_STRINGS_H_ + +#include "framework.h" + +#include +#include + +std::wstring stringToWstring(const std::string& str); + +std::string WstringToString(const std::wstring& wstr); + +#endif // XP_ACTIVATE32_STRINGS_H_ diff --git a/src/utils.cc b/src/utils.cc index 42dd90d..98f5328 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -122,9 +122,9 @@ float getWinNTVersion() { } std::wstring GetWinVersion() { - std::string ver = GetOSName(); - std::wstring wver = L"1.0"; + const std::string ver = GetOSName(); WinVer = ver; + std::wstring wver = stringToWstring(WinVer); return wver; } diff --git a/src/utils.h b/src/utils.h index a7a1949..ef5df4c 100644 --- a/src/utils.h +++ b/src/utils.h @@ -17,6 +17,7 @@ #include "constants.h" #include "framework.h" +#include "strings.h" extern wchar_t strings[16][256]; diff --git a/xp_activate32.vcxproj b/xp_activate32.vcxproj index 3dedda2..174afb6 100644 --- a/xp_activate32.vcxproj +++ b/xp_activate32.vcxproj @@ -152,6 +152,7 @@ + @@ -160,6 +161,7 @@ + diff --git a/xp_activate32.vcxproj.filters b/xp_activate32.vcxproj.filters index 9763411..95774da 100644 --- a/xp_activate32.vcxproj.filters +++ b/xp_activate32.vcxproj.filters @@ -26,6 +26,9 @@ Source Files + + Source Files + Source Files @@ -52,6 +55,9 @@ Header Files + + Header Files + Header Files