From aee907595cd768558e28bfe516b430c88c091ad7 Mon Sep 17 00:00:00 2001 From: Mikolaj Zalewski Date: Wed, 17 Oct 2007 13:59:07 -0700 Subject: [PATCH] ntdll: support for UTF-16 manifest with reverse endianness --- dlls/kernel32/tests/actctx.c | 26 +++++++++++++++++++++++--- dlls/ntdll/actctx.c | 29 +++++++++++++++++++++-------- 2 files changed, 44 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 c 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 c 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(co 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..0f66436 100644 --- a/dlls/ntdll/actctx.c +++ b/dlls/ntdll/actctx.c @@ -1498,8 +1498,27 @@ static NTSTATUS parse_manifest( struct a 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) + { + WCHAR *new_buff; + unsigned char *buf = buffer; + int i; + + if (!(new_buff = RtlAllocateHeap( GetProcessHeap(), 0, size ))) + return STATUS_NO_MEMORY; + for (i = 0; i < size; i += sizeof(WCHAR)) + new_buff[i / sizeof(WCHAR)] = (buf[i] << 8) | buf[i+1]; + 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 +1537,6 @@ static NTSTATUS parse_manifest( struct a 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; } -- 1.4.1