From b88680a20becab6853c38f0e1690772025ca9484 Mon Sep 17 00:00:00 2001 From: Alexander Frick Date: Wed, 26 Nov 2025 02:20:11 -0600 Subject: [PATCH] corrections to make everyone happy, it now compiles with Clang, MSVC, and MinGW! --- src/framework.h | 21 +++++++++++++++++++-- src/resource.h | 4 +++- src/utils.cc | 23 ++++++++++++++++++++++- src/utils.h | 30 ++++++++++++++---------------- src/version.h | 4 +++- src/xp_activate32.cc | 7 ++----- src/xp_activate32.h | 15 +-------------- 7 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/framework.h b/src/framework.h index 6989071..2eb5b3f 100644 --- a/src/framework.h +++ b/src/framework.h @@ -1,6 +1,20 @@ #pragma once -#include +#ifndef STRICT + #define STRICT +#endif + +#ifndef UNICODE + #define UNICODE +#endif + +#ifndef _UNICODE + #define _UNICODE +#endif + +#ifndef __MINGW32__ + #include +#endif // not __MINGW32__ #ifndef WINVER #define WINVER _WIN32_WINNT_WINXP @@ -21,9 +35,12 @@ #define _ATL_XP_TARGETING #endif // _ATL_XP_TARGETING -#include +#ifndef __MINGW32__ + #include +#endif // not __MINGW32__ #include +#include #include #include #include diff --git a/src/resource.h b/src/resource.h index 43d9861..b17709b 100644 --- a/src/resource.h +++ b/src/resource.h @@ -5,7 +5,9 @@ #pragma once -#pragma code_page(65001) // UTF-8 +#ifdef __clang__ + #pragma code_page(65001) // UTF-8 +#endif // __clang__ #include "version.h" diff --git a/src/utils.cc b/src/utils.cc index 0e0c0de..42dd90d 100644 --- a/src/utils.cc +++ b/src/utils.cc @@ -2,7 +2,23 @@ #include "globals.h" -static bool is_win11; +namespace { + static bool is_win11; + + static ULONG NT_MAJOR = 0; + + static ULONG NT_MINOR = 0; + + static ULONG NT_BUILD = 0; + + static std::wstring NT_CSD_VERSION; + + static std::string NT_SERVICE_PACK; + + static USHORT NT_SUITE; + + static UCHAR NT_TYPE; +} HANDLE LoadImageFromDLL(LPCWSTR dllName, UINT resourceId, @@ -431,11 +447,16 @@ std::string const GetNTString() { // See http://ref.x86asm.net/coder32.html void ImmediateDebugCrash() { #if defined(_WIN32) && !defined(_WIN64) + #ifdef __MINGW32__ + asm("int3\n\t" + "ud2"); + #else // 32 bit assembly code __asm int 3 // Execute int3 interrupt __asm { UD2 // Execute 0x0F, 0x0B } + #endif // __MINGW32__ #elif defined(_WIN64) // x86_64 /* MSVC-specific x64 ud2 since MSVC doesn't allow inline assembly when compiling for x64 */ diff --git a/src/utils.h b/src/utils.h index 6b32c1a..a7a1949 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,27 +1,25 @@ #ifndef XP_ACTIVATE32_UTILS_H_ #define XP_ACTIVATE32_UTILS_H_ +#ifdef __MINGW32__ + extern "C" { + static __inline__ __attribute__((always_inline)) unsigned long long __emulu( + const unsigned int a, const unsigned int b) { + unsigned long long retval; + __asm__("mull %[b]" : "=A"(retval) : [a] "a"(a), [b] "rm"(b)); + return retval; + } + } + #define __noop(...) ((void)0) +#endif // __MINGW32__ + +#include + #include "constants.h" #include "framework.h" extern wchar_t strings[16][256]; -namespace { - static ULONG NT_MAJOR = 0; - - static ULONG NT_MINOR = 0; - - static ULONG NT_BUILD = 0; - - static std::wstring NT_CSD_VERSION; - - static std::string NT_SERVICE_PACK; - - static USHORT NT_SUITE; - - static UCHAR NT_TYPE; -} - static std::string NT_FEATURE_VERSION; static std::string NT_POST_STRING; diff --git a/src/version.h b/src/version.h index 471f121..40ab092 100644 --- a/src/version.h +++ b/src/version.h @@ -1,7 +1,9 @@ #ifndef XP_ACTIVATE32_VERSION_H_ #define XP_ACTIVATE32_VERSION_H_ -#pragma code_page(65001) // UTF-8 +#ifdef __clang__ + #pragma code_page(65001) // UTF-8 +#endif // __clang__ // Macro to convert to string #if !defined(_STRINGIZER) && !defined(STRINGIZE) diff --git a/src/xp_activate32.cc b/src/xp_activate32.cc index 2e7f137..68dd123 100644 --- a/src/xp_activate32.cc +++ b/src/xp_activate32.cc @@ -1038,14 +1038,11 @@ INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) return FALSE; } -int WINAPI wWinMain(_In_ HINSTANCE hInstance, - _In_opt_ HINSTANCE hPrevInstance, - _In_ WCHAR *pCmdLine, - _In_ INT nCmdShow) { +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { UNREFERENCED_PARAMETER(hPrevInstance); /* Assign global HINSTANCE */ g_hInstance = hInstance; - MSG Msg; + //MSG Msg; long err_status; // Allow and allocate conhost diff --git a/src/xp_activate32.h b/src/xp_activate32.h index bedfabf..2bf2352 100644 --- a/src/xp_activate32.h +++ b/src/xp_activate32.h @@ -1,23 +1,10 @@ #ifndef XP_ACTIVATE32_H_ #define XP_ACTIVATE32_H_ -#include - #include "constants.h" #include "framework.h" #include "resource.h" - -#ifndef STRICT - #define STRICT -#endif - -#ifndef UNICODE - #define UNICODE -#endif - -#ifndef _UNICODE - #define _UNICODE -#endif +#include "utils.h" typedef struct { ui64 u[2];