List Archive

Thread

Thread Index

Message

From: Michał Janiszewski <janisozaur%gmail.com@localhost>
To: libzip mailing list <libzip-discuss%nih.at@localhost>
Subject: UWP builds
Date: Fri, 24 Nov 2017 12:30:02 +0100

Hi,
Please consider applying this patch which allows building for UWP.
For your convenience, the patch is also available at https://hastebin.com/diwavuqubo.diff
This only addresses building the library itself and won't support encryption, as seeding entropy is turned off, until someone who knows the platform better can implement it.
The patch is based on https://github.com/stammen/libzip-1.1

diff --git a/CMakeLists.txt b/CMakeLists.txt
index bfbc95d..2bc6752 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -117,6 +117,10 @@ ADD_DEFINITIONS("-D_CRT_SECURE_NO_WARNINGS")
 ADD_DEFINITIONS("-D_CRT_NONSTDC_NO_DEPRECATE")
 ENDIF(MSVC)
 
+if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore)
+  ADD_DEFINITIONS(-DWINRT)
+endif(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore)
+
 ADD_DEFINITIONS("-DHAVE_CONFIG_H")
 
 # rpath handling: use rpath in installed binaries
diff --git a/lib/zip_random_win32.c b/lib/zip_random_win32.c
index 967a54c..a72e097 100644
--- a/lib/zip_random_win32.c
+++ b/lib/zip_random_win32.c
@@ -37,6 +37,7 @@
 bool
 zip_random(zip_uint8_t *buffer, zip_uint16_t length)
 {
+#ifndef WINRT
     HCRYPTPROV hprov;
     if (!CryptAcquireContext(&hprov, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT | CRYPT_SILENT)) {
 	return false;
@@ -48,4 +49,7 @@ zip_random(zip_uint8_t *buffer, zip_uint16_t length)
 	return false;
     }
     return true;
+#else
+    return false;
+#endif // WINRT
 }
diff --git a/lib/zip_source_win32a.c b/lib/zip_source_win32a.c
index e343a70..625784f 100644
--- a/lib/zip_source_win32a.c
+++ b/lib/zip_source_win32a.c
@@ -31,7 +31,7 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-
+#ifndef WINRT
 #include <stdio.h>
 
 #include "zipint.h"
@@ -122,3 +122,5 @@ _win32_remove_a(const void *fname)
     DeleteFileA((const char *)fname);
     return 0;
 }
+
+#endif //WINRT
diff --git a/lib/zip_source_win32handle.c b/lib/zip_source_win32handle.c
index 7fe003d..f7ac12e 100644
--- a/lib/zip_source_win32handle.c
+++ b/lib/zip_source_win32handle.c
@@ -420,12 +420,15 @@ _win32_create_temp_file(_zip_source_win32_read_file_t *ctx)
     int i;
     HANDLE th = INVALID_HANDLE_VALUE;
     void *temp = NULL;
-    SECURITY_INFORMATION si;
-    SECURITY_ATTRIBUTES sa;
     PSECURITY_DESCRIPTOR psd = NULL;
     PSECURITY_ATTRIBUTES psa = NULL;
+
+
+#ifndef WINRT
     DWORD len;
     BOOL success;
+    SECURITY_ATTRIBUTES sa;
+    SECURITY_INFORMATION si;
 
     /*
     Read the DACL from the original file, so we can copy it to the temp file.
@@ -452,6 +455,10 @@ _win32_create_temp_file(_zip_source_win32_read_file_t *ctx)
     }
 
     value = GetTickCount();
+#else
+    value = (zip_uint32_t)GetTickCount64();
+#endif
+
     for (i = 0; i < 1024 && th == INVALID_HANDLE_VALUE; i++) {
 	th = ctx->ops->op_create_temp(ctx, &temp, value + i, psa);
 	if (th == INVALID_HANDLE_VALUE && GetLastError() != ERROR_FILE_EXISTS)
diff --git a/lib/zip_source_win32w.c b/lib/zip_source_win32w.c
index d8b8f86..092c044 100644
--- a/lib/zip_source_win32w.c
+++ b/lib/zip_source_win32w.c
@@ -83,7 +83,19 @@ _win32_strdup_w(const void *str)
 static HANDLE
 _win32_open_w(_zip_source_win32_read_file_t *ctx)
 {
+#ifdef WINRT
+    CREATEFILE2_EXTENDED_PARAMETERS extParams = { 0 };
+    extParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL;
+    extParams.dwFileFlags = FILE_FLAG_RANDOM_ACCESS;
+    extParams.dwSecurityQosFlags = SECURITY_ANONYMOUS;
+    extParams.dwSize = sizeof(extParams);
+    extParams.hTemplateFile = NULL;
+    extParams.lpSecurityAttributes = NULL;
+
+    return CreateFile2(ctx->fname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, OPEN_EXISTING, &extParams);
+#else
     return CreateFileW(ctx->fname, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+#endif
 }
 
 
@@ -103,7 +115,19 @@ _win32_create_temp_w(_zip_source_win32_read_file_t *ctx, void **temp, zip_uint32
 	return INVALID_HANDLE_VALUE;
     }
 
+#ifdef WINRT
+    CREATEFILE2_EXTENDED_PARAMETERS extParams = { 0 };
+    extParams.dwFileAttributes = FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY;
+    extParams.dwFileFlags = FILE_FLAG_RANDOM_ACCESS;
+    extParams.dwSecurityQosFlags = SECURITY_ANONYMOUS;
+    extParams.dwSize = sizeof(extParams);
+    extParams.hTemplateFile = NULL;
+    extParams.lpSecurityAttributes = NULL;
+
+    return CreateFile2((const wchar_t *)*temp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, CREATE_NEW, &extParams);
+#else
     return CreateFileW((const wchar_t *)*temp, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, sa, CREATE_NEW, FILE_ATTRIBUTE_NORMAL | FILE_ATTRIBUTE_TEMPORARY, NULL);
+#endif
 }
 
 
diff --git a/lib/zipwin32.h b/lib/zipwin32.h
index 60f8d0c..701a34c 100644
--- a/lib/zipwin32.h
+++ b/lib/zipwin32.h
@@ -35,7 +35,10 @@
 */
 
 /* 0x0501 => Windows XP; needs to be at least this value because of GetFileSizeEx */
+#ifndef WINRT
 #define _WIN32_WINNT 0x0501
+#endif
+
 #include <windows.h>
 
 /* context for Win32 source */
If this patch gets merged, would you consider doing another point-release, so that the patches used in vcpkg can be dropped?
Best regards,
Michał

--
Michal Janiszewski

Made by MHonArc.