ReactOS  0.4.14-dev-583-g2a1ba2c
builtin.c
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Hans Leidekker for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18 
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22 
23 #include <stdarg.h>
24 #ifdef __REACTOS__
25 #include <wchar.h>
26 #endif
27 
28 #include "ntstatus.h"
29 #define WIN32_NO_STATUS
30 #include "windef.h"
31 #include "winbase.h"
32 #include "winsock2.h"
33 #include "ws2tcpip.h"
34 #include "initguid.h"
35 #include "wbemcli.h"
36 #include "wbemprov.h"
37 #include "iphlpapi.h"
38 #include "netioapi.h"
39 #include "tlhelp32.h"
40 #ifndef __REACTOS__
41 #include "d3d10.h"
42 #endif
43 #include "winternl.h"
44 #include "winioctl.h"
45 #include "winsvc.h"
46 #include "winver.h"
47 #include "sddl.h"
48 #include "ntsecapi.h"
49 #ifdef __REACTOS__
50 #include <wingdi.h>
51 #include <winreg.h>
52 #endif
53 #include "winspool.h"
54 #include "setupapi.h"
55 
56 #include "wine/asm.h"
57 #include "wine/debug.h"
58 #include "wbemprox_private.h"
59 
61 
62 static const WCHAR class_associatorsW[] =
63  {'_','_','A','S','S','O','C','I','A','T','O','R','S',0};
64 static const WCHAR class_baseboardW[] =
65  {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
66 static const WCHAR class_biosW[] =
67  {'W','i','n','3','2','_','B','I','O','S',0};
68 static const WCHAR class_cdromdriveW[] =
69  {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
70 static const WCHAR class_compsysW[] =
71  {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
72 static const WCHAR class_compsysproductW[] =
73  {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m','P','r','o','d','u','c','t',0};
74 static const WCHAR class_datafileW[] =
75  {'C','I','M','_','D','a','t','a','F','i','l','e',0};
76 static const WCHAR class_desktopmonitorW[] =
77  {'W','i','n','3','2','_','D','e','s','k','t','o','p','M','o','n','i','t','o','r',0};
78 static const WCHAR class_directoryW[] =
79  {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
80 static const WCHAR class_diskdriveW[] =
81  {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
83  {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e','T','o','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
84 static const WCHAR class_diskpartitionW[] =
85  {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
87  {'W','i','n','3','2','_','D','i','s','p','l','a','y','C','o','n','t','r','o','l','l','e','r',
88  'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
89 static const WCHAR class_ip4routetableW[] =
90  {'W','i','n','3','2','_','I','P','4','R','o','u','t','e','T','a','b','l','e',0};
91 static const WCHAR class_logicaldiskW[] =
92  {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
93 static const WCHAR class_logicaldisk2W[] =
94  {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
96  {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k','T','o','P','a','r','t','i','t','i','o','n',0};
97 static const WCHAR class_networkadapterW[] =
98  {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
100  {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
101  'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
103  {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
104 static const WCHAR class_paramsW[] =
105  {'_','_','P','A','R','A','M','E','T','E','R','S',0};
106 static const WCHAR class_physicalmediaW[] =
107  {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
108 static const WCHAR class_physicalmemoryW[] =
109  {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
110 static const WCHAR class_pnpentityW[] =
111  {'W','i','n','3','2','_','P','n','P','E','n','t','i','t','y',0};
112 static const WCHAR class_printerW[] =
113  {'W','i','n','3','2','_','P','r','i','n','t','e','r',0};
115  {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
116  'N','E','R','_','O','U','T',0};
117 static const WCHAR class_processorW[] =
118  {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
119 static const WCHAR class_processor2W[] =
120  {'C','I','M','_','P','r','o','c','e','s','s','o','r',0};
121 static const WCHAR class_qualifiersW[] =
122  {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
124  {'W','i','n','3','2','_','Q','u','i','c','k','F','i','x','E','n','g','i','n','e','e','r','i','n','g',0};
125 static const WCHAR class_sidW[] =
126  {'W','i','n','3','2','_','S','I','D',0};
127 static const WCHAR class_sounddeviceW[] =
128  {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
130  {'W','i','n','3','2','_','S','y','s','t','e','m','E','n','c','l','o','s','u','r','e',0};
131 #ifndef __REACTOS__
133  {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
134 #endif
135 static const WCHAR class_winsatW[] =
136  {'W','i','n','3','2','_','W','i','n','S','A','T',0};
137 
138 static const WCHAR prop_accountnameW[] =
139  {'A','c','c','o','u','n','t','N','a','m','e',0};
140 static const WCHAR prop_acceptpauseW[] =
141  {'A','c','c','e','p','t','P','a','u','s','e',0};
142 static const WCHAR prop_acceptstopW[] =
143  {'A','c','c','e','p','t','S','t','o','p',0};
144 static const WCHAR prop_accessmaskW[] =
145  {'A','c','c','e','s','s','M','a','s','k',0};
146 #ifndef __REACTOS__
147 static const WCHAR prop_adapterdactypeW[] =
148  {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
149 static const WCHAR prop_adapterramW[] =
150  {'A','d','a','p','t','e','r','R','A','M',0};
151 #endif
152 static const WCHAR prop_adaptertypeW[] =
153  {'A','d','a','p','t','e','r','T','y','p','e',0};
154 static const WCHAR prop_adaptertypeidW[] =
155  {'A','d','a','p','t','e','r','T','y','p','e','I','D',0};
156 static const WCHAR prop_addresswidthW[] =
157  {'A','d','d','r','e','s','s','W','i','d','t','h',0};
158 static const WCHAR prop_antecedentW[] =
159  {'A','n','t','e','c','e','d','e','n','t',0};
160 static const WCHAR prop_architectureW[] =
161  {'A','r','c','h','i','t','e','c','t','u','r','e',0};
162 static const WCHAR prop_assocclassW[] =
163  {'A','s','s','o','c','C','l','a','s','s',0};
164 static const WCHAR prop_associatorW[] =
165  {'A','s','s','o','c','i','a','t','o','r',0};
166 static const WCHAR prop_attributesW[] =
167  {'A','t','t','r','i','b','u','t','e','s',0};
168 #ifndef __REACTOS__
169 static const WCHAR prop_availabilityW[] =
170  {'A','v','a','i','l','a','b','i','l','i','t','y',0};
171 #endif
173  {'B','i','n','a','r','y','R','e','p','r','e','s','e','n','t','a','t','i','o','n',0};
174 static const WCHAR prop_bitsperpixelW[] =
175  {'B','i','t','s','P','e','r','P','i','x','e','l',0};
176 static const WCHAR prop_boolvalueW[] =
177  {'B','o','o','l','V','a','l','u','e',0};
178 static const WCHAR prop_bootableW[] =
179  {'B','o','o','t','a','b','l','e',0};
180 static const WCHAR prop_bootpartitionW[] =
181  {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
182 static const WCHAR prop_buildnumberW[] =
183  {'B','u','i','l','d','N','u','m','b','e','r',0};
184 static const WCHAR prop_capacityW[] =
185  {'C','a','p','a','c','i','t','y',0};
186 static const WCHAR prop_captionW[] =
187  {'C','a','p','t','i','o','n',0};
188 static const WCHAR prop_chassistypesW[] =
189  {'C','h','a','s','s','i','s','T','y','p','e','s',0};
190 static const WCHAR prop_classW[] =
191  {'C','l','a','s','s',0};
192 static const WCHAR prop_codesetW[] =
193  {'C','o','d','e','S','e','t',0};
194 static const WCHAR prop_commandlineW[] =
195  {'C','o','m','m','a','n','d','L','i','n','e',0};
197  {'C','o','n','f','i','g','M','a','n','a','g','e','r','E','r','r','o','r','C','o','d','e',0};
199  {'C','o','n','f','i','g','u','r','e','d','C','l','o','c','k','S','p','e','e','d',0};
200 static const WCHAR prop_countrycodeW[] =
201  {'C','o','u','n','t','r','y','C','o','d','e',0};
202 static const WCHAR prop_cpuscoreW[] =
203  {'C','P','U','S','c','o','r','e',0};
204 static const WCHAR prop_cpustatusW[] =
205  {'C','p','u','S','t','a','t','u','s',0};
206 static const WCHAR prop_csdversionW[] =
207  {'C','S','D','V','e','r','s','i','o','n',0};
208 static const WCHAR prop_csnameW[] =
209  {'C','S','N','a','m','e',0};
210 #ifndef __REACTOS__
212  {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
213 #endif
215  {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
217  {'C','u','r','r','e','n','t','H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
218 static const WCHAR prop_currentlanguageW[] =
219  {'C','u','r','r','e','n','t','L','a','n','g','u','a','g','e',0};
221  {'C','u','r','r','e','n','t','R','e','f','r','e','s','h','R','a','t','e',0};
222 static const WCHAR prop_currentscanmodeW[] =
223  {'C','u','r','r','e','n','t','S','c','a','n','M','o','d','e',0};
224 static const WCHAR prop_currenttimezoneW[] =
225  {'C','u','r','r','e','n','t','T','i','m','e','Z','o','n','e',0};
227  {'C','u','r','r','e','n','t','V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
228 static const WCHAR prop_d3dscoreW[] =
229  {'D','3','D','S','c','o','r','e',0};
230 static const WCHAR prop_datawidthW[] =
231  {'D','a','t','a','W','i','d','t','h',0};
233  {'D','e','f','a','u','l','t','I','P','G','a','t','e','w','a','y',0};
234 static const WCHAR prop_defaultvalueW[] =
235  {'D','e','f','a','u','l','t','V','a','l','u','e',0};
236 static const WCHAR prop_dependentW[] =
237  {'D','e','p','e','n','d','e','n','t',0};
238 static const WCHAR prop_descriptionW[] =
239  {'D','e','s','c','r','i','p','t','i','o','n',0};
240 static const WCHAR prop_destinationW[] =
241  {'D','e','s','t','i','n','a','t','i','o','n',0};
242 static const WCHAR prop_deviceidW[] =
243  {'D','e','v','i','c','e','I','d',0};
244 static const WCHAR prop_devicelocatorW[] =
245  {'D','e','v','i','c','e','L','o','c','a','t','o','r',0};
246 static const WCHAR prop_dhcpenabledW[] =
247  {'D','H','C','P','E','n','a','b','l','e','d',0};
248 static const WCHAR prop_directionW[] =
249  {'D','i','r','e','c','t','i','o','n',0};
250 static const WCHAR prop_diskscoreW[] =
251  {'D','i','s','k','S','c','o','r','e',0};
252 static const WCHAR prop_displaynameW[] =
253  {'D','i','s','p','l','a','y','N','a','m','e',0};
254 static const WCHAR prop_diskindexW[] =
255  {'D','i','s','k','I','n','d','e','x',0};
256 static const WCHAR prop_dnshostnameW[] =
257  {'D','N','S','H','o','s','t','N','a','m','e',0};
259  {'D','N','S','S','e','r','v','e','r','S','e','a','r','c','h','O','r','d','e','r',0};
260 static const WCHAR prop_domainW[] =
261  {'D','o','m','a','i','n',0};
262 static const WCHAR prop_domainroleW[] =
263  {'D','o','m','a','i','n','R','o','l','e',0};
264 static const WCHAR prop_driveW[] =
265  {'D','r','i','v','e',0};
266 static const WCHAR prop_driverdateW[] =
267  {'D','r','i','v','e','r','D','a','t','e',0};
268 static const WCHAR prop_drivernameW[] =
269  {'D','r','i','v','e','r','N','a','m','e',0};
270 #ifndef __REACTOS__
271 static const WCHAR prop_driverversionW[] =
272  {'D','r','i','v','e','r','V','e','r','s','i','o','n',0};
273 #endif
274 static const WCHAR prop_drivetypeW[] =
275  {'D','r','i','v','e','T','y','p','e',0};
276 static const WCHAR prop_familyW[] =
277  {'F','a','m','i','l','y',0};
278 static const WCHAR prop_filesystemW[] =
279  {'F','i','l','e','S','y','s','t','e','m',0};
280 static const WCHAR prop_flavorW[] =
281  {'F','l','a','v','o','r',0};
282 static const WCHAR prop_freespaceW[] =
283  {'F','r','e','e','S','p','a','c','e',0};
285  {'F','r','e','e','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
286 static const WCHAR prop_handleW[] =
287  {'H','a','n','d','l','e',0};
288 static const WCHAR prop_graphicsscoreW[] =
289  {'G','r','a','p','h','i','c','s','S','c','o','r','e',0};
291  {'H','o','r','i','z','o','n','t','a','l','R','e','s','o','l','u','t','i','o','n',0};
292 static const WCHAR prop_hotfixidW[] =
293  {'H','o','t','F','i','x','I','D',0};
294 static const WCHAR prop_idW[] =
295  {'I','D',0};
297  {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
299  {'I','d','e','n','t','i','f','y','i','n','g','N','u','m','b','e','r',0};
300 static const WCHAR prop_indexW[] =
301  {'I','n','d','e','x',0};
302 static const WCHAR prop_installdateW[] =
303  {'I','n','s','t','a','l','l','D','a','t','e',0};
305  {'I','n','s','t','a','l','l','e','d','D','i','s','p','l','a','y','D','r','i','v','e','r','s',0};
306 static const WCHAR prop_interfaceindexW[] =
307  {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
308 static const WCHAR prop_interfacetypeW[] =
309  {'I','n','t','e','r','f','a','c','e','T','y','p','e',0};
310 static const WCHAR prop_intvalueW[] =
311  {'I','n','t','e','g','e','r','V','a','l','u','e',0};
312 static const WCHAR prop_ipaddressW[] =
313  {'I','P','A','d','d','r','e','s','s',0};
315  {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
316 static const WCHAR prop_ipenabledW[] =
317  {'I','P','E','n','a','b','l','e','d',0};
318 static const WCHAR prop_ipsubnet[] =
319  {'I','P','S','u','b','n','e','t',0};
320 static const WCHAR prop_lastbootuptimeW[] =
321  {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
322 static const WCHAR prop_levelW[] =
323  {'L','e','v','e','l',0};
324 static const WCHAR prop_localW[] =
325  {'L','o','c','a','l',0};
326 static const WCHAR prop_localdatetimeW[] =
327  {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
328 static const WCHAR prop_localeW[] =
329  {'L','o','c','a','l','e',0};
330 static const WCHAR prop_locationW[] =
331  {'L','o','c','a','t','i','o','n',0};
332 static const WCHAR prop_lockpresentW[] =
333  {'L','o','c','k','P','r','e','s','e','n','t',0};
334 static const WCHAR prop_macaddressW[] =
335  {'M','A','C','A','d','d','r','e','s','s',0};
336 static const WCHAR prop_manufacturerW[] =
337  {'M','a','n','u','f','a','c','t','u','r','e','r',0};
338 static const WCHAR prop_maxclockspeedW[] =
339  {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
340 static const WCHAR prop_mediatypeW[] =
341  {'M','e','d','i','a','T','y','p','e',0};
342 static const WCHAR prop_memberW[] =
343  {'M','e','m','b','e','r',0};
344 static const WCHAR prop_memoryscoreW[] =
345  {'M','e','m','o','r','y','S','c','o','r','e',0};
346 static const WCHAR prop_memorytypeW[] =
347  {'M','e','m','o','r','y','T','y','p','e',0};
348 static const WCHAR prop_methodW[] =
349  {'M','e','t','h','o','d',0};
350 static const WCHAR prop_modelW[] =
351  {'M','o','d','e','l',0};
353  {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
354 static const WCHAR prop_networkW[] =
355  {'N','e','t','w','o','r','k',0};
356 static const WCHAR prop_nexthopW[] =
357  {'N','e','x','t','H','o','p',0};
358 static const WCHAR prop_numcoresW[] =
359  {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
361  {'N','u','m','b','e','r','O','f','L','o','g','i','c','a','l','P','r','o','c','e','s','s','o','r','s',0};
362 static const WCHAR prop_numprocessorsW[] =
363  {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
365  {'O','p','e','r','a','t','i','n','g','S','y','s','t','e','m','S','K','U',0};
366 static const WCHAR prop_osarchitectureW[] =
367  {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
368 static const WCHAR prop_oslanguageW[] =
369  {'O','S','L','a','n','g','u','a','g','e',0};
370 static const WCHAR prop_osproductsuiteW[] =
371  {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
372 static const WCHAR prop_ostypeW[] =
373  {'O','S','T','y','p','e',0};
374 static const WCHAR prop_parameterW[] =
375  {'P','a','r','a','m','e','t','e','r',0};
376 static const WCHAR prop_partnumberW[] =
377  {'P','a','r','t','N','u','m','b','e','r',0};
378 static const WCHAR prop_physicaladapterW[] =
379  {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
381  {'P','i','x','e','l','s','P','e','r','X','L','o','g','i','c','a','l','I','n','c','h',0};
382 static const WCHAR prop_pnpdeviceidW[] =
383  {'P','N','P','D','e','v','i','c','e','I','D',0};
384 static const WCHAR prop_portnameW[] =
385  {'P','o','r','t','N','a','m','e',0};
386 static const WCHAR prop_pprocessidW[] =
387  {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
388 static const WCHAR prop_primaryW[] =
389  {'P','r','i','m','a','r','y',0};
390 static const WCHAR prop_processidW[] =
391  {'P','r','o','c','e','s','s','I','D',0};
392 static const WCHAR prop_processoridW[] =
393  {'P','r','o','c','e','s','s','o','r','I','d',0};
394 static const WCHAR prop_processortypeW[] =
395  {'P','r','o','c','e','s','s','o','r','T','y','p','e',0};
396 static const WCHAR prop_productW[] =
397  {'P','r','o','d','u','c','t',0};
398 static const WCHAR prop_productnameW[] =
399  {'P','r','o','d','u','c','t','N','a','m','e',0};
401  {'R','e','f','e','r','e','n','c','e','d','D','o','m','a','i','n','N','a','m','e',0};
402 static const WCHAR prop_releasedateW[] =
403  {'R','e','l','e','a','s','e','D','a','t','e',0};
404 static const WCHAR prop_revisionW[] =
405  {'R','e','v','i','s','i','o','n',0};
406 static const WCHAR prop_serialnumberW[] =
407  {'S','e','r','i','a','l','N','u','m','b','e','r',0};
409  {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
411  {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
412 static const WCHAR prop_servicetypeW[] =
413  {'S','e','r','v','i','c','e','T','y','p','e',0};
414 static const WCHAR prop_settingidW[] =
415  {'S','e','t','t','i','n','g','I','D',0};
416 static const WCHAR prop_skunumberW[] =
417  {'S','K','U','N','u','m','b','e','r',0};
419  {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
421  {'S','M','B','I','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
423  {'S','M','B','I','O','S','M','i','n','o','r','V','e','r','s','i','o','n',0};
424 static const WCHAR prop_startmodeW[] =
425  {'S','t','a','r','t','M','o','d','e',0};
426 static const WCHAR prop_sidW[] =
427  {'S','I','D',0};
428 static const WCHAR prop_sidlengthW[] =
429  {'S','i','d','L','e','n','g','t','h',0};
430 static const WCHAR prop_sizeW[] =
431  {'S','i','z','e',0};
432 static const WCHAR prop_speedW[] =
433  {'S','p','e','e','d',0};
434 static const WCHAR prop_startingoffsetW[] =
435  {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
436 static const WCHAR prop_stateW[] =
437  {'S','t','a','t','e',0};
438 static const WCHAR prop_statusW[] =
439  {'S','t','a','t','u','s',0};
440 static const WCHAR prop_statusinfoW[] =
441  {'S','t','a','t','u','s','I','n','f','o',0};
442 static const WCHAR prop_strvalueW[] =
443  {'S','t','r','i','n','g','V','a','l','u','e',0};
444 static const WCHAR prop_suitemaskW[] =
445  {'S','u','i','t','e','M','a','s','k',0};
446 static const WCHAR prop_systemdirectoryW[] =
447  {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
448 static const WCHAR prop_systemdriveW[] =
449  {'S','y','s','t','e','m','D','r','i','v','e',0};
450 static const WCHAR prop_systemnameW[] =
451  {'S','y','s','t','e','m','N','a','m','e',0};
452 static const WCHAR prop_tagW[] =
453  {'T','a','g',0};
454 static const WCHAR prop_threadcountW[] =
455  {'T','h','r','e','a','d','C','o','u','n','t',0};
456 static const WCHAR prop_timetakenW[] =
457  {'T','i','m','e','T','a','k','e','n',0};
459  {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
461  {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
463  {'T','o','t','a','l','V','i','s','i','b','l','e','M','e','m','o','r','y','S','i','z','e',0};
464 static const WCHAR prop_typeW[] =
465  {'T','y','p','e',0};
466 static const WCHAR prop_uniqueidW[] =
467  {'U','n','i','q','u','e','I','d',0};
468 static const WCHAR prop_usernameW[] =
469  {'U','s','e','r','N','a','m','e',0};
470 static const WCHAR prop_uuidW[] =
471  {'U','U','I','D',0};
472 static const WCHAR prop_vendorW[] =
473  {'V','e','n','d','o','r',0};
474 static const WCHAR prop_versionW[] =
475  {'V','e','r','s','i','o','n',0};
477  {'V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
478 #ifndef __REACTOS__
480  {'V','i','d','e','o','A','r','c','h','i','t','e','c','t','u','r','e',0};
481 static const WCHAR prop_videomemorytypeW[] =
482  {'V','i','d','e','o','M','e','m','o','r','y','T','y','p','e',0};
484  {'V','i','d','e','o','M','o','d','e','D','e','s','c','r','i','p','t','i','o','n',0};
485 static const WCHAR prop_videoprocessorW[] =
486  {'V','i','d','e','o','P','r','o','c','e','s','s','o','r',0};
487 #endif /* !__REACTOS__ */
488 static const WCHAR prop_volumenameW[] =
489  {'V','o','l','u','m','e','N','a','m','e',0};
491  {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
493  {'W','i','n','S','A','T','A','s','s','e','s','s','m','e','n','t','S','t','a','t','e',0};
494 static const WCHAR prop_winsprlevelW[] =
495  {'W','i','n','S','P','R','L','e','v','e','l',0};
496 static const WCHAR prop_workingsetsizeW[] =
497  {'W','o','r','k','i','n','g','S','e','t','S','i','z','e',0};
498 
499 /* column definitions must be kept in sync with record structures below */
500 static const struct column col_associator[] =
501 {
503  { prop_classW, CIM_STRING },
505 };
506 static const struct column col_baseboard[] =
507 {
509  { prop_modelW, CIM_STRING },
510  { prop_nameW, CIM_STRING },
515 };
516 static const struct column col_bios[] =
517 {
522  { prop_nameW, CIM_STRING },
529 };
530 static const struct column col_cdromdrive[] =
531 {
535  { prop_nameW, CIM_STRING },
537 };
538 static const struct column col_compsys[] =
539 {
544  { prop_modelW, CIM_STRING },
550 };
551 static const struct column col_compsysproduct[] =
552 {
559 };
560 static const struct column col_datafile[] =
561 {
564 };
565 static const struct column col_desktopmonitor[] =
566 {
568 };
569 static const struct column col_directory[] =
570 {
573 };
574 static const struct column col_diskdrive[] =
575 {
577  { prop_indexW, CIM_UINT32 },
581  { prop_modelW, CIM_STRING },
585 };
586 static const struct column col_diskdrivetodiskpartition[] =
587 {
590 };
591 static const struct column col_diskpartition[] =
592 {
597  { prop_indexW, CIM_UINT32 },
599  { prop_sizeW, CIM_UINT64 },
602 };
603 static const struct column col_displaycontrollerconfig[] =
604 {
610 };
611 static const struct column col_ip4routetable[] =
612 {
616 };
617 static const struct column col_logicaldisk[] =
618 {
624  { prop_sizeW, CIM_UINT64 },
627 };
628 static const struct column col_logicaldisktopartition[] =
629 {
632 };
633 static const struct column col_networkadapter[] =
634 {
639  { prop_indexW, CIM_UINT32 },
648 };
649 static const struct column col_networkadapterconfig[] =
650 {
663 };
664 static const struct column col_operatingsystem[] =
665 {
695 };
696 static const struct column col_param[] =
697 {
698  { prop_classW, CIM_STRING },
702  { prop_typeW, CIM_UINT32 },
704 };
705 static const struct column col_physicalmedia[] =
706 {
708  { prop_tagW, CIM_STRING }
709 };
710 static const struct column col_physicalmemory[] =
711 {
717 };
718 static const struct column col_pnpentity[] =
719 {
721 };
722 static const struct column col_printer[] =
723 {
733 };
734 static const struct column col_process[] =
735 {
745  /* methods */
747 };
748 static const struct column col_processor[] =
749 {
759  { prop_levelW, CIM_UINT16 },
770 };
771 static const struct column col_qualifier[] =
772 {
773  { prop_classW, CIM_STRING },
775  { prop_typeW, CIM_UINT32 },
777  { prop_nameW, CIM_STRING },
781 };
782 static const struct column col_quickfixengineering[] =
783 {
786 };
787 static const struct column col_service[] =
788 {
796  { prop_stateW, CIM_STRING },
798  /* methods */
803 };
804 static const struct column col_sid[] =
805 {
811 };
812 static const struct column col_sounddevice[] =
813 {
814  { prop_nameW, CIM_STRING },
817 };
818 static const struct column col_stdregprov[] =
819 {
824 };
825 static const struct column col_systemenclosure[] =
826 {
832  { prop_nameW, CIM_STRING },
833  { prop_tagW, CIM_STRING },
834 };
835 static const struct column col_systemsecurity[] =
836 {
839 };
840 
841 #ifndef __REACTOS__
842 static const struct column col_videocontroller[] =
843 {
866 };
867 #endif
868 
869 static const struct column col_winsat[] =
870 {
879 };
880 
881 
883  {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
885  {'N','o','n','e',0};
886 static const WCHAR baseboard_tagW[] =
887  {'B','a','s','e',' ','B','o','a','r','d',0};
888 static const WCHAR baseboard_versionW[] =
889  {'1','.','0',0};
890 static const WCHAR bios_descriptionW[] =
891  {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
892 static const WCHAR bios_manufacturerW[] =
893  {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
894 static const WCHAR bios_releasedateW[] =
895  {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
896 static const WCHAR bios_serialnumberW[] =
897  {'0',0};
899  {'W','i','n','e',0};
900 static const WCHAR bios_versionW[] =
901  {'W','I','N','E',' ',' ',' ','-',' ','1',0};
902 static const WCHAR cdromdrive_mediatypeW[] =
903  {'C','D','-','R','O','M',0};
904 static const WCHAR cdromdrive_nameW[] =
905  {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
907  {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
908  '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
909  '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
910  'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
911 static const WCHAR compsys_descriptionW[] =
912  {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
913 static const WCHAR compsys_domainW[] =
914  {'W','O','R','K','G','R','O','U','P',0};
915 static const WCHAR compsys_manufacturerW[] =
916  {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
917 static const WCHAR compsys_modelW[] =
918  {'W','i','n','e',0};
920  {'0',0};
921 static const WCHAR compsysproduct_nameW[] =
922  {'W','i','n','e',0};
923 static const WCHAR compsysproduct_uuidW[] =
924  {'d','e','a','d','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-','d','e','a','d','-',
925  'd','e','a','d','d','e','a','d','d','e','a','d',0};
927  {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
929  {'1','.','0',0};
931  {'I','D','E',0};
933  {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
935  {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
937  {'R','e','m','o','v','a','b','l','e',' ','m','e','d','i','a',0};
938 static const WCHAR diskdrive_modelW[] =
939  {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
941  {'I','D','E','\\','D','i','s','k','\\','V','E','N','_','W','I','N','E',0};
942 static const WCHAR diskdrive_serialW[] =
943  {'W','I','N','E','H','D','I','S','K',0};
945  {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
946  'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
947  '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
948 static const WCHAR os_32bitW[] =
949  {'3','2','-','b','i','t',0};
950 static const WCHAR os_64bitW[] =
951  {'6','4','-','b','i','t',0};
952 static const WCHAR os_installdateW[] =
953  {'2','0','1','4','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
954 static const WCHAR os_serialnumberW[] =
955  {'1','2','3','4','5','-','O','E','M','-','1','2','3','4','5','6','7','-','1','2','3','4','5',0};
956 static const WCHAR physicalmedia_tagW[] =
957  {'\\','\\','.','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
959  {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',0};
961  {'K','B','1','2','3','4','5','6','7',0};
963  {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
965  {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',0};
966 static const WCHAR systemenclosure_tagW[] =
967  {'S','y','s','t','e','m',' ','E','n','c','l','o','s','u','r','e',' ','0',0};
969  {'W','i','n','e',0};
971  {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
973  {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
975  {'2','0','1','7','0','1','0','1','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
977  {'1','.','0',0};
979  {'O','K',0};
980 static const WCHAR winsat_timetakenW[] =
981  {'M','o','s','t','R','e','c','e','n','t','A','s','s','e','s','s','m','e','n','t',0};
982 
983 #include "pshpack1.h"
985 {
987  const WCHAR *class;
989 };
991 {
993  const WCHAR *model;
994  const WCHAR *name;
995  const WCHAR *product;
997  const WCHAR *tag;
998  const WCHAR *version;
999 };
1001 {
1006  const WCHAR *name;
1012  const WCHAR *version;
1013 };
1015 {
1017  const WCHAR *drive;
1019  const WCHAR *name;
1021 };
1023 {
1025  const WCHAR *domain;
1028  const WCHAR *model;
1029  const WCHAR *name;
1033  const WCHAR *username;
1034 };
1036 {
1038  const WCHAR *name;
1040  const WCHAR *uuid;
1041  const WCHAR *vendor;
1042  const WCHAR *version;
1043 };
1045 {
1046  const WCHAR *name;
1047  const WCHAR *version;
1048 };
1050 {
1052 };
1054 {
1056  const WCHAR *name;
1057 };
1059 {
1065  const WCHAR *model;
1069 };
1071 {
1074 };
1076 {
1085  const WCHAR *type;
1086 };
1088 {
1090  const WCHAR *caption;
1092  const WCHAR *name;
1094 };
1096 {
1099  const WCHAR *nexthop;
1100 };
1102 {
1107  const WCHAR *name;
1111 };
1113 {
1116 };
1118 {
1127  const WCHAR *name;
1132 };
1134 {
1135  const struct array *defaultipgateway;
1141  const struct array *ipaddress;
1144  const struct array *ipsubnet;
1147 };
1149 {
1151  const WCHAR *caption;
1152  const WCHAR *codeset;
1155  const WCHAR *csname;
1161  const WCHAR *locale;
1163  const WCHAR *name;
1169  int primary;
1178  const WCHAR *version;
1179 };
1181 {
1182  const WCHAR *class;
1183  const WCHAR *method;
1188 };
1190 {
1192  const WCHAR *tag;
1193 };
1195 {
1201 };
1203 {
1205 };
1207 {
1212  int local;
1213  const WCHAR *location;
1214  const WCHAR *name;
1215  int network;
1216  const WCHAR *portname;
1217 };
1219 {
1220  const WCHAR *caption;
1223  const WCHAR *handle;
1224  const WCHAR *name;
1229  /* methods */
1231 };
1233 {
1236  const WCHAR *caption;
1246  const WCHAR *name;
1253  const WCHAR *version;
1254 };
1256 {
1257  const WCHAR *class;
1258  const WCHAR *member;
1261  const WCHAR *name;
1263  const WCHAR *strvalue;
1265 };
1267 {
1268  const WCHAR *caption;
1269  const WCHAR *hotfixid;
1270 };
1272 {
1276  const WCHAR *name;
1280  const WCHAR *state;
1282  /* methods */
1287 };
1289 {
1293  const WCHAR *sid;
1295 };
1297 {
1298  const WCHAR *name;
1301 };
1303 {
1308 };
1310 {
1313 };
1315 {
1316  const WCHAR *caption;
1317  const struct array *chassistypes;
1321  const WCHAR *name;
1322  const WCHAR *tag;
1323 };
1325 {
1329  const WCHAR *caption;
1341  const WCHAR *name;
1343  const WCHAR *status;
1348 };
1350 {
1359 };
1360 #include "poppack.h"
1361 
1362 static const struct record_associator data_associator[] =
1363 {
1366 };
1367 static const struct record_param data_param[] =
1368 {
1397 };
1398 
1399 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
1400  WBEM_FLAVOR_ORIGIN_PROPAGATED)
1401 
1403 {
1405 };
1406 static const struct record_qualifier data_qualifier[] =
1407 {
1410 };
1412 {
1414 };
1415 static const struct record_sounddevice data_sounddevice[] =
1416 {
1418 };
1419 static const struct record_stdregprov data_stdregprov[] =
1420 {
1422 };
1424 {
1425  1,
1426 };
1428 {
1429  sizeof(*systemenclosure_chassistypes),
1432 };
1434 {
1436 };
1437 static const struct record_winsat data_winsat[] =
1438 {
1439  { 8.0f, 8.0f, 8.0f, 8.0f, 8.0f, winsat_timetakenW, 1 /* Valid */, 8.0f },
1440 };
1441 
1442 /* check if row matches condition and update status */
1443 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
1444 {
1445  LONGLONG val;
1446  UINT type;
1447 
1448  if (!cond)
1449  {
1451  return TRUE;
1452  }
1453  if (eval_cond( table, row, cond, &val, &type ) != S_OK)
1454  {
1456  return FALSE;
1457  }
1459  return val != 0;
1460 }
1461 
1462 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
1463 {
1464  if (!table->num_rows_allocated)
1465  {
1466  if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
1467  table->num_rows_allocated = row_count;
1468  return TRUE;
1469  }
1470  if (row_count > table->num_rows_allocated)
1471  {
1472  BYTE *data;
1473  UINT count = max( row_count, table->num_rows_allocated * 2 );
1474  if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
1475  table->data = data;
1477  }
1478  return TRUE;
1479 }
1480 
1481 #include "pshpack1.h"
1483 {
1489 };
1490 
1492 {
1497 };
1498 
1500 {
1504 };
1505 
1507 {
1513 };
1514 
1516 {
1524 };
1525 
1527 {
1534 };
1535 
1537 {
1543  BYTE uuid[16];
1544 };
1545 #include "poppack.h"
1546 
1547 #define RSMB (('R' << 24) | ('S' << 16) | ('M' << 8) | 'B')
1548 
1549 static const struct smbios_header *find_smbios_entry( enum smbios_type type, const char *buf, UINT len )
1550 {
1551  const char *ptr, *start;
1552  const struct smbios_prologue *prologue;
1553  const struct smbios_header *hdr;
1554 
1555  if (len < sizeof(struct smbios_prologue)) return NULL;
1556  prologue = (const struct smbios_prologue *)buf;
1557  if (prologue->length > len - sizeof(*prologue) || prologue->length < sizeof(*hdr)) return NULL;
1558 
1559  start = (const char *)(prologue + 1);
1560  hdr = (const struct smbios_header *)start;
1561 
1562  for (;;)
1563  {
1564  if ((const char *)hdr - start >= prologue->length - sizeof(*hdr)) return NULL;
1565 
1566  if (!hdr->length)
1567  {
1568  WARN( "invalid entry\n" );
1569  return NULL;
1570  }
1571 
1572  if (hdr->type == type)
1573  {
1574  if ((const char *)hdr - start + hdr->length > prologue->length) return NULL;
1575  break;
1576  }
1577  else /* skip other entries and their strings */
1578  {
1579  for (ptr = (const char *)hdr + hdr->length; ptr - buf < len && *ptr; ptr++)
1580  {
1581  for (; ptr - buf < len; ptr++) if (!*ptr) break;
1582  }
1583  if (ptr == (const char *)hdr + hdr->length) ptr++;
1584  hdr = (const struct smbios_header *)(ptr + 1);
1585  }
1586  }
1587 
1588  return hdr;
1589 }
1590 
1591 static WCHAR *get_smbios_string( BYTE id, const char *buf, UINT offset, UINT buflen )
1592 {
1593  const char *ptr = buf + offset;
1594  UINT i = 0;
1595 
1596  if (!id || offset >= buflen) return NULL;
1597  for (ptr = buf + offset; ptr - buf < buflen && *ptr; ptr++)
1598  {
1599  if (++i == id) return heap_strdupAW( ptr );
1600  for (; ptr - buf < buflen; ptr++) if (!*ptr) break;
1601  }
1602  return NULL;
1603 }
1604 
1605 static WCHAR *get_baseboard_string( BYTE id, const char *buf, UINT len )
1606 {
1607  const struct smbios_header *hdr;
1608  const struct smbios_baseboard *baseboard;
1609  UINT offset;
1610 
1611  if (!(hdr = find_smbios_entry( SMBIOS_TYPE_BASEBOARD, buf, len ))) return NULL;
1612 
1613  baseboard = (const struct smbios_baseboard *)hdr;
1614  offset = (const char *)baseboard - buf + baseboard->hdr.length;
1615  return get_smbios_string( id, buf, offset, len );
1616 }
1617 
1619 {
1620  WCHAR *ret = get_baseboard_string( 1, buf, len );
1621  if (!ret) return heap_strdupW( baseboard_manufacturerW );
1622  return ret;
1623 }
1624 
1625 static WCHAR *get_baseboard_product( const char *buf, UINT len )
1626 {
1627  WCHAR *ret = get_baseboard_string( 2, buf, len );
1628  if (!ret) return heap_strdupW( baseboard_tagW );
1629  return ret;
1630 }
1631 
1633 {
1634  WCHAR *ret = get_baseboard_string( 4, buf, len );
1635  if (!ret) return heap_strdupW( baseboard_serialnumberW );
1636  return ret;
1637 }
1638 
1639 static WCHAR *get_baseboard_version( const char *buf, UINT len )
1640 {
1641  WCHAR *ret = get_baseboard_string( 3, buf, len );
1642  if (!ret) return heap_strdupW( baseboard_versionW );
1643  return ret;
1644 }
1645 
1646 static enum fill_status fill_baseboard( struct table *table, const struct expr *cond )
1647 {
1648  struct record_baseboard *rec;
1650  UINT row = 0, len;
1651  char *buf;
1652 
1653  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1654 
1655  len = GetSystemFirmwareTable( RSMB, 0, NULL, 0 );
1656  if (!(buf = heap_alloc( len ))) return FILL_STATUS_FAILED;
1658 
1659  rec = (struct record_baseboard *)table->data;
1661  rec->model = baseboard_tagW;
1662  rec->name = baseboard_tagW;
1663  rec->product = get_baseboard_product( buf, len );
1665  rec->tag = baseboard_tagW;
1666  rec->version = get_baseboard_version( buf, len );
1667  if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1668  else row++;
1669 
1670  heap_free( buf );
1671 
1672  TRACE("created %u rows\n", row);
1673  table->num_rows = row;
1674  return status;
1675 }
1676 
1678 {
1679  const struct smbios_prologue *prologue = (const struct smbios_prologue *)buf;
1680  if (len < sizeof(*prologue)) return 2;
1681  return prologue->major_version;
1682 }
1683 
1685 {
1686  const struct smbios_prologue *prologue = (const struct smbios_prologue *)buf;
1687  if (len < sizeof(*prologue)) return 0;
1688  return prologue->minor_version;
1689 }
1690 
1691 static WCHAR *get_bios_string( BYTE id, const char *buf, UINT len )
1692 {
1693  const struct smbios_header *hdr;
1694  const struct smbios_bios *bios;
1695  UINT offset;
1696 
1697  if (!(hdr = find_smbios_entry( SMBIOS_TYPE_BIOS, buf, len ))) return NULL;
1698 
1699  bios = (const struct smbios_bios *)hdr;
1700  offset = (const char *)bios - buf + bios->hdr.length;
1701  return get_smbios_string( id, buf, offset, len );
1702 }
1703 
1704 static WCHAR *get_bios_manufacturer( const char *buf, UINT len )
1705 {
1706  WCHAR *ret = get_bios_string( 1, buf, len );
1707  if (!ret) return heap_strdupW( bios_manufacturerW );
1708  return ret;
1709 }
1710 
1712 {
1713  static const WCHAR fmtW[] =
1714  {'%','0','4','u','%','0','2','u','%','0','2','u','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
1715  UINT year, month, day, len = lstrlenW( str );
1716  const WCHAR *p = str, *q;
1717  WCHAR *ret;
1718 
1719  while (len && iswspace( *p )) { p++; len--; }
1720  while (len && iswspace( p[len - 1] )) { len--; }
1721 
1722  q = p;
1723  while (len && iswdigit( *q )) { q++; len--; };
1724  if (q - p != 2 || !len || *q != '/') return NULL;
1725  month = (p[0] - '0') * 10 + p[1] - '0';
1726 
1727  p = ++q; len--;
1728  while (len && iswdigit( *q )) { q++; len--; };
1729  if (q - p != 2 || !len || *q != '/') return NULL;
1730  day = (p[0] - '0') * 10 + p[1] - '0';
1731 
1732  p = ++q; len--;
1733  while (len && iswdigit( *q )) { q++; len--; };
1734  if (q - p == 4) year = (p[0] - '0') * 1000 + (p[1] - '0') * 100 + (p[2] - '0') * 10 + p[3] - '0';
1735  else if (q - p == 2) year = 1900 + (p[0] - '0') * 10 + p[1] - '0';
1736  else return NULL;
1737 
1738  if (!(ret = heap_alloc( sizeof(fmtW) ))) return NULL;
1739  swprintf( ret, fmtW, year, month, day );
1740  return ret;
1741 }
1742 
1743 static WCHAR *get_bios_releasedate( const char *buf, UINT len )
1744 {
1745  WCHAR *ret, *date = get_bios_string( 3, buf, len );
1747  heap_free( date );
1748  return ret;
1749 }
1750 
1752 {
1753  WCHAR *ret = get_bios_string( 2, buf, len );
1754  if (!ret) return heap_strdupW( bios_smbiosbiosversionW );
1755  return ret;
1756 }
1757 
1758 static enum fill_status fill_bios( struct table *table, const struct expr *cond )
1759 {
1760  struct record_bios *rec;
1762  UINT row = 0, len;
1763  char *buf;
1764 
1765  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1766 
1767  len = GetSystemFirmwareTable( RSMB, 0, NULL, 0 );
1768  if (!(buf = heap_alloc( len ))) return FILL_STATUS_FAILED;
1770 
1771  rec = (struct record_bios *)table->data;
1772  rec->currentlanguage = NULL;
1774  rec->identificationcode = NULL;
1776  rec->name = bios_descriptionW;
1782  rec->version = bios_versionW;
1783  if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1784  else row++;
1785 
1786  heap_free( buf );
1787 
1788  TRACE("created %u rows\n", row);
1789  table->num_rows = row;
1790  return status;
1791 }
1792 
1793 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
1794 {
1795  static const WCHAR fmtW[] = {'%','c',':',0};
1796  WCHAR drive[3], root[] = {'A',':','\\',0};
1797  struct record_cdromdrive *rec;
1798  UINT i, row = 0, offset = 0;
1799  DWORD drives = GetLogicalDrives();
1801 
1802  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1803 
1804  for (i = 0; i < 26; i++)
1805  {
1806  if (drives & (1 << i))
1807  {
1808  root[0] = 'A' + i;
1809  if (GetDriveTypeW( root ) != DRIVE_CDROM)
1810  continue;
1811 
1812  if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1813 
1814  rec = (struct record_cdromdrive *)(table->data + offset);
1816  swprintf( drive, fmtW, 'A' + i );
1817  rec->drive = heap_strdupW( drive );
1819  rec->name = cdromdrive_nameW;
1821  if (!match_row( table, row, cond, &status ))
1822  {
1824  continue;
1825  }
1826  offset += sizeof(*rec);
1827  row++;
1828  }
1829  }
1830  TRACE("created %u rows\n", row);
1831  table->num_rows = row;
1832  return status;
1833 }
1834 
1836 {
1838 
1839  if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
1840  return info.NumberOfProcessors;
1841 }
1842 
1843 #ifdef __REACTOS__
1844 static UINT get_logical_processor_count( UINT *num_cores )
1845 {
1847  UINT i, j, count = 0;
1848  NTSTATUS status;
1849  ULONG len;
1850 
1851  if (num_cores) *num_cores = get_processor_count();
1854 
1855  if (!(info = heap_alloc( len ))) return get_processor_count();
1857  if (status != STATUS_SUCCESS)
1858  {
1859  heap_free( info );
1860  return get_processor_count();
1861  }
1862  if (num_cores) *num_cores = 0;
1863  for (i = 0; i < len / sizeof(*info); i++)
1864  {
1865  if (info[i].Relationship == RelationProcessorCore)
1866  {
1867  for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
1868  }
1869  else if (info[i].Relationship == RelationProcessorPackage && num_cores)
1870  {
1871  for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
1872  }
1873  }
1874  heap_free( info );
1875  return count;
1876 }
1877 #else
1878 static UINT get_logical_processor_count( UINT *num_physical, UINT *num_packages )
1879 {
1881  UINT core_relation_count = 0, package_relation_count = 0;
1882  NTSTATUS status;
1883  ULONG len, offset = 0;
1884  BOOL smt_enabled = FALSE;
1885  DWORD all = RelationAll;
1886 
1887  if (num_packages) *num_packages = 1;
1890 
1891  if (!(buf = heap_alloc( len ))) return get_processor_count();
1893  if (status != STATUS_SUCCESS)
1894  {
1895  heap_free( buf );
1896  return get_processor_count();
1897  }
1898 
1899  while (offset < len)
1900  {
1902 
1903  if (entry->Relationship == RelationProcessorCore)
1904  {
1905  core_relation_count++;
1906  if (entry->u.Processor.Flags & LTP_PC_SMT) smt_enabled = TRUE;
1907  }
1908  else if (entry->Relationship == RelationProcessorPackage)
1909  {
1910  package_relation_count++;
1911  }
1912  offset += entry->Size;
1913  }
1914 
1915  heap_free( buf );
1916  if (num_physical) *num_physical = core_relation_count;
1917  if (num_packages) *num_packages = package_relation_count;
1918  return smt_enabled ? core_relation_count * 2 : core_relation_count;
1919 }
1920 #endif
1921 
1923 {
1924  MEMORYSTATUSEX status;
1925 
1926  status.dwLength = sizeof(status);
1927  if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1928  return status.ullTotalPhys;
1929 }
1930 
1932 {
1933  MEMORYSTATUSEX status;
1934 
1935  status.dwLength = sizeof(status);
1936  if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1937  return status.ullAvailPhys;
1938 }
1939 
1941 {
1942  WCHAR *ret;
1944 
1945  if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1946  GetComputerNameW( ret, &size );
1947  return ret;
1948 }
1949 
1950 static WCHAR *get_username(void)
1951 {
1952  WCHAR *ret;
1953  DWORD compsize, usersize;
1954  DWORD size;
1955 
1956  compsize = 0;
1957  GetComputerNameW( NULL, &compsize );
1958  usersize = 0;
1959  GetUserNameW( NULL, &usersize );
1960  size = compsize + usersize; /* two null terminators account for the \ */
1961  if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
1962  GetComputerNameW( ret, &compsize );
1963  ret[compsize] = '\\';
1964  GetUserNameW( ret + compsize + 1, &usersize );
1965  return ret;
1966 }
1967 
1968 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
1969 {
1970  struct record_computersystem *rec;
1972  UINT row = 0;
1973 
1974  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1975 
1976  rec = (struct record_computersystem *)table->data;
1978  rec->domain = compsys_domainW;
1979  rec->domainrole = 0; /* standalone workstation */
1981  rec->model = compsys_modelW;
1982  rec->name = get_computername();
1983 #ifdef __REACTOS__
1986 #else
1988 #endif
1990  rec->username = get_username();
1991  if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1992  else row++;
1993 
1994  TRACE("created %u rows\n", row);
1995  table->num_rows = row;
1996  return status;
1997 }
1998 
1999 static WCHAR *get_compsysproduct_string( BYTE id, const char *buf, UINT len )
2000 {
2001  const struct smbios_header *hdr;
2002  const struct smbios_system *system;
2003  UINT offset;
2004 
2005  if (!(hdr = find_smbios_entry( SMBIOS_TYPE_SYSTEM, buf, len ))) return NULL;
2006 
2007  system = (const struct smbios_system *)hdr;
2008  offset = (const char *)system - buf + system->hdr.length;
2009  return get_smbios_string( id, buf, offset, len );
2010 }
2011 
2013 {
2016  return ret;
2017 }
2018 
2019 static WCHAR *get_compsysproduct_name( const char *buf, UINT len )
2020 {
2022  if (!ret) return heap_strdupW( compsysproduct_nameW );
2023  return ret;
2024 }
2025 
2026 static WCHAR *get_compsysproduct_uuid( const char *buf, UINT len )
2027 {
2028  static const WCHAR fmtW[] =
2029  {'%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-',
2030  '%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X','-','%','0','2','X','%','0','2','X',
2031  '%','0','2','X','%','0','2','X','%','0','2','X','%','0','2','X',0};
2032  static const BYTE none[] = {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};
2033  const struct smbios_header *hdr;
2034  const struct smbios_system *system;
2035  const BYTE *ptr;
2036  WCHAR *ret = NULL;
2037 
2038  if (!(hdr = find_smbios_entry( SMBIOS_TYPE_SYSTEM, buf, len )) || hdr->length < sizeof(*system)) goto done;
2039  system = (const struct smbios_system *)hdr;
2040  if (!memcmp( system->uuid, none, sizeof(none) ) || !(ret = heap_alloc( 37 * sizeof(WCHAR) ))) goto done;
2041 
2042  ptr = system->uuid;
2043  swprintf( ret, fmtW, ptr[0], ptr[1], ptr[2], ptr[3], ptr[4], ptr[5], ptr[6], ptr[7], ptr[8], ptr[9],
2044  ptr[10], ptr[11], ptr[12], ptr[13], ptr[14], ptr[15] );
2045 
2046 done:
2048  return ret;
2049 }
2050 
2051 static WCHAR *get_compsysproduct_vendor( const char *buf, UINT len )
2052 {
2054  if (!ret) return heap_strdupW( compsysproduct_vendorW );
2055  return ret;
2056 }
2057 
2059 {
2061  if (!ret) return heap_strdupW( compsysproduct_versionW );
2062  return ret;
2063 }
2064 
2065 static enum fill_status fill_compsysproduct( struct table *table, const struct expr *cond )
2066 {
2067  struct record_computersystemproduct *rec;
2069  UINT row = 0, len;
2070  char *buf;
2071 
2072  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2073 
2074  len = GetSystemFirmwareTable( RSMB, 0, NULL, 0 );
2075  if (!(buf = heap_alloc( len ))) return FILL_STATUS_FAILED;
2077 
2078  rec = (struct record_computersystemproduct *)table->data;
2080  rec->name = get_compsysproduct_name( buf, len );
2081  rec->skunumber = NULL;
2082  rec->uuid = get_compsysproduct_uuid( buf, len );
2085  if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2086  else row++;
2087 
2088  heap_free( buf );
2089 
2090  TRACE("created %u rows\n", row);
2091  table->num_rows = row;
2092  return status;
2093 }
2094 
2095 struct dirstack
2096 {
2101 };
2102 
2104 {
2105  struct dirstack *dirstack;
2106 
2107  if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
2108  if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
2109  {
2110  heap_free( dirstack );
2111  return NULL;
2112  }
2113  if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
2114  {
2115  heap_free( dirstack->dirs );
2116  heap_free( dirstack );
2117  return NULL;
2118  }
2119  dirstack->num_dirs = 0;
2121  return dirstack;
2122 }
2123 
2124 static void clear_dirstack( struct dirstack *dirstack )
2125 {
2126  UINT i;
2127  for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
2128  dirstack->num_dirs = 0;
2129 }
2130 
2131 static void free_dirstack( struct dirstack *dirstack )
2132 {
2134  heap_free( dirstack->dirs );
2136  heap_free( dirstack );
2137 }
2138 
2140 {
2141  UINT size, i = dirstack->num_dirs;
2142 
2143  if (!dir) return FALSE;
2144 
2145  if (i == dirstack->num_allocated)
2146  {
2147  WCHAR **tmp;
2148  UINT *len_tmp;
2149 
2150  size = dirstack->num_allocated * 2;
2151  if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
2152  dirstack->dirs = tmp;
2153  if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
2154  dirstack->len_dirs = len_tmp;
2156  }
2157  dirstack->dirs[i] = dir;
2158  dirstack->len_dirs[i] = len;
2159  dirstack->num_dirs++;
2160  return TRUE;
2161 }
2162 
2163 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
2164 {
2165  if (!dirstack->num_dirs)
2166  {
2167  *len = 0;
2168  return NULL;
2169  }
2170  dirstack->num_dirs--;
2172  return dirstack->dirs[dirstack->num_dirs];
2173 }
2174 
2175 static const WCHAR *peek_dir( struct dirstack *dirstack )
2176 {
2177  if (!dirstack->num_dirs) return NULL;
2178  return dirstack->dirs[dirstack->num_dirs - 1];
2179 }
2180 
2182 {
2183  UINT i = 0;
2184  WCHAR *ret;
2185 
2186  if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
2187  ret[i++] = drive;
2188  ret[i++] = ':';
2189  ret[i++] = '\\';
2190  if (path && len)
2191  {
2192  memcpy( ret + i, path, len * sizeof(WCHAR) );
2193  i += len;
2194  ret[i++] = '\\';
2195  }
2196  ret[i++] = '*';
2197  ret[i] = 0;
2198  return ret;
2199 }
2200 
2201 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
2202 {
2203  UINT i = 0, len = 0;
2204  const WCHAR *p;
2205  WCHAR *ret;
2206 
2207  for (p = path; *p; p++)
2208  {
2209  if (*p == '\\') len += 2;
2210  else len++;
2211  };
2212  if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
2213  ret[i++] = drive;
2214  ret[i++] = ':';
2215  ret[i++] = '\\';
2216  ret[i++] = '\\';
2217  for (p = path; *p; p++)
2218  {
2219  if (*p != '\\') ret[i++] = *p;
2220  else
2221  {
2222  ret[i++] = '\\';
2223  ret[i++] = '\\';
2224  }
2225  }
2226  ret[i] = 0;
2227  return ret;
2228 }
2229 
2231 {
2232  const WCHAR *p = path, *start;
2233  UINT len, i;
2234  WCHAR *ret;
2235 
2236  if (!iswalpha( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
2237  start = path + 4;
2238  len = lstrlenW( start );
2239  p = start + len - 1;
2240  if (*p == '\\') return NULL;
2241 
2242  while (p >= start && *p != '\\') { len--; p--; };
2243  while (p >= start && *p == '\\') { len--; p--; };
2244 
2245  if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
2246  for (i = 0, p = start; p < start + len; p++)
2247  {
2248  if (p[0] == '\\' && p[1] == '\\')
2249  {
2250  ret[i++] = '\\';
2251  p++;
2252  }
2253  else ret[i++] = *p;
2254  }
2255  ret[i] = 0;
2256  *ret_len = i;
2257  return ret;
2258 }
2259 
2260 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
2261 {
2262  UINT i;
2263  for (i = 0; i < dirstack->num_dirs; i++) if (!wcscmp( dirstack->dirs[i], path )) return TRUE;
2264  return FALSE;
2265 }
2266 
2267 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
2268 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
2269 {
2270  const struct expr *left, *right;
2271 
2272  if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
2273 
2274  left = cond->u.expr.left;
2275  right = cond->u.expr.right;
2276  if (cond->u.expr.op == OP_EQ)
2277  {
2278  UINT len;
2279  WCHAR *path;
2280  const WCHAR *str = NULL;
2281 
2282  if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
2283  !wcscmp( left->u.propval->name, prop_nameW ) &&
2284  towupper( right->u.sval[0] ) == towupper( root ))
2285  {
2286  str = right->u.sval;
2287  }
2288  else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
2289  !wcscmp( right->u.propval->name, prop_nameW ) &&
2290  towupper( left->u.sval[0] ) == towupper( root ))
2291  {
2292  str = left->u.sval;
2293  }
2294  if (str && (path = build_dirname( str, &len )))
2295  {
2296  if (seen_dir( dirstack, path ))
2297  {
2298  heap_free( path );
2299  return ++*count;
2300  }
2301  else if (push_dir( dirstack, path, len )) return ++*count;
2302  heap_free( path );
2303  return *count = 0;
2304  }
2305  }
2306  else if (cond->u.expr.op == OP_OR)
2307  {
2308  UINT left_count = 0, right_count = 0;
2309 
2310  if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
2311  if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
2312  return *count += left_count + right_count;
2313  }
2314  return *count = 0;
2315 }
2316 
2317 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
2318 {
2319  UINT len_path = 0, len_segment = lstrlenW( segment );
2320  WCHAR *ret;
2321 
2322  *len = 0;
2323  if (path) len_path = lstrlenW( path );
2324  if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
2325  if (path && len_path)
2326  {
2327  memcpy( ret, path, len_path * sizeof(WCHAR) );
2328  ret[len_path] = '\\';
2329  *len += len_path + 1;
2330  }
2331  memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
2332  *len += len_segment;
2333  ret[*len] = 0;
2334  return ret;
2335 }
2336 
2338 {
2339  static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
2341  DWORD size, len = 4 * 5 + ARRAY_SIZE( fmtW );
2342  void *block;
2343  WCHAR *ret;
2344 
2345  if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
2346  if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
2347  {
2348  heap_free( ret );
2349  return NULL;
2350  }
2351  if (!GetFileVersionInfoW( filename, 0, size, block ) ||
2352  !VerQueryValueW( block, slashW, (void **)&info, &size ))
2353  {
2354  heap_free( block );
2355  heap_free( ret );
2356  return NULL;
2357  }
2358  swprintf( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
2359  info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
2360  heap_free( block );
2361  return ret;
2362 }
2363 
2364 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
2365 {
2366  static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
2367  struct record_datafile *rec;
2368  UINT i, len, row = 0, offset = 0, num_expected_rows;
2369  WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
2370  DWORD drives = GetLogicalDrives();
2372  HANDLE handle;
2373  struct dirstack *dirstack;
2375 
2376  if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
2377 
2378  dirstack = alloc_dirstack(2);
2379 
2380  for (i = 0; i < 26; i++)
2381  {
2382  if (!(drives & (1 << i))) continue;
2383 
2384  root[0] = 'A' + i;
2385  if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
2386 
2387  num_expected_rows = 0;
2388  if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
2389 
2390  for (;;)
2391  {
2392  heap_free( glob );
2393  heap_free( path );
2394  path = pop_dir( dirstack, &len );
2395  if (!(glob = build_glob( root[0], path, len )))
2396  {
2398  goto done;
2399  }
2401  {
2402  do
2403  {
2404  if (!resize_table( table, row + 1, sizeof(*rec) ))
2405  {
2407  FindClose( handle );
2408  goto done;
2409  }
2410  if (!wcscmp( data.cFileName, dotW ) || !wcscmp( data.cFileName, dotdotW )) continue;
2411  new_path = append_path( path, data.cFileName, &len );
2412 
2413  if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
2414  {
2415  if (push_dir( dirstack, new_path, len )) continue;
2416  heap_free( new_path );
2417  FindClose( handle );
2419  goto done;
2420  }
2421  rec = (struct record_datafile *)(table->data + offset);
2422  rec->name = build_name( root[0], new_path );
2423  rec->version = get_file_version( rec->name );
2424  if (!match_row( table, row, cond, &status ))
2425  {
2427  continue;
2428  }
2429  else if (num_expected_rows && row == num_expected_rows - 1)
2430  {
2431  row++;
2432  FindClose( handle );
2434  goto done;
2435  }
2436  offset += sizeof(*rec);
2437  row++;
2438  }
2439  while (FindNextFileW( handle, &data ));
2440  FindClose( handle );
2441  }
2442  if (!peek_dir( dirstack )) break;
2443  }
2444  }
2445 
2446 done:
2448  heap_free( glob );
2449  heap_free( path );
2450 
2451  TRACE("created %u rows\n", row);
2452  table->num_rows = row;
2453  return status;
2454 }
2455 
2457 {
2458  HDC hdc = GetDC( NULL );
2459  UINT32 ret;
2460 
2461  if (!hdc) return 96;
2463  ReleaseDC( NULL, hdc );
2464  return ret;
2465 }
2466 
2467 static enum fill_status fill_desktopmonitor( struct table *table, const struct expr *cond )
2468 {
2469  struct record_desktopmonitor *rec;
2471  UINT row = 0;
2472 
2473  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2474 
2475  rec = (struct record_desktopmonitor *)table->data;
2477 
2478  if (match_row( table, row, cond, &status )) row++;
2479 
2480  TRACE("created %u rows\n", row);
2481  table->num_rows = row;
2482  return status;
2483 }
2484 
2485 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
2486 {
2487  static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
2488  struct record_directory *rec;
2489  UINT i, len, row = 0, offset = 0, num_expected_rows;
2490  WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
2491  DWORD drives = GetLogicalDrives();
2493  HANDLE handle;
2494  struct dirstack *dirstack;
2496 
2497  if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2498 
2499  dirstack = alloc_dirstack(2);
2500 
2501  for (i = 0; i < 26; i++)
2502  {
2503  if (!(drives & (1 << i))) continue;
2504 
2505  root[0] = 'A' + i;
2506  if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
2507 
2508  num_expected_rows = 0;
2509  if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
2510 
2511  for (;;)
2512  {
2513  heap_free( glob );
2514  heap_free( path );
2515  path = pop_dir( dirstack, &len );
2516  if (!(glob = build_glob( root[0], path, len )))
2517  {
2519  goto done;
2520  }
2522  {
2523  do
2524  {
2525  if (!resize_table( table, row + 1, sizeof(*rec) ))
2526  {
2527  FindClose( handle );
2529  goto done;
2530  }
2531  if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
2532  !wcscmp( data.cFileName, dotW ) || !wcscmp( data.cFileName, dotdotW ))
2533  continue;
2534 
2535  new_path = append_path( path, data.cFileName, &len );
2536  if (!(push_dir( dirstack, new_path, len )))
2537  {
2538  heap_free( new_path );
2539  FindClose( handle );
2541  goto done;
2542  }
2543  rec = (struct record_directory *)(table->data + offset);
2544  rec->accessmask = FILE_ALL_ACCESS;
2545  rec->name = build_name( root[0], new_path );
2546  if (!match_row( table, row, cond, &status ))
2547  {
2549  continue;
2550  }
2551  else if (num_expected_rows && row == num_expected_rows - 1)
2552  {
2553  row++;
2554  FindClose( handle );
2556  goto done;
2557  }
2558  offset += sizeof(*rec);
2559  row++;
2560  }
2561  while (FindNextFileW( handle, &data ));
2562  FindClose( handle );
2563  }
2564  if (!peek_dir( dirstack )) break;
2565  }
2566  }
2567 
2568 done:
2570  heap_free( glob );
2571  heap_free( path );
2572 
2573  TRACE("created %u rows\n", row);
2574  table->num_rows = row;
2575  return status;
2576 }
2577 
2578 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
2579 {
2580  WCHAR root[] = {'\\','\\','.','\\','A',':',0};
2583  HANDLE handle;
2584  DWORD bytes_returned;
2585 
2586  free.QuadPart = 512 * 1024 * 1024;
2588 
2589  root[4] = dir[0];
2592  {
2593  if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), &bytes_returned, NULL ))
2594  *disksize = info.DiskSize.QuadPart;
2595  CloseHandle( handle );
2596  }
2597  return free.QuadPart;
2598 }
2599 
2600 static enum fill_status fill_diskdrive( struct table *table, const struct expr *cond )
2601 {
2602  static const WCHAR fmtW[] =
2603  {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','%','u',0};
2604  WCHAR device_id[ARRAY_SIZE( fmtW ) + 10], root[] = {'A',':','\\',0};
2605  struct record_diskdrive *rec;
2606  UINT i, row = 0, offset = 0, index = 0, type;
2607  UINT64 size = 1024 * 1024 * 1024;
2608  DWORD drives = GetLogicalDrives();
2610 
2611  if (!resize_table( table, 2, sizeof(*rec) )) return FILL_STATUS_FAILED;
2612 
2613  for (i = 0; i < 26; i++)
2614  {
2615  if (drives & (1 << i))
2616  {
2617  root[0] = 'A' + i;
2618  type = GetDriveTypeW( root );
2619  if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
2620  continue;
2621 
2622  if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2623 
2624  rec = (struct record_diskdrive *)(table->data + offset);
2625  swprintf( device_id, fmtW, index );
2626  rec->device_id = heap_strdupW( device_id );
2627  rec->index = index++;
2631  rec->model = diskdrive_modelW;
2634  get_freespace( root, &size );
2635  rec->size = size;
2636  if (!match_row( table, row, cond, &status ))
2637  {
2639  continue;
2640  }
2641  offset += sizeof(*rec);
2642  row++;
2643  }
2644  }
2645  TRACE("created %u rows\n", row);
2646  table->num_rows = row;
2647  return status;
2648 }
2649 
2651 {
2654 };
2655 
2656 static void free_assocations( struct association *assoc, UINT count )
2657 {
2658  UINT i;
2659  if (!assoc) return;
2660  for (i = 0; i < count; i++)
2661  {
2662  heap_free( assoc[i].ref );
2663  heap_free( assoc[i].ref2 );
2664  }
2665  heap_free( assoc );
2666 }
2667 
2669 {
2670  static const WCHAR pathW[] =
2671  {'_','_','P','A','T','H',0};
2672  static const WCHAR selectW[] =
2673  {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
2674  'D','i','s','k','D','r','i','v','e',0};
2675  static const WCHAR select2W[] =
2676  {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
2677  'D','i','s','k','P','a','r','t','i','t','i','o','n',0};
2678  struct association *ret = NULL;
2679  struct query *query, *query2 = NULL;
2680  VARIANT val;
2681  HRESULT hr;
2682  UINT i;
2683 
2684  if (!(query = create_query())) return NULL;
2685  if ((hr = parse_query( selectW, &query->view, &query->mem )) != S_OK) goto done;
2686  if ((hr = execute_view( query->view )) != S_OK) goto done;
2687 
2688  if (!(query2 = create_query())) return FALSE;
2689  if ((hr = parse_query( select2W, &query2->view, &query2->mem )) != S_OK) goto done;
2690  if ((hr = execute_view( query2->view )) != S_OK) goto done;
2691 
2692  if (!(ret = heap_alloc_zero( query->view->result_count * sizeof(*ret) ))) goto done;
2693 
2694  for (i = 0; i < query->view->result_count; i++)
2695  {
2696  if ((hr = get_propval( query->view, i, pathW, &val, NULL, NULL )) != S_OK) goto done;
2697  if (!(ret[i].ref = heap_strdupW( V_BSTR(&val) ))) goto done;
2698  VariantClear( &val );
2699 
2700  if ((hr = get_propval( query2->view, i, pathW, &val, NULL, NULL )) != S_OK) goto done;
2701  if (!(ret[i].ref2 = heap_strdupW( V_BSTR(&val) ))) goto done;
2702  VariantClear( &val );
2703  }
2704 
2705  *count = query->view->result_count;
2706 
2707 done:
2708  if (!ret) free_assocations( ret, query->view->result_count );
2709  free_query( query );
2710  free_query( query2 );
2711  return ret;
2712 }
2713 
2714 static enum fill_status fill_diskdrivetodiskpartition( struct table *table, const struct expr *cond )
2715 {
2716  struct record_diskdrivetodiskpartition *rec;
2717  UINT i, row = 0, offset = 0, count = 0;
2719  struct association *assoc;
2720 
2721  if (!(assoc = get_diskdrivetodiskpartition_pairs( &count ))) return FILL_STATUS_FAILED;
2722  if (!count)
2723  {
2724  free_assocations( assoc, count );
2725  return FILL_STATUS_UNFILTERED;
2726  }
2727  if (!resize_table( table, count, sizeof(*rec) ))
2728  {
2729  free_assocations( assoc, count );
2730  return FILL_STATUS_FAILED;
2731  }
2732 
2733  for (i = 0; i < count; i++)
2734  {
2735  rec = (struct record_diskdrivetodiskpartition *)(table->data + offset);
2736  rec->antecedent = assoc[i].ref;
2737  rec->dependent = assoc[i].ref2;
2738  if (!match_row( table, row, cond, &status ))
2739  {
2741  continue;
2742  }
2743  offset += sizeof(*rec);
2744  row++;
2745  }
2746 
2747  heap_free( assoc );
2748 
2749  TRACE("created %u rows\n", row);
2750  table->num_rows = row;
2751  return status;
2752 }
2753 
2754 static WCHAR *get_filesystem( const WCHAR *root )
2755 {
2756  static const WCHAR ntfsW[] = {'N','T','F','S',0};
2757  WCHAR buffer[MAX_PATH + 1];
2758 
2760  return heap_strdupW( buffer );
2761  return heap_strdupW( ntfsW );
2762 }
2763 
2764 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
2765 {
2766  static const WCHAR fmtW[] =
2767  {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
2768  WCHAR device_id[32], root[] = {'A',':','\\',0};
2769  struct record_diskpartition *rec;
2770  UINT i, row = 0, offset = 0, type, index = 0;
2771  UINT64 size = 1024 * 1024 * 1024;
2772  DWORD drives = GetLogicalDrives();
2774 
2775  if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2776 
2777  for (i = 0; i < 26; i++)
2778  {
2779  if (drives & (1 << i))
2780  {
2781  root[0] = 'A' + i;
2782  type = GetDriveTypeW( root );
2783  if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
2784  continue;
2785 
2786  if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2787 
2788  rec = (struct record_diskpartition *)(table->data + offset);
2789  rec->bootable = (i == 2) ? -1 : 0;
2790  rec->bootpartition = (i == 2) ? -1 : 0;
2791  swprintf( device_id, fmtW, index );
2792  rec->device_id = heap_strdupW( device_id );
2793  rec->diskindex = index++;
2794  rec->index = 0;
2796  get_freespace( root, &size );
2797  rec->size = size;
2798  rec->startingoffset = 0;
2799  rec->type = get_filesystem( root );
2800  if (!match_row( table, row, cond, &status ))
2801  {
2803  continue;
2804  }
2805  offset += sizeof(*rec);
2806  row++;
2807  }
2808  }
2809  TRACE("created %u rows\n", row);
2810  table->num_rows = row;
2811  return status;
2812 }
2813 
2815 {
2816  HDC hdc = GetDC( NULL );
2817  UINT32 ret;
2818 
2819  if (!hdc) return 32;
2821  *hres = GetDeviceCaps( hdc, HORZRES );
2822  *vres = GetDeviceCaps( hdc, VERTRES );
2823  ReleaseDC( NULL, hdc );
2824  return ret;
2825 }
2826 
2827 static enum fill_status fill_displaycontrollerconfig( struct table *table, const struct expr *cond )
2828 {
2829  struct record_displaycontrollerconfig *rec;
2830  UINT row = 0, hres = 1024, vres = 768;
2832 
2833  if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2834 
2835  rec = (struct record_displaycontrollerconfig *)table->data;
2836  rec->bitsperpixel = get_bitsperpixel( &hres, &vres );
2838  rec->horizontalresolution = hres;
2840  rec->verticalresolution = vres;
2841  if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2842  else row++;
2843 
2844  TRACE("created %u rows\n", row);
2845  table->num_rows = row;
2846  return status;
2847 }
2848 
2850 {
2851  static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
2852  DWORD len = sizeof("ddd.ddd.ddd.ddd");
2853  WCHAR *ret;
2854 
2855  if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
2856  swprintf( ret, fmtW, (addr >> 24) & 0xff, (addr >> 16) & 0xff, (addr >> 8) & 0xff, addr & 0xff );
2857  return ret;
2858 }
2859 
2860 static enum fill_status fill_ip4routetable( struct table *table, const struct expr *cond )
2861 {
2862  struct record_ip4routetable *rec;
2863  UINT i, row = 0, offset = 0, size = 0;
2864