forked from wine-mirror/wine
/
apphelp.c
326 lines (281 loc) · 13.1 KB
/
apphelp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
/*
* Copyright 2012 Detlef Riekenberg
* Copyright 2013 Mislav Blažević
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#define COBJMACROS
#include <stdarg.h>
#include <stdio.h>
#include <initguid.h>
#include <exdisp.h>
#include <shlobj.h>
#include <urlmon.h>
#include <appcompatapi.h>
#include <winbase.h>
#include "../apphelp.h" /* TODO: include with relative path is not allowed?? */
#include "wine/test.h"
static HMODULE hdll;
static BOOL (WINAPI *pApphelpCheckShellObject)(REFCLSID, BOOL, ULONGLONG *);
static LPCWSTR (WINAPI *pSdbTagToString)(TAG);
static PDB (WINAPI *pSdbOpenDatabase)(LPCWSTR, PATH_TYPE);
static void (WINAPI *pSdbCloseDatabase)(PDB);
static TAG (WINAPI *pSdbGetTagFromTagID)(PDB, TAGID);
static DWORD (WINAPI *pSdbReadDWORDTag)(PDB, TAGID, DWORD);
static QWORD (WINAPI *pSdbReadQWORDTag)(PDB, TAGID, QWORD);
static TAGID (WINAPI *pSdbGetFirstChild)(PDB, TAGID);
static TAGID (WINAPI *pSdbGetNextChild)(PDB, TAGID, TAGID);
static LPWSTR (WINAPI *pSdbGetStringTagPtr)(PDB, TAGID);
static BOOL (WINAPI *pSdbReadStringTag)(PDB, TAGID, LPWSTR, DWORD);
static PDB (WINAPI *pSdbCreateDatabase)(LPCWSTR, PATH_TYPE);
static void (WINAPI *pSdbCloseDatabaseWrite)(PDB);
static BOOL (WINAPI *pSdbWriteDWORDTag)(PDB, TAG, DWORD);
static BOOL (WINAPI *pSdbWriteQWORDTag)(PDB, TAG, QWORD);
static BOOL (WINAPI *pSdbWriteBinaryTagFromFile)(PDB, TAG, LPCWSTR);
static PVOID (WINAPI *pSdbGetBinaryTagData)(PDB, TAGID);
static BOOL (WINAPI *pSdbWriteStringTag)(PDB, TAG, LPCWSTR);
static TAGID (WINAPI *pSdbBeginWriteListTag)(PDB, TAG);
static BOOL (WINAPI *pSdbEndWriteListTag)(PDB, TAGID);
static BOOL (WINAPI *pSdbWriteStringRefTag)(PDB, TAG, TAGID);
static BOOL (WINAPI *pSdbReadBinaryTag)(PDB, TAGID, PBYTE, DWORD);
static TAGID (WINAPI *pSdbFindFirstTag)(PDB, TAGID, TAG);
static BOOL (WINAPI *pSdbWriteNULLTag)(PDB, TAG);
static DWORD (WINAPI *pSdbGetTagDataSize)(PDB, TAGID);
static TAGID (WINAPI *pSdbFindNextTag)(PDB, TAGID, TAGID);
static BOOL (WINAPI *pSdbWriteWORDTag)(PDB, TAG, WORD);
static WORD (WINAPI *pSdbReadWORDTag)(PDB, TAGID, WORD);
DEFINE_GUID(GUID_NULL,0,0,0,0,0,0,0,0,0,0,0);
DEFINE_GUID(test_Microsoft_Browser_Architecture, 0xa5e46e3a, 0x8849, 0x11d1, 0x9d, 0x8c, 0x00, 0xc0, 0x4f, 0xc9, 0x9d, 0x61);
DEFINE_GUID(CLSID_MenuBand, 0x5b4dae26, 0xb807, 0x11d0, 0x98, 0x15, 0x00, 0xc0, 0x4f, 0xd9, 0x19, 0x72);
DEFINE_GUID(test_UserAssist, 0xdd313e04, 0xfeff, 0x11d1, 0x8e, 0xcd, 0x00, 0x00, 0xf8, 0x7a, 0x47, 0x0c);
static const CLSID * objects[] = {
&GUID_NULL,
/* used by IE */
&test_Microsoft_Browser_Architecture,
&CLSID_MenuBand,
&CLSID_ShellLink,
&CLSID_ShellWindows,
&CLSID_InternetSecurityManager,
&test_UserAssist,
NULL,};
static const char *debugstr_guid(REFIID riid)
{
static char buf[50];
sprintf(buf, "{%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
riid->Data1, riid->Data2, riid->Data3, riid->Data4[0],
riid->Data4[1], riid->Data4[2], riid->Data4[3], riid->Data4[4],
riid->Data4[5], riid->Data4[6], riid->Data4[7]);
return buf;
}
static void test_ApphelpCheckShellObject(void)
{
ULONGLONG flags;
BOOL res;
int i;
if (!pApphelpCheckShellObject)
{
win_skip("ApphelpCheckShellObject not available\n");
return;
}
for (i = 0; objects[i]; i++)
{
flags = 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pApphelpCheckShellObject(objects[i], FALSE, &flags);
ok(res && (flags == 0), "%s 0: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n",
debugstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
flags = 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pApphelpCheckShellObject(objects[i], TRUE, &flags);
ok(res && (flags == 0), "%s 1: got %d and 0x%x%08x with 0x%x (expected TRUE and 0)\n",
debugstr_guid(objects[i]), res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
}
/* NULL as pointer to flags is checked */
SetLastError(0xdeadbeef);
res = pApphelpCheckShellObject(&GUID_NULL, FALSE, NULL);
ok(res, "%s 0: got %d with 0x%x (expected != FALSE)\n", debugstr_guid(&GUID_NULL), res, GetLastError());
/* NULL as CLSID* crash on Windows */
if (0)
{
flags = 0xdeadbeef;
SetLastError(0xdeadbeef);
res = pApphelpCheckShellObject(NULL, FALSE, &flags);
trace("NULL as CLSID*: got %d and 0x%x%08x with 0x%x\n", res, (ULONG)(flags >> 32), (ULONG)flags, GetLastError());
}
}
static void test_SdbTagToString(void)
{
static const TAG invalid_values[] = {
1, TAG_TYPE_WORD, TAG_TYPE_MASK,
TAG_TYPE_DWORD | 0xFF,
TAG_TYPE_DWORD | (0x800 + 0xEE),
0x900, 0xFFFF, 0xDEAD, 0xBEEF
};
static const WCHAR invalid[] = {'I','n','v','a','l','i','d','T','a','g',0};
LPCWSTR ret;
WORD i;
for (i = 0; i < 9; ++i)
{
ret = pSdbTagToString(invalid_values[i]);
ok(lstrcmpW(ret, invalid) == 0, "unexpected string %s, should be %s\n",
wine_dbgstr_w(ret), wine_dbgstr_w(invalid));
}
}
static void Write(HANDLE file, LPCVOID buffer, DWORD size)
{
WriteFile(file, buffer, size, NULL, NULL);
}
static void test_Sdb(void)
{
static const WCHAR path[] = {'t','e','m','p',0};
static const WCHAR path2[] = {'t','e','m','p','2',0};
static const WCHAR tag_size_string[] = {'S','I','Z','E',0};
static const WCHAR tag_flag_lua_string[] = {'F','L','A','G','_','L','U','A',0};
static const TAG tags[5] = {
TAG_SIZE, TAG_FLAG_LUA, TAG_NAME,
TAG_STRINGTABLE, TAG_STRINGTABLE_ITEM
};
WCHAR buffer[6] = {0};
PDB db;
QWORD qword;
DWORD dword;
WORD word;
BOOL ret;
HANDLE file; /* temp file created for testing purpose */
TAG tag;
TAGID tagid, ptagid, stringref = 6;
LPCWSTR string;
PBYTE binary;
db = pSdbCreateDatabase(path, DOS_PATH);
ok (db != NULL, "failed to create database\n");
ret = pSdbWriteDWORDTag(db, tags[0], 0xDEADBEEF);
ok (ret, "failed to write DWORD tag\n");
ret = pSdbWriteQWORDTag(db, tags[1], 0xDEADBEEFBABE);
ok (ret, "failed to write QWORD tag\n");
ret = pSdbWriteStringRefTag(db, tags[2], stringref);
ok (ret, "failed to write stringref tag\n");
tagid = pSdbBeginWriteListTag(db, tags[3]);
ok (tagid != TAGID_NULL, "unexpected NULL tagid\n");
ret = pSdbWriteStringTag(db, tags[4], path);
ok (ret, "failed to write string tag\n");
ret = pSdbWriteNULLTag(db, TAG_GENERAL);
ok (ret, "failed to write NULL tag\n");
ret = pSdbWriteWORDTag(db, TAG_MATCH_MODE, 0xACE);
ok (ret, "failed to write WORD tag\n");
ret = pSdbEndWriteListTag(db, tagid);
ok (ret, "failed to update list size\n");
pSdbCloseDatabaseWrite(db);
db = pSdbOpenDatabase(path, DOS_PATH);
ok(db != NULL, "unexpected NULL handle\n");
tagid = pSdbGetFirstChild(db, TAGID_ROOT);
ok(tagid == _TAGID_ROOT, "unexpected tagid %u, expected %u\n", tagid, _TAGID_ROOT);
tag = pSdbGetTagFromTagID(db, tagid);
ok(tag == TAG_SIZE, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_SIZE);
string = pSdbTagToString(tag);
ok(lstrcmpW(string, tag_size_string) == 0, "unexpected string %s, expected %s\n",
wine_dbgstr_w(string), wine_dbgstr_w(tag_size_string));
dword = pSdbReadDWORDTag(db, tagid, 0);
ok(dword == 0xDEADBEEF, "unexpected value %u, expected 0xDEADBEEF\n", dword);
tagid = pSdbGetNextChild(db, TAGID_ROOT, tagid);
ok(tagid == _TAGID_ROOT + sizeof(TAG) + sizeof(DWORD), "unexpected tagid %u, expected %u\n",
tagid, _TAGID_ROOT + sizeof(TAG) + sizeof(DWORD));
tag = pSdbGetTagFromTagID(db, tagid);
ok (tag == TAG_FLAG_LUA, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_FLAG_LUA);
string = pSdbTagToString(tag);
ok(lstrcmpW(string, tag_flag_lua_string) == 0, "unexpected string %s, expected %s\n",
wine_dbgstr_w(string), wine_dbgstr_w(tag_flag_lua_string));
qword = pSdbReadQWORDTag(db, tagid, 0);
ok(qword == 0xDEADBEEFBABE, "unexpected value 0x%llx, expected 0xDEADBEEFBABE\n", qword);
tagid = pSdbGetNextChild(db, TAGID_ROOT, tagid);
string = pSdbGetStringTagPtr(db, tagid);
ok (string && (lstrcmpW(string, path) == 0), "unexpected string %s, expected %s\n",
wine_dbgstr_w(string), wine_dbgstr_w(path));
ptagid = pSdbGetNextChild(db, TAGID_ROOT, tagid);
tagid = pSdbGetFirstChild(db, ptagid);
string = pSdbGetStringTagPtr(db, tagid);
ok (string && (lstrcmpW(string, path) == 0), "unexpected string %s, expected %s\n",
wine_dbgstr_w(string), wine_dbgstr_w(path));
ok (pSdbReadStringTag(db, tagid, buffer, 6), "failed to write string to buffer\n");
ok (!pSdbReadStringTag(db, tagid, buffer, 3), "string was written to buffer, but failure was expected");
ok (pSdbGetTagDataSize(db, tagid) == 5 * sizeof(WCHAR), "string has unexpected size\n");
tagid = pSdbGetNextChild(db, ptagid, tagid);
tag = pSdbGetTagFromTagID(db, tagid);
ok (tag == TAG_GENERAL, "unexpected tag 0x%x, expected 0x%x\n", tag, TAG_GENERAL);
ok (pSdbGetTagDataSize(db, tagid) == 0, "null tag with size > 0\n");
tagid = pSdbGetNextChild(db, ptagid, tagid);
word = pSdbReadWORDTag(db, tagid, 0);
ok (word == 0xACE, "unexpected value 0x%x, expected 0x%x\n", word, 0xACE);
pSdbCloseDatabase(db);
DeleteFileW(path);
file = CreateFileW(path2, GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
ok (file != INVALID_HANDLE_VALUE, "failed to open file\n");
Write(file, &qword, 8);
CloseHandle(file);
db = pSdbCreateDatabase(path, DOS_PATH);
ok(db != NULL, "unexpected NULL handle\n");
ret = pSdbWriteBinaryTagFromFile(db, TAG_DATA_BITS, path2);
ok (ret, "failed to write tag from binary file\n");
pSdbCloseDatabaseWrite(db);
DeleteFileW(path2);
db = pSdbOpenDatabase(path, DOS_PATH);
ok(db != NULL, "unexpected NULL handle\n");
binary = pSdbGetBinaryTagData(db, _TAGID_ROOT);
ok (memcmp(binary, &qword, 8) == 0, "binary data is corrupt\n");
ret = pSdbReadBinaryTag(db, _TAGID_ROOT, (PBYTE)buffer, 12);
ok (ret, "failed to read binary tag\n");
ok (memcmp(buffer, &qword, 8) == 0, "binary data is corrupt\n");
pSdbCloseDatabase(db);
DeleteFileW(path);
}
START_TEST(apphelp)
{
hdll = LoadLibrary("apphelp.dll");
if (!hdll)
{
win_skip("apphelp.dll not available\n");
return;
}
pApphelpCheckShellObject = (void *) GetProcAddress(hdll, "ApphelpCheckShellObject");
pSdbTagToString = (void *) GetProcAddress(hdll, "SdbTagToString");
pSdbOpenDatabase = (void *) GetProcAddress(hdll, "SdbOpenDatabase");
pSdbCloseDatabase = (void *) GetProcAddress(hdll, "SdbCloseDatabase");
pSdbGetTagFromTagID = (void *) GetProcAddress(hdll, "SdbGetTagFromTagID");
pSdbGetFirstChild = (void *) GetProcAddress(hdll, "SdbGetFirstChild");
pSdbReadDWORDTag = (void *) GetProcAddress(hdll, "SdbReadDWORDTag");
pSdbReadQWORDTag = (void *) GetProcAddress(hdll, "SdbReadQWORDTag");
pSdbGetNextChild = (void *) GetProcAddress(hdll, "SdbGetNextChild");
pSdbGetStringTagPtr = (void *) GetProcAddress(hdll, "SdbGetStringTagPtr");
pSdbReadStringTag = (void *) GetProcAddress(hdll, "SdbReadStringTag");
pSdbCreateDatabase = (void *) GetProcAddress(hdll, "SdbCreateDatabase");
pSdbCloseDatabaseWrite = (void *) GetProcAddress(hdll, "SdbCloseDatabaseWrite");
pSdbWriteDWORDTag = (void *) GetProcAddress(hdll, "SdbWriteDWORDTag");
pSdbWriteQWORDTag = (void *) GetProcAddress(hdll, "SdbWriteQWORDTag");
pSdbWriteBinaryTagFromFile = (void *) GetProcAddress(hdll, "SdbWriteBinaryTagFromFile");
pSdbGetBinaryTagData = (void *) GetProcAddress(hdll, "SdbGetBinaryTagData");
pSdbWriteStringTag = (void *) GetProcAddress(hdll, "SdbWriteStringTag");
pSdbBeginWriteListTag = (void *)GetProcAddress(hdll, "SdbBeginWriteListTag");
pSdbEndWriteListTag = (void *) GetProcAddress(hdll, "SdbEndWriteListTag");
pSdbWriteStringRefTag = (void *) GetProcAddress(hdll, "SdbWriteStringRefTag");
pSdbReadBinaryTag = (void *) GetProcAddress(hdll, "SdbReadBinaryTag");
pSdbFindFirstTag = (void *) GetProcAddress(hdll, "SdbFindFirstTag");
pSdbWriteNULLTag = (void *) GetProcAddress(hdll, "SdbWriteNULLTag");
pSdbGetTagDataSize = (void *) GetProcAddress(hdll, "SdbGetTagDataSize");
pSdbFindNextTag = (void *) GetProcAddress(hdll, "SdbFindNextTag");
pSdbWriteWORDTag = (void *) GetProcAddress(hdll, "SdbWriteWORDTag");
pSdbReadWORDTag = (void *) GetProcAddress(hdll, "SdbReadWORDTag");
test_Sdb();
test_SdbTagToString();
test_ApphelpCheckShellObject();
}