diff --git a/setter/src/win32/attr.c b/setter/src/win32/attr.c index 3af4708..60bc83b 100644 --- a/setter/src/win32/attr.c +++ b/setter/src/win32/attr.c @@ -44,13 +44,9 @@ Copyright (C) 2011-2021 Natalia Portillo #include "attr.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; +extern DWORD oldVersion; void FileAttributes(const char* path) { diff --git a/setter/src/win32/deleted.c b/setter/src/win32/deleted.c index f8d0a94..46cafb0 100644 --- a/setter/src/win32/deleted.c +++ b/setter/src/win32/deleted.c @@ -41,14 +41,8 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "win32.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void DeleteFiles(const char* path) { char filename[9]; diff --git a/setter/src/win32/dirdepth.c b/setter/src/win32/dirdepth.c index ba68141..476ab9e 100644 --- a/setter/src/win32/dirdepth.c +++ b/setter/src/win32/dirdepth.c @@ -41,14 +41,8 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "win32.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void DirectoryDepth(const char* path) { BOOL ret; diff --git a/setter/src/win32/filename.c b/setter/src/win32/filename.c index 847f7ff..9054cd0 100644 --- a/setter/src/win32/filename.c +++ b/setter/src/win32/filename.c @@ -44,11 +44,6 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void Filenames(const char* path) { BOOL ret; diff --git a/setter/src/win32/files.c b/setter/src/win32/files.c index 603008f..42273c2 100644 --- a/setter/src/win32/files.c +++ b/setter/src/win32/files.c @@ -41,14 +41,8 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "win32.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void MillionFiles(const char* path) { char filename[9]; diff --git a/setter/src/win32/frag.c b/setter/src/win32/frag.c index 3a3fd91..4e2e20f 100644 --- a/setter/src/win32/frag.c +++ b/setter/src/win32/frag.c @@ -44,11 +44,6 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void Fragmentation(const char* path, size_t clusterSize) { size_t halfCluster = clusterSize / 2; diff --git a/setter/src/win32/links.c b/setter/src/win32/links.c index d0536b8..e765d27 100644 --- a/setter/src/win32/links.c +++ b/setter/src/win32/links.c @@ -44,13 +44,9 @@ Copyright (C) 2011-2021 Natalia Portillo #include "links.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; +extern DWORD oldVersion; void Links(const char* path) { @@ -64,6 +60,7 @@ void Links(const char* path) HANDLE h; LPSTR lpRootPathName; size_t pathSize = strlen(path); + HINSTANCE kernel32; if(WinGetVersionExA) { @@ -216,6 +213,8 @@ void Links(const char* path) printf("\tHard link, rc = 0x%08lx, wRc = %lu, cRc = %lu, lRc = %lu\n", rc, wRc, cRc, lRc); } + + FreeLibrary(kernel32); } #endif diff --git a/setter/src/win32/links.h b/setter/src/win32/links.h index 7cfe802..82655d4 100644 --- a/setter/src/win32/links.h +++ b/setter/src/win32/links.h @@ -5,7 +5,7 @@ #ifndef SETTER_SRC_WIN32_LINKS_H_ #define SETTER_SRC_WIN32_LINKS_H_ -BOOL(WINAPI* WinNtCreateHardLinkA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); -BOOL(WINAPI* WinNtCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD); +static BOOL(WINAPI* WinNtCreateHardLinkA)(LPCSTR, LPCSTR, LPSECURITY_ATTRIBUTES); +static BOOL(WINAPI* WinNtCreateSymbolicLinkA)(LPCSTR, LPCSTR, DWORD); #endif // SETTER_SRC_WIN32_LINKS_H_ diff --git a/setter/src/win32/os.c b/setter/src/win32/os.c index 3f157c3..6599161 100644 --- a/setter/src/win32/os.c +++ b/setter/src/win32/os.c @@ -37,17 +37,12 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include -#include #include #include "win32.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; +DWORD oldVersion; void GetOsInfo() { @@ -55,6 +50,7 @@ void GetOsInfo() BOOL ret; DWORD error; void* func; + HINSTANCE kernel32; kernel32 = LoadLibraryA("KERNEL32.DLL"); memset(&verInfo, 0, sizeof(WIN_OSVERSIONINFO)); @@ -90,6 +86,8 @@ void GetOsInfo() else printf("\tRunning under Windows NT %lu.%lu.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); + FreeLibrary(kernel32); + return; } @@ -102,6 +100,7 @@ void GetOsInfo() { error = GetLastError(); printf("Error %lu querying Windows version.\n", error); + FreeLibrary(kernel32); return; } @@ -195,6 +194,8 @@ void GetOsInfo() printf(" version %lu%02lud.\n", verInfo.dwMajorVersion, verInfo.dwMinorVersion); } } + + FreeLibrary(kernel32); } #endif diff --git a/setter/src/win32/perms.c b/setter/src/win32/perms.c index b3dccd0..b45d16b 100644 --- a/setter/src/win32/perms.c +++ b/setter/src/win32/perms.c @@ -34,21 +34,8 @@ Copyright (C) 2011-2021 Natalia Portillo #define _CRT_SECURE_NO_WARNINGS 1 -#include - -#include -#include -#include - -#include "win32.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void FilePermissions(const char* path) { /* Do nothing, not supported by target operating system */ } diff --git a/setter/src/win32/rsrcfork.c b/setter/src/win32/rsrcfork.c index 8d44435..0d4990a 100644 --- a/setter/src/win32/rsrcfork.c +++ b/setter/src/win32/rsrcfork.c @@ -44,13 +44,9 @@ Copyright (C) 2011-2021 Natalia Portillo #include "rsrcfork.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; +extern DWORD oldVersion; void ResourceFork(const char* path) { diff --git a/setter/src/win32/sparse.c b/setter/src/win32/sparse.c index b1316ce..773ae4f 100644 --- a/setter/src/win32/sparse.c +++ b/setter/src/win32/sparse.c @@ -44,11 +44,6 @@ Copyright (C) 2011-2021 Natalia Portillo #include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void Sparse(const char* path) { BOOL ret; diff --git a/setter/src/win32/time.c b/setter/src/win32/time.c index 7de2f02..ef445a1 100644 --- a/setter/src/win32/time.c +++ b/setter/src/win32/time.c @@ -41,14 +41,8 @@ Copyright (C) 2011-2021 Natalia Portillo #include #include "win32.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; - void Timestamps(const char* path) { char message[300]; diff --git a/setter/src/win32/volume.c b/setter/src/win32/volume.c index 34e5c5b..7307010 100644 --- a/setter/src/win32/volume.c +++ b/setter/src/win32/volume.c @@ -44,13 +44,9 @@ Copyright (C) 2011-2021 Natalia Portillo #include "volume.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; +extern DWORD oldVersion; void GetVolumeInfo(const char* path, size_t* clusterSize) { @@ -71,6 +67,7 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) ULARGE_INTEGER qwTotalNumberOfBytes; ULARGE_INTEGER qwTotalNumberOfFreeBytes; void* func; + HINSTANCE kernel32; *clusterSize = 0; @@ -314,8 +311,13 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) if(verInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS && verInfo.dwBuildNumber >= 1000 || verInfo.dwPlatformId == VER_PLATFORM_WIN32_NT && kernel32) { - func = GetProcAddress(kernel32, "GetDiskFreeSpaceExA"); - if(func) WinGetDiskFreeSpaceExA = func; + kernel32 = LoadLibraryA("kernel32.dll"); + + if(kernel32) + { + func = GetProcAddress(kernel32, "GetDiskFreeSpaceExA"); + if(func) WinGetDiskFreeSpaceExA = func; + } } if(WinGetDiskFreeSpaceExA) @@ -346,6 +348,8 @@ void GetVolumeInfo(const char* path, size_t* clusterSize) } free(lpRootPathName); + + if(func) FreeLibrary(kernel32); } #endif diff --git a/setter/src/win32/win32.h b/setter/src/win32/win32.h index ac7179a..b581bb5 100644 --- a/setter/src/win32/win32.h +++ b/setter/src/win32/win32.h @@ -256,6 +256,9 @@ typedef WIN_LPOSVERSIONINFOA WIN_LPOSVERSIONINFO; static BOOL(WINAPI* WinGetVersionExA)(WIN_LPOSVERSIONINFOA); +static DWORD dwMaxNameSize = MAX_PATH + 1; +static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; + #endif #endif diff --git a/setter/src/win32/xattr.c b/setter/src/win32/xattr.c index fb8aba1..2cb54ba 100644 --- a/setter/src/win32/xattr.c +++ b/setter/src/win32/xattr.c @@ -44,13 +44,9 @@ Copyright (C) 2011-2021 Natalia Portillo #include "xattr.h" -#include "../include/consts.h" #include "../include/defs.h" -static DWORD dwMaxNameSize = MAX_PATH + 1; -static DWORD dwFilePermissions = GENERIC_READ | GENERIC_WRITE; -static DWORD oldVersion; -static HINSTANCE kernel32; +extern DWORD oldVersion; void ExtendedAttributes(const char* path) { diff --git a/setter/src/win32/xattr.h b/setter/src/win32/xattr.h index da106e0..5f1af4b 100644 --- a/setter/src/win32/xattr.h +++ b/setter/src/win32/xattr.h @@ -205,7 +205,7 @@ unsigned char IconEA[3516] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -NTSTATUS(NTAPI* NtSetEaFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG); -NTSTATUS(NTAPI* NtQueryEaFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, BOOLEAN, PVOID, ULONG, PULONG, BOOLEAN); +static NTSTATUS(NTAPI* NtSetEaFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG); +static NTSTATUS(NTAPI* NtQueryEaFile)(HANDLE, PIO_STATUS_BLOCK, PVOID, ULONG, BOOLEAN, PVOID, ULONG, PULONG, BOOLEAN); #endif // SETTER_SRC_WIN32_XATTR_H_