[APPHELP] Simplify SdbTagToString.
[reactos.git] / reactos / dll / appcompat / apphelp / sdbapi.c
1 /*
2 * Copyright 2011 André Hentschel
3 * Copyright 2013 Mislav Blažević
4 * Copyright 2015,2016 Mark Jansen
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #define WIN32_NO_STATUS
22 #include "windows.h"
23 #include "ntndk.h"
24 #include "strsafe.h"
25 #include "apphelp.h"
26 #include "sdbstringtable.h"
27
28 #include "wine/unicode.h"
29
30
31 static const GUID GUID_DATABASE_MSI = {0xd8ff6d16,0x6a3a,0x468a, {0x8b,0x44,0x01,0x71,0x4d,0xdc,0x49,0xea}};
32 static const GUID GUID_DATABASE_SHIM = {0x11111111,0x1111,0x1111, {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11}};
33 static const GUID GUID_DATABASE_DRIVERS = {0xf9ab2228,0x3312,0x4a73, {0xb6,0xf9,0x93,0x6d,0x70,0xe1,0x12,0xef}};
34
35 static HANDLE SdbpHeap(void);
36
37 #if SDBAPI_DEBUG_ALLOC
38
39 typedef struct SHIM_ALLOC_ENTRY
40 {
41 PVOID Address;
42 SIZE_T Size;
43 int Line;
44 const char* File;
45 PVOID Next;
46 PVOID Prev;
47 } SHIM_ALLOC_ENTRY, *PSHIM_ALLOC_ENTRY;
48
49
50 static RTL_AVL_TABLE g_SdbpAllocationTable;
51
52
53 static RTL_GENERIC_COMPARE_RESULTS
54 NTAPI ShimAllocCompareRoutine(_In_ PRTL_AVL_TABLE Table, _In_ PVOID FirstStruct, _In_ PVOID SecondStruct)
55 {
56 PVOID First = ((PSHIM_ALLOC_ENTRY)FirstStruct)->Address;
57 PVOID Second = ((PSHIM_ALLOC_ENTRY)SecondStruct)->Address;
58
59 if (First < Second)
60 return GenericLessThan;
61 else if (First == Second)
62 return GenericEqual;
63 return GenericGreaterThan;
64 }
65
66 static PVOID NTAPI ShimAllocAllocateRoutine(_In_ PRTL_AVL_TABLE Table, _In_ CLONG ByteSize)
67 {
68 return HeapAlloc(SdbpHeap(), HEAP_ZERO_MEMORY, ByteSize);
69 }
70
71 static VOID NTAPI ShimAllocFreeRoutine(_In_ PRTL_AVL_TABLE Table, _In_ PVOID Buffer)
72 {
73 HeapFree(SdbpHeap(), 0, Buffer);
74 }
75
76 static void SdbpInsertAllocation(PVOID address, SIZE_T size, int line, const char* file)
77 {
78 SHIM_ALLOC_ENTRY Entry = {0};
79
80 Entry.Address = address;
81 Entry.Size = size;
82 Entry.Line = line;
83 Entry.File = file;
84 RtlInsertElementGenericTableAvl(&g_SdbpAllocationTable, &Entry, sizeof(Entry), NULL);
85 }
86
87 static void SdbpUpdateAllocation(PVOID address, PVOID newaddress, SIZE_T size, int line, const char* file)
88 {
89 SHIM_ALLOC_ENTRY Lookup = {0};
90 PSHIM_ALLOC_ENTRY Entry;
91 Lookup.Address = address;
92 Entry = RtlLookupElementGenericTableAvl(&g_SdbpAllocationTable, &Lookup);
93
94 if (address == newaddress)
95 {
96 Entry->Size = size;
97 }
98 else
99 {
100 Lookup.Address = newaddress;
101 Lookup.Size = size;
102 Lookup.Line = line;
103 Lookup.File = file;
104 Lookup.Prev = address;
105 RtlInsertElementGenericTableAvl(&g_SdbpAllocationTable, &Lookup, sizeof(Lookup), NULL);
106 Entry->Next = newaddress;
107 }
108 }
109
110 static void SdbpRemoveAllocation(PVOID address, int line, const char* file)
111 {
112 char buf[512];
113 SHIM_ALLOC_ENTRY Lookup = {0};
114 PSHIM_ALLOC_ENTRY Entry;
115
116 sprintf(buf, "\r\n===============\r\n%s(%d): SdbpFree called, tracing alloc:\r\n", file, line);
117 OutputDebugStringA(buf);
118
119 Lookup.Address = address;
120 while (Lookup.Address)
121 {
122 Entry = RtlLookupElementGenericTableAvl(&g_SdbpAllocationTable, &Lookup);
123 if (Entry)
124 {
125 Lookup = *Entry;
126 RtlDeleteElementGenericTableAvl(&g_SdbpAllocationTable, Entry);
127
128 sprintf(buf, " > %s(%d): %s%sAlloc( %d ) ==> %p\r\n", Lookup.File, Lookup.Line,
129 Lookup.Next ? "Invalidated " : "", Lookup.Prev ? "Re" : "", Lookup.Size, Lookup.Address);
130 OutputDebugStringA(buf);
131 Lookup.Address = Lookup.Prev;
132 }
133 else
134 {
135 Lookup.Address = NULL;
136 }
137 }
138 sprintf(buf, "\r\n===============\r\n");
139 OutputDebugStringA(buf);
140 }
141
142 #endif
143
144 static HANDLE g_Heap;
145 void SdbpHeapInit(void)
146 {
147 #if SDBAPI_DEBUG_ALLOC
148 RtlInitializeGenericTableAvl(&g_SdbpAllocationTable, ShimAllocCompareRoutine,
149 ShimAllocAllocateRoutine, ShimAllocFreeRoutine, NULL);
150 #endif
151 g_Heap = HeapCreate(0, 0x10000, 0);
152 }
153
154 void SdbpHeapDeinit(void)
155 {
156 #if SDBAPI_DEBUG_ALLOC
157 if (g_SdbpAllocationTable.NumberGenericTableElements != 0)
158 __debugbreak();
159 #endif
160 HeapDestroy(g_Heap);
161 }
162
163 static HANDLE SdbpHeap(void)
164 {
165 return g_Heap;
166 }
167
168 LPVOID SdbpAlloc(SIZE_T size
169 #if SDBAPI_DEBUG_ALLOC
170 , int line, const char* file
171 #endif
172 )
173 {
174 LPVOID mem = HeapAlloc(SdbpHeap(), HEAP_ZERO_MEMORY, size);
175 #if SDBAPI_DEBUG_ALLOC
176 SdbpInsertAllocation(mem, size, line, file);
177 #endif
178 return mem;
179 }
180
181 LPVOID SdbpReAlloc(LPVOID mem, SIZE_T size, SIZE_T oldSize
182 #if SDBAPI_DEBUG_ALLOC
183 , int line, const char* file
184 #endif
185 )
186 {
187 LPVOID newmem = HeapReAlloc(SdbpHeap(), HEAP_ZERO_MEMORY, mem, size);
188 #if SDBAPI_DEBUG_ALLOC
189 SdbpUpdateAllocation(mem, newmem, size, line, file);
190 #endif
191 return newmem;
192 }
193
194 void SdbpFree(LPVOID mem
195 #if SDBAPI_DEBUG_ALLOC
196 , int line, const char* file
197 #endif
198 )
199 {
200 #if SDBAPI_DEBUG_ALLOC
201 SdbpRemoveAllocation(mem, line, file);
202 #endif
203 HeapFree(SdbpHeap(), 0, mem);
204 }
205
206 PDB WINAPI SdbpCreate(LPCWSTR path, PATH_TYPE type, BOOL write)
207 {
208 NTSTATUS Status;
209 IO_STATUS_BLOCK io;
210 OBJECT_ATTRIBUTES attr;
211 UNICODE_STRING str;
212 PDB db;
213
214 if (type == DOS_PATH)
215 {
216 if (!RtlDosPathNameToNtPathName_U(path, &str, NULL, NULL))
217 return NULL;
218 }
219 else
220 RtlInitUnicodeString(&str, path);
221
222 /* SdbAlloc zeroes the memory. */
223 db = (PDB)SdbAlloc(sizeof(DB));
224 if (!db)
225 {
226 SHIM_ERR("Failed to allocate memory for shim database\n");
227 return NULL;
228 }
229
230 InitializeObjectAttributes(&attr, &str, OBJ_CASE_INSENSITIVE, NULL, NULL);
231
232 Status = NtCreateFile(&db->file, (write ? FILE_GENERIC_WRITE : FILE_GENERIC_READ )| SYNCHRONIZE,
233 &attr, &io, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ,
234 write ? FILE_SUPERSEDE : FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0);
235
236 if (type == DOS_PATH)
237 RtlFreeUnicodeString(&str);
238
239 if (!NT_SUCCESS(Status))
240 {
241 SdbCloseDatabase(db);
242 SHIM_ERR("Failed to create shim database file: %lx\n", Status);
243 return NULL;
244 }
245
246 return db;
247 }
248
249 void WINAPI SdbpFlush(PDB db)
250 {
251 IO_STATUS_BLOCK io;
252 NTSTATUS Status = NtWriteFile(db->file, NULL, NULL, NULL, &io,
253 db->data, db->write_iter, NULL, NULL);
254 if( !NT_SUCCESS(Status))
255 SHIM_WARN("failed with 0x%lx\n", Status);
256 }
257
258 DWORD SdbpStrlen(PCWSTR string)
259 {
260 return lstrlenW(string);
261 }
262
263 DWORD SdbpStrsize(PCWSTR string)
264 {
265 return (SdbpStrlen(string) + 1) * sizeof(WCHAR);
266 }
267
268 PWSTR SdbpStrDup(LPCWSTR string)
269 {
270 PWSTR ret = SdbpAlloc(SdbpStrsize(string));
271 lstrcpyW(ret, string);
272 return ret;
273 }
274
275
276 BOOL WINAPI SdbpOpenMemMappedFile(LPCWSTR path, PMEMMAPPED mapping)
277 {
278 NTSTATUS Status;
279 OBJECT_ATTRIBUTES ObjectAttributes;
280 IO_STATUS_BLOCK IoStatusBlock;
281 FILE_STANDARD_INFORMATION FileStandard;
282 UNICODE_STRING FileName;
283
284 RtlZeroMemory(mapping, sizeof(*mapping));
285
286 if(!RtlDosPathNameToNtPathName_U(path, &FileName, NULL, NULL))
287 {
288 RtlFreeUnicodeString(&FileName);
289 return FALSE;
290 }
291
292 InitializeObjectAttributes(&ObjectAttributes, &FileName, OBJ_CASE_INSENSITIVE, NULL, NULL);
293 Status = NtOpenFile(&mapping->file, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT);
294 RtlFreeUnicodeString(&FileName);
295
296 if (!NT_SUCCESS(Status))
297 {
298 SHIM_ERR("Failed to open file %S: 0x%lx\n", path, Status);
299 return FALSE;
300 }
301
302 Status = NtCreateSection(&mapping->section, STANDARD_RIGHTS_REQUIRED | SECTION_QUERY | SECTION_MAP_READ, 0, 0, PAGE_READONLY, SEC_COMMIT, mapping->file);
303 if (!NT_SUCCESS(Status))
304 {
305 /* Special case */
306 if (Status == STATUS_MAPPED_FILE_SIZE_ZERO)
307 {
308 NtClose(mapping->file);
309 mapping->file = mapping->section = NULL;
310 return TRUE;
311 }
312 SHIM_ERR("Failed to create mapping for file: 0x%lx\n", Status);
313 goto err_out;
314 }
315
316 Status = NtQueryInformationFile(mapping->file, &IoStatusBlock, &FileStandard, sizeof(FileStandard), FileStandardInformation);
317 if (!NT_SUCCESS(Status))
318 {
319 SHIM_ERR("Failed to read file info for file: 0x%lx\n", Status);
320 goto err_out;
321 }
322
323 mapping->mapped_size = mapping->size = FileStandard.EndOfFile.LowPart;
324 Status = NtMapViewOfSection(mapping->section, NtCurrentProcess(), (PVOID*)&mapping->view, 0, 0, 0, &mapping->mapped_size, ViewUnmap, 0, PAGE_READONLY);
325 if (!NT_SUCCESS(Status))
326 {
327 SHIM_ERR("Failed to map view of file: 0x%lx\n", Status);
328 goto err_out;
329 }
330
331 return TRUE;
332
333 err_out:
334 if (!mapping->view)
335 {
336 if (mapping->section)
337 NtClose(mapping->section);
338 NtClose(mapping->file);
339 }
340 return FALSE;
341 }
342
343 void WINAPI SdbpCloseMemMappedFile(PMEMMAPPED mapping)
344 {
345 /* Prevent a VAD warning */
346 if (mapping->view)
347 NtUnmapViewOfSection(NtCurrentProcess(), mapping->view);
348 NtClose(mapping->section);
349 NtClose(mapping->file);
350 RtlZeroMemory(mapping, sizeof(*mapping));
351 }
352
353 BOOL WINAPI SdbpCheckTagType(TAG tag, WORD type)
354 {
355 if ((tag & TAG_TYPE_MASK) != type)
356 return FALSE;
357 return TRUE;
358 }
359
360 BOOL WINAPI SdbpCheckTagIDType(PDB db, TAGID tagid, WORD type)
361 {
362 TAG tag = SdbGetTagFromTagID(db, tagid);
363 if (tag == TAG_NULL)
364 return FALSE;
365 return SdbpCheckTagType(tag, type);
366 }
367
368 PDB SdbpOpenDatabase(LPCWSTR path, PATH_TYPE type, PDWORD major, PDWORD minor)
369 {
370 IO_STATUS_BLOCK io;
371 PDB db;
372 NTSTATUS Status;
373 BYTE header[12];
374
375 db = SdbpCreate(path, type, FALSE);
376 if (!db)
377 return NULL;
378
379 db->size = GetFileSize(db->file, NULL);
380 db->data = SdbAlloc(db->size);
381 Status = NtReadFile(db->file, NULL, NULL, NULL, &io, db->data, db->size, NULL, NULL);
382
383 if (!NT_SUCCESS(Status))
384 {
385 SdbCloseDatabase(db);
386 SHIM_ERR("Failed to open shim database file: 0x%lx\n", Status);
387 return NULL;
388 }
389
390 if (!SdbpReadData(db, &header, 0, 12))
391 {
392 SdbCloseDatabase(db);
393 SHIM_ERR("Failed to read shim database header\n");
394 return NULL;
395 }
396
397 if (memcmp(&header[8], "sdbf", 4) != 0)
398 {
399 SdbCloseDatabase(db);
400 SHIM_ERR("Shim database header is invalid\n");
401 return NULL;
402 }
403
404 *major = *(DWORD*)&header[0];
405 *minor = *(DWORD*)&header[4];
406
407 return db;
408 }
409
410
411 /**
412 * Opens specified shim database file.
413 *
414 * @param [in] path Path to the shim database.
415 * @param [in] type Type of path. Either DOS_PATH or NT_PATH.
416 *
417 * @return Success: Handle to the shim database, NULL otherwise.
418 */
419 PDB WINAPI SdbOpenDatabase(LPCWSTR path, PATH_TYPE type)
420 {
421 PDB db;
422 DWORD major, minor;
423
424 db = SdbpOpenDatabase(path, type, &major, &minor);
425 if (!db)
426 return NULL;
427
428 if (major != 2 && major != 3)
429 {
430 SdbCloseDatabase(db);
431 SHIM_ERR("Invalid shim database version\n");
432 return NULL;
433 }
434
435 db->stringtable = SdbFindFirstTag(db, TAGID_ROOT, TAG_STRINGTABLE);
436 if(!SdbGetDatabaseID(db, &db->database_id))
437 {
438 SHIM_INFO("Failed to get the database id\n");
439 }
440 return db;
441 }
442
443 /**
444 * Closes specified database and frees its memory.
445 *
446 * @param [in] db Handle to the shim database.
447 */
448 void WINAPI SdbCloseDatabase(PDB db)
449 {
450 if (!db)
451 return;
452
453 if (db->file)
454 NtClose(db->file);
455 if (db->string_buffer)
456 SdbCloseDatabase(db->string_buffer);
457 if (db->string_lookup)
458 SdbpTableDestroy(&db->string_lookup);
459 SdbFree(db->data);
460 SdbFree(db);
461 }
462
463 /**
464 * Parses a string to retrieve a GUID.
465 *
466 * @param [in] GuidString The string to parse.
467 * @param [out] Guid The resulting GUID.
468 *
469 * @return TRUE if it succeeds, FALSE if it fails.
470 */
471 BOOL WINAPI SdbGUIDFromString(PCWSTR GuidString, GUID *Guid)
472 {
473 UNICODE_STRING GuidString_u;
474 RtlInitUnicodeString(&GuidString_u, GuidString);
475 return NT_SUCCESS(RtlGUIDFromString(&GuidString_u, Guid));
476 }
477
478 /**
479 * Converts a GUID to a string.
480 *
481 * @param [in] Guid The GUID to convert.
482 * @param [out] GuidString The resulting string representation of Guid.
483 * @param [in] Length The length of GuidString.
484 *
485 * @return TRUE if it succeeds, FALSE if it fails.
486 */
487 BOOL WINAPI SdbGUIDToString(CONST GUID *Guid, PWSTR GuidString, SIZE_T Length)
488 {
489 UNICODE_STRING GuidString_u;
490 if(NT_SUCCESS(RtlStringFromGUID(Guid, &GuidString_u)))
491 {
492 HRESULT hr = StringCchCopyNW(GuidString, Length, GuidString_u.Buffer, GuidString_u.Length / 2);
493 RtlFreeUnicodeString(&GuidString_u);
494 return SUCCEEDED(hr);
495 }
496 return FALSE;
497 }
498
499 /**
500 * Checks if the specified GUID is a NULL GUID
501 *
502 * @param [in] Guid The GUID to check.
503 *
504 * @return TRUE if it is a NULL GUID.
505 */
506 BOOL WINAPI SdbIsNullGUID(CONST GUID *Guid)
507 {
508 static GUID NullGuid = { 0 };
509 return !Guid || IsEqualGUID(&NullGuid, Guid);
510 }
511
512 /**
513 * Get the GUID from one of the standard databases.
514 *
515 * @param [in] Flags The ID to retrieve the guid from. (See SDB_DATABASE_MAIN_[xxx])
516 * @param [out] Guid The resulting GUID.
517 *
518 * @return TRUE if a known database ID.
519 */
520 BOOL WINAPI SdbGetStandardDatabaseGUID(DWORD Flags, GUID* Guid)
521 {
522 const GUID* copy_from = NULL;
523 switch(Flags & HID_DATABASE_TYPE_MASK)
524 {
525 case SDB_DATABASE_MAIN_MSI:
526 copy_from = &GUID_DATABASE_MSI;
527 break;
528 case SDB_DATABASE_MAIN_SHIM:
529 copy_from = &GUID_DATABASE_SHIM;
530 break;
531 case SDB_DATABASE_MAIN_DRIVERS:
532 copy_from = &GUID_DATABASE_DRIVERS;
533 break;
534 default:
535 SHIM_ERR("Cannot obtain database guid for databases other than main\n");
536 return FALSE;
537 }
538 if(Guid)
539 {
540 memcpy(Guid, copy_from, sizeof(GUID));
541 }
542 return TRUE;
543 }
544
545 /**
546 * Read the database version from the specified database.
547 *
548 * @param [in] database The database.
549 * @param [out] VersionHi The first part of the version number.
550 * @param [out] VersionLo The second part of the version number.
551 *
552 * @return TRUE if it succeeds or fails, FALSE if ???
553 */
554 BOOL WINAPI SdbGetDatabaseVersion(LPCWSTR database, PDWORD VersionHi, PDWORD VersionLo)
555 {
556 PDB db;
557
558 db = SdbpOpenDatabase(database, DOS_PATH, VersionHi, VersionLo);
559 if (db)
560 SdbCloseDatabase(db);
561
562 return TRUE;
563 }
564
565
566 /**
567 * Find the first named child tag.
568 *
569 * @param [in] database The database.
570 * @param [in] root The tag to start at
571 * @param [in] find The tag type to find
572 * @param [in] nametag The child of 'find' that contains the name
573 * @param [in] find_name The name to find
574 *
575 * @return The found tag, or TAGID_NULL on failure
576 */
577 TAGID WINAPI SdbFindFirstNamedTag(PDB db, TAGID root, TAGID find, TAGID nametag, LPCWSTR find_name)
578 {
579 TAGID iter;
580
581 iter = SdbFindFirstTag(db, root, find);
582
583 while (iter != TAGID_NULL)
584 {
585 TAGID tmp = SdbFindFirstTag(db, iter, nametag);
586 if (tmp != TAGID_NULL)
587 {
588 LPCWSTR name = SdbGetStringTagPtr(db, tmp);
589 if (name && !lstrcmpiW(name, find_name))
590 return iter;
591 }
592 iter = SdbFindNextTag(db, root, iter);
593 }
594 return TAGID_NULL;
595 }
596
597
598 /**
599 * Find a named layer in a multi-db.
600 *
601 * @param [in] hsdb The multi-database.
602 * @param [in] layerName The named tag to find.
603 *
604 * @return The layer, or TAGREF_NULL on failure
605 */
606 TAGREF WINAPI SdbGetLayerTagRef(HSDB hsdb, LPCWSTR layerName)
607 {
608 PDB db = hsdb->db;
609
610 TAGID database = SdbFindFirstTag(db, TAGID_ROOT, TAG_DATABASE);
611 if (database != TAGID_NULL)
612 {
613 TAGID layer = SdbFindFirstNamedTag(db, database, TAG_LAYER, TAG_NAME, layerName);
614 if (layer != TAGID_NULL)
615 {
616 TAGREF tr;
617 if (SdbTagIDToTagRef(hsdb, db, layer, &tr))
618 {
619 return tr;
620 }
621 }
622 }
623 return TAGREF_NULL;
624 }
625
626
627 /**
628 * Converts the specified string to an index key.
629 *
630 * @param [in] str The string which will be converted.
631 *
632 * @return The resulting index key
633 *
634 * @todo: Fix this for unicode strings.
635 */
636 LONGLONG WINAPI SdbMakeIndexKeyFromString(LPCWSTR str)
637 {
638 LONGLONG result = 0;
639 int shift = 56;
640
641 while (*str && shift >= 0)
642 {
643 WCHAR c = toupper(*(str++));
644
645 if (c & 0xff)
646 {
647 result |= (((LONGLONG)(c & 0xff)) << shift);
648 shift -= 8;
649 }
650
651 if (shift < 0)
652 break;
653
654 c >>= 8;
655
656 if (c & 0xff)
657 {
658 result |= (((LONGLONG)(c & 0xff)) << shift);
659 shift -= 8;
660 }
661 }
662
663 return result;
664 }
665
666
667 /**
668 * Converts specified tag into a string.
669 *
670 * @param [in] tag The tag which will be converted to a string.
671 *
672 * @return Success: Pointer to the string matching specified tag, or L"InvalidTag" on failure.
673 *
674 */
675 LPCWSTR WINAPI SdbTagToString(TAG tag)
676 {
677 switch (tag)
678 {
679 case TAG_NULL: return L"NULL";
680
681 /* TAG_TYPE_NULL */
682 case TAG_INCLUDE: return L"INCLUDE";
683 case TAG_GENERAL: return L"GENERAL";
684 case TAG_MATCH_LOGIC_NOT: return L"MATCH_LOGIC_NOT";
685 case TAG_APPLY_ALL_SHIMS: return L"APPLY_ALL_SHIMS";
686 case TAG_USE_SERVICE_PACK_FILES: return L"USE_SERVICE_PACK_FILES";
687 case TAG_MITIGATION_OS: return L"MITIGATION_OS";
688 case TAG_BLOCK_UPGRADE: return L"BLOCK_UPGRADE";
689 case TAG_INCLUDEEXCLUDEDLL: return L"INCLUDEEXCLUDEDLL";
690 case TAG_RAC_EVENT_OFF: return L"RAC_EVENT_OFF";
691 case TAG_TELEMETRY_OFF: return L"TELEMETRY_OFF";
692 case TAG_SHIM_ENGINE_OFF: return L"SHIM_ENGINE_OFF";
693 case TAG_LAYER_PROPAGATION_OFF: return L"LAYER_PROPAGATION_OFF";
694 case TAG_REINSTALL_UPGRADE: return L"REINSTALL_UPGRADE";
695
696 /* TAG_TYPE_WORD */
697 case TAG_MATCH_MODE: return L"MATCH_MODE";
698 case TAG_TAG: return L"TAG";
699 case TAG_INDEX_TAG: return L"INDEX_TAG";
700 case TAG_INDEX_KEY: return L"INDEX_KEY";
701
702 /* TAG_TYPE_DWORD */
703 case TAG_SIZE: return L"SIZE";
704 case TAG_OFFSET: return L"OFFSET";
705 case TAG_CHECKSUM: return L"CHECKSUM";
706 case TAG_SHIM_TAGID: return L"SHIM_TAGID";
707 case TAG_PATCH_TAGID: return L"PATCH_TAGID";
708 case TAG_MODULE_TYPE: return L"MODULE_TYPE";
709 case TAG_VERDATEHI: return L"VERDATEHI";
710 case TAG_VERDATELO: return L"VERDATELO";
711 case TAG_VERFILEOS: return L"VERFILEOS";
712 case TAG_VERFILETYPE: return L"VERFILETYPE";
713 case TAG_PE_CHECKSUM: return L"PE_CHECKSUM";
714 case TAG_PREVOSMAJORVER: return L"PREVOSMAJORVER";
715 case TAG_PREVOSMINORVER: return L"PREVOSMINORVER";
716 case TAG_PREVOSPLATFORMID: return L"PREVOSPLATFORMID";
717 case TAG_PREVOSBUILDNO: return L"PREVOSBUILDNO";
718 case TAG_PROBLEMSEVERITY: return L"PROBLEMSEVERITY";
719 case TAG_LANGID: return L"LANGID";
720 case TAG_VER_LANGUAGE: return L"VER_LANGUAGE";
721 case TAG_ENGINE: return L"ENGINE";
722 case TAG_HTMLHELPID: return L"HTMLHELPID";
723 case TAG_INDEX_FLAGS: return L"INDEX_FLAGS";
724 case TAG_FLAGS: return L"FLAGS";
725 case TAG_DATA_VALUETYPE: return L"DATA_VALUETYPE";
726 case TAG_DATA_DWORD: return L"DATA_DWORD";
727 case TAG_LAYER_TAGID: return L"LAYER_TAGID";
728 case TAG_MSI_TRANSFORM_TAGID: return L"MSI_TRANSFORM_TAGID";
729 case TAG_LINKER_VERSION: return L"LINKER_VERSION";
730 case TAG_LINK_DATE: return L"LINK_DATE";
731 case TAG_UPTO_LINK_DATE: return L"UPTO_LINK_DATE";
732 case TAG_OS_SERVICE_PACK: return L"OS_SERVICE_PACK";
733 case TAG_FLAG_TAGID: return L"FLAG_TAGID";
734 case TAG_RUNTIME_PLATFORM: return L"RUNTIME_PLATFORM";
735 case TAG_OS_SKU: return L"OS_SKU";
736 case TAG_OS_PLATFORM: return L"OS_PLATFORM";
737 case TAG_APP_NAME_RC_ID: return L"APP_NAME_RC_ID";
738 case TAG_VENDOR_NAME_RC_ID: return L"VENDOR_NAME_RC_ID";
739 case TAG_SUMMARY_MSG_RC_ID: return L"SUMMARY_MSG_RC_ID";
740 case TAG_VISTA_SKU: return L"VISTA_SKU";
741 case TAG_DESCRIPTION_RC_ID: return L"DESCRIPTION_RC_ID";
742 case TAG_PARAMETER1_RC_ID: return L"PARAMETER1_RC_ID";
743 case TAG_CONTEXT_TAGID: return L"CONTEXT_TAGID";
744 case TAG_EXE_WRAPPER: return L"EXE_WRAPPER";
745 case TAG_URL_ID: return L"URL_ID";
746 case TAG_TAGID: return L"TAGID";
747
748 /* TAG_TYPE_QWORD */
749 case TAG_TIME: return L"TIME";
750 case TAG_BIN_FILE_VERSION: return L"BIN_FILE_VERSION";
751 case TAG_BIN_PRODUCT_VERSION: return L"BIN_PRODUCT_VERSION";
752 case TAG_MODTIME: return L"MODTIME";
753 case TAG_FLAG_MASK_KERNEL: return L"FLAG_MASK_KERNEL";
754 case TAG_UPTO_BIN_PRODUCT_VERSION: return L"UPTO_BIN_PRODUCT_VERSION";
755 case TAG_DATA_QWORD: return L"DATA_QWORD";
756 case TAG_FLAG_MASK_USER: return L"FLAG_MASK_USER";
757 case TAG_FLAGS_NTVDM1: return L"FLAGS_NTVDM1";
758 case TAG_FLAGS_NTVDM2: return L"FLAGS_NTVDM2";
759 case TAG_FLAGS_NTVDM3: return L"FLAGS_NTVDM3";
760 case TAG_FLAG_MASK_SHELL: return L"FLAG_MASK_SHELL";
761 case TAG_UPTO_BIN_FILE_VERSION: return L"UPTO_BIN_FILE_VERSION";
762 case TAG_FLAG_MASK_FUSION: return L"FLAG_MASK_FUSION";
763 case TAG_FLAG_PROCESSPARAM: return L"FLAG_PROCESSPARAM";
764 case TAG_FLAG_LUA: return L"FLAG_LUA";
765 case TAG_FLAG_INSTALL: return L"FLAG_INSTALL";
766
767 /* TAG_TYPE_STRINGREF */
768 case TAG_NAME: return L"NAME";
769 case TAG_DESCRIPTION: return L"DESCRIPTION";
770 case TAG_MODULE: return L"MODULE";
771 case TAG_API: return L"API";
772 case TAG_VENDOR: return L"VENDOR";
773 case TAG_APP_NAME: return L"APP_NAME";
774 case TAG_COMMAND_LINE: return L"COMMAND_LINE";
775 case TAG_COMPANY_NAME: return L"COMPANY_NAME";
776 case TAG_DLLFILE: return L"DLLFILE";
777 case TAG_WILDCARD_NAME: return L"WILDCARD_NAME";
778 case TAG_PRODUCT_NAME: return L"PRODUCT_NAME";
779 case TAG_PRODUCT_VERSION: return L"PRODUCT_VERSION";
780 case TAG_FILE_DESCRIPTION: return L"FILE_DESCRIPTION";
781 case TAG_FILE_VERSION: return L"FILE_VERSION";
782 case TAG_ORIGINAL_FILENAME: return L"ORIGINAL_FILENAME";
783 case TAG_INTERNAL_NAME: return L"INTERNAL_NAME";
784 case TAG_LEGAL_COPYRIGHT: return L"LEGAL_COPYRIGHT";
785 case TAG_16BIT_DESCRIPTION: return L"16BIT_DESCRIPTION";
786 case TAG_APPHELP_DETAILS: return L"APPHELP_DETAILS";
787 case TAG_LINK_URL: return L"LINK_URL";
788 case TAG_LINK_TEXT: return L"LINK_TEXT";
789 case TAG_APPHELP_TITLE: return L"APPHELP_TITLE";
790 case TAG_APPHELP_CONTACT: return L"APPHELP_CONTACT";
791 case TAG_SXS_MANIFEST: return L"SXS_MANIFEST";
792 case TAG_DATA_STRING: return L"DATA_STRING";
793 case TAG_MSI_TRANSFORM_FILE: return L"MSI_TRANSFORM_FILE";
794 case TAG_16BIT_MODULE_NAME: return L"16BIT_MODULE_NAME";
795 case TAG_LAYER_DISPLAYNAME: return L"LAYER_DISPLAYNAME";
796 case TAG_COMPILER_VERSION: return L"COMPILER_VERSION";
797 case TAG_ACTION_TYPE: return L"ACTION_TYPE";
798 case TAG_EXPORT_NAME: return L"EXPORT_NAME";
799 case TAG_URL: return L"URL";
800
801 /* TAG_TYPE_LIST */
802 case TAG_DATABASE: return L"DATABASE";
803 case TAG_LIBRARY: return L"LIBRARY";
804 case TAG_INEXCLUD: return L"INEXCLUDE";
805 case TAG_SHIM: return L"SHIM";
806 case TAG_PATCH: return L"PATCH";
807 case TAG_APP: return L"APP";
808 case TAG_EXE: return L"EXE";
809 case TAG_MATCHING_FILE: return L"MATCHING_FILE";
810 case TAG_SHIM_REF: return L"SHIM_REF";
811 case TAG_PATCH_REF: return L"PATCH_REF";
812 case TAG_LAYER: return L"LAYER";
813 case TAG_FILE: return L"FILE";
814 case TAG_APPHELP: return L"APPHELP";
815 case TAG_LINK: return L"LINK";
816 case TAG_DATA: return L"DATA";
817 case TAG_MSI_TRANSFORM: return L"MSI_TRANSFORM";
818 case TAG_MSI_TRANSFORM_REF: return L"MSI_TRANSFORM_REF";
819 case TAG_MSI_PACKAGE: return L"MSI_PACKAGE";
820 case TAG_FLAG: return L"FLAG";
821 case TAG_MSI_CUSTOM_ACTION: return L"MSI_CUSTOM_ACTION";
822 case TAG_FLAG_REF: return L"FLAG_REF";
823 case TAG_ACTION: return L"ACTION";
824 case TAG_LOOKUP: return L"LOOKUP";
825 case TAG_CONTEXT: return L"CONTEXT";
826 case TAG_CONTEXT_REF: return L"CONTEXT_REF";
827 case TAG_SPC: return L"SPC";
828 case TAG_STRINGTABLE: return L"STRINGTABLE";
829 case TAG_INDEXES: return L"INDEXES";
830 case TAG_INDEX: return L"INDEX";
831
832 /* TAG_TYPE_STRING */
833 case TAG_STRINGTABLE_ITEM: return L"STRINGTABLE_ITEM";
834
835 /* TAG_TYPE_BINARY */
836 case TAG_PATCH_BITS: return L"PATCH_BITS";
837 case TAG_FILE_BITS: return L"FILE_BITS";
838 case TAG_EXE_ID: return L"EXE_ID";
839 case TAG_DATA_BITS: return L"DATA_BITS";
840 case TAG_MSI_PACKAGE_ID: return L"MSI_PACKAGE_ID";
841 case TAG_DATABASE_ID: return L"DATABASE_ID";
842 case TAG_CONTEXT_PLATFORM_ID: return L"CONTEXT_PLATFORM_ID";
843 case TAG_CONTEXT_BRANCH_ID: return L"CONTEXT_BRANCH_ID";
844 case TAG_FIX_ID: return L"FIX_ID";
845 case TAG_APP_ID: return L"APP_ID";
846 case TAG_INDEX_BITS: return L"INDEX_BITS";
847
848 break;
849 }
850 return L"InvalidTag";
851 }