From d8da11f0dcdf75a1b71c557ef036e4bc6b48d28d Mon Sep 17 00:00:00 2001 From: Andrew Dunstan Date: Fri, 12 Oct 2018 07:32:43 +1100 Subject: [PATCH] clean restrict.cpp --- Source/restrict.cpp | 103 +++++++++++++++++++------------------------- Source/restrict.h | 6 +-- 2 files changed, 48 insertions(+), 61 deletions(-) diff --git a/Source/restrict.cpp b/Source/restrict.cpp index 69430a3fe..a737957b7 100644 --- a/Source/restrict.cpp +++ b/Source/restrict.cpp @@ -2,72 +2,59 @@ #include "../types.h" -bool __cdecl SystemSupported() +BOOL __cdecl SystemSupported() { - bool v0; // di - struct _OSVERSIONINFOA VersionInformation; // [esp+4h] [ebp-94h] + OSVERSIONINFO VersionInformation; + BOOL ret = FALSE; - v0 = 0; - memset(&VersionInformation, 0, 0x94u); - VersionInformation.dwOSVersionInfoSize = 148; - if ( GetVersionEx(&VersionInformation) - && VersionInformation.dwPlatformId == 2 - && VersionInformation.dwMajorVersion >= 5 ) - { - v0 = 1; - } - return v0; + memset(&VersionInformation, 0, sizeof(VersionInformation)); + VersionInformation.dwOSVersionInfoSize = sizeof(VersionInformation); + if (GetVersionEx(&VersionInformation) + && VersionInformation.dwPlatformId == VER_PLATFORM_WIN32_NT + && VersionInformation.dwMajorVersion >= 5) { + ret = TRUE; + } + return ret; } -bool __cdecl RestrictedTest() +BOOL __cdecl RestrictedTest() { - bool v0; // si - FILE *v2; // eax - char Buffer[260]; // [esp+4h] [ebp-104h] + FILE *f; + char Buffer[MAX_PATH]; + BOOL ret = FALSE; - v0 = 0; - if ( SystemSupported() && GetWindowsDirectory(Buffer, 0x104u) ) - { - strcat(Buffer, "\\Diablo1RestrictedTest.foo"); - v2 = fopen(Buffer, "wt"); - if ( v2 ) - { - fclose(v2); - remove(Buffer); - } - else - { - v0 = 1; - } - } - return v0; + if (SystemSupported() && GetWindowsDirectory(Buffer, sizeof(Buffer))) { + strcat(Buffer, "\\Diablo1RestrictedTest.foo"); + f = fopen(Buffer, "wt"); + if (f) { + fclose(f); + remove(Buffer); + } else { + ret = TRUE; + } + } + return ret; } -bool __cdecl ReadOnlyTest() +BOOL __cdecl ReadOnlyTest() { - bool v0; // si - char *v1; // eax - FILE *v2; // eax - char Filename[260]; // [esp+4h] [ebp-104h] + char *c; + FILE *f; + char Filename[MAX_PATH]; + BOOL ret = FALSE; - v0 = 0; - if ( GetModuleFileName(ghInst, Filename, 0x104u) ) - { - v1 = strrchr(Filename, '\\'); - if ( v1 ) - { - strcpy(v1 + 1, "Diablo1ReadOnlyTest.foo"); - v2 = fopen(Filename, "wt"); - if ( v2 ) - { - fclose(v2); - remove(Filename); - } - else - { - v0 = 1; - } - } - } - return v0; + if (GetModuleFileName(ghInst, Filename, sizeof(Filename))) { + c = strrchr(Filename, '\\'); + if (c) { + strcpy(c + 1, "Diablo1ReadOnlyTest.foo"); + f = fopen(Filename, "wt"); + if (f) { + fclose(f); + remove(Filename); + } else { + ret = TRUE; + } + } + } + return ret; } diff --git a/Source/restrict.h b/Source/restrict.h index fa69dccd8..631b12bb5 100644 --- a/Source/restrict.h +++ b/Source/restrict.h @@ -2,8 +2,8 @@ #ifndef __RESTRICT_H__ #define __RESTRICT_H__ -bool __cdecl SystemSupported(); -bool __cdecl RestrictedTest(); -bool __cdecl ReadOnlyTest(); +BOOL __cdecl SystemSupported(); +BOOL __cdecl RestrictedTest(); +BOOL __cdecl ReadOnlyTest(); #endif /* __RESTRICT_H__ */