1 /* 2 * PROJECT: apphelp_apitest 3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) 4 * PURPOSE: Misc apphelp tests 5 * COPYRIGHT: Copyright 2012 Detlef Riekenberg 6 * Copyright 2013 Mislav Blažević 7 * Copyright 2015-2018 Mark Jansen (mark.jansen@reactos.org) 8 */ 9 10 #include <ntstatus.h> 11 #define WIN32_NO_STATUS 12 #include <windows.h> 13 #include <shlwapi.h> 14 #include <winnt.h> 15 #ifdef __REACTOS__ 16 #include <ntndk.h> 17 #else 18 #include <winternl.h> 19 #endif 20 21 #include <winerror.h> 22 #include <stdio.h> 23 #include <initguid.h> 24 #include <shlguid.h> 25 #include <shobjidl.h> 26 27 #include "wine/test.h" 28 29 #include "apphelp_apitest.h" 30 31 32 #define TAG_TYPE_MASK 0xF000 33 34 #define TAG_TYPE_NULL 0x1000 35 #define TAG_TYPE_BYTE 0x2000 36 #define TAG_TYPE_WORD 0x3000 37 #define TAG_TYPE_DWORD 0x4000 38 #define TAG_TYPE_QWORD 0x5000 39 #define TAG_TYPE_STRINGREF 0x6000 40 #define TAG_TYPE_LIST 0x7000 41 #define TAG_TYPE_STRING 0x8000 42 #define TAG_TYPE_BINARY 0x9000 43 #define TAG_NULL 0x0 44 #define TAG_SIZE (0x1 | TAG_TYPE_DWORD) 45 #define TAG_CHECKSUM (0x3 | TAG_TYPE_DWORD) 46 #define TAG_MODULE_TYPE (0x6 | TAG_TYPE_DWORD) 47 #define TAG_VERDATEHI (0x7 | TAG_TYPE_DWORD) 48 #define TAG_VERDATELO (0x8 | TAG_TYPE_DWORD) 49 #define TAG_VERFILEOS (0x9 | TAG_TYPE_DWORD) 50 #define TAG_VERFILETYPE (0xA | TAG_TYPE_DWORD) 51 #define TAG_PE_CHECKSUM (0xB | TAG_TYPE_DWORD) 52 #define TAG_VER_LANGUAGE (0x12 | TAG_TYPE_DWORD) 53 #define TAG_LINKER_VERSION (0x1C | TAG_TYPE_DWORD) 54 #define TAG_LINK_DATE (0x1D | TAG_TYPE_DWORD) 55 #define TAG_UPTO_LINK_DATE (0x1E | TAG_TYPE_DWORD) 56 #define TAG_EXE_WRAPPER (0x31 | TAG_TYPE_DWORD) 57 #define TAG_BIN_FILE_VERSION (0x2 | TAG_TYPE_QWORD) 58 #define TAG_BIN_PRODUCT_VERSION (0x3 | TAG_TYPE_QWORD) 59 #define TAG_UPTO_BIN_PRODUCT_VERSION (0x6 | TAG_TYPE_QWORD) 60 #define TAG_UPTO_BIN_FILE_VERSION (0xD | TAG_TYPE_QWORD) 61 #define TAG_NAME (0x1 | TAG_TYPE_STRINGREF) 62 #define TAG_COMPANY_NAME (0x9 | TAG_TYPE_STRINGREF) 63 #define TAG_PRODUCT_NAME (0x10 | TAG_TYPE_STRINGREF) 64 #define TAG_PRODUCT_VERSION (0x11 | TAG_TYPE_STRINGREF) 65 #define TAG_FILE_DESCRIPTION (0x12 | TAG_TYPE_STRINGREF) 66 #define TAG_FILE_VERSION (0x13 | TAG_TYPE_STRINGREF) 67 #define TAG_ORIGINAL_FILENAME (0x14 | TAG_TYPE_STRINGREF) 68 #define TAG_INTERNAL_NAME (0x15 | TAG_TYPE_STRINGREF) 69 #define TAG_LEGAL_COPYRIGHT (0x16 | TAG_TYPE_STRINGREF) 70 #define TAG_16BIT_DESCRIPTION (0x17 | TAG_TYPE_STRINGREF) 71 #define TAG_16BIT_MODULE_NAME (0x20 | TAG_TYPE_STRINGREF) 72 #define TAG_EXPORT_NAME (0x24 | TAG_TYPE_STRINGREF) 73 74 75 #define ATTRIBUTE_AVAILABLE 0x1 76 #define ATTRIBUTE_FAILED 0x2 77 78 typedef struct tagATTRINFO { 79 TAG type; 80 DWORD flags; /* ATTRIBUTE_AVAILABLE, ATTRIBUTE_FAILED */ 81 union { 82 QWORD qwattr; 83 DWORD dwattr; 84 WCHAR *lpattr; 85 }; 86 } ATTRINFO, *PATTRINFO; 87 88 static HMODULE hdll; 89 static BOOL (WINAPI *pApphelpCheckShellObject)(REFCLSID, BOOL, ULONGLONG *); 90 static LPCWSTR (WINAPI *pSdbTagToString)(TAG tag); 91 static BOOL (WINAPI *pSdbGUIDToString)(REFGUID Guid, PWSTR GuidString, SIZE_T Length); 92 static BOOL (WINAPI *pSdbIsNullGUID)(REFGUID Guid); 93 static BOOL (WINAPI *pSdbGetStandardDatabaseGUID)(DWORD Flags, GUID* Guid); 94 static BOOL (WINAPI *pSdbGetFileAttributes)(LPCWSTR wszPath, PATTRINFO *ppAttrInfo, LPDWORD pdwAttrCount); 95 static BOOL (WINAPI *pSdbFreeFileAttributes)(PATTRINFO AttrInfo); 96 static HRESULT (WINAPI* pSdbGetAppPatchDir)(PVOID hsdb, LPWSTR path, DWORD size); 97 98 /* 'Known' database guids */ 99 DEFINE_GUID(GUID_DATABASE_MSI,0xd8ff6d16,0x6a3a,0x468a,0x8b,0x44,0x01,0x71,0x4d,0xdc,0x49,0xea); 100 DEFINE_GUID(GUID_DATABASE_SHIM,0x11111111,0x1111,0x1111,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11); 101 DEFINE_GUID(GUID_DATABASE_DRIVERS,0xf9ab2228,0x3312,0x4a73,0xb6,0xf9,0x93,0x6d,0x70,0xe1,0x12,0xef); 102 103 DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0); 104 105 DEFINE_GUID(test_Microsoft_Browser_Architecture, 0xa5e46e3a, 0x8849, 0x11d1, 0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61); 106 DEFINE_GUID(test_UserAssist, 0xdd313e04, 0xfeff, 0x11d1, 0x8e, 0xcd, 0x00, 0x00, 0xf8, 0x7a, 0x47, 0x0c); 107 DEFINE_GUID(CLSID_InternetSecurityManager, 0x7b8a2d94, 0x0ac9, 0x11d1, 0x89, 0x6c, 0x00, 0xc0, 0x4f, 0xB6, 0xbf, 0xc4); 108 109 static const CLSID * objects[] = { 110 &GUID_NULL, 111 /* used by IE */ 112 &test_Microsoft_Browser_Architecture, 113 &CLSID_MenuBand, 114 &CLSID_ShellLink, 115 &CLSID_ShellWindows, 116 &CLSID_InternetSecurityManager, 117 &test_UserAssist, 118 (const CLSID *)NULL 119 }; 120 121 static void test_ApphelpCheckShellObject(void) 122 { 123 ULONGLONG flags; 124 BOOL res; 125 int i; 126 127 if (!pApphelpCheckShellObject) 128 { 129 win_skip("ApphelpCheckShellObject not available\n"); 130 return; 131 } 132 133 for (i = 0; objects[i]; i++) 134 { 135 flags = 0xdeadbeef; 136 SetLastError(0xdeadbeef); 137 res = pApphelpCheckShellObject(objects[i], FALSE, &flags); 138 ok(res && (flags == 0), "%s 0: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n", 139 wine_dbgstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError()); 140 141 flags = 0xdeadbeef; 142 SetLastError(0xdeadbeef); 143 res = pApphelpCheckShellObject(objects[i], TRUE, &flags); 144 ok(res && (flags == 0), "%s 1: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n", 145 wine_dbgstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError()); 146 147 } 148 149 /* NULL as pointer to flags is checked */ 150 SetLastError(0xdeadbeef); 151 res = pApphelpCheckShellObject(&GUID_NULL, FALSE, NULL); 152 ok(res, "%s 0: got %d with 0x%x (expected != FALSE)\n", wine_dbgstr_guid(&GUID_NULL), res, GetLastError()); 153 154 /* NULL as CLSID* crash on Windows */ 155 if (0) 156 { 157 flags = 0xdeadbeef; 158 SetLastError(0xdeadbeef); 159 res = pApphelpCheckShellObject(NULL, FALSE, &flags); 160 trace("NULL as CLSID*: got %d and 0x%x%08x with 0x%x\n", res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError()); 161 } 162 } 163 164 static void test_SdbTagToString(void) 165 { 166 static const TAG invalid_values[] = { 167 1, TAG_TYPE_WORD, TAG_TYPE_MASK, 168 TAG_TYPE_DWORD | 0xFF, 169 TAG_TYPE_DWORD | (0x800 + 0xEE), 170 0x900, 0xFFFF, 0xDEAD, 0xBEEF 171 }; 172 static const WCHAR invalid[] = {'I','n','v','a','l','i','d','T','a','g',0}; 173 LPCWSTR ret; 174 WORD i; 175 176 for (i = 0; i < 9; ++i) 177 { 178 ret = pSdbTagToString(invalid_values[i]); 179 ok(lstrcmpW(ret, invalid) == 0, "unexpected string %s, should be %s\n", 180 wine_dbgstr_w(ret), wine_dbgstr_w(invalid)); 181 } 182 } 183 184 static int strcmp_wa(LPCWSTR strw, const char *stra) 185 { 186 CHAR buf[512]; 187 WideCharToMultiByte(CP_ACP, 0, strw, -1, buf, sizeof(buf), 0, 0); 188 return lstrcmpA(buf, stra); 189 } 190 191 void test_tag(TAG base, const char* names[], size_t upperlimit, int line) 192 { 193 TAG n; 194 for (n = 0; names[n]; ++n) 195 { 196 LPCWSTR tagstr = pSdbTagToString(base | n); 197 ok_(__FILE__, line + 2)(!strcmp_wa(tagstr, names[n]), "Got %s instead of '%s' for %x\n", wine_dbgstr_w(tagstr), names[n], base | n); 198 } 199 for (; n < upperlimit; ++n) 200 { 201 LPCWSTR tagstr = pSdbTagToString(base | n); 202 ok_(__FILE__, line + 2)(!strcmp_wa(tagstr, "InvalidTag"), "Got %s instead of 'InvalidTag' for %x\n", wine_dbgstr_w(tagstr), base | n); 203 } 204 } 205 206 static struct 207 { 208 TAG base; 209 DWORD upper_limit; 210 DWORD line; 211 DWORD min_ver; 212 DWORD max_ver; 213 const char* tags[7*8]; 214 } data[] = { 215 { 216 TAG_TYPE_NULL, 0x1000, __LINE__, WINVER_ANY, WINVER_2003, 217 { 218 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", NULL 219 } 220 }, 221 { 222 TAG_TYPE_NULL, 0x1000, __LINE__, WINVER_VISTA, WINVER_VISTA, 223 { 224 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", "MITIGATION_OS", "BLOCK_UPGRADE", 225 "INCLUDEEXCLUDEDLL", NULL 226 } 227 }, 228 { 229 TAG_TYPE_NULL, 0x1000, __LINE__, WINVER_WIN7, WINVER_ANY, 230 { 231 "InvalidTag", "INCLUDE", "GENERAL", "MATCH_LOGIC_NOT", "APPLY_ALL_SHIMS", "USE_SERVICE_PACK_FILES", "MITIGATION_OS", "BLOCK_UPGRADE", 232 "INCLUDEEXCLUDEDLL", "RAC_EVENT_OFF", "TELEMETRY_OFF", "SHIM_ENGINE_OFF", "LAYER_PROPAGATION_OFF", "REINSTALL_UPGRADE", NULL 233 } 234 }, 235 236 { 237 TAG_TYPE_BYTE, 0x1000, __LINE__, WINVER_ANY, WINVER_ANY, 238 { 239 "InvalidTag", NULL 240 } 241 }, 242 243 { 244 TAG_TYPE_WORD, 0x800, __LINE__, WINVER_ANY, WINVER_WIN7, 245 { 246 "InvalidTag", "MATCH_MODE", NULL 247 } 248 }, 249 { 250 TAG_TYPE_WORD, 0x800, __LINE__, WINVER_WIN8, WINVER_ANY, 251 { 252 "InvalidTag", "MATCH_MODE", "QUIRK_COMPONENT_CODE_ID", "QUIRK_CODE_ID", NULL 253 } 254 }, 255 { 256 TAG_TYPE_WORD | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY, 257 { 258 "InvalidTag", "TAG", "INDEX_TAG", "INDEX_KEY", NULL 259 } 260 }, 261 262 { 263 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_ANY, WINVER_WINXP, 264 { 265 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERFILEDATEHI", 266 "VERFILEDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVERSION", "PREVOSMINORVERSION", "PREVOSPLATFORMID", "PREVOSBUILDNO", 267 "PROBLEM_SEVERITY", "APPHELP_LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEXFLAGS", "FLAGS", 268 "VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK", 269 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", NULL 270 } 271 }, 272 { 273 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_2003, WINVER_2003, 274 { 275 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERFILEDATEHI", 276 "VERFILEDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVERSION", "PREVOSMINORVERSION", "PREVOSPLATFORMID", "PREVOSBUILDNO", 277 "PROBLEM_SEVERITY", "APPHELP_LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEXFLAGS", "FLAGS", 278 "VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK", 279 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", NULL 280 } 281 }, 282 { 283 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_VISTA, WINVER_VISTA, 284 { 285 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERDATEHI", 286 "VERDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVER", "PREVOSMINORVER", "PREVOSPLATFORMID", "PREVOSBUILDNO", 287 "PROBLEMSEVERITY", "LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEX_FLAGS", "FLAGS", 288 "DATA_VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK", 289 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", "APP_NAME_RC_ID", "VENDOR_NAME_RC_ID", "SUMMARY_MSG_RC_ID", "VISTA_SKU", 290 NULL 291 } 292 }, 293 { 294 TAG_TYPE_DWORD, 0x800, __LINE__, WINVER_WIN7, WINVER_ANY, 295 { 296 "InvalidTag", "SIZE", "OFFSET", "CHECKSUM", "SHIM_TAGID", "PATCH_TAGID", "MODULE_TYPE", "VERDATEHI", 297 "VERDATELO", "VERFILEOS", "VERFILETYPE", "PE_CHECKSUM", "PREVOSMAJORVER", "PREVOSMINORVER", "PREVOSPLATFORMID", "PREVOSBUILDNO", 298 "PROBLEMSEVERITY", "LANGID", "VER_LANGUAGE", "InvalidTag", "ENGINE", "HTMLHELPID", "INDEX_FLAGS", "FLAGS", 299 "DATA_VALUETYPE", "DATA_DWORD", "LAYER_TAGID", "MSI_TRANSFORM_TAGID", "LINKER_VERSION", "LINK_DATE", "UPTO_LINK_DATE", "OS_SERVICE_PACK", 300 "FLAG_TAGID", "RUNTIME_PLATFORM", "OS_SKU", "OS_PLATFORM", "APP_NAME_RC_ID", "VENDOR_NAME_RC_ID", "SUMMARY_MSG_RC_ID", "VISTA_SKU", 301 "DESCRIPTION_RC_ID", "PARAMETER1_RC_ID", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", 302 "CONTEXT_TAGID", "EXE_WRAPPER", "URL_ID", NULL 303 } 304 }, 305 { 306 TAG_TYPE_DWORD | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY, 307 { 308 "InvalidTag", "TAGID", NULL 309 } 310 }, 311 312 { 313 TAG_TYPE_QWORD, 0x1000, __LINE__, WINVER_ANY, WINVER_WINXP, 314 { 315 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD", 316 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", NULL 317 } 318 }, 319 { 320 TAG_TYPE_QWORD, 0x1000, __LINE__, WINVER_2003, WINVER_2003, 321 { 322 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD", 323 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", "FLAG_MASK_FUSION", "FLAGS_PROCESSPARAM", 324 NULL 325 } 326 }, 327 { 328 TAG_TYPE_QWORD, 0x1000, __LINE__, WINVER_VISTA, WINVER_ANY, 329 { 330 "InvalidTag", "TIME", "BIN_FILE_VERSION", "BIN_PRODUCT_VERSION", "MODTIME", "FLAG_MASK_KERNEL", "UPTO_BIN_PRODUCT_VERSION", "DATA_QWORD", 331 "FLAG_MASK_USER", "FLAGS_NTVDM1", "FLAGS_NTVDM2", "FLAGS_NTVDM3", "FLAG_MASK_SHELL", "UPTO_BIN_FILE_VERSION", "FLAG_MASK_FUSION", "FLAG_PROCESSPARAM", 332 "FLAG_LUA", "FLAG_INSTALL", NULL 333 } 334 }, 335 336 { 337 TAG_TYPE_STRINGREF, 0x1000, __LINE__, WINVER_ANY, WINVER_2003, 338 { 339 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag", 340 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", 341 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "S16BIT_DESCRIPTION", 342 "PROBLEM_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE", 343 "S16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", NULL 344 } 345 }, 346 { 347 TAG_TYPE_STRINGREF, 0x1000, __LINE__, WINVER_VISTA, WINVER_VISTA, 348 { 349 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag", 350 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", 351 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "16BIT_DESCRIPTION", 352 "APPHELP_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE", 353 "16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", "EXPORT_NAME", NULL 354 } 355 }, 356 { 357 TAG_TYPE_STRINGREF, 0x1000, __LINE__, WINVER_WIN7, WINVER_ANY, 358 { 359 "InvalidTag", "NAME", "DESCRIPTION", "MODULE", "API", "VENDOR", "APP_NAME", "InvalidTag", 360 "COMMAND_LINE", "COMPANY_NAME", "DLLFILE", "WILDCARD_NAME", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", 361 "PRODUCT_NAME", "PRODUCT_VERSION", "FILE_DESCRIPTION", "FILE_VERSION", "ORIGINAL_FILENAME", "INTERNAL_NAME", "LEGAL_COPYRIGHT", "16BIT_DESCRIPTION", 362 "APPHELP_DETAILS", "LINK_URL", "LINK_TEXT", "APPHELP_TITLE", "APPHELP_CONTACT", "SXS_MANIFEST", "DATA_STRING", "MSI_TRANSFORM_FILE", 363 "16BIT_MODULE_NAME", "LAYER_DISPLAYNAME", "COMPILER_VERSION", "ACTION_TYPE", "EXPORT_NAME", "URL", NULL 364 } 365 }, 366 367 { 368 TAG_TYPE_LIST, 0x800, __LINE__, WINVER_ANY, WINVER_2003, 369 { 370 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE", 371 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA", 372 "MSI TRANSFORM", "MSI TRANSFORM REF", "MSI PACKAGE", "FLAG", "MSI CUSTOM ACTION", "FLAG_REF", "ACTION", NULL 373 } 374 }, 375 { 376 TAG_TYPE_LIST, 0x800, __LINE__, WINVER_VISTA, WINVER_VISTA, 377 { 378 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE", 379 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA", 380 "MSI_TRANSFORM", "MSI_TRANSFORM_REF", "MSI_PACKAGE", "FLAG", "MSI_CUSTOM_ACTION", "FLAG_REF", "ACTION", "LOOKUP", 381 NULL 382 } 383 }, 384 { 385 TAG_TYPE_LIST, 0x800, __LINE__, WINVER_WIN7, WINVER_ANY, 386 { 387 "InvalidTag", "DATABASE", "LIBRARY", "INEXCLUDE", "SHIM", "PATCH", "APP", "EXE", 388 "MATCHING_FILE", "SHIM_REF", "PATCH_REF", "LAYER", "FILE", "APPHELP", "LINK", "DATA", 389 "MSI_TRANSFORM", "MSI_TRANSFORM_REF", "MSI_PACKAGE", "FLAG", "MSI_CUSTOM_ACTION", "FLAG_REF", "ACTION", "LOOKUP", 390 "CONTEXT", "CONTEXT_REF", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", 391 "SPC", NULL 392 } 393 }, 394 { 395 TAG_TYPE_LIST | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY, 396 { 397 "InvalidTag", "STRINGTABLE", "INDEXES", "INDEX", NULL 398 } 399 }, 400 401 { 402 TAG_TYPE_STRING, 0x800, __LINE__, WINVER_ANY, WINVER_ANY, 403 { 404 "InvalidTag", NULL 405 } 406 }, 407 { 408 TAG_TYPE_STRING | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_2003, 409 { 410 "InvalidTag", "STRTAB_ITEM", NULL 411 } 412 }, 413 { 414 TAG_TYPE_STRING | 0x800, 0x800, __LINE__, WINVER_VISTA, WINVER_ANY, 415 { 416 "InvalidTag", "STRINGTABLE_ITEM", NULL 417 } 418 }, 419 420 421 { 422 TAG_TYPE_BINARY, 0x800, __LINE__, WINVER_ANY, WINVER_2003, 423 { 424 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID(GUID)", "DATA_BITS", "MSI_PACKAGE_ID(GUID)", "DATABASE_ID(GUID)", 425 NULL 426 } 427 }, 428 { 429 TAG_TYPE_BINARY, 0x800, __LINE__, WINVER_VISTA, WINVER_VISTA, 430 { 431 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID", "DATA_BITS", "MSI_PACKAGE_ID", "DATABASE_ID", 432 NULL 433 } 434 }, 435 { 436 TAG_TYPE_BINARY, 0x800, __LINE__, WINVER_WIN7, WINVER_ANY, 437 { 438 "InvalidTag", "InvalidTag", "PATCH_BITS", "FILE_BITS", "EXE_ID", "DATA_BITS", "MSI_PACKAGE_ID", "DATABASE_ID", 439 "CONTEXT_PLATFORM_ID", "CONTEXT_BRANCH_ID", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", "InvalidTag", 440 "FIX_ID", "APP_ID", NULL 441 } 442 }, 443 { 444 TAG_TYPE_BINARY | 0x800, 0x800, __LINE__, WINVER_ANY, WINVER_ANY, 445 { 446 "InvalidTag", "INDEX_BITS", NULL 447 } 448 }, 449 450 { 0, 0, 0, 0, 0, { NULL } } 451 }; 452 453 454 static void test_SdbTagToStringAllTags(void) 455 { 456 int n; 457 for (n = 0; data[n].base; ++n) 458 { 459 if ((data[n].min_ver == WINVER_ANY || g_WinVersion >= data[n].min_ver) && 460 (data[n].max_ver == WINVER_ANY || g_WinVersion <= data[n].max_ver)) 461 { 462 test_tag(data[n].base, data[n].tags, data[n].upper_limit, data[n].line); 463 } 464 } 465 } 466 467 static void test_GuidFunctions(void) 468 { 469 GUID guid; 470 ok(pSdbIsNullGUID(&GUID_NULL), "expected GUID_NULL to be recognized as NULL GUID\n"); 471 ok(pSdbIsNullGUID(NULL), "expected NULL to be recognized as NULL GUID\n"); 472 ok(pSdbIsNullGUID(&test_UserAssist) == 0, "expected a set GUID not to be recognized as NULL GUID\n"); 473 474 memset(&guid, 0, sizeof(guid)); 475 ok(pSdbGetStandardDatabaseGUID(0, &guid) == 0,"Expected SdbGetStandardDatabaseGUID to fail\n"); 476 ok(IsEqualGUID(&GUID_NULL, &guid), "Expected guid not to be changed\n"); 477 478 ok(pSdbGetStandardDatabaseGUID(0x80020000, NULL),"Expected SdbGetStandardDatabaseGUID to succeed\n"); 479 480 memset(&guid, 0, sizeof(guid)); 481 ok(pSdbGetStandardDatabaseGUID(0x80020000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n"); 482 ok(IsEqualGUID(&GUID_DATABASE_MSI, &guid), "Expected guid to equal GUID_DATABASE_MSI, was: %s\n", wine_dbgstr_guid(&guid)); 483 484 memset(&guid, 0, sizeof(guid)); 485 ok(pSdbGetStandardDatabaseGUID(0x80030000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n"); 486 ok(IsEqualGUID(&GUID_DATABASE_SHIM, &guid), "Expected guid to equal GUID_DATABASE_SHIM, was: %s\n", wine_dbgstr_guid(&guid)); 487 488 memset(&guid, 0, sizeof(guid)); 489 ok(pSdbGetStandardDatabaseGUID(0x80040000, &guid),"Expected SdbGetStandardDatabaseGUID to succeed\n"); 490 ok(IsEqualGUID(&GUID_DATABASE_DRIVERS, &guid), "Expected guid to equal GUID_DATABASE_DRIVERS, was: %s\n", wine_dbgstr_guid(&guid)); 491 } 492 493 static void expect_tag_skip_imp(PATTRINFO pattr, DWORD num) 494 { 495 PATTRINFO p = &pattr[num]; 496 winetest_ok(p->type == TAG_NULL, "expected entry #%d to be TAG_NULL, was %x\n", num, p->type); 497 winetest_ok(p->flags == ATTRIBUTE_FAILED, "expected entry #%d to be failed, was %d\n", num, p->flags); 498 winetest_ok(p->qwattr == 0, "expected entry #%d to be 0, was 0x%I64x\n", num, p->qwattr); 499 } 500 static void expect_tag_empty_imp(PATTRINFO pattr, DWORD num) 501 { 502 PATTRINFO p = &pattr[num]; 503 winetest_ok(p->type == TAG_NULL, "expected entry #%d to be TAG_NULL, was %x\n", num, p->type); 504 winetest_ok(p->flags == 0, "expected entry #%d to be 0, was %d\n", num, p->flags); 505 winetest_ok(p->qwattr == 0, "expected entry #%d to be 0, was 0x%I64x\n", num, p->qwattr); 506 } 507 508 static void expect_tag_dword_imp(PATTRINFO pattr, DWORD num, TAG tag, DWORD value) 509 { 510 PATTRINFO p = &pattr[num]; 511 winetest_ok(p->type == tag, "expected entry #%d to be %x, was %x\n", num, tag, p->type); 512 winetest_ok(p->flags == ATTRIBUTE_AVAILABLE, "expected entry #%d to be available, was %d\n", num, p->flags); 513 winetest_ok(p->dwattr == value, "expected entry #%d to be 0x%x, was 0x%x\n", num, value, p->dwattr); 514 } 515 516 static void expect_tag_qword_imp(PATTRINFO pattr, DWORD num, TAG tag, QWORD value) 517 { 518 PATTRINFO p = &pattr[num]; 519 winetest_ok(p->type == tag, "expected entry #%d to be %x, was %x\n", num, tag, p->type); 520 winetest_ok(p->flags == ATTRIBUTE_AVAILABLE, "expected entry #%d to be available, was %d\n", num, p->flags); 521 winetest_ok(p->qwattr == value, "expected entry #%d to be 0x%I64x, was 0x%I64x\n", num, value, p->qwattr); 522 } 523 524 static void expect_tag_str_imp(PATTRINFO pattr, DWORD num, TAG tag, const WCHAR* value) 525 { 526 PATTRINFO p = &pattr[num]; 527 winetest_ok(p->type == tag, "expected entry #%d to be %x, was %x\n", num, tag, p->type); 528 winetest_ok(p->flags == ATTRIBUTE_AVAILABLE, "expected entry #%d to be available, was %d\n", num, p->flags); 529 winetest_ok(p->lpattr && wcscmp(p->lpattr, value) == 0, "expected entry #%d to be %s, was %s\n", num, wine_dbgstr_w(value), wine_dbgstr_w(p->lpattr)); 530 } 531 532 #define expect_tag_skip (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_skip_imp 533 #define expect_tag_empty (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_empty_imp 534 #define expect_tag_dword (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_dword_imp 535 #define expect_tag_qword (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_qword_imp 536 #define expect_tag_str (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : expect_tag_str_imp 537 #define expect_tag_skip_range(ptr, from, to) \ 538 do { \ 539 int n = (from), n_end = (to); \ 540 winetest_set_location(__FILE__, __LINE__); \ 541 for ( ; n < n_end; ++n) \ 542 expect_tag_skip_imp((ptr), n); \ 543 } while (0) 544 #define test_crc (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_crc_imp 545 #define test_crc2 (winetest_set_location(__FILE__, __LINE__), 0) ? (void)0 : test_crc2_imp 546 547 void test_onefile(WCHAR* filename) 548 { 549 PATTRINFO pattrinfo; 550 DWORD num; 551 552 if (!pSdbFreeFileAttributes) 553 { 554 hdll = LoadLibraryA("apphelp.dll"); 555 pSdbTagToString = (void *)GetProcAddress(hdll, "SdbTagToString"); 556 pSdbGetFileAttributes = (void *)GetProcAddress(hdll, "SdbGetFileAttributes"); 557 pSdbFreeFileAttributes = (void *)GetProcAddress(hdll, "SdbFreeFileAttributes"); 558 } 559 560 if (pSdbGetFileAttributes(filename, &pattrinfo, &num)) 561 { 562 if (pattrinfo[16].flags == ATTRIBUTE_AVAILABLE) 563 { 564 if (pattrinfo[16].type != TAG_MODULE_TYPE)//SdbpSetAttrFail(&attr_info[16]); /* TAG_MODULE_TYPE (1: WIN16?) (3: WIN32?) (WIN64?), Win32VersionValue? */) 565 printf("FAIL TAG_MODULE_TYPE (%S)\n", filename); 566 if (pattrinfo[16].dwattr != 3 && pattrinfo[16].dwattr != 2) 567 printf("TAG_MODULE_TYPE(%S): %d\n", filename, pattrinfo[16].dwattr); // C:\Program Files (x86)\Windows Kits\8.1\Lib\win7\stub512.com 568 if (pattrinfo[16].dwattr == 2) 569 { 570 printf("TAG_MODULE_TYPE(%S): %d, %d\n", filename, pattrinfo[16].dwattr, pattrinfo[0].dwattr); 571 } 572 } 573 574 if (pattrinfo[27].flags == ATTRIBUTE_AVAILABLE) 575 { 576 if (pattrinfo[27].type != TAG_EXE_WRAPPER) 577 printf("FAIL TAG_EXE_WRAPPER (%S)\n", filename); 578 if (pattrinfo[27].dwattr != 0) 579 printf("TAG_EXE_WRAPPER(%S): %d\n", filename, pattrinfo[27].dwattr); 580 } 581 582 pSdbFreeFileAttributes(pattrinfo); 583 } 584 } 585 586 static void test_crc_imp(size_t len, DWORD expected) 587 { 588 static const WCHAR path[] = {'t','e','s','t','x','x','.','e','x','e',0}; 589 static char crc_test[] = {4, 4, 4, 4, 1, 1, 1, 1, 4, 4, 4, 4, 2, 2, 2, 2}; 590 591 PATTRINFO pattrinfo = (PATTRINFO)0xdead; 592 DWORD num = 333; 593 BOOL ret; 594 595 test_create_file_imp(L"testxx.exe", crc_test, len); 596 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 597 winetest_ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 598 winetest_ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 599 winetest_ok(num == 28, "expected 28 items, got %d.\n", num); 600 601 if (num == 28 && ret) 602 { 603 expect_tag_dword_imp(pattrinfo, 1, TAG_CHECKSUM, expected); 604 } 605 if (ret) 606 pSdbFreeFileAttributes(pattrinfo); 607 } 608 609 static void test_crc2_imp(DWORD len, int fill, DWORD expected) 610 { 611 static const WCHAR path[] = {'t','e','s','t','x','x','.','e','x','e',0}; 612 613 PATTRINFO pattrinfo = (PATTRINFO)0xdead; 614 DWORD num = 333; 615 BOOL ret; 616 size_t n; 617 char* crc_test = malloc(len); 618 for (n = 0; n < len; ++n) 619 crc_test[n] = (char)(fill ? fill : n); 620 621 test_create_file_imp(L"testxx.exe", crc_test, len); 622 free(crc_test); 623 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 624 winetest_ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 625 winetest_ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 626 winetest_ok(num == 28, "expected 28 items, got %d.\n", num); 627 628 if (num == 28 && ret) 629 { 630 expect_tag_dword_imp(pattrinfo, 0, TAG_SIZE, len); 631 expect_tag_dword_imp(pattrinfo, 1, TAG_CHECKSUM, expected); 632 } 633 if (ret) 634 pSdbFreeFileAttributes(pattrinfo); 635 } 636 637 638 639 static void test_ApplicationAttributes(void) 640 { 641 static const WCHAR path[] = {'t','e','s','t','x','x','.','e','x','e',0}; 642 static const WCHAR PRODUCT_VERSION[] = {'1','.','0','.','0','.','1',0}; 643 static const WCHAR FILE_DESCRIPTION[] = {'F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0}; 644 static const WCHAR COMPANY_NAME[] = {'C','o','m','p','a','n','y','N','a','m','e',0}; 645 static const WCHAR PRODUCT_NAME[] = {'P','r','o','d','u','c','t','N','a','m','e',0}; 646 static const WCHAR FILE_VERSION[] = {'1','.','0','.','0','.','0',0}; 647 static const WCHAR ORIGINAL_FILENAME[] = {'O','r','i','g','i','n','a','l','F','i','l','e','n','a','m','e',0}; 648 static const WCHAR INTERNAL_NAME[] = {'I','n','t','e','r','n','a','l','N','a','m','e',0}; 649 static const WCHAR LEGAL_COPYRIGHT[] = {'L','e','g','a','l','C','o','p','y','r','i','g','h','t',0}; 650 static const WCHAR EXPORT_NAME[] = {'T','e','S','t','2','.','e','x','e',0}; 651 static const WCHAR OS2_DESCRIPTION[] = {'M','O','D',' ','D','E','S','C','R','I','P','T','I','O','N',' ','H','E','R','E',0}; 652 static const WCHAR OS2_EXPORT_NAME[] = {'T','E','S','T','M','O','D','.','h','X','x',0}; 653 static const WCHAR OS2_DESCRIPTION_broken[] = {'Z',0}; 654 static const WCHAR OS2_EXPORT_NAME_broken[] = {'E',0}; 655 656 PATTRINFO pattrinfo = (PATTRINFO)0xdead; 657 DWORD num = 333; 658 BOOL ret; 659 660 /* ensure the file is not there. */ 661 DeleteFileA("testxx.exe"); 662 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 663 ok(ret == FALSE, "expected SdbGetFileAttributes to fail.\n"); 664 ok(pattrinfo == (PATTRINFO)0xdead, "expected the pointer not to change.\n"); 665 ok(num == 333, "expected the number of items not to change.\n"); 666 if (ret) 667 pSdbFreeFileAttributes(pattrinfo); 668 669 /* Test a file with as much features as possible */ 670 test_create_exe(L"testxx.exe", 0); 671 672 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 673 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 674 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 675 ok(num == 28, "expected 28 items, got %d.\n", num); 676 677 if (num == 28 && ret) 678 { 679 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0x800); 680 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0x178bd629); 681 expect_tag_qword(pattrinfo, 2, TAG_BIN_FILE_VERSION, 0x1000000000000ull); 682 expect_tag_qword(pattrinfo, 3, TAG_BIN_PRODUCT_VERSION, 0x1000000000001ull); 683 expect_tag_str(pattrinfo, 4, TAG_PRODUCT_VERSION, PRODUCT_VERSION); 684 expect_tag_str(pattrinfo, 5, TAG_FILE_DESCRIPTION, FILE_DESCRIPTION); 685 expect_tag_str(pattrinfo, 6, TAG_COMPANY_NAME, COMPANY_NAME); 686 expect_tag_str(pattrinfo, 7, TAG_PRODUCT_NAME, PRODUCT_NAME); 687 expect_tag_str(pattrinfo, 8, TAG_FILE_VERSION, FILE_VERSION); 688 expect_tag_str(pattrinfo, 9, TAG_ORIGINAL_FILENAME, ORIGINAL_FILENAME); 689 expect_tag_str(pattrinfo, 10, TAG_INTERNAL_NAME, INTERNAL_NAME); 690 expect_tag_str(pattrinfo, 11, TAG_LEGAL_COPYRIGHT, LEGAL_COPYRIGHT); 691 expect_tag_dword(pattrinfo, 12, TAG_VERDATEHI, 0x1d1a019); 692 expect_tag_dword(pattrinfo, 13, TAG_VERDATELO, 0xac754c50); 693 expect_tag_dword(pattrinfo, 14, TAG_VERFILEOS, VOS__WINDOWS32); 694 expect_tag_dword(pattrinfo, 15, TAG_VERFILETYPE, VFT_APP); 695 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x3); /* Win32 */ 696 expect_tag_dword(pattrinfo, 17, TAG_PE_CHECKSUM, 0xBAAD); 697 expect_tag_dword(pattrinfo, 18, TAG_LINKER_VERSION, 0x40002); 698 expect_tag_skip(pattrinfo, 19); /* TAG_16BIT_DESCRIPTION */ 699 expect_tag_skip(pattrinfo, 20); /* TAG_16BIT_MODULE_NAME */ 700 expect_tag_qword(pattrinfo, 21, TAG_UPTO_BIN_FILE_VERSION, 0x1000000000000ull); 701 expect_tag_qword(pattrinfo, 22, TAG_UPTO_BIN_PRODUCT_VERSION, 0x1000000000001ull); 702 expect_tag_dword(pattrinfo, 23, TAG_LINK_DATE, 0x12345); 703 expect_tag_dword(pattrinfo, 24, TAG_UPTO_LINK_DATE, 0x12345); 704 expect_tag_str(pattrinfo, 25, TAG_EXPORT_NAME, EXPORT_NAME); 705 expect_tag_dword(pattrinfo, 26, TAG_VER_LANGUAGE, 0xffff); 706 expect_tag_dword(pattrinfo, 27, TAG_EXE_WRAPPER, 0x0); 707 } 708 if (ret) 709 pSdbFreeFileAttributes(pattrinfo); 710 711 712 /* Disable resource and exports */ 713 test_create_exe(L"testxx.exe", 1); 714 715 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 716 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 717 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 718 ok(num == 28, "expected 28 items, got %d.\n", num); 719 720 if (num == 28 && ret) 721 { 722 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0x800); 723 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0xea7caffd); 724 expect_tag_skip_range(pattrinfo, 2, 16); 725 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x3); /* Win32 */ 726 expect_tag_dword(pattrinfo, 17, TAG_PE_CHECKSUM, 0xBAAD); 727 expect_tag_dword(pattrinfo, 18, TAG_LINKER_VERSION, 0x40002); 728 expect_tag_skip_range(pattrinfo, 19, 23); 729 expect_tag_dword(pattrinfo, 23, TAG_LINK_DATE, 0x12345); 730 expect_tag_dword(pattrinfo, 24, TAG_UPTO_LINK_DATE, 0x12345); 731 expect_tag_skip(pattrinfo, 25); /* TAG_EXPORT_NAME */ 732 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */ 733 expect_tag_dword(pattrinfo, 27, TAG_EXE_WRAPPER, 0x0); 734 } 735 if (ret) 736 pSdbFreeFileAttributes(pattrinfo); 737 738 /* A file with just 'MZ' */ 739 test_create_file(L"testxx.exe", "MZ", 2); 740 741 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 742 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 743 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 744 ok(num == 28, "expected 28 items, got %d.\n", num); 745 746 if (num == 28 && ret) 747 { 748 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0x2); 749 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0); 750 expect_tag_skip_range(pattrinfo, 2, 16); 751 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x1); 752 expect_tag_skip_range(pattrinfo, 17, 26); 753 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */ 754 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */ 755 } 756 if (ret) 757 pSdbFreeFileAttributes(pattrinfo); 758 759 /* Empty file */ 760 test_create_file(L"testxx.exe", NULL, 0); 761 762 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 763 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 764 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 765 ok(num == 28, "expected 28 items, got %d.\n", num); 766 767 if (num == 28 && ret) 768 { 769 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0); 770 expect_tag_skip_range(pattrinfo, 1, 26); 771 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */ 772 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */ 773 } 774 if (ret) 775 pSdbFreeFileAttributes(pattrinfo); 776 777 /* minimal NE executable */ 778 test_create_ne(L"testxx.exe", 0); 779 780 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 781 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 782 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 783 ok(num == 28, "expected 28 items, got %d.\n", num); 784 785 if (num == 28 && ret) 786 { 787 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0xa8); 788 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0xf2abe4e9); 789 expect_tag_skip_range(pattrinfo, 2, 16); 790 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x2); 791 expect_tag_skip(pattrinfo, 17); /* TAG_PE_CHECKSUM */ 792 expect_tag_skip(pattrinfo, 18); /* TAG_LINKER_VERSION */ 793 expect_tag_str(pattrinfo, 19, TAG_16BIT_DESCRIPTION, OS2_DESCRIPTION); 794 expect_tag_str(pattrinfo, 20, TAG_16BIT_MODULE_NAME, OS2_EXPORT_NAME); 795 expect_tag_skip_range(pattrinfo, 21, 26); 796 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */ 797 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */ 798 } 799 if (ret) 800 pSdbFreeFileAttributes(pattrinfo); 801 802 /* NE executable with description / module name pointers zero, to show they are always used */ 803 test_create_ne(L"testxx.exe", 1); 804 805 ret = pSdbGetFileAttributes(path, &pattrinfo, &num); 806 ok(ret != FALSE, "expected SdbGetFileAttributes to succeed.\n"); 807 ok(pattrinfo != (PATTRINFO)0xdead, "expected a valid pointer.\n"); 808 ok(num == 28, "expected 28 items, got %d.\n", num); 809 810 if (num == 28 && ret) 811 { 812 expect_tag_dword(pattrinfo, 0, TAG_SIZE, 0xa8); 813 expect_tag_dword(pattrinfo, 1, TAG_CHECKSUM, 0xddcbe4c9); 814 expect_tag_skip_range(pattrinfo, 2, 16); 815 expect_tag_dword(pattrinfo, 16, TAG_MODULE_TYPE, 0x2); 816 expect_tag_skip(pattrinfo, 17); /* TAG_PE_CHECKSUM */ 817 expect_tag_skip(pattrinfo, 18); /* TAG_LINKER_VERSION */ 818 expect_tag_str(pattrinfo, 19, TAG_16BIT_DESCRIPTION, OS2_DESCRIPTION_broken); /* the 'Z' from 'MZ' */ 819 expect_tag_str(pattrinfo, 20, TAG_16BIT_MODULE_NAME, OS2_EXPORT_NAME_broken); /* the 'E' from 'NE' */ 820 expect_tag_skip_range(pattrinfo, 21, 26); 821 expect_tag_empty(pattrinfo, 26); /* TAG_VER_LANGUAGE */ 822 expect_tag_skip(pattrinfo, 27); /* TAG_EXE_WRAPPER */ 823 } 824 if (ret) 825 pSdbFreeFileAttributes(pattrinfo); 826 827 test_crc(1, 0); 828 test_crc(2, 0); 829 test_crc(3, 0); 830 test_crc(4, 0x2020202); 831 test_crc(5, 0x2020202); 832 test_crc(6, 0x2020202); 833 test_crc(7, 0x2020202); 834 test_crc(8, 0x81818181); 835 test_crc(9, 0x81818181); 836 test_crc(10, 0x81818181); 837 test_crc(11, 0x81818181); 838 test_crc(12, 0xc2c2c2c2); 839 test_crc(16, 0x62626262); 840 841 /* This seems to be the cutoff point */ 842 test_crc2(0xffc, 4, 0xfbfbfcfc); 843 test_crc2(0xffc, 8, 0x7070717); 844 test_crc2(0xffc, 0xcc, 0xc8eba002); 845 test_crc2(0xffc, 0, 0x4622028d); 846 847 test_crc2(0x1000, 4, 0x80); 848 test_crc2(0x1000, 8, 0x8787878f); 849 test_crc2(0x1000, 0xcc, 0x4adc3667); 850 test_crc2(0x1000, 0, 0xa3108044); 851 852 /* Here is another cutoff point */ 853 test_crc2(0x11fc, 4, 0x80); 854 test_crc2(0x11fc, 8, 0x8787878f); 855 test_crc2(0x11fc, 0xcc, 0x4adc3667); 856 test_crc2(0x11fc, 0, 0xf03e0800); 857 858 test_crc2(0x1200, 4, 0x80); 859 test_crc2(0x1200, 8, 0x8787878f); 860 test_crc2(0x1200, 0xcc, 0x4adc3667); 861 test_crc2(0x1200, 0, 0xa3108044); 862 863 /* After that, it stays the same for all sizes */ 864 test_crc2(0xf000, 4, 0x80); 865 test_crc2(0xf000, 8, 0x8787878f); 866 test_crc2(0xf000, 0xcc, 0x4adc3667); 867 test_crc2(0xf000, 0, 0xa3108044); 868 869 870 DeleteFileA("testxx.exe"); 871 } 872 873 /* Showing that SdbGetAppPatchDir returns HRESULT */ 874 static void test_SdbGetAppPatchDir(void) 875 { 876 WCHAR Buffer[MAX_PATH]; 877 HRESULT hr, expect_hr; 878 int n; 879 880 881 _SEH2_TRY 882 { 883 hr = pSdbGetAppPatchDir(NULL, NULL, 0); 884 ok_hex(hr, S_FALSE); 885 } 886 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) 887 { 888 /* Some versions accept it, some don't */ 889 trace("SdbGetAppPatchDir did not handle a NULL pointer very gracefully.\n"); 890 } 891 _SEH2_END; 892 893 894 895 memset(Buffer, 0xbb, sizeof(Buffer)); 896 hr = pSdbGetAppPatchDir(NULL, Buffer, 0); 897 if (g_WinVersion < WINVER_WIN7) 898 expect_hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER); 899 else if (g_WinVersion < WINVER_WIN10) 900 expect_hr = S_OK; 901 else 902 expect_hr = S_FALSE; 903 ok_hex(hr, expect_hr); 904 905 if (g_WinVersion < WINVER_WIN7) 906 expect_hr = HRESULT_FROM_WIN32(ERROR_INSUFFICIENT_BUFFER); 907 else if (g_WinVersion < WINVER_WIN10) 908 expect_hr = S_OK; 909 else 910 expect_hr = TRUE; 911 912 memset(Buffer, 0xbb, sizeof(Buffer)); 913 hr = pSdbGetAppPatchDir(NULL, Buffer, 1); 914 ok_hex(hr, expect_hr); 915 916 917 for (n = 2; n < _countof(Buffer) - 1; ++n) 918 { 919 memset(Buffer, 0xbb, sizeof(Buffer)); 920 hr = pSdbGetAppPatchDir(NULL, Buffer, n); 921 ok(Buffer[n] == 0xbbbb, "Expected SdbGetAppPatchDir to leave WCHAR at %d untouched, was: %d\n", 922 n, Buffer[n]); 923 ok(hr == S_OK || hr == expect_hr, "Expected S_OK or 0x%x, was: 0x%x (at %d)\n", expect_hr, hr, n); 924 } 925 } 926 START_TEST(apphelp) 927 { 928 //SetEnvironmentVariable("SHIM_DEBUG_LEVEL", "4"); 929 //SetEnvironmentVariable("DEBUGCHANNEL", "+apphelp"); 930 silence_debug_output(); 931 932 hdll = LoadLibraryA("apphelp.dll"); 933 g_WinVersion = get_module_version(hdll); 934 trace("Detected apphelp.dll version: 0x%x\n", g_WinVersion); 935 936 #define RESOLVE(fnc) do { p##fnc = (void *) GetProcAddress(hdll, #fnc); ok(!!p##fnc, #fnc " not found.\n"); } while (0) 937 RESOLVE(ApphelpCheckShellObject); 938 RESOLVE(SdbTagToString); 939 RESOLVE(SdbGUIDToString); 940 RESOLVE(SdbIsNullGUID); 941 RESOLVE(SdbGetStandardDatabaseGUID); 942 RESOLVE(SdbGetFileAttributes); 943 RESOLVE(SdbFreeFileAttributes); 944 RESOLVE(SdbGetAppPatchDir); 945 #undef RESOLVE 946 947 test_ApphelpCheckShellObject(); 948 test_GuidFunctions(); 949 test_ApplicationAttributes(); 950 test_SdbTagToString(); 951 test_SdbTagToStringAllTags(); 952 if (pSdbGetAppPatchDir) 953 test_SdbGetAppPatchDir(); 954 } 955