xref: /reactos/dll/win32/wbemprox/builtin.c (revision e32507b5)
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 
60 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
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};
82 static const WCHAR class_diskdrivetodiskpartitionW[] =
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};
86 static const WCHAR class_displaycontrollerconfigW[] =
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};
95 static const WCHAR class_logicaldisktopartitionW[] =
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};
99 static const WCHAR class_networkadapterconfigW[] =
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};
102 static const WCHAR class_operatingsystemW[] =
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};
114 static const WCHAR class_process_getowner_outW[] =
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};
123 static const WCHAR class_quickfixengineeringW[] =
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};
129 static const WCHAR class_systemenclosureW[] =
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__
132 static const WCHAR class_videocontrollerW[] =
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
172 static const WCHAR prop_binaryrepresentationW[] =
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};
196 static const WCHAR prop_configmanagererrorcodeW[] =
197     {'C','o','n','f','i','g','M','a','n','a','g','e','r','E','r','r','o','r','C','o','d','e',0};
198 static const WCHAR prop_configuredclockspeedW[] =
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__
211 static const WCHAR prop_currentbitsperpixelW[] =
212     {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
213 #endif
214 static const WCHAR prop_currentclockspeedW[] =
215     {'C','u','r','r','e','n','t','C','l','o','c','k','S','p','e','e','d',0};
216 static const WCHAR prop_currenthorizontalresW[] =
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};
220 static const WCHAR prop_currentrefreshrateW[] =
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};
226 static const WCHAR prop_currentverticalresW[] =
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};
232 static const WCHAR prop_defaultipgatewayW[] =
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};
258 static const WCHAR prop_dnsserversearchorderW[] =
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};
284 static const WCHAR prop_freephysicalmemoryW[] =
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};
290 static const WCHAR prop_horizontalresolutionW[] =
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};
296 static const WCHAR prop_identificationcodeW[] =
297     {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
298 static const WCHAR prop_identifyingnumberW[] =
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};
304 static const WCHAR prop_installeddisplaydriversW[]=
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};
314 static const WCHAR prop_ipconnectionmetricW[] =
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};
352 static const WCHAR prop_netconnectionstatusW[] =
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};
360 static const WCHAR prop_numlogicalprocessorsW[] =
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};
364 static const WCHAR prop_operatingsystemskuW[] =
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};
380 static const WCHAR prop_pixelsperxlogicalinchW[] =
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};
400 static const WCHAR prop_referenceddomainnameW[] =
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};
408 static const WCHAR prop_servicepackmajorW[] =
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};
410 static const WCHAR prop_servicepackminorW[] =
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};
418 static const WCHAR prop_smbiosbiosversionW[] =
419     {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
420 static const WCHAR prop_smbiosmajorversionW[] =
421     {'S','M','B','I','O','S','M','a','j','o','r','V','e','r','s','i','o','n',0};
422 static const WCHAR prop_smbiosminorversionW[] =
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};
458 static const WCHAR prop_totalphysicalmemoryW[] =
459     {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
460 static const WCHAR prop_totalvirtualmemorysizeW[] =
461     {'T','o','t','a','l','V','i','r','t','u','a','l','M','e','m','o','r','y','S','i','z','e',0};
462 static const WCHAR prop_totalvisiblememorysizeW[] =
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};
476 static const WCHAR prop_verticalresolutionW[] =
477     {'V','e','r','t','i','c','a','l','R','e','s','o','l','u','t','i','o','n',0};
478 #ifndef __REACTOS__
479 static const WCHAR prop_videoarchitectureW[] =
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};
483 static const WCHAR prop_videomodedescriptionW[] =
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};
490 static const WCHAR prop_volumeserialnumberW[] =
491     {'V','o','l','u','m','e','S','e','r','i','a','l','N','u','m','b','e','r',0};
492 static const WCHAR prop_winsatassessmentstateW[] =
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 {
502     { prop_assocclassW, CIM_STRING },
503     { prop_classW,      CIM_STRING },
504     { prop_associatorW, CIM_STRING }
505 };
506 static const struct column col_baseboard[] =
507 {
508     { prop_manufacturerW,  CIM_STRING|COL_FLAG_DYNAMIC },
509     { prop_modelW,         CIM_STRING },
510     { prop_nameW,          CIM_STRING },
511     { prop_productW,       CIM_STRING|COL_FLAG_DYNAMIC },
512     { prop_serialnumberW,  CIM_STRING|COL_FLAG_DYNAMIC },
513     { prop_tagW,           CIM_STRING|COL_FLAG_KEY },
514     { prop_versionW,       CIM_STRING|COL_FLAG_DYNAMIC }
515 };
516 static const struct column col_bios[] =
517 {
518     { prop_currentlanguageW,    CIM_STRING },
519     { prop_descriptionW,        CIM_STRING },
520     { prop_identificationcodeW, CIM_STRING },
521     { prop_manufacturerW,       CIM_STRING|COL_FLAG_DYNAMIC },
522     { prop_nameW,               CIM_STRING },
523     { prop_releasedateW,        CIM_DATETIME|COL_FLAG_DYNAMIC },
524     { prop_serialnumberW,       CIM_STRING },
525     { prop_smbiosbiosversionW,  CIM_STRING|COL_FLAG_DYNAMIC },
526     { prop_smbiosmajorversionW, CIM_UINT16 },
527     { prop_smbiosminorversionW, CIM_UINT16 },
528     { prop_versionW,            CIM_STRING|COL_FLAG_KEY }
529 };
530 static const struct column col_cdromdrive[] =
531 {
532     { prop_deviceidW,    CIM_STRING|COL_FLAG_KEY },
533     { prop_driveW,       CIM_STRING|COL_FLAG_DYNAMIC },
534     { prop_mediatypeW,   CIM_STRING },
535     { prop_nameW,        CIM_STRING },
536     { prop_pnpdeviceidW, CIM_STRING }
537 };
538 static const struct column col_compsys[] =
539 {
540     { prop_descriptionW,          CIM_STRING },
541     { prop_domainW,               CIM_STRING },
542     { prop_domainroleW,           CIM_UINT16 },
543     { prop_manufacturerW,         CIM_STRING },
544     { prop_modelW,                CIM_STRING },
545     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
546     { prop_numlogicalprocessorsW, CIM_UINT32 },
547     { prop_numprocessorsW,        CIM_UINT32 },
548     { prop_totalphysicalmemoryW,  CIM_UINT64 },
549     { prop_usernameW,             CIM_STRING|COL_FLAG_DYNAMIC }
550 };
551 static const struct column col_compsysproduct[] =
552 {
553     { prop_identifyingnumberW,  CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
554     { prop_nameW,               CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
555     { prop_skunumberW,          CIM_STRING },
556     { prop_uuidW,               CIM_STRING|COL_FLAG_DYNAMIC },
557     { prop_vendorW,             CIM_STRING|COL_FLAG_DYNAMIC },
558     { prop_versionW,            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
559 };
560 static const struct column col_datafile[] =
561 {
562     { prop_nameW,    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
563     { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
564 };
565 static const struct column col_desktopmonitor[] =
566 {
567     { prop_pixelsperxlogicalinchW, CIM_UINT32 }
568 };
569 static const struct column col_directory[] =
570 {
571     { prop_accessmaskW, CIM_UINT32 },
572     { prop_nameW,       CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
573 };
574 static const struct column col_diskdrive[] =
575 {
576     { prop_deviceidW,      CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
577     { prop_indexW,         CIM_UINT32 },
578     { prop_interfacetypeW, CIM_STRING },
579     { prop_manufacturerW,  CIM_STRING },
580     { prop_mediatypeW,     CIM_STRING },
581     { prop_modelW,         CIM_STRING },
582     { prop_pnpdeviceidW,   CIM_STRING },
583     { prop_serialnumberW,  CIM_STRING },
584     { prop_sizeW,          CIM_UINT64 }
585 };
586 static const struct column col_diskdrivetodiskpartition[] =
587 {
588     { prop_antecedentW, CIM_REFERENCE|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
589     { prop_dependentW,  CIM_REFERENCE|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
590 };
591 static const struct column col_diskpartition[] =
592 {
593     { prop_bootableW,       CIM_BOOLEAN },
594     { prop_bootpartitionW,  CIM_BOOLEAN },
595     { prop_deviceidW,       CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
596     { prop_diskindexW,      CIM_UINT32 },
597     { prop_indexW,          CIM_UINT32 },
598     { prop_pnpdeviceidW,    CIM_STRING|COL_FLAG_DYNAMIC },
599     { prop_sizeW,           CIM_UINT64 },
600     { prop_startingoffsetW, CIM_UINT64 },
601     { prop_typeW,           CIM_STRING|COL_FLAG_DYNAMIC }
602 };
603 static const struct column col_displaycontrollerconfig[] =
604 {
605     { prop_bitsperpixelW,         CIM_UINT32 },
606     { prop_captionW,              CIM_STRING },
607     { prop_horizontalresolutionW, CIM_UINT32 },
608     { prop_nameW,                 CIM_STRING|COL_FLAG_KEY },
609     { prop_verticalresolutionW,   CIM_UINT32 }
610 };
611 static const struct column col_ip4routetable[] =
612 {
613     { prop_destinationW,    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
614     { prop_interfaceindexW, CIM_SINT32|COL_FLAG_KEY },
615     { prop_nexthopW,        CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
616 };
617 static const struct column col_logicaldisk[] =
618 {
619     { prop_deviceidW,           CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
620     { prop_drivetypeW,          CIM_UINT32 },
621     { prop_filesystemW,         CIM_STRING|COL_FLAG_DYNAMIC },
622     { prop_freespaceW,          CIM_UINT64 },
623     { prop_nameW,               CIM_STRING|COL_FLAG_DYNAMIC },
624     { prop_sizeW,               CIM_UINT64 },
625     { prop_volumenameW,         CIM_STRING|COL_FLAG_DYNAMIC },
626     { prop_volumeserialnumberW, CIM_STRING|COL_FLAG_DYNAMIC }
627 };
628 static const struct column col_logicaldisktopartition[] =
629 {
630     { prop_antecedentW, CIM_REFERENCE|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
631     { prop_dependentW,  CIM_REFERENCE|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
632 };
633 static const struct column col_networkadapter[] =
634 {
635     { prop_adaptertypeW,         CIM_STRING },
636     { prop_adaptertypeidW,       CIM_UINT16 },
637     { prop_descriptionW,         CIM_STRING|COL_FLAG_DYNAMIC },
638     { prop_deviceidW,            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
639     { prop_indexW,               CIM_UINT32 },
640     { prop_interfaceindexW,      CIM_UINT32 },
641     { prop_macaddressW,          CIM_STRING|COL_FLAG_DYNAMIC },
642     { prop_manufacturerW,        CIM_STRING },
643     { prop_nameW,                CIM_STRING|COL_FLAG_DYNAMIC },
644     { prop_netconnectionstatusW, CIM_UINT16 },
645     { prop_physicaladapterW,     CIM_BOOLEAN },
646     { prop_pnpdeviceidW,         CIM_STRING },
647     { prop_speedW,               CIM_UINT64 }
648 };
649 static const struct column col_networkadapterconfig[] =
650 {
651     { prop_defaultipgatewayW,     CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
652     { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
653     { prop_dhcpenabledW,          CIM_BOOLEAN },
654     { prop_dnshostnameW,          CIM_STRING|COL_FLAG_DYNAMIC },
655     { prop_dnsserversearchorderW, CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
656     { prop_indexW,                CIM_UINT32|COL_FLAG_KEY },
657     { prop_ipaddressW,            CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
658     { prop_ipconnectionmetricW,   CIM_UINT32 },
659     { prop_ipenabledW,            CIM_BOOLEAN },
660     { prop_ipsubnet,              CIM_STRING|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
661     { prop_macaddressW,           CIM_STRING|COL_FLAG_DYNAMIC },
662     { prop_settingidW,            CIM_STRING|COL_FLAG_DYNAMIC }
663 };
664 static const struct column col_operatingsystem[] =
665 {
666     { prop_buildnumberW,            CIM_STRING|COL_FLAG_DYNAMIC },
667     { prop_captionW,                CIM_STRING|COL_FLAG_DYNAMIC },
668     { prop_codesetW,                CIM_STRING|COL_FLAG_DYNAMIC },
669     { prop_countrycodeW,            CIM_STRING|COL_FLAG_DYNAMIC },
670     { prop_csdversionW,             CIM_STRING|COL_FLAG_DYNAMIC },
671     { prop_csnameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
672     { prop_currenttimezoneW,        CIM_SINT16 },
673     { prop_freephysicalmemoryW,     CIM_UINT64 },
674     { prop_installdateW,            CIM_DATETIME },
675     { prop_lastbootuptimeW,         CIM_DATETIME|COL_FLAG_DYNAMIC },
676     { prop_localdatetimeW,          CIM_DATETIME|COL_FLAG_DYNAMIC },
677     { prop_localeW,                 CIM_STRING|COL_FLAG_DYNAMIC },
678     { prop_manufacturerW,           CIM_STRING },
679     { prop_nameW,                   CIM_STRING|COL_FLAG_DYNAMIC },
680     { prop_operatingsystemskuW,     CIM_UINT32 },
681     { prop_osarchitectureW,         CIM_STRING },
682     { prop_oslanguageW,             CIM_UINT32 },
683     { prop_osproductsuiteW,         CIM_UINT32 },
684     { prop_ostypeW,                 CIM_UINT16 },
685     { prop_primaryW,                CIM_BOOLEAN },
686     { prop_serialnumberW,           CIM_STRING },
687     { prop_servicepackmajorW,       CIM_UINT16 },
688     { prop_servicepackminorW,       CIM_UINT16 },
689     { prop_suitemaskW,              CIM_UINT32 },
690     { prop_systemdirectoryW,        CIM_STRING|COL_FLAG_DYNAMIC },
691     { prop_systemdriveW,            CIM_STRING|COL_FLAG_DYNAMIC },
692     { prop_totalvirtualmemorysizeW, CIM_UINT64 },
693     { prop_totalvisiblememorysizeW, CIM_UINT64 },
694     { prop_versionW,                CIM_STRING|COL_FLAG_DYNAMIC }
695 };
696 static const struct column col_param[] =
697 {
698     { prop_classW,        CIM_STRING },
699     { prop_methodW,       CIM_STRING },
700     { prop_directionW,    CIM_SINT32 },
701     { prop_parameterW,    CIM_STRING },
702     { prop_typeW,         CIM_UINT32 },
703     { prop_defaultvalueW, CIM_UINT32 }
704 };
705 static const struct column col_physicalmedia[] =
706 {
707     { prop_serialnumberW,       CIM_STRING },
708     { prop_tagW,                CIM_STRING }
709 };
710 static const struct column col_physicalmemory[] =
711 {
712     { prop_capacityW,             CIM_UINT64 },
713     { prop_configuredclockspeedW, CIM_UINT32 },
714     { prop_devicelocatorW,        CIM_STRING },
715     { prop_memorytypeW,           CIM_UINT16 },
716     { prop_partnumberW,           CIM_STRING }
717 };
718 static const struct column col_pnpentity[] =
719 {
720     { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
721 };
722 static const struct column col_printer[] =
723 {
724     { prop_attributesW,           CIM_UINT32 },
725     { prop_deviceidW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
726     { prop_drivernameW,           CIM_STRING|COL_FLAG_DYNAMIC },
727     { prop_horizontalresolutionW, CIM_UINT32 },
728     { prop_localW,                CIM_BOOLEAN },
729     { prop_locationW,             CIM_STRING|COL_FLAG_DYNAMIC },
730     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
731     { prop_networkW,              CIM_BOOLEAN },
732     { prop_portnameW,             CIM_STRING|COL_FLAG_DYNAMIC },
733 };
734 static const struct column col_process[] =
735 {
736     { prop_captionW,        CIM_STRING|COL_FLAG_DYNAMIC },
737     { prop_commandlineW,    CIM_STRING|COL_FLAG_DYNAMIC },
738     { prop_descriptionW,    CIM_STRING|COL_FLAG_DYNAMIC },
739     { prop_handleW,         CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
740     { prop_nameW,           CIM_STRING|COL_FLAG_DYNAMIC },
741     { prop_pprocessidW,     CIM_UINT32 },
742     { prop_processidW,      CIM_UINT32 },
743     { prop_threadcountW,    CIM_UINT32 },
744     { prop_workingsetsizeW, CIM_UINT64 },
745     /* methods */
746     { method_getownerW,     CIM_FLAG_ARRAY|COL_FLAG_METHOD }
747 };
748 static const struct column col_processor[] =
749 {
750     { prop_addresswidthW,         CIM_UINT16 },
751     { prop_architectureW,         CIM_UINT16 },
752     { prop_captionW,              CIM_STRING|COL_FLAG_DYNAMIC },
753     { prop_cpustatusW,            CIM_UINT16 },
754     { prop_currentclockspeedW,    CIM_UINT32 },
755     { prop_datawidthW,            CIM_UINT16 },
756     { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
757     { prop_deviceidW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
758     { prop_familyW,               CIM_UINT16 },
759     { prop_levelW,                CIM_UINT16 },
760     { prop_manufacturerW,         CIM_STRING|COL_FLAG_DYNAMIC },
761     { prop_maxclockspeedW,        CIM_UINT32 },
762     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
763     { prop_numcoresW,             CIM_UINT32 },
764     { prop_numlogicalprocessorsW, CIM_UINT32 },
765     { prop_processoridW,          CIM_STRING|COL_FLAG_DYNAMIC },
766     { prop_processortypeW,        CIM_UINT16 },
767     { prop_revisionW,             CIM_UINT16 },
768     { prop_uniqueidW,             CIM_STRING },
769     { prop_versionW,              CIM_STRING|COL_FLAG_DYNAMIC }
770 };
771 static const struct column col_qualifier[] =
772 {
773     { prop_classW,     CIM_STRING },
774     { prop_memberW,    CIM_STRING },
775     { prop_typeW,      CIM_UINT32 },
776     { prop_flavorW,    CIM_SINT32 },
777     { prop_nameW,      CIM_STRING },
778     { prop_intvalueW,  CIM_SINT32 },
779     { prop_strvalueW,  CIM_STRING },
780     { prop_boolvalueW, CIM_BOOLEAN }
781 };
782 static const struct column col_quickfixengineering[] =
783 {
784     { prop_captionW,  CIM_STRING },
785     { prop_hotfixidW, CIM_STRING|COL_FLAG_KEY }
786 };
787 static const struct column col_service[] =
788 {
789     { prop_acceptpauseW,      CIM_BOOLEAN },
790     { prop_acceptstopW,       CIM_BOOLEAN },
791     { prop_displaynameW,      CIM_STRING|COL_FLAG_DYNAMIC },
792     { prop_nameW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
793     { prop_processidW,        CIM_UINT32 },
794     { prop_servicetypeW,      CIM_STRING },
795     { prop_startmodeW,        CIM_STRING },
796     { prop_stateW,            CIM_STRING },
797     { prop_systemnameW,       CIM_STRING|COL_FLAG_DYNAMIC },
798     /* methods */
799     { method_pauseserviceW,   CIM_FLAG_ARRAY|COL_FLAG_METHOD },
800     { method_resumeserviceW,  CIM_FLAG_ARRAY|COL_FLAG_METHOD },
801     { method_startserviceW,   CIM_FLAG_ARRAY|COL_FLAG_METHOD },
802     { method_stopserviceW,    CIM_FLAG_ARRAY|COL_FLAG_METHOD }
803 };
804 static const struct column col_sid[] =
805 {
806     { prop_accountnameW,            CIM_STRING|COL_FLAG_DYNAMIC },
807     { prop_binaryrepresentationW,   CIM_UINT8|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
808     { prop_referenceddomainnameW,   CIM_STRING|COL_FLAG_DYNAMIC },
809     { prop_sidW,                    CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
810     { prop_sidlengthW,              CIM_UINT32 }
811 };
812 static const struct column col_sounddevice[] =
813 {
814     { prop_nameW,        CIM_STRING },
815     { prop_productnameW, CIM_STRING },
816     { prop_statusinfoW,  CIM_UINT16 }
817 };
818 static const struct column col_stdregprov[] =
819 {
820     { method_createkeyW,      CIM_FLAG_ARRAY|COL_FLAG_METHOD },
821     { method_enumkeyW,        CIM_FLAG_ARRAY|COL_FLAG_METHOD },
822     { method_enumvaluesW,     CIM_FLAG_ARRAY|COL_FLAG_METHOD },
823     { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
824 };
825 static const struct column col_systemenclosure[] =
826 {
827     { prop_captionW,      CIM_STRING },
828     { prop_chassistypesW, CIM_UINT16|CIM_FLAG_ARRAY|COL_FLAG_DYNAMIC },
829     { prop_descriptionW,  CIM_STRING },
830     { prop_lockpresentW,  CIM_BOOLEAN },
831     { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
832     { prop_nameW,         CIM_STRING },
833     { prop_tagW,          CIM_STRING },
834 };
835 static const struct column col_systemsecurity[] =
836 {
837     { method_getsdW,                    CIM_FLAG_ARRAY|COL_FLAG_METHOD },
838     { method_setsdW,                    CIM_FLAG_ARRAY|COL_FLAG_METHOD },
839 };
840 
841 #ifndef __REACTOS__
842 static const struct column col_videocontroller[] =
843 {
844     { prop_adapterdactypeW,         CIM_STRING },
845     { prop_adapterramW,             CIM_UINT32 },
846     { prop_availabilityW,           CIM_UINT16 },
847     { prop_captionW,                CIM_STRING|COL_FLAG_DYNAMIC },
848     { prop_configmanagererrorcodeW, CIM_UINT32 },
849     { prop_currentbitsperpixelW,    CIM_UINT32 },
850     { prop_currenthorizontalresW,   CIM_UINT32 },
851     { prop_currentrefreshrateW,     CIM_UINT32 },
852     { prop_currentscanmodeW,        CIM_UINT16 },
853     { prop_currentverticalresW,     CIM_UINT32 },
854     { prop_descriptionW,            CIM_STRING|COL_FLAG_DYNAMIC },
855     { prop_deviceidW,               CIM_STRING|COL_FLAG_KEY },
856     { prop_driverdateW,             CIM_DATETIME },
857     { prop_driverversionW,          CIM_STRING },
858     { prop_installeddisplaydriversW,CIM_STRING },
859     { prop_nameW,                   CIM_STRING|COL_FLAG_DYNAMIC },
860     { prop_pnpdeviceidW,            CIM_STRING|COL_FLAG_DYNAMIC },
861     { prop_statusW,                 CIM_STRING },
862     { prop_videoarchitectureW,      CIM_UINT16 },
863     { prop_videomemorytypeW,        CIM_UINT16 },
864     { prop_videomodedescriptionW,   CIM_STRING|COL_FLAG_DYNAMIC },
865     { prop_videoprocessorW,         CIM_STRING|COL_FLAG_DYNAMIC },
866 };
867 #endif
868 
869 static const struct column col_winsat[] =
870 {
871     { prop_cpuscoreW,              CIM_REAL32 },
872     { prop_d3dscoreW,              CIM_REAL32 },
873     { prop_diskscoreW,             CIM_REAL32 },
874     { prop_graphicsscoreW,         CIM_REAL32 },
875     { prop_memoryscoreW,           CIM_REAL32 },
876     { prop_timetakenW,             CIM_STRING|COL_FLAG_KEY },
877     { prop_winsatassessmentstateW, CIM_UINT32 },
878     { prop_winsprlevelW,           CIM_REAL32 },
879 };
880 
881 
882 static const WCHAR baseboard_manufacturerW[] =
883     {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
884 static const WCHAR baseboard_serialnumberW[] =
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};
898 static const WCHAR bios_smbiosbiosversionW[] =
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};
906 static const WCHAR cdromdrive_pnpdeviceidW[]=
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};
919 static const WCHAR compsysproduct_identifyingnumberW[] =
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};
926 static const WCHAR compsysproduct_vendorW[] =
927     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
928 static const WCHAR compsysproduct_versionW[] =
929     {'1','.','0',0};
930 static const WCHAR diskdrive_interfacetypeW[] =
931     {'I','D','E',0};
932 static const WCHAR diskdrive_manufacturerW[] =
933     {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
934 static const WCHAR diskdrive_mediatype_fixedW[] =
935     {'F','i','x','e','d',' ','h','a','r','d',' ','d','i','s','k',0};
936 static const WCHAR diskdrive_mediatype_removableW[] =
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};
940 static const WCHAR diskdrive_pnpdeviceidW[] =
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};
944 static const WCHAR networkadapter_pnpdeviceidW[]=
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};
958 static const WCHAR quickfixengineering_captionW[] =
959     {'h','t','t','p',':','/','/','w','i','n','e','h','q','.','o','r','g',0};
960 static const WCHAR quickfixengineering_hotfixidW[] =
961     {'K','B','1','2','3','4','5','6','7',0};
962 static const WCHAR sounddevice_productnameW[] =
963     {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
964 static const WCHAR systemenclosure_systemenclosureW[] =
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};
968 static const WCHAR systemenclosure_manufacturerW[] =
969     {'W','i','n','e',0};
970 static const WCHAR videocontroller_dactypeW[] =
971     {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
972 static const WCHAR videocontroller_deviceidW[] =
973     {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
974 static const WCHAR videocontroller_driverdateW[] =
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};
976 static const WCHAR videocontroller_driverversionW[] =
977     {'1','.','0',0};
978 static const WCHAR videocontroller_statusW[] =
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"
984 struct record_associator
985 {
986     const WCHAR *assocclass;
987     const WCHAR *class;
988     const WCHAR *associator;
989 };
990 struct record_baseboard
991 {
992     const WCHAR *manufacturer;
993     const WCHAR *model;
994     const WCHAR *name;
995     const WCHAR *product;
996     const WCHAR *serialnumber;
997     const WCHAR *tag;
998     const WCHAR *version;
999 };
1000 struct record_bios
1001 {
1002     const WCHAR *currentlanguage;
1003     const WCHAR *description;
1004     const WCHAR *identificationcode;
1005     const WCHAR *manufacturer;
1006     const WCHAR *name;
1007     const WCHAR *releasedate;
1008     const WCHAR *serialnumber;
1009     const WCHAR *smbiosbiosversion;
1010     UINT16       smbiosmajorversion;
1011     UINT16       smbiosminorversion;
1012     const WCHAR *version;
1013 };
1014 struct record_cdromdrive
1015 {
1016     const WCHAR *device_id;
1017     const WCHAR *drive;
1018     const WCHAR *mediatype;
1019     const WCHAR *name;
1020     const WCHAR *pnpdevice_id;
1021 };
1022 struct record_computersystem
1023 {
1024     const WCHAR *description;
1025     const WCHAR *domain;
1026     UINT16       domainrole;
1027     const WCHAR *manufacturer;
1028     const WCHAR *model;
1029     const WCHAR *name;
1030     UINT32       num_logical_processors;
1031     UINT32       num_processors;
1032     UINT64       total_physical_memory;
1033     const WCHAR *username;
1034 };
1035 struct record_computersystemproduct
1036 {
1037     const WCHAR *identifyingnumber;
1038     const WCHAR *name;
1039     const WCHAR *skunumber;
1040     const WCHAR *uuid;
1041     const WCHAR *vendor;
1042     const WCHAR *version;
1043 };
1044 struct record_datafile
1045 {
1046     const WCHAR *name;
1047     const WCHAR *version;
1048 };
1049 struct record_desktopmonitor
1050 {
1051     UINT32       pixelsperxlogicalinch;
1052 };
1053 struct record_directory
1054 {
1055     UINT32       accessmask;
1056     const WCHAR *name;
1057 };
1058 struct record_diskdrive
1059 {
1060     const WCHAR *device_id;
1061     UINT32       index;
1062     const WCHAR *interfacetype;
1063     const WCHAR *manufacturer;
1064     const WCHAR *mediatype;
1065     const WCHAR *model;
1066     const WCHAR *pnpdevice_id;
1067     const WCHAR *serialnumber;
1068     UINT64       size;
1069 };
1070 struct record_diskdrivetodiskpartition
1071 {
1072     const WCHAR *antecedent;
1073     const WCHAR *dependent;
1074 };
1075 struct record_diskpartition
1076 {
1077     int          bootable;
1078     int          bootpartition;
1079     const WCHAR *device_id;
1080     UINT32       diskindex;
1081     UINT32       index;
1082     const WCHAR *pnpdevice_id;
1083     UINT64       size;
1084     UINT64       startingoffset;
1085     const WCHAR *type;
1086 };
1087 struct record_displaycontrollerconfig
1088 {
1089     UINT32       bitsperpixel;
1090     const WCHAR *caption;
1091     UINT32       horizontalresolution;
1092     const WCHAR *name;
1093     UINT32       verticalresolution;
1094 };
1095 struct record_ip4routetable
1096 {
1097     const WCHAR *destination;
1098     INT32        interfaceindex;
1099     const WCHAR *nexthop;
1100 };
1101 struct record_logicaldisk
1102 {
1103     const WCHAR *device_id;
1104     UINT32       drivetype;
1105     const WCHAR *filesystem;
1106     UINT64       freespace;
1107     const WCHAR *name;
1108     UINT64       size;
1109     const WCHAR *volumename;
1110     const WCHAR *volumeserialnumber;
1111 };
1112 struct record_logicaldisktopartition
1113 {
1114     const WCHAR *antecedent;
1115     const WCHAR *dependent;
1116 };
1117 struct record_networkadapter
1118 {
1119     const WCHAR *adaptertype;
1120     UINT16       adaptertypeid;
1121     const WCHAR *description;
1122     const WCHAR *device_id;
1123     UINT32       index;
1124     UINT32       interface_index;
1125     const WCHAR *mac_address;
1126     const WCHAR *manufacturer;
1127     const WCHAR *name;
1128     UINT16       netconnection_status;
1129     int          physicaladapter;
1130     const WCHAR *pnpdevice_id;
1131     UINT64       speed;
1132 };
1133 struct record_networkadapterconfig
1134 {
1135     const struct array *defaultipgateway;
1136     const WCHAR        *description;
1137     int                 dhcpenabled;
1138     const WCHAR        *dnshostname;
1139     const struct array *dnsserversearchorder;
1140     UINT32              index;
1141     const struct array *ipaddress;
1142     UINT32              ipconnectionmetric;
1143     int                 ipenabled;
1144     const struct array *ipsubnet;
1145     const WCHAR        *mac_address;
1146     const WCHAR        *settingid;
1147 };
1148 struct record_operatingsystem
1149 {
1150     const WCHAR *buildnumber;
1151     const WCHAR *caption;
1152     const WCHAR *codeset;
1153     const WCHAR *countrycode;
1154     const WCHAR *csdversion;
1155     const WCHAR *csname;
1156     INT16        currenttimezone;
1157     UINT64       freephysicalmemory;
1158     const WCHAR *installdate;
1159     const WCHAR *lastbootuptime;
1160     const WCHAR *localdatetime;
1161     const WCHAR *locale;
1162     const WCHAR *manufacturer;
1163     const WCHAR *name;
1164     UINT32       operatingsystemsku;
1165     const WCHAR *osarchitecture;
1166     UINT32       oslanguage;
1167     UINT32       osproductsuite;
1168     UINT16       ostype;
1169     int          primary;
1170     const WCHAR *serialnumber;
1171     UINT16       servicepackmajor;
1172     UINT16       servicepackminor;
1173     UINT32       suitemask;
1174     const WCHAR *systemdirectory;
1175     const WCHAR *systemdrive;
1176     UINT64       totalvirtualmemorysize;
1177     UINT64       totalvisiblememorysize;
1178     const WCHAR *version;
1179 };
1180 struct record_param
1181 {
1182     const WCHAR *class;
1183     const WCHAR *method;
1184     INT32        direction;
1185     const WCHAR *parameter;
1186     UINT32       type;
1187     UINT32       defaultvalue;
1188 };
1189 struct record_physicalmedia
1190 {
1191     const WCHAR *serialnumber;
1192     const WCHAR *tag;
1193 };
1194 struct record_physicalmemory
1195 {
1196     UINT64       capacity;
1197     UINT32       configuredclockspeed;
1198     const WCHAR *devicelocator;
1199     UINT16       memorytype;
1200     const WCHAR *partnumber;
1201 };
1202 struct record_pnpentity
1203 {
1204     const WCHAR *device_id;
1205 };
1206 struct record_printer
1207 {
1208     UINT32       attributes;
1209     const WCHAR *device_id;
1210     const WCHAR *drivername;
1211     UINT32       horizontalresolution;
1212     int          local;
1213     const WCHAR *location;
1214     const WCHAR *name;
1215     int          network;
1216     const WCHAR *portname;
1217 };
1218 struct record_process
1219 {
1220     const WCHAR *caption;
1221     const WCHAR *commandline;
1222     const WCHAR *description;
1223     const WCHAR *handle;
1224     const WCHAR *name;
1225     UINT32       pprocess_id;
1226     UINT32       process_id;
1227     UINT32       thread_count;
1228     UINT64       workingsetsize;
1229     /* methods */
1230     class_method *get_owner;
1231 };
1232 struct record_processor
1233 {
1234     UINT16       addresswidth;
1235     UINT16       architecture;
1236     const WCHAR *caption;
1237     UINT16       cpu_status;
1238     UINT32       currentclockspeed;
1239     UINT16       datawidth;
1240     const WCHAR *description;
1241     const WCHAR *device_id;
1242     UINT16       family;
1243     UINT16       level;
1244     const WCHAR *manufacturer;
1245     UINT32       maxclockspeed;
1246     const WCHAR *name;
1247     UINT32       num_cores;
1248     UINT32       num_logical_processors;
1249     const WCHAR *processor_id;
1250     UINT16       processortype;
1251     UINT16       revision;
1252     const WCHAR *unique_id;
1253     const WCHAR *version;
1254 };
1255 struct record_qualifier
1256 {
1257     const WCHAR *class;
1258     const WCHAR *member;
1259     UINT32       type;
1260     INT32        flavor;
1261     const WCHAR *name;
1262     INT32        intvalue;
1263     const WCHAR *strvalue;
1264     int          boolvalue;
1265 };
1266 struct record_quickfixengineering
1267 {
1268     const WCHAR *caption;
1269     const WCHAR *hotfixid;
1270 };
1271 struct record_service
1272 {
1273     int          accept_pause;
1274     int          accept_stop;
1275     const WCHAR *displayname;
1276     const WCHAR *name;
1277     UINT32       process_id;
1278     const WCHAR *servicetype;
1279     const WCHAR *startmode;
1280     const WCHAR *state;
1281     const WCHAR *systemname;
1282     /* methods */
1283     class_method *pause_service;
1284     class_method *resume_service;
1285     class_method *start_service;
1286     class_method *stop_service;
1287 };
1288 struct record_sid
1289 {
1290     const WCHAR *accountname;
1291     const struct array *binaryrepresentation;
1292     const WCHAR *referenceddomainname;
1293     const WCHAR *sid;
1294     UINT32       sidlength;
1295 };
1296 struct record_sounddevice
1297 {
1298     const WCHAR *name;
1299     const WCHAR *productname;
1300     UINT16       statusinfo;
1301 };
1302 struct record_stdregprov
1303 {
1304     class_method *createkey;
1305     class_method *enumkey;
1306     class_method *enumvalues;
1307     class_method *getstringvalue;
1308 };
1309 struct record_systemsecurity
1310 {
1311     class_method *getsd;
1312     class_method *setsd;
1313 };
1314 struct record_systemenclosure
1315 {
1316     const WCHAR        *caption;
1317     const struct array *chassistypes;
1318     const WCHAR        *description;
1319     int                 lockpresent;
1320     const WCHAR        *manufacturer;
1321     const WCHAR        *name;
1322     const WCHAR        *tag;
1323 };
1324 struct record_videocontroller
1325 {
1326     const WCHAR *adapter_dactype;
1327     UINT32       adapter_ram;
1328     UINT16       availability;
1329     const WCHAR *caption;
1330     UINT32       config_errorcode;
1331     UINT32       current_bitsperpixel;
1332     UINT32       current_horizontalres;
1333     UINT32       current_refreshrate;
1334     UINT16       current_scanmode;
1335     UINT32       current_verticalres;
1336     const WCHAR *description;
1337     const WCHAR *device_id;
1338     const WCHAR *driverdate;
1339     const WCHAR *driverversion;
1340     const WCHAR *installeddriver;
1341     const WCHAR *name;
1342     const WCHAR *pnpdevice_id;
1343     const WCHAR *status;
1344     UINT16       videoarchitecture;
1345     UINT16       videomemorytype;
1346     const WCHAR *videomodedescription;
1347     const WCHAR *videoprocessor;
1348 };
1349 struct record_winsat
1350 {
1351     FLOAT        cpuscore;
1352     FLOAT        d3dscore;
1353     FLOAT        diskscrore;
1354     FLOAT        graphicsscore;
1355     FLOAT        memoryscore;
1356     const WCHAR *timetaken;
1357     UINT32       winsatassessmentstate;
1358     FLOAT        winsprlevel;
1359 };
1360 #include "poppack.h"
1361 
1362 static const struct record_associator data_associator[] =
1363 {
1364     { class_diskdrivetodiskpartitionW, class_diskpartitionW, class_diskdriveW },
1365     { class_logicaldisktopartitionW, class_logicaldiskW, class_diskpartitionW },
1366 };
1367 static const struct record_param data_param[] =
1368 {
1369     { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32 },
1370     { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
1371     { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
1372     { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32 },
1373     { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32 },
1374     { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32 },
1375     { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32 },
1376     { class_stdregprovW, method_createkeyW, 1, param_defkeyW, CIM_SINT32, 0x80000002 },
1377     { class_stdregprovW, method_createkeyW, 1, param_subkeynameW, CIM_STRING },
1378     { class_stdregprovW, method_createkeyW, -1, param_returnvalueW, CIM_UINT32 },
1379     { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0x80000002 },
1380     { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
1381     { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32 },
1382     { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1383     { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0x80000002 },
1384     { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
1385     { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32 },
1386     { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
1387     { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
1388     { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0x80000002 },
1389     { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
1390     { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
1391     { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32 },
1392     { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING },
1393     { class_systemsecurityW, method_getsdW, -1, param_returnvalueW, CIM_UINT32 },
1394     { class_systemsecurityW, method_getsdW, -1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1395     { class_systemsecurityW, method_setsdW, 1, param_sdW, CIM_UINT8|CIM_FLAG_ARRAY },
1396     { class_systemsecurityW, method_setsdW, -1, param_returnvalueW, CIM_UINT32 },
1397 };
1398 
1399 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
1400                    WBEM_FLAVOR_ORIGIN_PROPAGATED)
1401 
1402 static const struct record_physicalmedia data_physicalmedia[] =
1403 {
1404     { diskdrive_serialW, physicalmedia_tagW }
1405 };
1406 static const struct record_qualifier data_qualifier[] =
1407 {
1408     { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
1409     { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
1410 };
1411 static const struct record_quickfixengineering data_quickfixengineering[] =
1412 {
1413     { quickfixengineering_captionW, quickfixengineering_hotfixidW },
1414 };
1415 static const struct record_sounddevice data_sounddevice[] =
1416 {
1417     { sounddevice_productnameW, sounddevice_productnameW, 3 /* enabled */ }
1418 };
1419 static const struct record_stdregprov data_stdregprov[] =
1420 {
1421     { reg_create_key, reg_enum_key, reg_enum_values, reg_get_stringvalue }
1422 };
1423 static UINT16 systemenclosure_chassistypes[] =
1424 {
1425     1,
1426 };
1427 static const struct array systemenclosure_chassistypes_array =
1428 {
1429     sizeof(*systemenclosure_chassistypes),
1430     ARRAY_SIZE(systemenclosure_chassistypes),
1431     &systemenclosure_chassistypes
1432 };
1433 static const struct record_systemsecurity data_systemsecurity[] =
1434 {
1435     { security_get_sd, security_set_sd }
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     {
1450         *status = FILL_STATUS_UNFILTERED;
1451         return TRUE;
1452     }
1453     if (eval_cond( table, row, cond, &val, &type ) != S_OK)
1454     {
1455         *status = FILL_STATUS_FAILED;
1456         return FALSE;
1457     }
1458     *status = FILL_STATUS_FILTERED;
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;
1476         table->num_rows_allocated = count;
1477     }
1478     return TRUE;
1479 }
1480 
1481 #include "pshpack1.h"
1482 struct smbios_prologue
1483 {
1484     BYTE  calling_method;
1485     BYTE  major_version;
1486     BYTE  minor_version;
1487     BYTE  revision;
1488     DWORD length;
1489 };
1490 
1491 enum smbios_type
1492 {
1493     SMBIOS_TYPE_BIOS,
1494     SMBIOS_TYPE_SYSTEM,
1495     SMBIOS_TYPE_BASEBOARD,
1496     SMBIOS_TYPE_CHASSIS,
1497 };
1498 
1499 struct smbios_header
1500 {
1501     BYTE type;
1502     BYTE length;
1503     WORD handle;
1504 };
1505 
1506 struct smbios_baseboard
1507 {
1508     struct smbios_header hdr;
1509     BYTE                 vendor;
1510     BYTE                 product;
1511     BYTE                 version;
1512     BYTE                 serial;
1513 };
1514 
1515 struct smbios_bios
1516 {
1517     struct smbios_header hdr;
1518     BYTE                 vendor;
1519     BYTE                 version;
1520     WORD                 start;
1521     BYTE                 date;
1522     BYTE                 size;
1523     UINT64               characteristics;
1524 };
1525 
1526 struct smbios_chassis
1527 {
1528     struct smbios_header hdr;
1529     BYTE                 vendor;
1530     BYTE                 type;
1531     BYTE                 version;
1532     BYTE                 serial;
1533     BYTE                 asset_tag;
1534 };
1535 
1536 struct smbios_system
1537 {
1538     struct smbios_header hdr;
1539     BYTE                 vendor;
1540     BYTE                 product;
1541     BYTE                 version;
1542     BYTE                 serial;
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 
1618 static WCHAR *get_baseboard_manufacturer( const char *buf, UINT len )
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 
1632 static WCHAR *get_baseboard_serialnumber( const char *buf, UINT len )
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;
1649     enum fill_status status = FILL_STATUS_UNFILTERED;
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;
1657     GetSystemFirmwareTable( RSMB, 0, buf, len );
1658 
1659     rec = (struct record_baseboard *)table->data;
1660     rec->manufacturer = get_baseboard_manufacturer( buf, len );
1661     rec->model        = baseboard_tagW;
1662     rec->name         = baseboard_tagW;
1663     rec->product      = get_baseboard_product( buf, len );
1664     rec->serialnumber = get_baseboard_serialnumber( 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 
1677 static UINT16 get_bios_smbiosmajorversion( const char *buf, UINT len )
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 
1684 static UINT16 get_bios_smbiosminorversion( const char *buf, UINT len )
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 
1711 static WCHAR *convert_bios_date( const WCHAR *str )
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 );
1746     if (!date || !(ret = convert_bios_date( date ))) ret = heap_strdupW( bios_releasedateW );
1747     heap_free( date );
1748     return ret;
1749 }
1750 
1751 static WCHAR *get_bios_smbiosbiosversion( const char *buf, UINT len )
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;
1761     enum fill_status status = FILL_STATUS_UNFILTERED;
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;
1769     GetSystemFirmwareTable( RSMB, 0, buf, len );
1770 
1771     rec = (struct record_bios *)table->data;
1772     rec->currentlanguage    = NULL;
1773     rec->description        = bios_descriptionW;
1774     rec->identificationcode = NULL;
1775     rec->manufacturer       = get_bios_manufacturer( buf, len );
1776     rec->name               = bios_descriptionW;
1777     rec->releasedate        = get_bios_releasedate( buf, len );
1778     rec->serialnumber       = bios_serialnumberW;
1779     rec->smbiosbiosversion  = get_bios_smbiosbiosversion( buf, len );
1780     rec->smbiosmajorversion = get_bios_smbiosmajorversion( buf, len );
1781     rec->smbiosminorversion = get_bios_smbiosminorversion( buf, len );
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();
1800     enum fill_status status = FILL_STATUS_UNFILTERED;
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);
1815             rec->device_id    = cdromdrive_pnpdeviceidW;
1816             swprintf( drive, fmtW, 'A' + i );
1817             rec->drive        = heap_strdupW( drive );
1818             rec->mediatype    = cdromdrive_mediatypeW;
1819             rec->name         = cdromdrive_nameW;
1820             rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
1821             if (!match_row( table, row, cond, &status ))
1822             {
1823                 free_row_values( table, row );
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 
1835 static UINT get_processor_count(void)
1836 {
1837     SYSTEM_BASIC_INFORMATION info;
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 {
1846     SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
1847     UINT i, j, count = 0;
1848     NTSTATUS status;
1849     ULONG len;
1850 
1851     if (num_cores) *num_cores = get_processor_count();
1852     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
1853     if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
1854 
1855     if (!(info = heap_alloc( len ))) return get_processor_count();
1856     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
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 {
1880     SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *buf, *entry;
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;
1888     status = NtQuerySystemInformationEx( SystemLogicalProcessorInformationEx, &all, sizeof(all), NULL, 0, &len );
1889     if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
1890 
1891     if (!(buf = heap_alloc( len ))) return get_processor_count();
1892     status = NtQuerySystemInformationEx( SystemLogicalProcessorInformationEx, &all, sizeof(all), buf, len, NULL );
1893     if (status != STATUS_SUCCESS)
1894     {
1895         heap_free( buf );
1896         return get_processor_count();
1897     }
1898 
1899     while (offset < len)
1900     {
1901         entry = (SYSTEM_LOGICAL_PROCESSOR_INFORMATION_EX *)((char *)buf + offset);
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 
1922 static UINT64 get_total_physical_memory(void)
1923 {
1924     MEMORYSTATUSEX status;
1925 
1926     status.dwLength = sizeof(status);
1927     if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1928     return status.ullTotalPhys;
1929 }
1930 
1931 static UINT64 get_available_physical_memory(void)
1932 {
1933     MEMORYSTATUSEX status;
1934 
1935     status.dwLength = sizeof(status);
1936     if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
1937     return status.ullAvailPhys;
1938 }
1939 
1940 static WCHAR *get_computername(void)
1941 {
1942     WCHAR *ret;
1943     DWORD size = MAX_COMPUTERNAME_LENGTH + 1;
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;
1971     enum fill_status status = FILL_STATUS_UNFILTERED;
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;
1977     rec->description            = compsys_descriptionW;
1978     rec->domain                 = compsys_domainW;
1979     rec->domainrole             = 0; /* standalone workstation */
1980     rec->manufacturer           = compsys_manufacturerW;
1981     rec->model                  = compsys_modelW;
1982     rec->name                   = get_computername();
1983 #ifdef __REACTOS__
1984     rec->num_logical_processors = get_logical_processor_count( NULL );
1985     rec->num_processors         = get_processor_count();
1986 #else
1987     rec->num_logical_processors = get_logical_processor_count( NULL, &rec->num_processors );
1988 #endif
1989     rec->total_physical_memory  = get_total_physical_memory();
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 
2012 static WCHAR *get_compsysproduct_identifyingnumber( const char *buf, UINT len )
2013 {
2014     WCHAR *ret = get_compsysproduct_string( 4, buf, len );
2015     if (!ret) return heap_strdupW( compsysproduct_identifyingnumberW );
2016     return ret;
2017 }
2018 
2019 static WCHAR *get_compsysproduct_name( const char *buf, UINT len )
2020 {
2021     WCHAR *ret = get_compsysproduct_string( 2, buf, len );
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:
2047     if (!ret) ret = heap_strdupW( compsysproduct_uuidW );
2048     return ret;
2049 }
2050 
2051 static WCHAR *get_compsysproduct_vendor( const char *buf, UINT len )
2052 {
2053     WCHAR *ret = get_compsysproduct_string( 1, buf, len );
2054     if (!ret) return heap_strdupW( compsysproduct_vendorW );
2055     return ret;
2056 }
2057 
2058 static WCHAR *get_compsysproduct_version( const char *buf, UINT len )
2059 {
2060     WCHAR *ret = get_compsysproduct_string( 3, buf, len );
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;
2068     enum fill_status status = FILL_STATUS_UNFILTERED;
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;
2076     GetSystemFirmwareTable( RSMB, 0, buf, len );
2077 
2078     rec = (struct record_computersystemproduct *)table->data;
2079     rec->identifyingnumber = get_compsysproduct_identifyingnumber( buf, len );
2080     rec->name              = get_compsysproduct_name( buf, len );
2081     rec->skunumber         = NULL;
2082     rec->uuid              = get_compsysproduct_uuid( buf, len );
2083     rec->vendor            = get_compsysproduct_vendor( buf, len );
2084     rec->version           = get_compsysproduct_version( 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 {
2097     WCHAR **dirs;
2098     UINT   *len_dirs;
2099     UINT    num_dirs;
2100     UINT    num_allocated;
2101 };
2102 
2103 static struct dirstack *alloc_dirstack( UINT size )
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;
2120     dirstack->num_allocated = size;
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 {
2133     clear_dirstack( dirstack );
2134     heap_free( dirstack->dirs );
2135     heap_free( dirstack->len_dirs );
2136     heap_free( dirstack );
2137 }
2138 
2139 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
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;
2155         dirstack->num_allocated = size;
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--;
2171     *len = dirstack->len_dirs[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 
2181 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
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 
2230 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
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 
2337 static WCHAR *get_file_version( const WCHAR *filename )
2338 {
2339     static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
2340     VS_FIXEDFILEINFO *info;
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();
2371     WIN32_FIND_DATAW data;
2372     HANDLE handle;
2373     struct dirstack *dirstack;
2374     enum fill_status status = FILL_STATUS_UNFILTERED;
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             {
2397                 status = FILL_STATUS_FAILED;
2398                 goto done;
2399             }
2400             if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
2401             {
2402                 do
2403                 {
2404                     if (!resize_table( table, row + 1, sizeof(*rec) ))
2405                     {
2406                         status = FILL_STATUS_FAILED;
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 );
2418                         status = FILL_STATUS_FAILED;
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                     {
2426                         free_row_values( table, row );
2427                         continue;
2428                     }
2429                     else if (num_expected_rows && row == num_expected_rows - 1)
2430                     {
2431                         row++;
2432                         FindClose( handle );
2433                         status = FILL_STATUS_FILTERED;
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:
2447     free_dirstack( dirstack );
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 
2456 static UINT32 get_pixelsperxlogicalinch(void)
2457 {
2458     HDC hdc = GetDC( NULL );
2459     UINT32 ret;
2460 
2461     if (!hdc) return 96;
2462     ret = GetDeviceCaps( hdc, LOGPIXELSX );
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;
2470     enum fill_status status = FILL_STATUS_UNFILTERED;
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;
2476     rec->pixelsperxlogicalinch = get_pixelsperxlogicalinch();
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();
2492     WIN32_FIND_DATAW data;
2493     HANDLE handle;
2494     struct dirstack *dirstack;
2495     enum fill_status status = FILL_STATUS_UNFILTERED;
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             {
2518                 status = FILL_STATUS_FAILED;
2519                 goto done;
2520             }
2521             if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
2522             {
2523                 do
2524                 {
2525                     if (!resize_table( table, row + 1, sizeof(*rec) ))
2526                     {
2527                         FindClose( handle );
2528                         status = FILL_STATUS_FAILED;
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 );
2540                         status = FILL_STATUS_FAILED;
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                     {
2548                         free_row_values( table, row );
2549                         continue;
2550                     }
2551                     else if (num_expected_rows && row == num_expected_rows - 1)
2552                     {
2553                         row++;
2554                         FindClose( handle );
2555                         status = FILL_STATUS_FILTERED;
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:
2569     free_dirstack( dirstack );
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};
2581     ULARGE_INTEGER free;
2582     DISK_GEOMETRY_EX info;
2583     HANDLE handle;
2584     DWORD bytes_returned;
2585 
2586     free.QuadPart = 512 * 1024 * 1024;
2587     GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
2588 
2589     root[4] = dir[0];
2590     handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
2591     if (handle != INVALID_HANDLE_VALUE)
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();
2609     enum fill_status status = FILL_STATUS_UNFILTERED;
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++;
2628             rec->interfacetype = diskdrive_interfacetypeW;
2629             rec->manufacturer  = diskdrive_manufacturerW;
2630             rec->mediatype     = (type == DRIVE_FIXED) ? diskdrive_mediatype_fixedW : diskdrive_mediatype_removableW;
2631             rec->model         = diskdrive_modelW;
2632             rec->pnpdevice_id  = diskdrive_pnpdeviceidW;
2633             rec->serialnumber  = diskdrive_serialW;
2634             get_freespace( root, &size );
2635             rec->size          = size;
2636             if (!match_row( table, row, cond, &status ))
2637             {
2638                 free_row_values( table, row );
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 
2650 struct association
2651 {
2652     WCHAR *ref;
2653     WCHAR *ref2;
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 
2668 static struct association *get_diskdrivetodiskpartition_pairs( UINT *count )
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;
2718     enum fill_status status = FILL_STATUS_UNFILTERED;
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         {
2740             free_row_values( table, row );
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 
2759     if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
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();
2773     enum fill_status status = FILL_STATUS_UNFILTERED;
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;
2795             rec->pnpdevice_id   = heap_strdupW( device_id );
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             {
2802                 free_row_values( table, row );
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 
2814 static UINT32 get_bitsperpixel( UINT *hres, UINT *vres )
2815 {
2816     HDC hdc = GetDC( NULL );
2817     UINT32 ret;
2818 
2819     if (!hdc) return 32;
2820     ret = GetDeviceCaps( hdc, BITSPIXEL );
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;
2831     enum fill_status status = FILL_STATUS_UNFILTERED;
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 );
2837     rec->caption              = videocontroller_deviceidW;
2838     rec->horizontalresolution = hres;
2839     rec->name                 = videocontroller_deviceidW;
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 
2849 static WCHAR *get_ip4_string( DWORD addr )
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     MIB_IPFORWARDTABLE *forwards;
2865     enum fill_status status = FILL_STATUS_UNFILTERED;
2866 
2867     if (GetIpForwardTable( NULL, &size, TRUE ) != ERROR_INSUFFICIENT_BUFFER) return FILL_STATUS_FAILED;
2868     if (!(forwards = heap_alloc( size ))) return FILL_STATUS_FAILED;
2869     if (GetIpForwardTable( forwards, &size, TRUE ))
2870     {
2871         heap_free( forwards );
2872         return FILL_STATUS_FAILED;
2873     }
2874     if (!resize_table( table, max(forwards->dwNumEntries, 1), sizeof(*rec) ))
2875     {
2876         heap_free( forwards );
2877         return FILL_STATUS_FAILED;
2878     }
2879 
2880     for (i = 0; i < forwards->dwNumEntries; i++)
2881     {
2882         rec = (struct record_ip4routetable *)(table->data + offset);
2883 
2884         rec->destination    = get_ip4_string( ntohl(forwards->table[i].dwForwardDest) );
2885         rec->interfaceindex = forwards->table[i].dwForwardIfIndex;
2886         rec->nexthop        = get_ip4_string( ntohl(forwards->table[i].dwForwardNextHop) );
2887 
2888         if (!match_row( table, row, cond, &status ))
2889         {
2890             free_row_values( table, row );
2891             continue;
2892         }
2893         offset += sizeof(*rec);
2894         row++;
2895     }
2896     TRACE("created %u rows\n", row);
2897     table->num_rows = row;
2898 
2899     heap_free( forwards );
2900     return status;
2901 }
2902 
2903 static WCHAR *get_volumename( const WCHAR *root )
2904 {
2905     WCHAR buf[MAX_PATH + 1] = {0};
2906     GetVolumeInformationW( root, buf, ARRAY_SIZE( buf ), NULL, NULL, NULL, NULL, 0 );
2907     return heap_strdupW( buf );
2908 }
2909 static WCHAR *get_volumeserialnumber( const WCHAR *root )
2910 {
2911     static const WCHAR fmtW[] = {'%','0','8','X',0};
2912     DWORD serial = 0;
2913     WCHAR buffer[9];
2914 
2915     GetVolumeInformationW( root, NULL, 0, &serial, NULL, NULL, NULL, 0 );
2916     swprintf( buffer, fmtW, serial );
2917     return heap_strdupW( buffer );
2918 }
2919 
2920 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
2921 {
2922     static const WCHAR fmtW[] = {'%','c',':',0};
2923     WCHAR device_id[3], root[] = {'A',':','\\',0};
2924     struct record_logicaldisk *rec;
2925     UINT i, row = 0, offset = 0, type;
2926     UINT64 size = 1024 * 1024 * 1024;
2927     DWORD drives = GetLogicalDrives();
2928     enum fill_status status = FILL_STATUS_UNFILTERED;
2929 
2930     if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
2931 
2932     for (i = 0; i < 26; i++)
2933     {
2934         if (drives & (1 << i))
2935         {
2936             root[0] = 'A' + i;
2937             type = GetDriveTypeW( root );
2938             if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
2939                 continue;
2940 
2941             if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2942 
2943             rec = (struct record_logicaldisk *)(table->data + offset);
2944             swprintf( device_id, fmtW, 'A' + i );
2945             rec->device_id          = heap_strdupW( device_id );
2946             rec->drivetype          = type;
2947             rec->filesystem         = get_filesystem( root );
2948             rec->freespace          = get_freespace( root, &size );
2949             rec->name               = heap_strdupW( device_id );
2950             rec->size               = size;
2951             rec->volumename         = get_volumename( root );
2952             rec->volumeserialnumber = get_volumeserialnumber( root );
2953             if (!match_row( table, row, cond, &status ))
2954             {
2955                 free_row_values( table, row );
2956                 continue;
2957             }
2958             offset += sizeof(*rec);
2959             row++;
2960         }
2961     }
2962     TRACE("created %u rows\n", row);
2963     table->num_rows = row;
2964     return status;
2965 }
2966 
2967 static struct association *get_logicaldisktopartition_pairs( UINT *count )
2968 {
2969     static const WCHAR pathW[] =
2970         {'_','_','P','A','T','H',0};
2971     static const WCHAR selectW[] =
2972         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
2973          'D','i','s','k','P','a','r','t','i','t','i','o','n',0};
2974     static const WCHAR select2W[] =
2975         {'S','E','L','E','C','T',' ','*',' ','F','R','O','M',' ','W','i','n','3','2','_',
2976          'L','o','g','i','c','a','l','D','i','s','k',' ','W','H','E','R','E',' ',
2977          'D','r','i','v','e','T','y','p','e','=','2',' ','O','R',' ','D','r','i','v','e','T','y','p','e','=','3',0};
2978     struct association *ret = NULL;
2979     struct query *query, *query2 = NULL;
2980     VARIANT val;
2981     HRESULT hr;
2982     UINT i;
2983 
2984     if (!(query = create_query())) return NULL;
2985     if ((hr = parse_query( selectW, &query->view, &query->mem )) != S_OK) goto done;
2986     if ((hr = execute_view( query->view )) != S_OK) goto done;
2987 
2988     if (!(query2 = create_query())) return FALSE;
2989     if ((hr = parse_query( select2W, &query2->view, &query2->mem )) != S_OK) goto done;
2990     if ((hr = execute_view( query2->view )) != S_OK) goto done;
2991 
2992     if (!(ret = heap_alloc_zero( query->view->result_count * sizeof(*ret) ))) goto done;
2993 
2994     /* assume fixed and removable disks are enumerated in the same order as partitions */
2995     for (i = 0; i < query->view->result_count; i++)
2996     {
2997         if ((hr = get_propval( query->view, i, pathW, &val, NULL, NULL )) != S_OK) goto done;
2998         if (!(ret[i].ref = heap_strdupW( V_BSTR(&val) ))) goto done;
2999         VariantClear( &val );
3000 
3001         if ((hr = get_propval( query2->view, i, pathW, &val, NULL, NULL )) != S_OK) goto done;
3002         if (!(ret[i].ref2 = heap_strdupW( V_BSTR(&val) ))) goto done;
3003         VariantClear( &val );
3004     }
3005 
3006     *count = query->view->result_count;
3007 
3008 done:
3009     if (!ret) free_assocations( ret, query->view->result_count );
3010     free_query( query );
3011     free_query( query2 );
3012     return ret;
3013 }
3014 
3015 static enum fill_status fill_logicaldisktopartition( struct table *table, const struct expr *cond )
3016 {
3017     struct record_logicaldisktopartition *rec;
3018     UINT i, row = 0, offset = 0, count = 0;
3019     enum fill_status status = FILL_STATUS_UNFILTERED;
3020     struct association *assoc;
3021 
3022     if (!(assoc = get_logicaldisktopartition_pairs( &count ))) return FILL_STATUS_FAILED;
3023     if (!count)
3024     {
3025         free_assocations( assoc, count );
3026         return FILL_STATUS_UNFILTERED;
3027     }
3028     if (!resize_table( table, count, sizeof(*rec) ))
3029     {
3030         free_assocations( assoc, count );
3031         return FILL_STATUS_FAILED;
3032     }
3033 
3034     for (i = 0; i < count; i++)
3035     {
3036         rec = (struct record_logicaldisktopartition *)(table->data + offset);
3037         rec->antecedent = assoc[i].ref;
3038         rec->dependent  = assoc[i].ref2;
3039         if (!match_row( table, row, cond, &status ))
3040         {
3041             free_row_values( table, row );
3042             continue;
3043         }
3044         offset += sizeof(*rec);
3045         row++;
3046     }
3047 
3048     heap_free( assoc );
3049 
3050     TRACE("created %u rows\n", row);
3051     table->num_rows = row;
3052     return status;
3053 }
3054 
3055 static UINT16 get_connection_status( IF_OPER_STATUS status )
3056 {
3057     switch (status)
3058     {
3059     case IfOperStatusDown:
3060         return 0; /* Disconnected */
3061     case IfOperStatusUp:
3062         return 2; /* Connected */
3063     default:
3064         ERR("unhandled status %u\n", status);
3065         break;
3066     }
3067     return 0;
3068 }
3069 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
3070 {
3071     static const WCHAR fmtW[] =
3072         {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
3073          '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
3074     WCHAR *ret;
3075 
3076     if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
3077     swprintf( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
3078     return ret;
3079 }
3080 static const WCHAR *get_adaptertype( DWORD type, int *id, int *physical )
3081 {
3082     static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
3083     static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
3084     static const WCHAR firewireW[] = {'1','3','9','4',0};
3085     static const WCHAR tunnelW[]   = {'T','u','n','n','e','l',0};
3086 
3087     switch (type)
3088     {
3089     case IF_TYPE_ETHERNET_CSMACD:
3090         *id = 0;
3091         *physical = -1;
3092         return ethernetW;
3093     case IF_TYPE_IEEE80211:
3094         *id = 9;
3095         *physical = -1;
3096         return wirelessW;
3097     case IF_TYPE_IEEE1394:
3098         *id = 13;
3099         *physical = -1;
3100         return firewireW;
3101     case IF_TYPE_TUNNEL:
3102         *id = 15;
3103         *physical = 0;
3104         return tunnelW;
3105     default:
3106         *id = -1;
3107         *physical = 0;
3108         return NULL;
3109     }
3110 }
3111 
3112 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
3113 {
3114     static const WCHAR fmtW[] = {'%','u',0};
3115     WCHAR device_id[11];
3116     struct record_networkadapter *rec;
3117     IP_ADAPTER_ADDRESSES *aa, *buffer;
3118     UINT row = 0, offset = 0, count = 0;
3119     DWORD size = 0, ret;
3120     int adaptertypeid, physical;
3121     enum fill_status status = FILL_STATUS_UNFILTERED;
3122 
3123     ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
3124     if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
3125 
3126     if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
3127     if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
3128     {
3129         heap_free( buffer );
3130         return FILL_STATUS_FAILED;
3131     }
3132     for (aa = buffer; aa; aa = aa->Next)
3133     {
3134         if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
3135     }
3136     if (!resize_table( table, count, sizeof(*rec) ))
3137     {
3138         heap_free( buffer );
3139         return FILL_STATUS_FAILED;
3140     }
3141     for (aa = buffer; aa; aa = aa->Next)
3142     {
3143         if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
3144 
3145         rec = (struct record_networkadapter *)(table->data + offset);
3146         swprintf( device_id, fmtW, aa->u.s.IfIndex );
3147         rec->adaptertype          = get_adaptertype( aa->IfType, &adaptertypeid, &physical );
3148         rec->adaptertypeid        = adaptertypeid;
3149         rec->description          = heap_strdupW( aa->Description );
3150         rec->device_id            = heap_strdupW( device_id );
3151         rec->index                = aa->u.s.IfIndex;
3152         rec->interface_index      = aa->u.s.IfIndex;
3153         rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
3154         rec->manufacturer         = compsys_manufacturerW;
3155         rec->name                 = heap_strdupW( aa->FriendlyName );
3156         rec->netconnection_status = get_connection_status( aa->OperStatus );
3157         rec->physicaladapter      = physical;
3158         rec->pnpdevice_id         = networkadapter_pnpdeviceidW;
3159         rec->speed                = 1000000;
3160         if (!match_row( table, row, cond, &status ))
3161         {
3162             free_row_values( table, row );
3163             continue;
3164         }
3165         offset += sizeof(*rec);
3166         row++;
3167     }
3168     TRACE("created %u rows\n", row);
3169     table->num_rows = row;
3170 
3171     heap_free( buffer );
3172     return status;
3173 }
3174 
3175 static WCHAR *get_dnshostname( IP_ADAPTER_UNICAST_ADDRESS *addr )
3176 {
3177     const SOCKET_ADDRESS *sa = &addr->Address;
3178     WCHAR buf[NI_MAXHOST];
3179 
3180     if (!addr) return NULL;
3181     if (GetNameInfoW( sa->lpSockaddr, sa->iSockaddrLength, buf, ARRAY_SIZE( buf ), NULL,
3182                       0, NI_NAMEREQD )) return NULL;
3183     return heap_strdupW( buf );
3184 }
3185 static struct array *get_defaultipgateway( IP_ADAPTER_GATEWAY_ADDRESS *list )
3186 {
3187     IP_ADAPTER_GATEWAY_ADDRESS *gateway;
3188     struct array *ret;
3189     ULONG buflen, i = 0, count = 0;
3190     WCHAR **ptr, buf[54]; /* max IPv6 address length */
3191 
3192     if (!list) return NULL;
3193     for (gateway = list; gateway; gateway = gateway->Next) count++;
3194 
3195     if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
3196     if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
3197     {
3198         heap_free( ret );
3199         return NULL;
3200     }
3201     for (gateway = list; gateway; gateway = gateway->Next)
3202     {
3203         buflen = ARRAY_SIZE( buf );
3204         if (WSAAddressToStringW( gateway->Address.lpSockaddr, gateway->Address.iSockaddrLength,
3205                                  NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
3206         {
3207             for (; i > 0; i--) heap_free( ptr[i - 1] );
3208             heap_free( ptr );
3209             heap_free( ret );
3210             return NULL;
3211         }
3212     }
3213     ret->elem_size = sizeof(*ptr);
3214     ret->count     = count;
3215     ret->ptr       = ptr;
3216     return ret;
3217 }
3218 static struct array *get_dnsserversearchorder( IP_ADAPTER_DNS_SERVER_ADDRESS *list )
3219 {
3220     IP_ADAPTER_DNS_SERVER_ADDRESS *server;
3221     struct array *ret;
3222     ULONG buflen, i = 0, count = 0;
3223     WCHAR **ptr, *p, buf[54]; /* max IPv6 address length */
3224 
3225     if (!list) return NULL;
3226     for (server = list; server; server = server->Next) count++;
3227 
3228     if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
3229     if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
3230     {
3231         heap_free( ret );
3232         return NULL;
3233     }
3234     for (server = list; server; server = server->Next)
3235     {
3236         buflen = ARRAY_SIZE( buf );
3237         if (WSAAddressToStringW( server->Address.lpSockaddr, server->Address.iSockaddrLength,
3238                                  NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
3239         {
3240             for (; i > 0; i--) heap_free( ptr[i - 1] );
3241             heap_free( ptr );
3242             heap_free( ret );
3243             return NULL;
3244         }
3245         if ((p = wcsrchr( ptr[i - 1], ':' ))) *p = 0;
3246     }
3247     ret->elem_size = sizeof(*ptr);
3248     ret->count     = count;
3249     ret->ptr       = ptr;
3250     return ret;
3251 }
3252 
3253 #ifndef __REACTOS__
3254 
3255 static struct array *get_ipaddress( IP_ADAPTER_UNICAST_ADDRESS_LH *list )
3256 {
3257     IP_ADAPTER_UNICAST_ADDRESS_LH *address;
3258     struct array *ret;
3259     ULONG buflen, i = 0, count = 0;
3260     WCHAR **ptr, buf[54]; /* max IPv6 address length */
3261 
3262     if (!list) return NULL;
3263     for (address = list; address; address = address->Next) count++;
3264 
3265     if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
3266     if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
3267     {
3268         heap_free( ret );
3269         return NULL;
3270     }
3271     for (address = list; address; address = address->Next)
3272     {
3273         buflen = ARRAY_SIZE( buf );
3274         if (WSAAddressToStringW( address->Address.lpSockaddr, address->Address.iSockaddrLength,
3275                                  NULL, buf, &buflen) || !(ptr[i++] = heap_strdupW( buf )))
3276         {
3277             for (; i > 0; i--) heap_free( ptr[i - 1] );
3278             heap_free( ptr );
3279             heap_free( ret );
3280             return NULL;
3281         }
3282     }
3283     ret->elem_size = sizeof(*ptr);
3284     ret->count     = count;
3285     ret->ptr       = ptr;
3286     return ret;
3287 }
3288 static struct array *get_ipsubnet( IP_ADAPTER_UNICAST_ADDRESS_LH *list )
3289 {
3290     IP_ADAPTER_UNICAST_ADDRESS_LH *address;
3291     struct array *ret;
3292     ULONG i = 0, count = 0;
3293     WCHAR **ptr;
3294 
3295     if (!list) return NULL;
3296     for (address = list; address; address = address->Next) count++;
3297 
3298     if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
3299     if (!(ptr = heap_alloc( sizeof(*ptr) * count )))
3300     {
3301         heap_free( ret );
3302         return NULL;
3303     }
3304     for (address = list; address; address = address->Next)
3305     {
3306         if (address->Address.lpSockaddr->sa_family == AF_INET)
3307         {
3308             WCHAR buf[INET_ADDRSTRLEN];
3309             SOCKADDR_IN addr;
3310             ULONG buflen = ARRAY_SIZE( buf );
3311 
3312             memset( &addr, 0, sizeof(addr) );
3313             addr.sin_family = AF_INET;
3314             if (ConvertLengthToIpv4Mask( address->OnLinkPrefixLength, &addr.sin_addr.S_un.S_addr ) != NO_ERROR
3315                     || WSAAddressToStringW( (SOCKADDR*)&addr, sizeof(addr), NULL, buf, &buflen))
3316                 ptr[i] = NULL;
3317             else
3318                 ptr[i] = heap_strdupW( buf );
3319         }
3320         else
3321         {
3322             static const WCHAR fmtW[] = {'%','u',0};
3323             WCHAR buf[11];
3324 
3325             swprintf( buf, fmtW, address->OnLinkPrefixLength );
3326             ptr[i] = heap_strdupW( buf );
3327         }
3328         if (!ptr[i++])
3329         {
3330             for (; i > 0; i--) heap_free( ptr[i - 1] );
3331             heap_free( ptr );
3332             heap_free( ret );
3333             return NULL;
3334         }
3335     }
3336     ret->elem_size = sizeof(*ptr);
3337     ret->count     = count;
3338     ret->ptr       = ptr;
3339     return ret;
3340 }
3341 
3342 #endif /* !__REACTOS__ */
3343 
3344 static WCHAR *get_settingid( UINT32 index )
3345 {
3346     GUID guid;
3347     WCHAR *ret, *str;
3348     memset( &guid, 0, sizeof(guid) );
3349     guid.Data1 = index;
3350     UuidToStringW( &guid, &str );
3351     ret = heap_strdupW( str );
3352     RpcStringFreeW( &str );
3353     return ret;
3354 }
3355 
3356 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
3357 {
3358     struct record_networkadapterconfig *rec;
3359     IP_ADAPTER_ADDRESSES *aa, *buffer;
3360     UINT row = 0, offset = 0, count = 0;
3361     DWORD size = 0, ret;
3362     enum fill_status status = FILL_STATUS_UNFILTERED;
3363 
3364     ret = GetAdaptersAddresses( AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, NULL, &size );
3365     if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
3366 
3367     if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
3368     if (GetAdaptersAddresses( AF_UNSPEC, GAA_FLAG_INCLUDE_ALL_GATEWAYS, NULL, buffer, &size ))
3369     {
3370         heap_free( buffer );
3371         return FILL_STATUS_FAILED;
3372     }
3373     for (aa = buffer; aa; aa = aa->Next)
3374     {
3375         if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
3376     }
3377     if (!resize_table( table, count, sizeof(*rec) ))
3378     {
3379         heap_free( buffer );
3380         return FILL_STATUS_FAILED;
3381     }
3382     for (aa = buffer; aa; aa = aa->Next)
3383     {
3384         if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
3385 
3386         rec = (struct record_networkadapterconfig *)(table->data + offset);
3387         rec->defaultipgateway     = get_defaultipgateway( aa->FirstGatewayAddress );
3388         rec->description          = heap_strdupW( aa->Description );
3389         rec->dhcpenabled          = -1;
3390         rec->dnshostname          = get_dnshostname( aa->FirstUnicastAddress );
3391         rec->dnsserversearchorder = get_dnsserversearchorder( aa->FirstDnsServerAddress );
3392         rec->index                = aa->u.s.IfIndex;
3393 #ifndef __REACTOS__
3394         rec->ipaddress            = get_ipaddress( aa->FirstUnicastAddress );
3395 #endif
3396         rec->ipconnectionmetric   = 20;
3397         rec->ipenabled            = -1;
3398 #ifndef __REACTOS__
3399         rec->ipsubnet             = get_ipsubnet( aa->FirstUnicastAddress );
3400 #endif
3401         rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
3402         rec->settingid            = get_settingid( rec->index );
3403         if (!match_row( table, row, cond, &status ))
3404         {
3405             free_row_values( table, row );
3406             continue;
3407         }
3408         offset += sizeof(*rec);
3409         row++;
3410     }
3411     TRACE("created %u rows\n", row);
3412     table->num_rows = row;
3413 
3414     heap_free( buffer );
3415     return status;
3416 }
3417 
3418 static enum fill_status fill_physicalmemory( struct table *table, const struct expr *cond )
3419 {
3420     static const WCHAR dimm0W[] = {'D','I','M','M',' ','0',0};
3421     struct record_physicalmemory *rec;
3422     enum fill_status status = FILL_STATUS_UNFILTERED;
3423     UINT row = 0;
3424 
3425     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
3426 
3427     rec = (struct record_physicalmemory *)table->data;
3428     rec->capacity             = get_total_physical_memory();
3429     rec->configuredclockspeed = 0;
3430     rec->devicelocator        = dimm0W;
3431     rec->memorytype           = 9; /* RAM */
3432     rec->partnumber           = NULL;
3433     if (!match_row( table, row, cond, &status )) free_row_values( table, row );
3434     else row++;
3435 
3436     TRACE("created %u rows\n", row);
3437     table->num_rows = row;
3438     return status;
3439 }
3440 
3441 static enum fill_status fill_pnpentity( struct table *table, const struct expr *cond )
3442 {
3443     struct record_pnpentity *rec;
3444     enum fill_status status = FILL_STATUS_UNFILTERED;
3445     HDEVINFO device_info_set;
3446     SP_DEVINFO_DATA devinfo = {0};
3447     DWORD idx;
3448 
3449     device_info_set = SetupDiGetClassDevsW( NULL, NULL, NULL, DIGCF_ALLCLASSES|DIGCF_PRESENT );
3450 
3451     devinfo.cbSize = sizeof(devinfo);
3452 
3453     idx = 0;
3454     while (SetupDiEnumDeviceInfo( device_info_set, idx++, &devinfo ))
3455     {
3456         /* noop */
3457     }
3458 
3459     resize_table( table, idx, sizeof(*rec) );
3460     table->num_rows = 0;
3461     rec = (struct record_pnpentity *)table->data;
3462 
3463     idx = 0;
3464     while (SetupDiEnumDeviceInfo( device_info_set, idx++, &devinfo ))
3465     {
3466         WCHAR device_id[MAX_PATH];
3467         if (SetupDiGetDeviceInstanceIdW( device_info_set, &devinfo, device_id,
3468                     ARRAY_SIZE(device_id), NULL ))
3469         {
3470             rec->device_id = heap_strdupW( device_id );
3471 
3472             table->num_rows++;
3473             if (!match_row( table, table->num_rows - 1, cond, &status ))
3474             {
3475                 free_row_values( table, table->num_rows - 1 );
3476                 table->num_rows--;
3477             }
3478             else
3479                 rec++;
3480         }
3481     }
3482 
3483     SetupDiDestroyDeviceInfoList( device_info_set );
3484 
3485     return status;
3486 }
3487 
3488 static enum fill_status fill_printer( struct table *table, const struct expr *cond )
3489 {
3490     static const WCHAR fmtW[] = {'P','r','i','n','t','e','r','%','d',0};
3491     struct record_printer *rec;
3492     enum fill_status status = FILL_STATUS_UNFILTERED;
3493     PRINTER_INFO_2W *info;
3494     DWORD i, offset = 0, count = 0, size = 0, num_rows = 0;
3495     WCHAR id[20];
3496 
3497     EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &size, &count );
3498     if (!count) return FILL_STATUS_UNFILTERED;
3499 
3500     if (!(info = heap_alloc( size ))) return FILL_STATUS_FAILED;
3501     if (!EnumPrintersW( PRINTER_ENUM_LOCAL, NULL, 2, (BYTE *)info, size, &size, &count ))
3502     {
3503         heap_free( info );
3504         return FILL_STATUS_FAILED;
3505     }
3506     if (!resize_table( table, count, sizeof(*rec) ))
3507     {
3508         heap_free( info );
3509         return FILL_STATUS_FAILED;
3510     }
3511 
3512     for (i = 0; i < count; i++)
3513     {
3514         rec = (struct record_printer *)(table->data + offset);
3515         rec->attributes           = info[i].Attributes;
3516         swprintf( id, fmtW, i );
3517         rec->device_id            = heap_strdupW( id );
3518         rec->drivername           = heap_strdupW( info[i].pDriverName );
3519         rec->horizontalresolution = info[i].pDevMode->u1.s1.dmPrintQuality;
3520         rec->local                = -1;
3521         rec->location             = heap_strdupW( info[i].pLocation );
3522         rec->name                 = heap_strdupW( info[i].pPrinterName );
3523         rec->network              = 0;
3524         rec->portname             = heap_strdupW( info[i].pPortName );
3525         if (!match_row( table, i, cond, &status ))
3526         {
3527             free_row_values( table, i );
3528             continue;
3529         }
3530         offset += sizeof(*rec);
3531         num_rows++;
3532     }
3533     TRACE("created %u rows\n", num_rows);
3534     table->num_rows = num_rows;
3535 
3536     heap_free( info );
3537     return status;
3538 }
3539 
3540 static WCHAR *get_cmdline( DWORD process_id )
3541 {
3542     if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
3543     return NULL; /* FIXME handle different process case */
3544 }
3545 
3546 static enum fill_status fill_process( struct table *table, const struct expr *cond )
3547 {
3548     static const WCHAR fmtW[] = {'%','u',0};
3549     WCHAR handle[11];
3550     struct record_process *rec;
3551     PROCESSENTRY32W entry;
3552     HANDLE snap;
3553     enum fill_status status = FILL_STATUS_FAILED;
3554     UINT row = 0, offset = 0;
3555 
3556     snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
3557     if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
3558 
3559     entry.dwSize = sizeof(entry);
3560     if (!Process32FirstW( snap, &entry )) goto done;
3561     if (!resize_table( table, 8, sizeof(*rec) )) goto done;
3562 
3563     do
3564     {
3565         if (!resize_table( table, row + 1, sizeof(*rec) ))
3566         {
3567             status = FILL_STATUS_FAILED;
3568             goto done;
3569         }
3570 
3571         rec = (struct record_process *)(table->data + offset);
3572         rec->caption        = heap_strdupW( entry.szExeFile );
3573         rec->commandline    = get_cmdline( entry.th32ProcessID );
3574         rec->description    = heap_strdupW( entry.szExeFile );
3575         swprintf( handle, fmtW, entry.th32ProcessID );
3576         rec->handle         = heap_strdupW( handle );
3577         rec->name           = heap_strdupW( entry.szExeFile );
3578         rec->process_id     = entry.th32ProcessID;
3579         rec->pprocess_id    = entry.th32ParentProcessID;
3580         rec->thread_count   = entry.cntThreads;
3581         rec->workingsetsize = 0;
3582         rec->get_owner      = process_get_owner;
3583         if (!match_row( table, row, cond, &status ))
3584         {
3585             free_row_values( table, row );
3586             continue;
3587         }
3588         offset += sizeof(*rec);
3589         row++;
3590     } while (Process32NextW( snap, &entry ));
3591 
3592     TRACE("created %u rows\n", row);
3593     table->num_rows = row;
3594 
3595 done:
3596     CloseHandle( snap );
3597     return status;
3598 }
3599 
3600 extern void do_cpuid( unsigned int ax, unsigned int *p );
3601 #if defined(_MSC_VER)
3602 void do_cpuid( unsigned int ax, unsigned int *p )
3603 {
3604     __cpuid( p, ax );
3605 }
3606 #elif defined(__i386__)
3607 __ASM_GLOBAL_FUNC( do_cpuid,
3608                    "pushl %esi\n\t"
3609                    "pushl %ebx\n\t"
3610                    "movl 12(%esp),%eax\n\t"
3611                    "movl 16(%esp),%esi\n\t"
3612                    "cpuid\n\t"
3613                    "movl %eax,(%esi)\n\t"
3614                    "movl %ebx,4(%esi)\n\t"
3615                    "movl %ecx,8(%esi)\n\t"
3616                    "movl %edx,12(%esi)\n\t"
3617                    "popl %ebx\n\t"
3618                    "popl %esi\n\t"
3619                    "ret" )
3620 #elif defined(__x86_64__)
3621 __ASM_GLOBAL_FUNC( do_cpuid,
3622                    "pushq %rsi\n\t"
3623                    "pushq %rbx\n\t"
3624                    "movq %rcx,%rax\n\t"
3625                    "movq %rdx,%rsi\n\t"
3626                    "cpuid\n\t"
3627                    "movl %eax,(%rsi)\n\t"
3628                    "movl %ebx,4(%rsi)\n\t"
3629                    "movl %ecx,8(%rsi)\n\t"
3630                    "movl %edx,12(%rsi)\n\t"
3631                    "popq %rbx\n\t"
3632                    "popq %rsi\n\t"
3633                    "ret" )
3634 #else
3635 void do_cpuid( unsigned int ax, unsigned int *p )
3636 {
3637     FIXME("\n");
3638 }
3639 #endif
3640 
3641 static unsigned int get_processor_model( unsigned int reg0, unsigned int *stepping, unsigned int *family )
3642 {
3643     unsigned int model, family_id = (reg0 & (0x0f << 8)) >> 8;
3644 
3645     model = (reg0 & (0x0f << 4)) >> 4;
3646     if (family_id == 6 || family_id == 15) model |= (reg0 & (0x0f << 16)) >> 12;
3647     if (family)
3648     {
3649         *family = family_id;
3650         if (family_id == 15) *family += (reg0 & (0xff << 20)) >> 20;
3651     }
3652     *stepping = reg0 & 0x0f;
3653     return model;
3654 }
3655 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
3656 {
3657     unsigned int i;
3658     unsigned char *p = (unsigned char *)regs;
3659 
3660     for (i = 0; i < len; i++) { buffer[i] = *p++; }
3661     buffer[i] = 0;
3662 }
3663 static void get_processor_manufacturer( WCHAR *manufacturer, UINT len )
3664 {
3665     unsigned int tmp, regs[4] = {0, 0, 0, 0};
3666 
3667     do_cpuid( 0, regs );
3668     tmp = regs[2];      /* swap edx and ecx */
3669     regs[2] = regs[3];
3670     regs[3] = tmp;
3671 
3672     regs_to_str( regs + 1, min( 12, len ), manufacturer );
3673 }
3674 static const WCHAR *get_osarchitecture(void)
3675 {
3676     SYSTEM_INFO info;
3677     GetNativeSystemInfo( &info );
3678     if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
3679     return os_32bitW;
3680 }
3681 static void get_processor_caption( WCHAR *caption, UINT len )
3682 {
3683     static const WCHAR fmtW[] =
3684         {'%','s',' ','F','a','m','i','l','y',' ','%','u',' ',
3685          'M','o','d','e','l',' ','%','u',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
3686     static const WCHAR x86W[] = {'x','8','6',0};
3687     static const WCHAR intel64W[] = {'I','n','t','e','l','6','4',0};
3688     static const WCHAR amd64W[] = {'A','M','D','6','4',0};
3689     static const WCHAR authenticamdW[] = {'A','u','t','h','e','n','t','i','c','A','M','D',0};
3690     const WCHAR *arch;
3691     WCHAR manufacturer[13];
3692     unsigned int regs[4] = {0, 0, 0, 0}, family, model, stepping;
3693 
3694     get_processor_manufacturer( manufacturer, ARRAY_SIZE( manufacturer ) );
3695     if (get_osarchitecture() == os_32bitW) arch = x86W;
3696     else if (!wcscmp( manufacturer, authenticamdW )) arch = amd64W;
3697     else arch = intel64W;
3698 
3699     do_cpuid( 1, regs );
3700 
3701     model = get_processor_model( regs[0], &stepping, &family );
3702     swprintf( caption, fmtW, arch, family, model, stepping );
3703 }
3704 static void get_processor_version( WCHAR *version, UINT len )
3705 {
3706     static const WCHAR fmtW[] =
3707         {'M','o','d','e','l',' ','%','u',',',' ','S','t','e','p','p','i','n','g',' ','%','u',0};
3708     unsigned int regs[4] = {0, 0, 0, 0}, model, stepping;
3709 
3710     do_cpuid( 1, regs );
3711 
3712     model = get_processor_model( regs[0], &stepping, NULL );
3713     swprintf( version, fmtW, model, stepping );
3714 }
3715 static UINT16 get_processor_revision(void)
3716 {
3717     unsigned int regs[4] = {0, 0, 0, 0};
3718     do_cpuid( 1, regs );
3719     return regs[0];
3720 }
3721 static void get_processor_id( WCHAR *processor_id, UINT len )
3722 {
3723     static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
3724     unsigned int regs[4] = {0, 0, 0, 0};
3725 
3726     do_cpuid( 1, regs );
3727     swprintf( processor_id, fmtW, regs[3], regs[0] );
3728 }
3729 static void get_processor_name( WCHAR *name )
3730 {
3731     unsigned int regs[4] = {0, 0, 0, 0};
3732     int i;
3733 
3734     do_cpuid( 0x80000000, regs );
3735     if (regs[0] >= 0x80000004)
3736     {
3737         do_cpuid( 0x80000002, regs );
3738         regs_to_str( regs, 16, name );
3739         do_cpuid( 0x80000003, regs );
3740         regs_to_str( regs, 16, name + 16 );
3741         do_cpuid( 0x80000004, regs );
3742         regs_to_str( regs, 16, name + 32 );
3743     }
3744     for (i = lstrlenW(name) - 1; i >= 0 && name[i] == ' '; i--) name[i] = 0;
3745 }
3746 static UINT get_processor_currentclockspeed( UINT index )
3747 {
3748     PROCESSOR_POWER_INFORMATION *info;
3749     UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
3750     NTSTATUS status;
3751 
3752     if ((info = heap_alloc( size )))
3753     {
3754         status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
3755         if (!status) ret = info[index].CurrentMhz;
3756         heap_free( info );
3757     }
3758     return ret;
3759 }
3760 static UINT get_processor_maxclockspeed( UINT index )
3761 {
3762     PROCESSOR_POWER_INFORMATION *info;
3763     UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
3764     NTSTATUS status;
3765 
3766     if ((info = heap_alloc( size )))
3767     {
3768         status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
3769         if (!status) ret = info[index].MaxMhz;
3770         heap_free( info );
3771     }
3772     return ret;
3773 }
3774 
3775 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
3776 {
3777     static const WCHAR fmtW[] = {'C','P','U','%','u',0};
3778     WCHAR caption[100], device_id[14], processor_id[17], manufacturer[13], name[49] = {0}, version[50];
3779     struct record_processor *rec;
3780 #ifdef __REACTOS__
3781     UINT i, offset = 0, num_rows = 0, num_cores, num_logical_processors, count = get_processor_count();
3782 #else
3783     UINT i, offset = 0, num_rows = 0, num_logical, num_physical, num_packages;
3784 #endif
3785     enum fill_status status = FILL_STATUS_UNFILTERED;
3786 
3787 #ifdef __REACTOS__
3788     if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
3789 #else
3790     num_logical = get_logical_processor_count( &num_physical, &num_packages );
3791 
3792     if (!resize_table( table, num_packages, sizeof(*rec) )) return FILL_STATUS_FAILED;
3793 #endif
3794 
3795     get_processor_caption( caption, ARRAY_SIZE( caption ) );
3796     get_processor_id( processor_id, ARRAY_SIZE( processor_id ) );
3797     get_processor_manufacturer( manufacturer, ARRAY_SIZE( manufacturer ) );
3798     get_processor_name( name );
3799     get_processor_version( version, ARRAY_SIZE( version ) );
3800 
3801 #ifdef __REACTOS__
3802     num_logical_processors = get_logical_processor_count( &num_cores ) / count;
3803     num_cores /= count;
3804 
3805     for (i = 0; i < count; i++)
3806 #else
3807     for (i = 0; i < num_packages; i++)
3808 #endif
3809     {
3810         rec = (struct record_processor *)(table->data + offset);
3811         rec->addresswidth           = get_osarchitecture() == os_32bitW ? 32 : 64;
3812         rec->architecture           = get_osarchitecture() == os_32bitW ? 0 : 9;
3813         rec->caption                = heap_strdupW( caption );
3814         rec->cpu_status             = 1; /* CPU Enabled */
3815         rec->currentclockspeed      = get_processor_currentclockspeed( i );
3816         rec->datawidth              = get_osarchitecture() == os_32bitW ? 32 : 64;
3817         rec->description            = heap_strdupW( caption );
3818         swprintf( device_id, fmtW, i );
3819         rec->device_id              = heap_strdupW( device_id );
3820         rec->family                 = 2; /* Unknown */
3821         rec->level                  = 15;
3822         rec->manufacturer           = heap_strdupW( manufacturer );
3823         rec->maxclockspeed          = get_processor_maxclockspeed( i );
3824         rec->name                   = heap_strdupW( name );
3825 #ifdef __REACTOS__
3826         rec->num_cores              = num_cores;
3827         rec->num_logical_processors = num_logical_processors;
3828 #else
3829         rec->num_cores              = num_physical / num_packages;
3830         rec->num_logical_processors = num_logical / num_packages;
3831 #endif
3832         rec->processor_id           = heap_strdupW( processor_id );
3833         rec->processortype          = 3; /* central processor */
3834         rec->revision               = get_processor_revision();
3835         rec->unique_id              = NULL;
3836         rec->version                = heap_strdupW( version );
3837         if (!match_row( table, i, cond, &status ))
3838         {
3839             free_row_values( table, i );
3840             continue;
3841         }
3842         offset += sizeof(*rec);
3843         num_rows++;
3844     }
3845 
3846     TRACE("created %u rows\n", num_rows);
3847     table->num_rows = num_rows;
3848     return status;
3849 }
3850 
3851 static WCHAR *get_lastbootuptime(void)
3852 {
3853     static const WCHAR fmtW[] =
3854         {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
3855          '.','%','0','6','u','+','0','0','0',0};
3856     SYSTEM_TIMEOFDAY_INFORMATION ti;
3857     TIME_FIELDS tf;
3858     WCHAR *ret;
3859 
3860     if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
3861 
3862     NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
3863     RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
3864     swprintf( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
3865     return ret;
3866 }
3867 static WCHAR *get_localdatetime(void)
3868 {
3869     static const WCHAR fmtW[] =
3870         {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
3871          '.','%','0','6','u','%','+','0','3','d',0};
3872     TIME_ZONE_INFORMATION tzi;
3873     SYSTEMTIME st;
3874     WCHAR *ret;
3875     DWORD Status;
3876     LONG Bias;
3877 
3878     Status = GetTimeZoneInformation(&tzi);
3879 
3880     if(Status == TIME_ZONE_ID_INVALID) return NULL;
3881     Bias = tzi.Bias;
3882     if(Status == TIME_ZONE_ID_DAYLIGHT)
3883         Bias+= tzi.DaylightBias;
3884     else
3885         Bias+= tzi.StandardBias;
3886     if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
3887 
3888     GetLocalTime(&st);
3889     swprintf( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias );
3890     return ret;
3891 }
3892 static WCHAR *get_systemdirectory(void)
3893 {
3894     void *redir;
3895     WCHAR *ret;
3896 
3897     if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
3898     Wow64DisableWow64FsRedirection( &redir );
3899     GetSystemDirectoryW( ret, MAX_PATH );
3900     Wow64RevertWow64FsRedirection( redir );
3901     return ret;
3902 }
3903 static WCHAR *get_systemdrive(void)
3904 {
3905     WCHAR *ret = heap_alloc( 3 * sizeof(WCHAR) ); /* "c:" */
3906     if (ret && GetEnvironmentVariableW( prop_systemdriveW, ret, 3 )) return ret;
3907     heap_free( ret );
3908     return NULL;
3909 }
3910 static WCHAR *get_codeset(void)
3911 {
3912     static const WCHAR fmtW[] = {'%','u',0};
3913     WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
3914     if (ret) swprintf( ret, fmtW, GetACP() );
3915     return ret;
3916 }
3917 static WCHAR *get_countrycode(void)
3918 {
3919     WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
3920     if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
3921     return ret;
3922 }
3923 static WCHAR *get_locale(void)
3924 {
3925     WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
3926     if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
3927     return ret;
3928 }
3929 static WCHAR *get_osbuildnumber( OSVERSIONINFOEXW *ver )
3930 {
3931     static const WCHAR fmtW[] = {'%','u',0};
3932     WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
3933     if (ret) swprintf( ret, fmtW, ver->dwBuildNumber );
3934     return ret;
3935 }
3936 static WCHAR *get_oscaption( OSVERSIONINFOEXW *ver )
3937 {
3938     static const WCHAR windowsW[] =
3939         {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' '};
3940     static const WCHAR win2000W[] =
3941         {'2','0','0','0',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
3942     static const WCHAR win2003W[] =
3943         {'S','e','r','v','e','r',' ','2','0','0','3',' ','S','t','a','n','d','a','r','d',' ','E','d','i','t','i','o','n',0};
3944     static const WCHAR winxpW[] =
3945         {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
3946     static const WCHAR winxp64W[] =
3947         {'X','P',' ','P','r','o','f','e','s','s','i','o','n','a','l',' ','x','6','4',' ','E','d','i','t','i','o','n',0};
3948     static const WCHAR vistaW[] =
3949         {'V','i','s','t','a',' ','U','l','t','i','m','a','t','e',0};
3950     static const WCHAR win2008W[] =
3951         {'S','e','r','v','e','r',' ','2','0','0','8',' ','S','t','a','n','d','a','r','d',0};
3952     static const WCHAR win7W[] =
3953         {'7',' ','P','r','o','f','e','s','s','i','o','n','a','l',0};
3954     static const WCHAR win2008r2W[] =
3955         {'S','e','r','v','e','r',' ','2','0','0','8',' ','R','2',' ','S','t','a','n','d','a','r','d',0};
3956     static const WCHAR win8W[] =
3957         {'8',' ','P','r','o',0};
3958     static const WCHAR win81W[] =
3959         {'8','.','1',' ','P','r','o',0};
3960     static const WCHAR win10W[] =
3961         {'1','0',' ','P','r','o',0};
3962     int len = ARRAY_SIZE( windowsW );
3963     WCHAR *ret;
3964 
3965     if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(win2003W) ))) return NULL;
3966     memcpy( ret, windowsW, sizeof(windowsW) );
3967     if (ver->dwMajorVersion == 10 && ver->dwMinorVersion == 0) memcpy( ret + len, win10W, sizeof(win10W) );
3968     else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 3) memcpy( ret + len, win8W, sizeof(win8W) );
3969     else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 2) memcpy( ret + len, win81W, sizeof(win81W) );
3970     else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 1)
3971     {
3972         if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, win7W, sizeof(win7W) );
3973         else memcpy( ret + len, win2008r2W, sizeof(win2008r2W) );
3974     }
3975     else if (ver->dwMajorVersion == 6 && ver->dwMinorVersion == 0)
3976     {
3977         if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, vistaW, sizeof(vistaW) );
3978         else memcpy( ret + len, win2008W, sizeof(win2008W) );
3979     }
3980     else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 2)
3981     {
3982         if (ver->wProductType == VER_NT_WORKSTATION) memcpy( ret + len, winxp64W, sizeof(winxp64W) );
3983         else memcpy( ret + len, win2003W, sizeof(win2003W) );
3984     }
3985     else if (ver->dwMajorVersion == 5 && ver->dwMinorVersion == 1) memcpy( ret + len, winxpW, sizeof(winxpW) );
3986     else memcpy( ret + len, win2000W, sizeof(win2000W) );
3987     return ret;
3988 }
3989 static WCHAR *get_osname( const WCHAR *caption )
3990 {
3991     static const WCHAR partitionW[] =
3992         {'|','C',':','\\','W','I','N','D','O','W','S','|','\\','D','e','v','i','c','e','\\',
3993          'H','a','r','d','d','i','s','k','0','\\','P','a','r','t','i','t','i','o','n','1',0};
3994     int len = lstrlenW( caption );
3995     WCHAR *ret;
3996 
3997     if (!(ret = heap_alloc( len * sizeof(WCHAR) + sizeof(partitionW) ))) return NULL;
3998     memcpy( ret, caption, len * sizeof(WCHAR) );
3999     memcpy( ret + len, partitionW, sizeof(partitionW) );
4000     return ret;
4001 }
4002 static WCHAR *get_osversion( OSVERSIONINFOEXW *ver )
4003 {
4004     static const WCHAR fmtW[] = {'%','u','.','%','u','.','%','u',0};
4005     WCHAR *ret = heap_alloc( 33 * sizeof(WCHAR) );
4006     if (ret) swprintf( ret, fmtW, ver->dwMajorVersion, ver->dwMinorVersion, ver->dwBuildNumber );
4007     return ret;
4008 }
4009 #ifndef __REACTOS__
4010 static DWORD get_operatingsystemsku(void)
4011 {
4012     DWORD ret = PRODUCT_UNDEFINED;
4013     GetProductInfo( 6, 0, 0, 0, &ret );
4014     return ret;
4015 }
4016 #endif
4017 static INT16 get_currenttimezone(void)
4018 {
4019     TIME_ZONE_INFORMATION info;
4020     DWORD status = GetTimeZoneInformation( &info );
4021     if (status == TIME_ZONE_ID_INVALID) return 0;
4022     if (status == TIME_ZONE_ID_DAYLIGHT) return -(info.Bias + info.DaylightBias);
4023     return -(info.Bias + info.StandardBias);
4024 }
4025 
4026 static enum fill_status fill_operatingsystem( struct table *table, const struct expr *cond )
4027 {
4028     static const WCHAR wineprojectW[] = {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
4029     struct record_operatingsystem *rec;
4030     enum fill_status status = FILL_STATUS_UNFILTERED;
4031     OSVERSIONINFOEXW ver;
4032     UINT row = 0;
4033 
4034     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
4035 
4036     ver.dwOSVersionInfoSize = sizeof(ver);
4037     GetVersionExW( (OSVERSIONINFOW *)&ver );
4038 
4039     rec = (struct record_operatingsystem *)table->data;
4040     rec->buildnumber            = get_osbuildnumber( &ver );
4041     rec->caption                = get_oscaption( &ver );
4042     rec->codeset                = get_codeset();
4043     rec->countrycode            = get_countrycode();
4044     rec->csdversion             = ver.szCSDVersion[0] ? heap_strdupW( ver.szCSDVersion ) : NULL;
4045     rec->csname                 = get_computername();
4046     rec->currenttimezone        = get_currenttimezone();
4047     rec->freephysicalmemory     = get_available_physical_memory() / 1024;
4048     rec->installdate            = os_installdateW;
4049     rec->lastbootuptime         = get_lastbootuptime();
4050     rec->localdatetime          = get_localdatetime();
4051     rec->locale                 = get_locale();
4052     rec->manufacturer           = wineprojectW;
4053     rec->name                   = get_osname( rec->caption );
4054 #ifndef __REACTOS__
4055     rec->operatingsystemsku     = get_operatingsystemsku();
4056 #endif
4057     rec->osarchitecture         = get_osarchitecture();
4058     rec->oslanguage             = GetSystemDefaultLangID();
4059     rec->osproductsuite         = 2461140; /* Windows XP Professional  */
4060     rec->ostype                 = 18;      /* WINNT */
4061     rec->primary                = -1;
4062     rec->serialnumber           = os_serialnumberW;
4063     rec->servicepackmajor       = ver.wServicePackMajor;
4064     rec->servicepackminor       = ver.wServicePackMinor;
4065     rec->suitemask              = 272;     /* Single User + Terminal */
4066     rec->systemdirectory        = get_systemdirectory();
4067     rec->systemdrive            = get_systemdrive();
4068     rec->totalvirtualmemorysize = get_total_physical_memory() / 1024;
4069     rec->totalvisiblememorysize = rec->totalvirtualmemorysize;
4070     rec->version                = get_osversion( &ver );
4071     if (!match_row( table, row, cond, &status )) free_row_values( table, row );
4072     else row++;
4073 
4074     TRACE("created %u rows\n", row);
4075     table->num_rows = row;
4076     return status;
4077 }
4078 
4079 static const WCHAR *get_service_type( DWORD type )
4080 {
4081     static const WCHAR filesystem_driverW[] =
4082         {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
4083     static const WCHAR kernel_driverW[] =
4084         {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
4085     static const WCHAR own_processW[] =
4086         {'O','w','n',' ','P','r','o','c','e','s','s',0};
4087     static const WCHAR share_processW[] =
4088         {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
4089 
4090     if (type & SERVICE_KERNEL_DRIVER)            return kernel_driverW;
4091     else if (type & SERVICE_FILE_SYSTEM_DRIVER)  return filesystem_driverW;
4092     else if (type & SERVICE_WIN32_OWN_PROCESS)   return own_processW;
4093     else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
4094     else ERR("unhandled type 0x%08x\n", type);
4095     return NULL;
4096 }
4097 static const WCHAR *get_service_state( DWORD state )
4098 {
4099     static const WCHAR runningW[] =
4100         {'R','u','n','n','i','n','g',0};
4101     static const WCHAR start_pendingW[] =
4102         {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
4103     static const WCHAR stop_pendingW[] =
4104         {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
4105     static const WCHAR stoppedW[] =
4106         {'S','t','o','p','p','e','d',0};
4107     static const WCHAR unknownW[] =
4108         {'U','n','k','n','o','w','n',0};
4109 
4110     switch (state)
4111     {
4112     case SERVICE_STOPPED:       return stoppedW;
4113     case SERVICE_START_PENDING: return start_pendingW;
4114     case SERVICE_STOP_PENDING:  return stop_pendingW;
4115     case SERVICE_RUNNING:       return runningW;
4116     default:
4117         ERR("unknown state %u\n", state);
4118         return unknownW;
4119     }
4120 }
4121 static const WCHAR *get_service_startmode( DWORD mode )
4122 {
4123     static const WCHAR bootW[] = {'B','o','o','t',0};
4124     static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
4125     static const WCHAR autoW[] = {'A','u','t','o',0};
4126     static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
4127     static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
4128     static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
4129 
4130     switch (mode)
4131     {
4132     case SERVICE_BOOT_START:   return bootW;
4133     case SERVICE_SYSTEM_START: return systemW;
4134     case SERVICE_AUTO_START:   return autoW;
4135     case SERVICE_DEMAND_START: return manualW;
4136     case SERVICE_DISABLED:     return disabledW;
4137     default:
4138         ERR("unknown mode 0x%x\n", mode);
4139         return unknownW;
4140     }
4141 }
4142 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
4143 {
4144     QUERY_SERVICE_CONFIGW *config = NULL;
4145     SC_HANDLE service;
4146     DWORD size;
4147 
4148     if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
4149     QueryServiceConfigW( service, NULL, 0, &size );
4150     if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
4151     if (!(config = heap_alloc( size ))) goto done;
4152     if (QueryServiceConfigW( service, config, size, &size )) goto done;
4153     heap_free( config );
4154     config = NULL;
4155 
4156 done:
4157     CloseServiceHandle( service );
4158     return config;
4159 }
4160 
4161 static enum fill_status fill_service( struct table *table, const struct expr *cond )
4162 {
4163     struct record_service *rec;
4164     SC_HANDLE manager;
4165     ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
4166     SERVICE_STATUS_PROCESS *status;
4167     WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
4168     DWORD len = ARRAY_SIZE( sysnameW );
4169     UINT i, row = 0, offset = 0, size = 256, needed, count;
4170     enum fill_status fill_status = FILL_STATUS_FAILED;
4171     BOOL ret;
4172 
4173     if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
4174     if (!(services = heap_alloc( size ))) goto done;
4175 
4176     ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
4177                                  SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
4178                                  &count, NULL, NULL );
4179     if (!ret)
4180     {
4181         if (GetLastError() != ERROR_MORE_DATA) goto done;
4182         size = needed;
4183         if (!(tmp = heap_realloc( services, size ))) goto done;
4184         services = tmp;
4185         ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
4186                                      SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
4187                                      &count, NULL, NULL );
4188         if (!ret) goto done;
4189     }
4190     if (!resize_table( table, count, sizeof(*rec) )) goto done;
4191 
4192     GetComputerNameW( sysnameW, &len );
4193     fill_status = FILL_STATUS_UNFILTERED;
4194 
4195     for (i = 0; i < count; i++)
4196     {
4197         QUERY_SERVICE_CONFIGW *config;
4198 
4199         if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
4200 
4201         status = &services[i].ServiceStatusProcess;
4202         rec = (struct record_service *)(table->data + offset);
4203         rec->accept_pause   = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
4204         rec->accept_stop    = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
4205         rec->displayname    = heap_strdupW( services[i].lpDisplayName );
4206         rec->name           = heap_strdupW( services[i].lpServiceName );
4207         rec->process_id     = status->dwProcessId;
4208         rec->servicetype    = get_service_type( status->dwServiceType );
4209         rec->startmode      = get_service_startmode( config->dwStartType );
4210         rec->state          = get_service_state( status->dwCurrentState );
4211         rec->systemname     = heap_strdupW( sysnameW );
4212         rec->pause_service  = service_pause_service;
4213         rec->resume_service = service_resume_service;
4214         rec->start_service  = service_start_service;
4215         rec->stop_service   = service_stop_service;
4216         heap_free( config );
4217         if (!match_row( table, row, cond, &fill_status ))
4218         {
4219             free_row_values( table, row );
4220             continue;
4221         }
4222         offset += sizeof(*rec);
4223         row++;
4224     }
4225 
4226     TRACE("created %u rows\n", row);
4227     table->num_rows = row;
4228 
4229 done:
4230     CloseServiceHandle( manager );
4231     heap_free( services );
4232     return fill_status;
4233 }
4234 
4235 static WCHAR *get_accountname( LSA_TRANSLATED_NAME *name )
4236 {
4237     if (!name || !name->Name.Buffer) return NULL;
4238     return heap_strdupW( name->Name.Buffer );
4239 }
4240 static struct array *get_binaryrepresentation( PSID sid, UINT len )
4241 {
4242     struct array *ret;
4243     UINT8 *ptr;
4244 
4245     if (!(ret = heap_alloc( sizeof(*ret) ))) return NULL;
4246     if (!(ptr = heap_alloc( len )))
4247     {
4248         heap_free( ret );
4249         return NULL;
4250     }
4251     memcpy( ptr, sid, len );
4252     ret->elem_size = sizeof(*ptr);
4253     ret->count     = len;
4254     ret->ptr       = ptr;
4255     return ret;
4256 }
4257 static WCHAR *get_referenceddomainname( LSA_REFERENCED_DOMAIN_LIST *domain )
4258 {
4259     if (!domain || !domain->Domains || !domain->Domains->Name.Buffer) return NULL;
4260     return heap_strdupW( domain->Domains->Name.Buffer );
4261 }
4262 static const WCHAR *find_sid_str( const struct expr *cond )
4263 {
4264     const struct expr *left, *right;
4265     const WCHAR *ret = NULL;
4266 
4267     if (!cond || cond->type != EXPR_COMPLEX || cond->u.expr.op != OP_EQ) return NULL;
4268 
4269     left = cond->u.expr.left;
4270     right = cond->u.expr.right;
4271     if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL && !wcsicmp( left->u.propval->name, prop_sidW ))
4272     {
4273         ret = right->u.sval;
4274     }
4275     else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL && !wcsicmp( right->u.propval->name, prop_sidW ))
4276     {
4277         ret = left->u.sval;
4278     }
4279     return ret;
4280 }
4281 
4282 static enum fill_status fill_sid( struct table *table, const struct expr *cond )
4283 {
4284     PSID sid;
4285     LSA_REFERENCED_DOMAIN_LIST *domain;
4286     LSA_TRANSLATED_NAME *name;
4287     LSA_HANDLE handle;
4288     LSA_OBJECT_ATTRIBUTES attrs;
4289     const WCHAR *str;
4290     struct record_sid *rec;
4291     UINT len;
4292 
4293     if (!(str = find_sid_str( cond ))) return FILL_STATUS_FAILED;
4294     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
4295 
4296     if (!ConvertStringSidToSidW( str, &sid )) return FILL_STATUS_FAILED;
4297     len = GetLengthSid( sid );
4298 
4299     memset( &attrs, 0, sizeof(attrs) );
4300     attrs.Length = sizeof(attrs);
4301     if (LsaOpenPolicy( NULL, &attrs, POLICY_ALL_ACCESS, &handle ))
4302     {
4303         LocalFree( sid );
4304         return FILL_STATUS_FAILED;
4305     }
4306     if (LsaLookupSids( handle, 1, &sid, &domain, &name ))
4307     {
4308         LocalFree( sid );
4309         LsaClose( handle );
4310         return FILL_STATUS_FAILED;
4311     }
4312 
4313     rec = (struct record_sid *)table->data;
4314     rec->accountname            = get_accountname( name );
4315     rec->binaryrepresentation   = get_binaryrepresentation( sid, len );
4316     rec->referenceddomainname   = get_referenceddomainname( domain );
4317     rec->sid                    = heap_strdupW( str );
4318     rec->sidlength              = len;
4319 
4320     TRACE("created 1 row\n");
4321     table->num_rows = 1;
4322 
4323     LsaFreeMemory( domain );
4324     LsaFreeMemory( name );
4325     LocalFree( sid );
4326     LsaClose( handle );
4327     return FILL_STATUS_FILTERED;
4328 }
4329 
4330 static WCHAR *get_systemenclosure_string( BYTE id, const char *buf, UINT len )
4331 {
4332     const struct smbios_header *hdr;
4333     const struct smbios_chassis *chassis;
4334     UINT offset;
4335 
4336     if (!(hdr = find_smbios_entry( SMBIOS_TYPE_CHASSIS, buf, len ))) return NULL;
4337 
4338     chassis = (const struct smbios_chassis *)hdr;
4339     offset = (const char *)chassis - buf + chassis->hdr.length;
4340     return get_smbios_string( id, buf, offset, len );
4341 }
4342 
4343 static WCHAR *get_systemenclosure_manufacturer( const char *buf, UINT len )
4344 {
4345     WCHAR *ret = get_systemenclosure_string( 1, buf, len );
4346     if (!ret) return heap_strdupW( systemenclosure_manufacturerW );
4347     return ret;
4348 }
4349 
4350 static int get_systemenclosure_lockpresent( const char *buf, UINT len )
4351 {
4352     const struct smbios_header *hdr;
4353     const struct smbios_chassis *chassis;
4354 
4355     if (!(hdr = find_smbios_entry( SMBIOS_TYPE_CHASSIS, buf, len )) || hdr->length < sizeof(*chassis)) return 0;
4356 
4357     chassis = (const struct smbios_chassis *)hdr;
4358     return (chassis->type & 0x80) ? -1 : 0;
4359 }
4360 
4361 static struct array *dup_array( const struct array *src )
4362 {
4363     struct array *dst;
4364     if (!(dst = heap_alloc( sizeof(*dst) ))) return NULL;
4365     if (!(dst->ptr = heap_alloc( src->count * src->elem_size )))
4366     {
4367         heap_free( dst );
4368         return NULL;
4369     }
4370     memcpy( dst->ptr, src->ptr, src->count * src->elem_size );
4371     dst->elem_size = src->elem_size;
4372     dst->count     = src->count;
4373     return dst;
4374 }
4375 
4376 static struct array *get_systemenclosure_chassistypes( const char *buf, UINT len )
4377 {
4378     const struct smbios_header *hdr;
4379     const struct smbios_chassis *chassis;
4380     struct array *ret = NULL;
4381     UINT16 *types;
4382 
4383     if (!(hdr = find_smbios_entry( SMBIOS_TYPE_CHASSIS, buf, len )) || hdr->length < sizeof(*chassis)) goto done;
4384     chassis = (const struct smbios_chassis *)hdr;
4385 
4386     if (!(ret = heap_alloc( sizeof(*ret) ))) goto done;
4387     if (!(types = heap_alloc( sizeof(*types) )))
4388     {
4389         heap_free( ret );
4390         return NULL;
4391     }
4392     types[0] = chassis->type & ~0x80;
4393 
4394     ret->elem_size = sizeof(*types);
4395     ret->count     = 1;
4396     ret->ptr       = types;
4397 
4398 done:
4399     if (!ret) ret = dup_array( &systemenclosure_chassistypes_array );
4400     return ret;
4401 }
4402 
4403 static enum fill_status fill_systemenclosure( struct table *table, const struct expr *cond )
4404 {
4405     struct record_systemenclosure *rec;
4406     enum fill_status status = FILL_STATUS_UNFILTERED;
4407     UINT row = 0, len;
4408     char *buf;
4409 
4410     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
4411 
4412     len = GetSystemFirmwareTable( RSMB, 0, NULL, 0 );
4413     if (!(buf = heap_alloc( len ))) return FILL_STATUS_FAILED;
4414     GetSystemFirmwareTable( RSMB, 0, buf, len );
4415 
4416     rec = (struct record_systemenclosure *)table->data;
4417     rec->caption      = systemenclosure_systemenclosureW;
4418     rec->chassistypes = get_systemenclosure_chassistypes( buf, len );
4419     rec->description  = systemenclosure_systemenclosureW;
4420     rec->lockpresent  = get_systemenclosure_lockpresent( buf, len );
4421     rec->manufacturer = get_systemenclosure_manufacturer( buf, len );
4422     rec->name         = systemenclosure_systemenclosureW;
4423     rec->tag          = systemenclosure_tagW;
4424     if (!match_row( table, row, cond, &status )) free_row_values( table, row );
4425     else row++;
4426 
4427     heap_free( buf );
4428 
4429     TRACE("created %u rows\n", row);
4430     table->num_rows = row;
4431     return status;
4432 }
4433 
4434 #ifndef __REACTOS__
4435 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
4436 {
4437     static const WCHAR fmtW[] =
4438         {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
4439          '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
4440          '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
4441     UINT len = sizeof(fmtW) + 2;
4442     WCHAR *ret;
4443 
4444     if (!(ret = heap_alloc( len * sizeof(WCHAR) ))) return NULL;
4445     swprintf( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
4446     return ret;
4447 }
4448 #endif
4449 
4450 #define HW_VENDOR_AMD    0x1002
4451 #define HW_VENDOR_NVIDIA 0x10de
4452 #define HW_VENDOR_VMWARE 0x15ad
4453 #define HW_VENDOR_INTEL  0x8086
4454 
4455 #ifndef __REACTOS__
4456 
4457 static const WCHAR *get_installeddriver( UINT vendorid )
4458 {
4459     static const WCHAR driver_amdW[] = {'a','t','i','c','f','x','3','2','.','d','l','l',0};
4460     static const WCHAR driver_intelW[] = {'i','g','d','u','m','d','i','m','3','2','.','d','l','l',0};
4461     static const WCHAR driver_nvidiaW[] = {'n','v','d','3','d','u','m','.','d','l','l',0};
4462     static const WCHAR driver_wineW[] = {'w','i','n','e','.','d','l','l',0};
4463 
4464     /* FIXME: wined3d has a better table, but we cannot access this information through dxgi */
4465 
4466     if (vendorid == HW_VENDOR_AMD)
4467         return driver_amdW;
4468     else if (vendorid == HW_VENDOR_NVIDIA)
4469         return driver_nvidiaW;
4470     else if (vendorid == HW_VENDOR_INTEL)
4471         return driver_intelW;
4472     return driver_wineW;
4473 }
4474 
4475 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
4476 {
4477     static const WCHAR fmtW[] = {'%','u',' ','x',' ','%','u',' ','x',' ','%','I','6','4','u',' ','c','o','l','o','r','s',0};
4478     struct record_videocontroller *rec;
4479     HRESULT hr;
4480     IDXGIFactory *factory = NULL;
4481     IDXGIAdapter *adapter = NULL;
4482     DXGI_ADAPTER_DESC desc;
4483     UINT row = 0, hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
4484     const WCHAR *name = videocontroller_deviceidW;
4485     enum fill_status status = FILL_STATUS_UNFILTERED;
4486     WCHAR mode[44];
4487 
4488     if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
4489 
4490     memset (&desc, 0, sizeof(desc));
4491     hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
4492     if (FAILED(hr)) goto done;
4493 
4494     hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
4495     if (FAILED(hr)) goto done;
4496 
4497     hr = IDXGIAdapter_GetDesc( adapter, &desc );
4498     if (SUCCEEDED(hr))
4499     {
4500         vidmem = desc.DedicatedVideoMemory;
4501         name   = desc.Description;
4502     }
4503 
4504 done:
4505     rec = (struct record_videocontroller *)table->data;
4506     rec->adapter_dactype       = videocontroller_dactypeW;
4507     rec->adapter_ram           = vidmem;
4508     rec->availability          = 3; /* Running or Full Power */
4509     rec->config_errorcode      = 0; /* no error */
4510     rec->caption               = heap_strdupW( name );
4511     rec->current_bitsperpixel  = get_bitsperpixel( &hres, &vres );
4512     rec->current_horizontalres = hres;
4513     rec->current_refreshrate   = 0; /* default refresh rate */
4514     rec->current_scanmode      = 2; /* Unknown */
4515     rec->current_verticalres   = vres;
4516     rec->description           = heap_strdupW( name );
4517     rec->device_id             = videocontroller_deviceidW;
4518     rec->driverdate            = videocontroller_driverdateW;
4519     rec->driverversion         = videocontroller_driverversionW;
4520     rec->installeddriver       = get_installeddriver( desc.VendorId );
4521     rec->name                  = heap_strdupW( name );
4522     rec->pnpdevice_id          = get_pnpdeviceid( &desc );
4523     rec->status                = videocontroller_statusW;
4524     rec->videoarchitecture     = 2; /* Unknown */
4525     rec->videomemorytype       = 2; /* Unknown */
4526     swprintf( mode, fmtW, hres, vres, (UINT64)1 << rec->current_bitsperpixel );
4527     rec->videomodedescription  = heap_strdupW( mode );
4528     rec->videoprocessor        = heap_strdupW( name );
4529     if (!match_row( table, row, cond, &status )) free_row_values( table, row );
4530     else row++;
4531 
4532     TRACE("created %u rows\n", row);
4533     table->num_rows = row;
4534 
4535     if (adapter) IDXGIAdapter_Release( adapter );
4536     if (factory) IDXGIFactory_Release( factory );
4537     return status;
4538 }
4539 
4540 #endif /* !__REACTOS__ */
4541 
4542 #define C(c) sizeof(c)/sizeof(c[0]), c
4543 #define D(d) sizeof(d)/sizeof(d[0]), 0, (BYTE *)d
4544 static struct table builtin_classes[] =
4545 {
4546     { class_associatorsW, C(col_associator), D(data_associator) },
4547     { class_baseboardW, C(col_baseboard), 0, 0, NULL, fill_baseboard },
4548     { class_biosW, C(col_bios), 0, 0, NULL, fill_bios },
4549     { class_cdromdriveW, C(col_cdromdrive), 0, 0, NULL, fill_cdromdrive },
4550     { class_compsysW, C(col_compsys), 0, 0, NULL, fill_compsys },
4551     { class_compsysproductW, C(col_compsysproduct), 0, 0, NULL, fill_compsysproduct },
4552     { class_datafileW, C(col_datafile), 0, 0, NULL, fill_datafile },
4553     { class_desktopmonitorW, C(col_desktopmonitor), 0, 0, NULL, fill_desktopmonitor },
4554     { class_directoryW, C(col_directory), 0, 0, NULL, fill_directory },
4555     { class_diskdriveW, C(col_diskdrive), 0, 0, NULL, fill_diskdrive },
4556     { class_diskdrivetodiskpartitionW, C(col_diskdrivetodiskpartition), 0, 0, NULL, fill_diskdrivetodiskpartition },
4557     { class_diskpartitionW, C(col_diskpartition), 0, 0, NULL, fill_diskpartition },
4558     { class_displaycontrollerconfigW, C(col_displaycontrollerconfig), 0, 0, NULL, fill_displaycontrollerconfig },
4559     { class_ip4routetableW, C(col_ip4routetable), 0, 0, NULL, fill_ip4routetable },
4560     { class_logicaldiskW, C(col_logicaldisk), 0, 0, NULL, fill_logicaldisk },
4561     { class_logicaldisk2W, C(col_logicaldisk), 0, 0, NULL, fill_logicaldisk },
4562     { class_logicaldisktopartitionW, C(col_logicaldisktopartition), 0, 0, NULL, fill_logicaldisktopartition },
4563     { class_networkadapterW, C(col_networkadapter), 0, 0, NULL, fill_networkadapter },
4564     { class_networkadapterconfigW, C(col_networkadapterconfig), 0, 0, NULL, fill_networkadapterconfig },
4565     { class_operatingsystemW, C(col_operatingsystem), 0, 0, NULL, fill_operatingsystem },
4566     { class_paramsW, C(col_param), D(data_param) },
4567     { class_physicalmediaW, C(col_physicalmedia), D(data_physicalmedia) },
4568     { class_physicalmemoryW, C(col_physicalmemory), 0, 0, NULL, fill_physicalmemory },
4569     { class_pnpentityW, C(col_pnpentity), 0, 0, NULL, fill_pnpentity },
4570     { class_printerW, C(col_printer), 0, 0, NULL, fill_printer },
4571     { class_processW, C(col_process), 0, 0, NULL, fill_process },
4572     { class_processorW, C(col_processor), 0, 0, NULL, fill_processor },
4573     { class_processor2W, C(col_processor), 0, 0, NULL, fill_processor },
4574     { class_qualifiersW, C(col_qualifier), D(data_qualifier) },
4575     { class_quickfixengineeringW, C(col_quickfixengineering), D(data_quickfixengineering) },
4576     { class_serviceW, C(col_service), 0, 0, NULL, fill_service },
4577     { class_sidW, C(col_sid), 0, 0, NULL, fill_sid },
4578     { class_sounddeviceW, C(col_sounddevice), D(data_sounddevice) },
4579     { class_stdregprovW, C(col_stdregprov), D(data_stdregprov) },
4580     { class_systemsecurityW, C(col_systemsecurity), D(data_systemsecurity) },
4581     { class_systemenclosureW, C(col_systemenclosure), 0, 0, NULL, fill_systemenclosure },
4582 #ifndef __REACTOS__
4583     /* Requires dxgi.dll */
4584     { class_videocontrollerW, C(col_videocontroller), 0, 0, NULL, fill_videocontroller },
4585 #endif
4586     { class_winsatW, C(col_winsat), D(data_winsat) },
4587 };
4588 #undef C
4589 #undef D
4590 
4591 void init_table_list( void )
4592 {
4593     static struct list tables = LIST_INIT( tables );
4594     UINT i;
4595 
4596     for (i = 0; i < ARRAY_SIZE(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
4597     table_list = &tables;
4598 }
4599