wbemprox: Don't list loopback network adapters.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob4b02ea2f72a46269936ee6da51cfaae869adcebb
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
19 #define COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
23 #include "config.h"
24 #include <stdarg.h>
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "initguid.h"
31 #include "wbemcli.h"
32 #include "wbemprov.h"
33 #include "winsock2.h"
34 #include "iphlpapi.h"
35 #include "tlhelp32.h"
36 #include "d3d10.h"
37 #include "winternl.h"
38 #include "winioctl.h"
39 #include "winsvc.h"
40 #include "winver.h"
42 #include "wine/debug.h"
43 #include "wbemprox_private.h"
45 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
47 static const WCHAR class_baseboardW[] =
48 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
49 static const WCHAR class_biosW[] =
50 {'W','i','n','3','2','_','B','I','O','S',0};
51 static const WCHAR class_cdromdriveW[] =
52 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
53 static const WCHAR class_compsysW[] =
54 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
55 static const WCHAR class_datafileW[] =
56 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
57 static const WCHAR class_directoryW[] =
58 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
59 static const WCHAR class_diskdriveW[] =
60 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
61 static const WCHAR class_diskpartitionW[] =
62 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
63 static const WCHAR class_logicaldiskW[] =
64 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
65 static const WCHAR class_logicaldisk2W[] =
66 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
67 static const WCHAR class_networkadapterW[] =
68 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
69 static const WCHAR class_networkadapterconfigW[] =
70 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',
71 'C','o','n','f','i','g','u','r','a','t','i','o','n',0};
72 static const WCHAR class_osW[] =
73 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
74 static const WCHAR class_paramsW[] =
75 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
76 static const WCHAR class_physicalmediaW[] =
77 {'W','i','n','3','2','_','P','h','y','s','i','c','a','l','M','e','d','i','a',0};
78 static const WCHAR class_qualifiersW[] =
79 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
80 static const WCHAR class_process_getowner_outW[] =
81 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
82 'N','E','R','_','O','U','T',0};
83 static const WCHAR class_processorW[] =
84 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
85 static const WCHAR class_sounddeviceW[] =
86 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
87 static const WCHAR class_videocontrollerW[] =
88 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
90 static const WCHAR prop_acceptpauseW[] =
91 {'A','c','c','e','p','t','P','a','u','s','e',0};
92 static const WCHAR prop_acceptstopW[] =
93 {'A','c','c','e','p','t','S','t','o','p',0};
94 static const WCHAR prop_accessmaskW[] =
95 {'A','c','c','e','s','s','M','a','s','k',0};
96 static const WCHAR prop_adapterdactypeW[] =
97 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
98 static const WCHAR prop_adapterramW[] =
99 {'A','d','a','p','t','e','r','R','A','M',0};
100 static const WCHAR prop_adaptertypeW[] =
101 {'A','d','a','p','t','e','r','T','y','p','e',0};
102 static const WCHAR prop_addresswidthW[] =
103 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
104 static const WCHAR prop_bootableW[] =
105 {'B','o','o','t','a','b','l','e',0};
106 static const WCHAR prop_bootpartitionW[] =
107 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
108 static const WCHAR prop_captionW[] =
109 {'C','a','p','t','i','o','n',0};
110 static const WCHAR prop_classW[] =
111 {'C','l','a','s','s',0};
112 static const WCHAR prop_codesetW[] =
113 {'C','o','d','e','S','e','t',0};
114 static const WCHAR prop_commandlineW[] =
115 {'C','o','m','m','a','n','d','L','i','n','e',0};
116 static const WCHAR prop_countrycodeW[] =
117 {'C','o','u','n','t','r','y','C','o','d','e',0};
118 static const WCHAR prop_cpustatusW[] =
119 {'C','p','u','S','t','a','t','u','s',0};
120 static const WCHAR prop_csdversionW[] =
121 {'C','S','D','V','e','r','s','i','o','n',0};
122 static const WCHAR prop_currentbitsperpixelW[] =
123 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
124 static const WCHAR prop_currenthorizontalresW[] =
125 {'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};
126 static const WCHAR prop_currentverticalresW[] =
127 {'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};
128 static const WCHAR prop_defaultvalueW[] =
129 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
130 static const WCHAR prop_descriptionW[] =
131 {'D','e','s','c','r','i','p','t','i','o','n',0};
132 static const WCHAR prop_deviceidW[] =
133 {'D','e','v','i','c','e','I','d',0};
134 static const WCHAR prop_directionW[] =
135 {'D','i','r','e','c','t','i','o','n',0};
136 static const WCHAR prop_displaynameW[] =
137 {'D','i','s','p','l','a','y','N','a','m','e',0};
138 static const WCHAR prop_diskindexW[] =
139 {'D','i','s','k','I','n','d','e','x',0};
140 static const WCHAR prop_domainW[] =
141 {'D','o','m','a','i','n',0};
142 static const WCHAR prop_domainroleW[] =
143 {'D','o','m','a','i','n','R','o','l','e',0};
144 static const WCHAR prop_driveW[] =
145 {'D','r','i','v','e',0};
146 static const WCHAR prop_drivetypeW[] =
147 {'D','r','i','v','e','T','y','p','e',0};
148 static const WCHAR prop_familyW[] =
149 {'F','a','m','i','l','y',0};
150 static const WCHAR prop_filesystemW[] =
151 {'F','i','l','e','S','y','s','t','e','m',0};
152 static const WCHAR prop_flavorW[] =
153 {'F','l','a','v','o','r',0};
154 static const WCHAR prop_freespaceW[] =
155 {'F','r','e','e','S','p','a','c','e',0};
156 static const WCHAR prop_handleW[] =
157 {'H','a','n','d','l','e',0};
158 static const WCHAR prop_idW[] =
159 {'I','D',0};
160 static const WCHAR prop_identificationcodeW[] =
161 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
162 static const WCHAR prop_indexW[] =
163 {'I','n','d','e','x',0};
164 static const WCHAR prop_interfaceindexW[] =
165 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
166 static const WCHAR prop_intvalueW[] =
167 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
168 static const WCHAR prop_ipconnectionmetricW[] =
169 {'I','P','C','o','n','n','e','c','t','i','o','n','M','e','t','r','i','c',0};
170 static const WCHAR prop_ipenabledW[] =
171 {'I','P','E','n','a','b','l','e','d',0};
172 static const WCHAR prop_lastbootuptimeW[] =
173 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
174 static const WCHAR prop_localdatetimeW[] =
175 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
176 static const WCHAR prop_localeW[] =
177 {'L','o','c','a','l','e',0};
178 static const WCHAR prop_macaddressW[] =
179 {'M','A','C','A','d','d','r','e','s','s',0};
180 static const WCHAR prop_manufacturerW[] =
181 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
182 static const WCHAR prop_maxclockspeedW[] =
183 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
184 static const WCHAR prop_memberW[] =
185 {'M','e','m','b','e','r',0};
186 static const WCHAR prop_methodW[] =
187 {'M','e','t','h','o','d',0};
188 static const WCHAR prop_modelW[] =
189 {'M','o','d','e','l',0};
190 static const WCHAR prop_netconnectionstatusW[] =
191 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
192 static const WCHAR prop_numcoresW[] =
193 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
194 static const WCHAR prop_numlogicalprocessorsW[] =
195 {'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};
196 static const WCHAR prop_numprocessorsW[] =
197 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
198 static const WCHAR prop_osarchitectureW[] =
199 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
200 static const WCHAR prop_oslanguageW[] =
201 {'O','S','L','a','n','g','u','a','g','e',0};
202 static const WCHAR prop_osproductsuiteW[] =
203 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
204 static const WCHAR prop_ostypeW[] =
205 {'O','S','T','y','p','e',0};
206 static const WCHAR prop_parameterW[] =
207 {'P','a','r','a','m','e','t','e','r',0};
208 static const WCHAR prop_physicaladapterW[] =
209 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
210 static const WCHAR prop_pnpdeviceidW[] =
211 {'P','N','P','D','e','v','i','c','e','I','D',0};
212 static const WCHAR prop_pprocessidW[] =
213 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
214 static const WCHAR prop_processidW[] =
215 {'P','r','o','c','e','s','s','I','D',0};
216 static const WCHAR prop_processoridW[] =
217 {'P','r','o','c','e','s','s','o','r','I','d',0};
218 static const WCHAR prop_productnameW[] =
219 {'P','r','o','d','u','c','t','N','a','m','e',0};
220 static const WCHAR prop_releasedateW[] =
221 {'R','e','l','e','a','s','e','D','a','t','e',0};
222 static const WCHAR prop_serialnumberW[] =
223 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
224 static const WCHAR prop_servicepackmajorW[] =
225 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
226 static const WCHAR prop_servicepackminorW[] =
227 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
228 static const WCHAR prop_servicetypeW[] =
229 {'S','e','r','v','i','c','e','T','y','p','e',0};
230 static const WCHAR prop_smbiosbiosversionW[] =
231 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
232 static const WCHAR prop_startmodeW[] =
233 {'S','t','a','r','t','M','o','d','e',0};
234 static const WCHAR prop_sizeW[] =
235 {'S','i','z','e',0};
236 static const WCHAR prop_speedW[] =
237 {'S','p','e','e','d',0};
238 static const WCHAR prop_startingoffsetW[] =
239 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
240 static const WCHAR prop_stateW[] =
241 {'S','t','a','t','e',0};
242 static const WCHAR prop_strvalueW[] =
243 {'S','t','r','i','n','g','V','a','l','u','e',0};
244 static const WCHAR prop_suitemaskW[] =
245 {'S','u','i','t','e','M','a','s','k',0};
246 static const WCHAR prop_systemdirectoryW[] =
247 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
248 static const WCHAR prop_systemnameW[] =
249 {'S','y','s','t','e','m','N','a','m','e',0};
250 static const WCHAR prop_tagW[] =
251 {'T','a','g',0};
252 static const WCHAR prop_threadcountW[] =
253 {'T','h','r','e','a','d','C','o','u','n','t',0};
254 static const WCHAR prop_totalphysicalmemoryW[] =
255 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
256 static const WCHAR prop_typeW[] =
257 {'T','y','p','e',0};
258 static const WCHAR prop_uniqueidW[] =
259 {'U','n','i','q','u','e','I','d',0};
260 static const WCHAR prop_varianttypeW[] =
261 {'V','a','r','i','a','n','t','T','y','p','e',0};
262 static const WCHAR prop_versionW[] =
263 {'V','e','r','s','i','o','n',0};
265 /* column definitions must be kept in sync with record structures below */
266 static const struct column col_baseboard[] =
268 { prop_manufacturerW, CIM_STRING },
269 { prop_modelW, CIM_STRING },
270 { prop_nameW, CIM_STRING },
271 { prop_serialnumberW, CIM_STRING },
272 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
274 static const struct column col_bios[] =
276 { prop_descriptionW, CIM_STRING },
277 { prop_identificationcodeW, CIM_STRING },
278 { prop_manufacturerW, CIM_STRING },
279 { prop_releasedateW, CIM_DATETIME },
280 { prop_serialnumberW, CIM_STRING },
281 { prop_smbiosbiosversionW, CIM_STRING },
282 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
284 static const struct column col_cdromdrive[] =
286 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
287 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
288 { prop_nameW, CIM_STRING },
289 { prop_pnpdeviceidW, CIM_STRING }
291 static const struct column col_compsys[] =
293 { prop_descriptionW, CIM_STRING },
294 { prop_domainW, CIM_STRING },
295 { prop_domainroleW, CIM_UINT16 },
296 { prop_manufacturerW, CIM_STRING },
297 { prop_modelW, CIM_STRING },
298 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
299 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
300 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
301 { prop_totalphysicalmemoryW, CIM_UINT64 }
303 static const struct column col_datafile[] =
305 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
306 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
308 static const struct column col_directory[] =
310 { prop_accessmaskW, CIM_UINT32 },
311 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
313 static const struct column col_diskdrive[] =
315 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
316 { prop_indexW, CIM_UINT32, VT_I4 },
317 { prop_manufacturerW, CIM_STRING },
318 { prop_modelW, CIM_STRING },
319 { prop_serialnumberW, CIM_STRING }
321 static const struct column col_diskpartition[] =
323 { prop_bootableW, CIM_BOOLEAN },
324 { prop_bootpartitionW, CIM_BOOLEAN },
325 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
326 { prop_diskindexW, CIM_UINT32, VT_I4 },
327 { prop_indexW, CIM_UINT32, VT_I4 },
328 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
329 { prop_sizeW, CIM_UINT64 },
330 { prop_startingoffsetW, CIM_UINT64 },
331 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
333 static const struct column col_logicaldisk[] =
335 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
336 { prop_drivetypeW, CIM_UINT32, VT_I4 },
337 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
338 { prop_freespaceW, CIM_UINT64 },
339 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
340 { prop_sizeW, CIM_UINT64 }
342 static const struct column col_networkadapter[] =
344 { prop_adaptertypeW, CIM_STRING },
345 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
346 { prop_indexW, CIM_UINT32, VT_I4 },
347 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
348 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
349 { prop_manufacturerW, CIM_STRING },
350 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
351 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
352 { prop_physicaladapterW, CIM_BOOLEAN },
353 { prop_pnpdeviceidW, CIM_STRING },
354 { prop_speedW, CIM_UINT64 }
356 static const struct column col_networkadapterconfig[] =
358 { prop_indexW, CIM_UINT32|COL_FLAG_KEY },
359 { prop_ipconnectionmetricW, CIM_UINT32 },
360 { prop_ipenabledW, CIM_BOOLEAN },
361 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
363 static const struct column col_os[] =
365 { prop_captionW, CIM_STRING },
366 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
367 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
368 { prop_csdversionW, CIM_STRING },
369 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
370 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
371 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
372 { prop_nameW, CIM_STRING },
373 { prop_osarchitectureW, CIM_STRING },
374 { prop_oslanguageW, CIM_UINT32, VT_I4 },
375 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
376 { prop_ostypeW, CIM_UINT16, VT_I4 },
377 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
378 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
379 { prop_suitemaskW, CIM_UINT32, VT_I4 },
380 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
381 { prop_versionW, CIM_STRING }
383 static const struct column col_param[] =
385 { prop_classW, CIM_STRING },
386 { prop_methodW, CIM_STRING },
387 { prop_directionW, CIM_SINT32 },
388 { prop_parameterW, CIM_STRING },
389 { prop_typeW, CIM_UINT32 },
390 { prop_varianttypeW, CIM_UINT32 },
391 { prop_defaultvalueW, CIM_UINT32 }
393 static const struct column col_physicalmedia[] =
395 { prop_serialnumberW, CIM_STRING }
397 static const struct column col_process[] =
399 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
400 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
401 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
402 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
403 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
404 { prop_pprocessidW, CIM_UINT32, VT_I4 },
405 { prop_processidW, CIM_UINT32, VT_I4 },
406 { prop_threadcountW, CIM_UINT32, VT_I4 },
407 /* methods */
408 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
410 static const struct column col_processor[] =
412 { prop_addresswidthW, CIM_UINT16, VT_I4 },
413 { prop_cpustatusW, CIM_UINT16 },
414 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
415 { prop_familyW, CIM_UINT16, VT_I4 },
416 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
417 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
418 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
419 { prop_numcoresW, CIM_UINT32, VT_I4 },
420 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
421 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
422 { prop_uniqueidW, CIM_STRING }
424 static const struct column col_qualifier[] =
426 { prop_classW, CIM_STRING },
427 { prop_memberW, CIM_STRING },
428 { prop_typeW, CIM_UINT32 },
429 { prop_flavorW, CIM_SINT32 },
430 { prop_nameW, CIM_STRING },
431 { prop_intvalueW, CIM_SINT32 },
432 { prop_strvalueW, CIM_STRING }
434 static const struct column col_service[] =
436 { prop_acceptpauseW, CIM_BOOLEAN },
437 { prop_acceptstopW, CIM_BOOLEAN },
438 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
439 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
440 { prop_processidW, CIM_UINT32 },
441 { prop_servicetypeW, CIM_STRING },
442 { prop_startmodeW, CIM_STRING },
443 { prop_stateW, CIM_STRING },
444 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
445 /* methods */
446 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
447 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
448 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
449 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
451 static const struct column col_sounddevice[] =
453 { prop_nameW, CIM_STRING },
454 { prop_productnameW, CIM_STRING }
456 static const struct column col_stdregprov[] =
458 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
459 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
460 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
462 static const struct column col_videocontroller[] =
464 { prop_adapterdactypeW, CIM_STRING },
465 { prop_adapterramW, CIM_UINT32, VT_I4 },
466 { prop_currentbitsperpixelW, CIM_UINT32 },
467 { prop_currenthorizontalresW, CIM_UINT32 },
468 { prop_currentverticalresW, CIM_UINT32 },
469 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
470 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
471 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
472 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
475 static const WCHAR baseboard_manufacturerW[] =
476 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
477 static const WCHAR baseboard_serialnumberW[] =
478 {'N','o','n','e',0};
479 static const WCHAR baseboard_tagW[] =
480 {'B','a','s','e',' ','B','o','a','r','d',0};
481 static const WCHAR bios_descriptionW[] =
482 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
483 static const WCHAR bios_manufacturerW[] =
484 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
485 static const WCHAR bios_releasedateW[] =
486 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
487 static const WCHAR bios_serialnumberW[] =
488 {'0',0};
489 static const WCHAR bios_smbiosbiosversionW[] =
490 {'W','i','n','e',0};
491 static const WCHAR bios_versionW[] =
492 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
493 static const WCHAR cdromdrive_nameW[] =
494 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
495 static const WCHAR cdromdrive_pnpdeviceidW[]=
496 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
497 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
498 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
499 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
500 static const WCHAR compsys_descriptionW[] =
501 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
502 static const WCHAR compsys_domainW[] =
503 {'W','O','R','K','G','R','O','U','P',0};
504 static const WCHAR compsys_manufacturerW[] =
505 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
506 static const WCHAR compsys_modelW[] =
507 {'W','i','n','e',0};
508 static const WCHAR diskdrive_deviceidW[] =
509 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
510 static const WCHAR diskdrive_modelW[] =
511 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
512 static const WCHAR diskdrive_manufacturerW[] =
513 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
514 static const WCHAR diskdrive_serialW[] =
515 {'W','I','N','E','H','D','I','S','K',0};
516 static const WCHAR networkadapter_pnpdeviceidW[]=
517 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
518 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
519 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
520 static const WCHAR os_captionW[] =
521 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
522 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
523 static const WCHAR os_csdversionW[] =
524 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
525 static const WCHAR os_32bitW[] =
526 {'3','2','-','b','i','t',0};
527 static const WCHAR os_64bitW[] =
528 {'6','4','-','b','i','t',0};
529 static const WCHAR os_nameW[] =
530 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
531 'P','r','o','f','e','s','s','i','o','n','a','l','|','C',':','\\','W','I','N','D','O','W','S',
532 '|','\\','D','e','v','i','c','e','\\','H','a','r','d','d','i','s','k','0',
533 '\\','P','a','r','t','i','t','i','o','n','1',0};
534 static const WCHAR os_versionW[] =
535 {'5','.','1','.','2','6','0','0',0};
536 static const WCHAR sounddevice_productnameW[] =
537 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
538 static const WCHAR videocontroller_dactypeW[] =
539 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
540 static const WCHAR videocontroller_deviceidW[] =
541 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
543 #include "pshpack1.h"
544 struct record_baseboard
546 const WCHAR *manufacturer;
547 const WCHAR *model;
548 const WCHAR *name;
549 const WCHAR *serialnumber;
550 const WCHAR *tag;
552 struct record_bios
554 const WCHAR *description;
555 const WCHAR *identificationcode;
556 const WCHAR *manufacturer;
557 const WCHAR *releasedate;
558 const WCHAR *serialnumber;
559 const WCHAR *smbiosbiosversion;
560 const WCHAR *version;
562 struct record_cdromdrive
564 const WCHAR *device_id;
565 const WCHAR *drive;
566 const WCHAR *name;
567 const WCHAR *pnpdevice_id;
569 struct record_computersystem
571 const WCHAR *description;
572 const WCHAR *domain;
573 UINT16 domainrole;
574 const WCHAR *manufacturer;
575 const WCHAR *model;
576 const WCHAR *name;
577 UINT32 num_logical_processors;
578 UINT32 num_processors;
579 UINT64 total_physical_memory;
581 struct record_datafile
583 const WCHAR *name;
584 const WCHAR *version;
586 struct record_directory
588 UINT32 accessmask;
589 const WCHAR *name;
591 struct record_diskdrive
593 const WCHAR *device_id;
594 UINT32 index;
595 const WCHAR *manufacturer;
596 const WCHAR *name;
597 const WCHAR *serialnumber;
599 struct record_diskpartition
601 int bootable;
602 int bootpartition;
603 const WCHAR *device_id;
604 UINT32 diskindex;
605 UINT32 index;
606 const WCHAR *pnpdevice_id;
607 UINT64 size;
608 UINT64 startingoffset;
609 const WCHAR *type;
611 struct record_logicaldisk
613 const WCHAR *device_id;
614 UINT32 drivetype;
615 const WCHAR *filesystem;
616 UINT64 freespace;
617 const WCHAR *name;
618 UINT64 size;
620 struct record_networkadapter
622 const WCHAR *adaptertype;
623 const WCHAR *device_id;
624 UINT32 index;
625 UINT32 interface_index;
626 const WCHAR *mac_address;
627 const WCHAR *manufacturer;
628 const WCHAR *name;
629 UINT16 netconnection_status;
630 int physicaladapter;
631 const WCHAR *pnpdevice_id;
632 UINT64 speed;
634 struct record_networkadapterconfig
636 UINT32 index;
637 UINT32 ipconnectionmetric;
638 int ipenabled;
639 const WCHAR *mac_address;
641 struct record_operatingsystem
643 const WCHAR *caption;
644 const WCHAR *codeset;
645 const WCHAR *countrycode;
646 const WCHAR *csdversion;
647 const WCHAR *lastbootuptime;
648 const WCHAR *localdatetime;
649 const WCHAR *locale;
650 const WCHAR *name;
651 const WCHAR *osarchitecture;
652 UINT32 oslanguage;
653 UINT32 osproductsuite;
654 UINT16 ostype;
655 UINT16 servicepackmajor;
656 UINT16 servicepackminor;
657 UINT32 suitemask;
658 const WCHAR *systemdirectory;
659 const WCHAR *version;
661 struct record_param
663 const WCHAR *class;
664 const WCHAR *method;
665 INT32 direction;
666 const WCHAR *parameter;
667 UINT32 type;
668 UINT32 varianttype;
669 UINT32 defaultvalue;
671 struct record_physicalmedia
673 const WCHAR *serialnumber;
675 struct record_process
677 const WCHAR *caption;
678 const WCHAR *commandline;
679 const WCHAR *description;
680 const WCHAR *handle;
681 const WCHAR *name;
682 UINT32 pprocess_id;
683 UINT32 process_id;
684 UINT32 thread_count;
685 /* methods */
686 class_method *get_owner;
688 struct record_processor
690 UINT16 addresswidth;
691 UINT16 cpu_status;
692 const WCHAR *device_id;
693 UINT16 family;
694 const WCHAR *manufacturer;
695 UINT32 maxclockspeed;
696 const WCHAR *name;
697 UINT32 num_cores;
698 UINT32 num_logical_processors;
699 const WCHAR *processor_id;
700 const WCHAR *unique_id;
702 struct record_qualifier
704 const WCHAR *class;
705 const WCHAR *member;
706 UINT32 type;
707 INT32 flavor;
708 const WCHAR *name;
709 INT32 intvalue;
710 const WCHAR *strvalue;
712 struct record_service
714 int accept_pause;
715 int accept_stop;
716 const WCHAR *displayname;
717 const WCHAR *name;
718 UINT32 process_id;
719 const WCHAR *servicetype;
720 const WCHAR *startmode;
721 const WCHAR *state;
722 const WCHAR *systemname;
723 /* methods */
724 class_method *pause_service;
725 class_method *resume_service;
726 class_method *start_service;
727 class_method *stop_service;
729 struct record_sounddevice
731 const WCHAR *name;
732 const WCHAR *productname;
734 struct record_stdregprov
736 class_method *enumkey;
737 class_method *enumvalues;
738 class_method *getstringvalue;
740 struct record_videocontroller
742 const WCHAR *adapter_dactype;
743 UINT32 adapter_ram;
744 UINT32 current_bitsperpixel;
745 UINT32 current_horizontalres;
746 UINT32 current_verticalres;
747 const WCHAR *description;
748 const WCHAR *device_id;
749 const WCHAR *name;
750 const WCHAR *pnpdevice_id;
752 #include "poppack.h"
754 static const struct record_baseboard data_baseboard[] =
756 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
758 static const struct record_bios data_bios[] =
760 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
761 bios_smbiosbiosversionW, bios_versionW }
763 static const struct record_diskdrive data_diskdrive[] =
765 { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
767 static const struct record_param data_param[] =
769 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
770 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
771 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
772 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
773 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
774 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
775 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
776 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
777 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
778 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
779 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
780 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
781 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
782 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
783 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
784 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
785 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
786 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
787 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
788 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
789 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
792 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
793 WBEM_FLAVOR_ORIGIN_PROPAGATED)
795 static const struct record_physicalmedia data_physicalmedia[] =
797 { diskdrive_serialW }
799 static const struct record_qualifier data_qualifier[] =
801 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
802 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
804 static const struct record_sounddevice data_sounddevice[] =
806 { sounddevice_productnameW, sounddevice_productnameW }
808 static const struct record_stdregprov data_stdregprov[] =
810 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
813 /* check if row matches condition and update status */
814 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
816 LONGLONG val;
817 UINT type;
819 if (!cond)
821 *status = FILL_STATUS_UNFILTERED;
822 return TRUE;
824 if (eval_cond( table, row, cond, &val, &type ) != S_OK)
826 *status = FILL_STATUS_FAILED;
827 return FALSE;
829 *status = FILL_STATUS_FILTERED;
830 return val != 0;
833 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
835 if (!table->num_rows_allocated)
837 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
838 table->num_rows_allocated = row_count;
839 return TRUE;
841 if (row_count >= table->num_rows_allocated)
843 BYTE *data;
844 UINT count = table->num_rows_allocated * 2;
845 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
846 table->data = data;
847 table->num_rows_allocated = count;
849 return TRUE;
852 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
854 static const WCHAR fmtW[] = {'%','c',':',0};
855 WCHAR drive[3], root[] = {'A',':','\\',0};
856 struct record_cdromdrive *rec;
857 UINT i, row = 0, offset = 0;
858 DWORD drives = GetLogicalDrives();
859 enum fill_status status = FILL_STATUS_UNFILTERED;
861 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
863 for (i = 0; i < sizeof(drives); i++)
865 if (drives & (1 << i))
867 root[0] = 'A' + i;
868 if (GetDriveTypeW( root ) != DRIVE_CDROM)
869 continue;
871 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
873 rec = (struct record_cdromdrive *)(table->data + offset);
874 rec->device_id = cdromdrive_pnpdeviceidW;
875 sprintfW( drive, fmtW, 'A' + i );
876 rec->drive = heap_strdupW( drive );
877 rec->name = cdromdrive_nameW;
878 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
879 if (!match_row( table, row, cond, &status ))
881 free_row_values( table, row );
882 continue;
884 offset += sizeof(*rec);
885 row++;
888 TRACE("created %u rows\n", row);
889 table->num_rows = row;
890 return status;
893 static UINT get_processor_count(void)
895 SYSTEM_BASIC_INFORMATION info;
897 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
898 return info.NumberOfProcessors;
901 static UINT get_logical_processor_count( UINT *num_cores )
903 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
904 UINT i, j, count = 0;
905 NTSTATUS status;
906 ULONG len;
908 if (num_cores) *num_cores = get_processor_count();
909 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
910 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
912 if (!(info = heap_alloc( len ))) return get_processor_count();
913 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
914 if (status != STATUS_SUCCESS)
916 heap_free( info );
917 return get_processor_count();
919 if (num_cores) *num_cores = 0;
920 for (i = 0; i < len / sizeof(*info); i++)
922 if (info[i].Relationship == RelationProcessorCore)
924 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
926 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
928 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
931 heap_free( info );
932 return count;
935 static UINT64 get_total_physical_memory(void)
937 MEMORYSTATUSEX status;
939 status.dwLength = sizeof(status);
940 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
941 return status.ullTotalPhys;
944 static WCHAR *get_computername(void)
946 WCHAR *ret;
947 DWORD size = MAX_COMPUTERNAME_LENGTH;
949 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
950 GetComputerNameW( ret, &size );
951 return ret;
954 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
956 struct record_computersystem *rec;
957 enum fill_status status = FILL_STATUS_UNFILTERED;
958 UINT row = 0;
960 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
962 rec = (struct record_computersystem *)table->data;
963 rec->description = compsys_descriptionW;
964 rec->domain = compsys_domainW;
965 rec->domainrole = 0; /* standalone workstation */
966 rec->manufacturer = compsys_manufacturerW;
967 rec->model = compsys_modelW;
968 rec->name = get_computername();
969 rec->num_logical_processors = get_logical_processor_count( NULL );
970 rec->num_processors = get_processor_count();
971 rec->total_physical_memory = get_total_physical_memory();
972 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
973 else row++;
975 TRACE("created %u rows\n", row);
976 table->num_rows = row;
977 return status;
980 struct dirstack
982 WCHAR **dirs;
983 UINT *len_dirs;
984 UINT num_dirs;
985 UINT num_allocated;
988 static struct dirstack *alloc_dirstack( UINT size )
990 struct dirstack *dirstack;
992 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
993 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
995 heap_free( dirstack );
996 return NULL;
998 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
1000 heap_free( dirstack->dirs );
1001 heap_free( dirstack );
1002 return NULL;
1004 dirstack->num_dirs = 0;
1005 dirstack->num_allocated = size;
1006 return dirstack;
1009 static void clear_dirstack( struct dirstack *dirstack )
1011 UINT i;
1012 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
1013 dirstack->num_dirs = 0;
1016 static void free_dirstack( struct dirstack *dirstack )
1018 clear_dirstack( dirstack );
1019 heap_free( dirstack->dirs );
1020 heap_free( dirstack->len_dirs );
1021 heap_free( dirstack );
1024 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1026 UINT size, i = dirstack->num_dirs;
1028 if (!dir) return FALSE;
1030 if (i == dirstack->num_allocated)
1032 WCHAR **tmp;
1033 UINT *len_tmp;
1035 size = dirstack->num_allocated * 2;
1036 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1037 dirstack->dirs = tmp;
1038 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1039 dirstack->len_dirs = len_tmp;
1040 dirstack->num_allocated = size;
1042 dirstack->dirs[i] = dir;
1043 dirstack->len_dirs[i] = len;
1044 dirstack->num_dirs++;
1045 return TRUE;
1048 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1050 if (!dirstack->num_dirs)
1052 *len = 0;
1053 return NULL;
1055 dirstack->num_dirs--;
1056 *len = dirstack->len_dirs[dirstack->num_dirs];
1057 return dirstack->dirs[dirstack->num_dirs];
1060 static const WCHAR *peek_dir( struct dirstack *dirstack )
1062 if (!dirstack->num_dirs) return NULL;
1063 return dirstack->dirs[dirstack->num_dirs - 1];
1066 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1068 UINT i = 0;
1069 WCHAR *ret;
1071 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1072 ret[i++] = drive;
1073 ret[i++] = ':';
1074 ret[i++] = '\\';
1075 if (path && len)
1077 memcpy( ret + i, path, len * sizeof(WCHAR) );
1078 i += len;
1079 ret[i++] = '\\';
1081 ret[i++] = '*';
1082 ret[i] = 0;
1083 return ret;
1086 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1088 UINT i = 0, len = 0;
1089 const WCHAR *p;
1090 WCHAR *ret;
1092 for (p = path; *p; p++)
1094 if (*p == '\\') len += 2;
1095 else len++;
1097 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1098 ret[i++] = drive;
1099 ret[i++] = ':';
1100 ret[i++] = '\\';
1101 ret[i++] = '\\';
1102 for (p = path; *p; p++)
1104 if (*p != '\\') ret[i++] = *p;
1105 else
1107 ret[i++] = '\\';
1108 ret[i++] = '\\';
1111 ret[i] = 0;
1112 return ret;
1115 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1117 const WCHAR *p = path, *start;
1118 UINT len, i;
1119 WCHAR *ret;
1121 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1122 start = path + 4;
1123 len = strlenW( start );
1124 p = start + len - 1;
1125 if (*p == '\\') return NULL;
1127 while (p >= start && *p != '\\') { len--; p--; };
1128 while (p >= start && *p == '\\') { len--; p--; };
1130 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1131 for (i = 0, p = start; p < start + len; p++)
1133 if (p[0] == '\\' && p[1] == '\\')
1135 ret[i++] = '\\';
1136 p++;
1138 else ret[i++] = *p;
1140 ret[i] = 0;
1141 *ret_len = i;
1142 return ret;
1145 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1147 UINT i;
1148 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1149 return FALSE;
1152 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1153 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1155 const struct expr *left, *right;
1157 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1159 left = cond->u.expr.left;
1160 right = cond->u.expr.right;
1161 if (cond->u.expr.op == OP_EQ)
1163 UINT len;
1164 WCHAR *path;
1165 const WCHAR *str = NULL;
1167 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1168 !strcmpW( left->u.propval->name, prop_nameW ) &&
1169 toupperW( right->u.sval[0] ) == toupperW( root ))
1171 str = right->u.sval;
1173 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1174 !strcmpW( right->u.propval->name, prop_nameW ) &&
1175 toupperW( left->u.sval[0] ) == toupperW( root ))
1177 str = left->u.sval;
1179 if (str && (path = build_dirname( str, &len )))
1181 if (seen_dir( dirstack, path ))
1183 heap_free( path );
1184 return ++*count;
1186 else if (push_dir( dirstack, path, len )) return ++*count;
1187 heap_free( path );
1188 return *count = 0;
1191 else if (cond->u.expr.op == OP_OR)
1193 UINT left_count = 0, right_count = 0;
1195 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1196 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1197 return *count += left_count + right_count;
1199 return *count = 0;
1202 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1204 UINT len_path = 0, len_segment = strlenW( segment );
1205 WCHAR *ret;
1207 *len = 0;
1208 if (path) len_path = strlenW( path );
1209 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1210 if (path && len_path)
1212 memcpy( ret, path, len_path * sizeof(WCHAR) );
1213 ret[len_path] = '\\';
1214 *len += len_path + 1;
1216 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1217 *len += len_segment;
1218 ret[*len] = 0;
1219 return ret;
1222 static WCHAR *get_file_version( const WCHAR *filename )
1224 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1225 VS_FIXEDFILEINFO *info;
1226 DWORD size;
1227 void *block;
1228 WCHAR *ret;
1230 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1231 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1233 heap_free( ret );
1234 return NULL;
1236 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1237 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1239 heap_free( block );
1240 heap_free( ret );
1241 return NULL;
1243 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1244 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1245 heap_free( block );
1246 return ret;
1249 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1251 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1252 struct record_datafile *rec;
1253 UINT i, len, row = 0, offset = 0, num_expected_rows;
1254 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1255 DWORD drives = GetLogicalDrives();
1256 WIN32_FIND_DATAW data;
1257 HANDLE handle;
1258 struct dirstack *dirstack = alloc_dirstack(2);
1259 enum fill_status status = FILL_STATUS_UNFILTERED;
1261 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1263 for (i = 0; i < sizeof(drives); i++)
1265 if (!(drives & (1 << i))) continue;
1267 root[0] = 'A' + i;
1268 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1270 num_expected_rows = 0;
1271 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1273 for (;;)
1275 path = pop_dir( dirstack, &len );
1276 if (!(glob = build_glob( root[0], path, len )))
1278 status = FILL_STATUS_FAILED;
1279 goto done;
1281 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1285 if (!resize_table( table, row + 1, sizeof(*rec) ))
1287 status = FILL_STATUS_FAILED;
1288 goto done;
1290 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1291 new_path = append_path( path, data.cFileName, &len );
1293 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1295 if (push_dir( dirstack, new_path, len )) continue;
1296 heap_free( new_path );
1297 status = FILL_STATUS_FAILED;
1298 goto done;
1300 rec = (struct record_datafile *)(table->data + offset);
1301 rec->name = build_name( root[0], new_path );
1302 rec->version = get_file_version( rec->name );
1303 if (!match_row( table, row, cond, &status ))
1305 free_row_values( table, row );
1306 continue;
1308 else if (num_expected_rows && row == num_expected_rows - 1)
1310 row++;
1311 FindClose( handle );
1312 status = FILL_STATUS_FILTERED;
1313 goto done;
1315 offset += sizeof(*rec);
1316 row++;
1318 while (FindNextFileW( handle, &data ));
1319 FindClose( handle );
1321 if (!peek_dir( dirstack )) break;
1322 heap_free( glob );
1323 heap_free( path );
1327 done:
1328 free_dirstack( dirstack );
1329 heap_free( glob );
1330 heap_free( path );
1332 TRACE("created %u rows\n", row);
1333 table->num_rows = row;
1334 return status;
1337 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1339 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1340 struct record_directory *rec;
1341 UINT i, len, row = 0, offset = 0, num_expected_rows;
1342 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1343 DWORD drives = GetLogicalDrives();
1344 WIN32_FIND_DATAW data;
1345 HANDLE handle;
1346 struct dirstack *dirstack;
1347 enum fill_status status = FILL_STATUS_UNFILTERED;
1349 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1351 dirstack = alloc_dirstack(2);
1353 for (i = 0; i < sizeof(drives); i++)
1355 if (!(drives & (1 << i))) continue;
1357 root[0] = 'A' + i;
1358 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1360 num_expected_rows = 0;
1361 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1363 for (;;)
1365 path = pop_dir( dirstack, &len );
1366 if (!(glob = build_glob( root[0], path, len )))
1368 status = FILL_STATUS_FAILED;
1369 goto done;
1371 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1375 if (!resize_table( table, row + 1, sizeof(*rec) ))
1377 FindClose( handle );
1378 status = FILL_STATUS_FAILED;
1379 goto done;
1381 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1382 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1383 continue;
1385 new_path = append_path( path, data.cFileName, &len );
1386 if (!(push_dir( dirstack, new_path, len )))
1388 heap_free( new_path );
1389 FindClose( handle );
1390 status = FILL_STATUS_FAILED;
1391 goto done;
1393 rec = (struct record_directory *)(table->data + offset);
1394 rec->accessmask = FILE_ALL_ACCESS;
1395 rec->name = build_name( root[0], new_path );
1396 if (!match_row( table, row, cond, &status ))
1398 free_row_values( table, row );
1399 continue;
1401 else if (num_expected_rows && row == num_expected_rows - 1)
1403 row++;
1404 FindClose( handle );
1405 status = FILL_STATUS_FILTERED;
1406 goto done;
1408 offset += sizeof(*rec);
1409 row++;
1411 while (FindNextFileW( handle, &data ));
1412 FindClose( handle );
1414 if (!peek_dir( dirstack )) break;
1415 heap_free( glob );
1416 heap_free( path );
1420 done:
1421 free_dirstack( dirstack );
1422 heap_free( glob );
1423 heap_free( path );
1425 TRACE("created %u rows\n", row);
1426 table->num_rows = row;
1427 return status;
1430 static WCHAR *get_filesystem( const WCHAR *root )
1432 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1433 WCHAR buffer[MAX_PATH + 1];
1435 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1436 return heap_strdupW( buffer );
1437 return heap_strdupW( ntfsW );
1440 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1442 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1443 ULARGE_INTEGER free;
1444 DISK_GEOMETRY_EX info;
1445 HANDLE handle;
1447 free.QuadPart = 512 * 1024 * 1024;
1448 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1450 root[4] = dir[0];
1451 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1452 if (handle != INVALID_HANDLE_VALUE)
1454 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1455 *disksize = info.DiskSize.QuadPart;
1456 CloseHandle( handle );
1458 return free.QuadPart;
1461 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1463 static const WCHAR fmtW[] =
1464 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1465 WCHAR device_id[32], root[] = {'A',':','\\',0};
1466 struct record_diskpartition *rec;
1467 UINT i, row = 0, offset = 0, type, index = 0;
1468 UINT64 size = 1024 * 1024 * 1024;
1469 DWORD drives = GetLogicalDrives();
1470 enum fill_status status = FILL_STATUS_UNFILTERED;
1472 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1474 for (i = 0; i < sizeof(drives); i++)
1476 if (drives & (1 << i))
1478 root[0] = 'A' + i;
1479 type = GetDriveTypeW( root );
1480 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1481 continue;
1483 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1485 rec = (struct record_diskpartition *)(table->data + offset);
1486 rec->bootable = (i == 2) ? -1 : 0;
1487 rec->bootpartition = (i == 2) ? -1 : 0;
1488 sprintfW( device_id, fmtW, index );
1489 rec->device_id = heap_strdupW( device_id );
1490 rec->diskindex = index;
1491 rec->index = 0;
1492 rec->pnpdevice_id = heap_strdupW( device_id );
1493 get_freespace( root, &size );
1494 rec->size = size;
1495 rec->startingoffset = 0;
1496 rec->type = get_filesystem( root );
1497 if (!match_row( table, row, cond, &status ))
1499 free_row_values( table, row );
1500 continue;
1502 offset += sizeof(*rec);
1503 row++;
1504 index++;
1507 TRACE("created %u rows\n", row);
1508 table->num_rows = row;
1509 return status;
1512 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1514 static const WCHAR fmtW[] = {'%','c',':',0};
1515 WCHAR device_id[3], root[] = {'A',':','\\',0};
1516 struct record_logicaldisk *rec;
1517 UINT i, row = 0, offset = 0, type;
1518 UINT64 size = 1024 * 1024 * 1024;
1519 DWORD drives = GetLogicalDrives();
1520 enum fill_status status = FILL_STATUS_UNFILTERED;
1522 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1524 for (i = 0; i < sizeof(drives); i++)
1526 if (drives & (1 << i))
1528 root[0] = 'A' + i;
1529 type = GetDriveTypeW( root );
1530 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1531 continue;
1533 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1535 rec = (struct record_logicaldisk *)(table->data + offset);
1536 sprintfW( device_id, fmtW, 'A' + i );
1537 rec->device_id = heap_strdupW( device_id );
1538 rec->drivetype = type;
1539 rec->filesystem = get_filesystem( root );
1540 rec->freespace = get_freespace( root, &size );
1541 rec->name = heap_strdupW( device_id );
1542 rec->size = size;
1543 if (!match_row( table, row, cond, &status ))
1545 free_row_values( table, row );
1546 continue;
1548 offset += sizeof(*rec);
1549 row++;
1552 TRACE("created %u rows\n", row);
1553 table->num_rows = row;
1554 return status;
1557 static UINT16 get_connection_status( IF_OPER_STATUS status )
1559 switch (status)
1561 case IfOperStatusDown:
1562 return 0; /* Disconnected */
1563 case IfOperStatusUp:
1564 return 2; /* Connected */
1565 default:
1566 ERR("unhandled status %u\n", status);
1567 break;
1569 return 0;
1571 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1573 static const WCHAR fmtW[] =
1574 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1575 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1576 WCHAR *ret;
1578 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1579 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1580 return ret;
1582 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1584 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1585 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1586 static const WCHAR firewireW[] = {'1','3','9','4',0};
1587 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1589 switch (type)
1591 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1592 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1593 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1594 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1595 default: *physical = 0; return NULL;
1599 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1601 static const WCHAR fmtW[] = {'%','u',0};
1602 WCHAR device_id[11];
1603 struct record_networkadapter *rec;
1604 IP_ADAPTER_ADDRESSES *aa, *buffer;
1605 UINT row = 0, offset = 0, count = 0;
1606 DWORD size = 0, ret;
1607 int physical;
1608 enum fill_status status = FILL_STATUS_UNFILTERED;
1610 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1611 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1613 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1614 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1616 heap_free( buffer );
1617 return FILL_STATUS_FAILED;
1619 for (aa = buffer; aa; aa = aa->Next)
1621 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1623 if (!resize_table( table, count, sizeof(*rec) ))
1625 heap_free( buffer );
1626 return FILL_STATUS_FAILED;
1628 for (aa = buffer; aa; aa = aa->Next)
1630 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1632 rec = (struct record_networkadapter *)(table->data + offset);
1633 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1634 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1635 rec->device_id = heap_strdupW( device_id );
1636 rec->index = aa->u.s.IfIndex;
1637 rec->interface_index = aa->u.s.IfIndex;
1638 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1639 rec->manufacturer = compsys_manufacturerW;
1640 rec->name = heap_strdupW( aa->FriendlyName );
1641 rec->netconnection_status = get_connection_status( aa->OperStatus );
1642 rec->physicaladapter = physical;
1643 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1644 rec->speed = 1000000;
1645 if (!match_row( table, row, cond, &status ))
1647 free_row_values( table, row );
1648 continue;
1650 offset += sizeof(*rec);
1651 row++;
1653 TRACE("created %u rows\n", row);
1654 table->num_rows = row;
1656 heap_free( buffer );
1657 return status;
1660 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1662 struct record_networkadapterconfig *rec;
1663 IP_ADAPTER_ADDRESSES *aa, *buffer;
1664 UINT row = 0, offset = 0, count = 0;
1665 DWORD size = 0, ret;
1666 enum fill_status status = FILL_STATUS_UNFILTERED;
1668 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1669 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1671 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1672 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1674 heap_free( buffer );
1675 return FILL_STATUS_FAILED;
1677 for (aa = buffer; aa; aa = aa->Next)
1679 if (aa->IfType != IF_TYPE_SOFTWARE_LOOPBACK) count++;
1681 if (!resize_table( table, count, sizeof(*rec) ))
1683 heap_free( buffer );
1684 return FILL_STATUS_FAILED;
1686 for (aa = buffer; aa; aa = aa->Next)
1688 if (aa->IfType == IF_TYPE_SOFTWARE_LOOPBACK) continue;
1690 rec = (struct record_networkadapterconfig *)(table->data + offset);
1691 rec->index = aa->u.s.IfIndex;
1692 rec->ipconnectionmetric = 20;
1693 rec->ipenabled = -1;
1694 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1695 if (!match_row( table, row, cond, &status ))
1697 free_row_values( table, row );
1698 continue;
1700 offset += sizeof(*rec);
1701 row++;
1703 TRACE("created %u rows\n", row);
1704 table->num_rows = row;
1706 heap_free( buffer );
1707 return status;
1710 static WCHAR *get_cmdline( DWORD process_id )
1712 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1713 return NULL; /* FIXME handle different process case */
1716 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1718 static const WCHAR fmtW[] = {'%','u',0};
1719 WCHAR handle[11];
1720 struct record_process *rec;
1721 PROCESSENTRY32W entry;
1722 HANDLE snap;
1723 enum fill_status status = FILL_STATUS_FAILED;
1724 UINT row = 0, offset = 0;
1726 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1727 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1729 entry.dwSize = sizeof(entry);
1730 if (!Process32FirstW( snap, &entry )) goto done;
1731 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1735 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1737 rec = (struct record_process *)(table->data + offset);
1738 rec->caption = heap_strdupW( entry.szExeFile );
1739 rec->commandline = get_cmdline( entry.th32ProcessID );
1740 rec->description = heap_strdupW( entry.szExeFile );
1741 sprintfW( handle, fmtW, entry.th32ProcessID );
1742 rec->handle = heap_strdupW( handle );
1743 rec->name = heap_strdupW( entry.szExeFile );
1744 rec->process_id = entry.th32ProcessID;
1745 rec->pprocess_id = entry.th32ParentProcessID;
1746 rec->thread_count = entry.cntThreads;
1747 rec->get_owner = process_get_owner;
1748 if (!match_row( table, row, cond, &status ))
1750 free_row_values( table, row );
1751 continue;
1753 offset += sizeof(*rec);
1754 row++;
1755 } while (Process32NextW( snap, &entry ));
1757 TRACE("created %u rows\n", row);
1758 table->num_rows = row;
1759 status = FILL_STATUS_UNFILTERED;
1761 done:
1762 CloseHandle( snap );
1763 return status;
1766 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1768 #ifdef __i386__
1769 __asm__("pushl %%ebx\n\t"
1770 "cpuid\n\t"
1771 "movl %%ebx, %%esi\n\t"
1772 "popl %%ebx"
1773 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1774 : "0" (ax));
1775 #endif
1778 static void get_processor_id( WCHAR *processor_id )
1780 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1781 unsigned int regs[4] = {0, 0, 0, 0};
1783 do_cpuid( 1, regs );
1784 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1786 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1788 unsigned int i;
1789 unsigned char *p = (unsigned char *)regs;
1791 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1792 buffer[i] = 0;
1794 static void get_processor_manufacturer( WCHAR *manufacturer )
1796 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1798 do_cpuid( 0, regs );
1799 tmp = regs[2]; /* swap edx and ecx */
1800 regs[2] = regs[3];
1801 regs[3] = tmp;
1803 regs_to_str( regs + 1, 12, manufacturer );
1805 static void get_processor_name( WCHAR *name )
1807 unsigned int regs[4] = {0, 0, 0, 0};
1809 do_cpuid( 0x80000000, regs );
1810 if (regs[0] >= 0x80000004)
1812 do_cpuid( 0x80000002, regs );
1813 regs_to_str( regs, 16, name );
1814 do_cpuid( 0x80000003, regs );
1815 regs_to_str( regs, 16, name + 16 );
1816 do_cpuid( 0x80000004, regs );
1817 regs_to_str( regs, 16, name + 32 );
1820 static UINT get_processor_maxclockspeed( void )
1822 PROCESSOR_POWER_INFORMATION *info;
1823 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1824 NTSTATUS status;
1826 if ((info = heap_alloc( size )))
1828 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1829 if (!status) ret = info[0].MaxMhz;
1830 heap_free( info );
1832 return ret;
1834 static const WCHAR *get_osarchitecture(void)
1836 SYSTEM_INFO info;
1837 GetNativeSystemInfo( &info );
1838 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1839 return os_32bitW;
1842 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
1844 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1845 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1846 struct record_processor *rec;
1847 UINT i, offset = 0, maxclockspeed, num_cores, num_logical_processors, count = get_processor_count();
1848 enum fill_status status = FILL_STATUS_UNFILTERED;
1850 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
1852 get_processor_id( processor_id );
1853 get_processor_manufacturer( manufacturer );
1854 get_processor_name( name );
1856 maxclockspeed = get_processor_maxclockspeed();
1857 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
1858 num_cores /= count;
1860 for (i = 0; i < count; i++)
1862 rec = (struct record_processor *)(table->data + offset);
1863 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
1864 rec->cpu_status = 1; /* CPU Enabled */
1865 sprintfW( device_id, fmtW, i );
1866 rec->device_id = heap_strdupW( device_id );
1867 rec->family = 2; /* Unknown */
1868 rec->manufacturer = heap_strdupW( manufacturer );
1869 rec->maxclockspeed = maxclockspeed;
1870 rec->name = heap_strdupW( name );
1871 rec->num_cores = num_cores;
1872 rec->num_logical_processors = num_logical_processors;
1873 rec->processor_id = heap_strdupW( processor_id );
1874 rec->unique_id = NULL;
1875 if (!match_row( table, i, cond, &status ))
1877 free_row_values( table, i );
1878 continue;
1880 offset += sizeof(*rec);
1883 TRACE("created %u rows\n", count);
1884 table->num_rows = count;
1885 return status;
1888 static WCHAR *get_lastbootuptime(void)
1890 static const WCHAR fmtW[] =
1891 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1892 '.','%','0','6','u','+','0','0','0',0};
1893 SYSTEM_TIMEOFDAY_INFORMATION ti;
1894 TIME_FIELDS tf;
1895 WCHAR *ret;
1897 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1899 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1900 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1901 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1902 return ret;
1904 static WCHAR *get_localdatetime(void)
1906 static const WCHAR fmtW[] =
1907 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1908 '.','%','0','6','u','%','+','0','3','d',0};
1909 TIME_ZONE_INFORMATION tzi;
1910 SYSTEMTIME st;
1911 WCHAR *ret;
1912 DWORD Status;
1913 LONG Bias;
1915 Status = GetTimeZoneInformation(&tzi);
1917 if(Status == TIME_ZONE_ID_INVALID) return NULL;
1918 Bias = tzi.Bias;
1919 if(Status == TIME_ZONE_ID_DAYLIGHT)
1920 Bias+= tzi.DaylightBias;
1921 else
1922 Bias+= tzi.StandardBias;
1923 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1925 GetLocalTime(&st);
1926 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
1927 return ret;
1929 static WCHAR *get_systemdirectory(void)
1931 void *redir;
1932 WCHAR *ret;
1934 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1935 Wow64DisableWow64FsRedirection( &redir );
1936 GetSystemDirectoryW( ret, MAX_PATH );
1937 Wow64RevertWow64FsRedirection( redir );
1938 return ret;
1940 static WCHAR *get_codeset(void)
1942 static const WCHAR fmtW[] = {'%','u',0};
1943 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
1944 if (ret) sprintfW( ret, fmtW, GetACP() );
1945 return ret;
1947 static WCHAR *get_countrycode(void)
1949 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
1950 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
1951 return ret;
1953 static WCHAR *get_locale(void)
1955 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
1956 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
1957 return ret;
1960 static enum fill_status fill_os( struct table *table, const struct expr *cond )
1962 struct record_operatingsystem *rec;
1963 enum fill_status status = FILL_STATUS_UNFILTERED;
1964 UINT row = 0;
1966 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1968 rec = (struct record_operatingsystem *)table->data;
1969 rec->caption = os_captionW;
1970 rec->codeset = get_codeset();
1971 rec->countrycode = get_countrycode();
1972 rec->csdversion = os_csdversionW;
1973 rec->lastbootuptime = get_lastbootuptime();
1974 rec->localdatetime = get_localdatetime();
1975 rec->locale = get_locale();
1976 rec->name = os_nameW;
1977 rec->osarchitecture = get_osarchitecture();
1978 rec->oslanguage = GetSystemDefaultLangID();
1979 rec->osproductsuite = 2461140; /* Windows XP Professional */
1980 rec->ostype = 18; /* WINNT */
1981 rec->servicepackmajor = 3;
1982 rec->servicepackminor = 0;
1983 rec->suitemask = 272; /* Single User + Terminal */
1984 rec->systemdirectory = get_systemdirectory();
1985 rec->version = os_versionW;
1986 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1987 else row++;
1989 TRACE("created %u rows\n", row);
1990 table->num_rows = row;
1991 return status;
1994 static const WCHAR *get_service_type( DWORD type )
1996 static const WCHAR filesystem_driverW[] =
1997 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1998 static const WCHAR kernel_driverW[] =
1999 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
2000 static const WCHAR own_processW[] =
2001 {'O','w','n',' ','P','r','o','c','e','s','s',0};
2002 static const WCHAR share_processW[] =
2003 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
2005 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
2006 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
2007 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
2008 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
2009 else ERR("unhandled type 0x%08x\n", type);
2010 return NULL;
2012 static const WCHAR *get_service_state( DWORD state )
2014 static const WCHAR runningW[] =
2015 {'R','u','n','n','i','n','g',0};
2016 static const WCHAR start_pendingW[] =
2017 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
2018 static const WCHAR stop_pendingW[] =
2019 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
2020 static const WCHAR stoppedW[] =
2021 {'S','t','o','p','p','e','d',0};
2022 static const WCHAR unknownW[] =
2023 {'U','n','k','n','o','w','n',0};
2025 switch (state)
2027 case SERVICE_STOPPED: return stoppedW;
2028 case SERVICE_START_PENDING: return start_pendingW;
2029 case SERVICE_STOP_PENDING: return stop_pendingW;
2030 case SERVICE_RUNNING: return runningW;
2031 default:
2032 ERR("unknown state %u\n", state);
2033 return unknownW;
2036 static const WCHAR *get_service_startmode( DWORD mode )
2038 static const WCHAR bootW[] = {'B','o','o','t',0};
2039 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2040 static const WCHAR autoW[] = {'A','u','t','o',0};
2041 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2042 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2043 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2045 switch (mode)
2047 case SERVICE_BOOT_START: return bootW;
2048 case SERVICE_SYSTEM_START: return systemW;
2049 case SERVICE_AUTO_START: return autoW;
2050 case SERVICE_DEMAND_START: return manualW;
2051 case SERVICE_DISABLED: return disabledW;
2052 default:
2053 ERR("unknown mode 0x%x\n", mode);
2054 return unknownW;
2057 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2059 QUERY_SERVICE_CONFIGW *config = NULL;
2060 SC_HANDLE service;
2061 DWORD size;
2063 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2064 QueryServiceConfigW( service, NULL, 0, &size );
2065 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2066 if (!(config = heap_alloc( size ))) goto done;
2067 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2068 heap_free( config );
2069 config = NULL;
2071 done:
2072 CloseServiceHandle( service );
2073 return config;
2076 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2078 struct record_service *rec;
2079 SC_HANDLE manager;
2080 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2081 SERVICE_STATUS_PROCESS *status;
2082 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2083 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2084 UINT i, row = 0, offset = 0, size = 256, needed, count;
2085 enum fill_status fill_status = FILL_STATUS_FAILED;
2086 BOOL ret;
2088 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2089 if (!(services = heap_alloc( size ))) goto done;
2091 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2092 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2093 &count, NULL, NULL );
2094 if (!ret)
2096 if (GetLastError() != ERROR_MORE_DATA) goto done;
2097 size = needed;
2098 if (!(tmp = heap_realloc( services, size ))) goto done;
2099 services = tmp;
2100 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2101 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2102 &count, NULL, NULL );
2103 if (!ret) goto done;
2105 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2107 GetComputerNameW( sysnameW, &len );
2108 fill_status = FILL_STATUS_UNFILTERED;
2110 for (i = 0; i < count; i++)
2112 QUERY_SERVICE_CONFIGW *config;
2114 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2116 status = &services[i].ServiceStatusProcess;
2117 rec = (struct record_service *)(table->data + offset);
2118 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2119 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2120 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2121 rec->name = heap_strdupW( services[i].lpServiceName );
2122 rec->process_id = status->dwProcessId;
2123 rec->servicetype = get_service_type( status->dwServiceType );
2124 rec->startmode = get_service_startmode( config->dwStartType );
2125 rec->state = get_service_state( status->dwCurrentState );
2126 rec->systemname = heap_strdupW( sysnameW );
2127 rec->pause_service = service_pause_service;
2128 rec->resume_service = service_resume_service;
2129 rec->start_service = service_start_service;
2130 rec->stop_service = service_stop_service;
2131 heap_free( config );
2132 if (!match_row( table, row, cond, &fill_status ))
2134 free_row_values( table, row );
2135 continue;
2137 offset += sizeof(*rec);
2138 row++;
2141 TRACE("created %u rows\n", row);
2142 table->num_rows = row;
2144 done:
2145 CloseServiceHandle( manager );
2146 heap_free( services );
2147 return fill_status;
2150 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2152 HDC hdc = GetDC( NULL );
2153 UINT32 ret;
2155 if (!hdc) return 32;
2156 ret = GetDeviceCaps( hdc, BITSPIXEL );
2157 *hres = GetDeviceCaps( hdc, HORZRES );
2158 *vres = GetDeviceCaps( hdc, VERTRES );
2159 ReleaseDC( NULL, hdc );
2160 return ret;
2162 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2164 static const WCHAR fmtW[] =
2165 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2166 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2167 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2168 WCHAR *ret;
2170 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2171 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2172 return ret;
2175 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2178 struct record_videocontroller *rec;
2179 HRESULT hr;
2180 IDXGIFactory *factory = NULL;
2181 IDXGIAdapter *adapter = NULL;
2182 DXGI_ADAPTER_DESC desc;
2183 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2184 const WCHAR *name = videocontroller_deviceidW;
2185 enum fill_status status = FILL_STATUS_UNFILTERED;
2186 UINT row = 0;
2188 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2190 memset (&desc, 0, sizeof(desc));
2191 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2192 if (FAILED(hr)) goto done;
2194 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2195 if (FAILED(hr)) goto done;
2197 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2198 if (SUCCEEDED(hr))
2200 vidmem = desc.DedicatedVideoMemory;
2201 name = desc.Description;
2204 done:
2205 rec = (struct record_videocontroller *)table->data;
2206 rec->adapter_dactype = videocontroller_dactypeW;
2207 rec->adapter_ram = vidmem;
2208 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2209 rec->current_horizontalres = hres;
2210 rec->current_verticalres = vres;
2211 rec->description = heap_strdupW( name );
2212 rec->device_id = videocontroller_deviceidW;
2213 rec->name = heap_strdupW( name );
2214 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2215 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2216 else row++;
2218 TRACE("created %u rows\n", row);
2219 table->num_rows = row;
2221 if (adapter) IDXGIAdapter_Release( adapter );
2222 if (factory) IDXGIFactory_Release( factory );
2223 return status;
2226 static struct table builtin_classes[] =
2228 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2229 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2230 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2231 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2232 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2233 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2234 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), 0, (BYTE *)data_diskdrive },
2235 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2236 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2237 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2238 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2239 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2240 fill_networkadapterconfig },
2241 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2242 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2243 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2244 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2245 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2246 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2247 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2248 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2249 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2250 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2253 void init_table_list( void )
2255 static struct list tables = LIST_INIT( tables );
2256 UINT i;
2258 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2259 table_list = &tables;