Mikolaj Zalewski : ntdll: Support for UTF-16 manifests with reverse endianness.

Alexandre Julliard julliard at winehq.org
Thu Oct 18 07:59:36 CDT 2007


Module: wine
Branch: master
Commit: 5bfd7044ea0a25006f0a6defe1a8ab77192554e5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=5bfd7044ea0a25006f0a6defe1a8ab77192554e5

Author: Mikolaj Zalewski <mikolajz at google.com>
Date:   Wed Oct 17 13:59:07 2007 -0700

ntdll: Support for UTF-16 manifests with reverse endianness.

---

 dlls/kernel32/tests/actctx.c |   26 +++++++++++++++++++++++---
 dlls/ntdll/actctx.c          |   31 +++++++++++++++++++++++--------
 2 files changed, 46 insertions(+), 11 deletions(-)

diff --git a/dlls/kernel32/tests/actctx.c b/dlls/kernel32/tests/actctx.c
index e2e6b24..0e687b5 100644
--- a/dlls/kernel32/tests/actctx.c
+++ b/dlls/kernel32/tests/actctx.c
@@ -216,7 +216,7 @@ static BOOL create_manifest_file(const char *filename, const char *manifest, int
     return TRUE;
 }
 
-static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM)
+static BOOL create_wide_manifest(const char *filename, const char *manifest, BOOL fBOM, BOOL fReverse)
 {
     WCHAR *wmanifest = HeapAlloc(GetProcessHeap(), 0, (strlen(manifest)+2) * sizeof(WCHAR));
     BOOL ret;
@@ -224,6 +224,12 @@ static BOOL create_wide_manifest(const char *filename, const char *manifest, BOO
 
     MultiByteToWideChar(CP_ACP, 0, manifest, -1, &wmanifest[1], (strlen(manifest)+1) * sizeof(WCHAR));
     wmanifest[0] = 0xfeff;
+    if (fReverse)
+    {
+        int i;
+        for (i = 0; i < strlen(manifest)+1; i++)
+            wmanifest[i] = (wmanifest[i] << 8) | ((wmanifest[i] >> 8) & 0xff);
+    }
     ret = create_manifest_file(filename, (char *)&wmanifest[offset], (strlen(manifest)+1-offset) * sizeof(WCHAR), NULL, NULL);
     HeapFree(GetProcessHeap(), 0, wmanifest);
     return ret;
@@ -625,7 +631,7 @@ static void test_create_wide_and_fail(const char *manifest, BOOL fBOM)
     actctx.cbSize = sizeof(ACTCTXW);
     actctx.lpSource = path;
 
-    create_wide_manifest("bad.manifest", manifest, fBOM);
+    create_wide_manifest("bad.manifest", manifest, fBOM, FALSE);
     handle = pCreateActCtxW(&actctx);
     ok(handle == INVALID_HANDLE_VALUE, "handle != INVALID_HANDLE_VALUE\n");
     ok(GetLastError() == ERROR_SXS_CANT_GEN_ACTCTX, "GetLastError == %u\n", GetLastError());
@@ -1021,7 +1027,21 @@ static void test_actctx(void)
     RemoveDirectoryW(work_dir_subdir);
 
     trace("UTF-16 manifest1, with BOM\n");
-    if(!create_wide_manifest("test1.manifest", manifest1, TRUE)) {
+    if(!create_wide_manifest("test1.manifest", manifest1, TRUE, FALSE)) {
+        skip("Could not create manifest file\n");
+        return;
+    }
+
+    handle = test_create("test1.manifest", manifest1);
+    DeleteFileA("test1.manifest");
+    if (handle != INVALID_HANDLE_VALUE) {
+        test_detailed_info(handle, &detailed_info1);
+        test_info_in_assembly(handle, 1, &manifest1_info);
+        pReleaseActCtx(handle);
+    }
+
+    trace("UTF-16 manifest1, reverse endian, with BOM\n");
+    if(!create_wide_manifest("test1.manifest", manifest1, TRUE, TRUE)) {
         skip("Could not create manifest file\n");
         return;
     }
diff --git a/dlls/ntdll/actctx.c b/dlls/ntdll/actctx.c
index e26dc02..fe83be6 100644
--- a/dlls/ntdll/actctx.c
+++ b/dlls/ntdll/actctx.c
@@ -1498,8 +1498,29 @@ static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_ident
     assembly->manifest.type = assembly->manifest.info ? ACTIVATION_CONTEXT_PATH_TYPE_WIN32_FILE
                                                       : ACTIVATION_CONTEXT_PATH_TYPE_NONE;
 
-    unicode_tests = IS_TEXT_UNICODE_SIGNATURE;
-    if (!RtlIsTextUnicode( buffer, size, &unicode_tests ))
+    unicode_tests = IS_TEXT_UNICODE_SIGNATURE | IS_TEXT_UNICODE_REVERSE_SIGNATURE;
+    if (RtlIsTextUnicode( buffer, size, &unicode_tests ))
+    {
+        xmlbuf.ptr = buffer;
+        xmlbuf.end = xmlbuf.ptr + size / sizeof(WCHAR);
+        status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
+    }
+    else if (unicode_tests & IS_TEXT_UNICODE_REVERSE_SIGNATURE)
+    {
+        const WCHAR *buf = buffer;
+        WCHAR *new_buff;
+        unsigned int i;
+
+        if (!(new_buff = RtlAllocateHeap( GetProcessHeap(), 0, size )))
+            return STATUS_NO_MEMORY;
+        for (i = 0; i < size / sizeof(WCHAR); i++)
+            new_buff[i] = RtlUshortByteSwap( buf[i] );
+        xmlbuf.ptr = new_buff;
+        xmlbuf.end = xmlbuf.ptr + size / sizeof(WCHAR);
+        status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
+        RtlFreeHeap( GetProcessHeap(), 0, new_buff );
+    }
+    else
     {
         /* let's assume utf-8 for now */
         int len = wine_utf8_mbstowcs( 0, buffer, size, NULL, 0 );
@@ -1518,12 +1539,6 @@ static NTSTATUS parse_manifest( struct actctx_loader* acl, struct assembly_ident
         status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
         RtlFreeHeap( GetProcessHeap(), 0, new_buff );
     }
-    else
-    {
-        xmlbuf.ptr = buffer;
-        xmlbuf.end = xmlbuf.ptr + size / sizeof(WCHAR);
-        status = parse_manifest_buffer( acl, assembly, ai, &xmlbuf );
-    }
     return status;
 }
 




More information about the wine-cvs mailing list