gdiplus: Mark the Graphics object as busy before freeing it.
[wine/multimedia.git] / dlls / wbemprox / builtin.c
blob2db27c054fd9875472ee486fabacf74f8207d41a
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_ipenabledW[] =
169 {'I','P','E','n','a','b','l','e','d',0};
170 static const WCHAR prop_lastbootuptimeW[] =
171 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
172 static const WCHAR prop_localdatetimeW[] =
173 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
174 static const WCHAR prop_localeW[] =
175 {'L','o','c','a','l','e',0};
176 static const WCHAR prop_macaddressW[] =
177 {'M','A','C','A','d','d','r','e','s','s',0};
178 static const WCHAR prop_manufacturerW[] =
179 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
180 static const WCHAR prop_maxclockspeedW[] =
181 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
182 static const WCHAR prop_memberW[] =
183 {'M','e','m','b','e','r',0};
184 static const WCHAR prop_methodW[] =
185 {'M','e','t','h','o','d',0};
186 static const WCHAR prop_modelW[] =
187 {'M','o','d','e','l',0};
188 static const WCHAR prop_netconnectionstatusW[] =
189 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
190 static const WCHAR prop_numcoresW[] =
191 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
192 static const WCHAR prop_numlogicalprocessorsW[] =
193 {'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};
194 static const WCHAR prop_numprocessorsW[] =
195 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
196 static const WCHAR prop_osarchitectureW[] =
197 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
198 static const WCHAR prop_oslanguageW[] =
199 {'O','S','L','a','n','g','u','a','g','e',0};
200 static const WCHAR prop_osproductsuiteW[] =
201 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
202 static const WCHAR prop_ostypeW[] =
203 {'O','S','T','y','p','e',0};
204 static const WCHAR prop_parameterW[] =
205 {'P','a','r','a','m','e','t','e','r',0};
206 static const WCHAR prop_physicaladapterW[] =
207 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
208 static const WCHAR prop_pnpdeviceidW[] =
209 {'P','N','P','D','e','v','i','c','e','I','D',0};
210 static const WCHAR prop_pprocessidW[] =
211 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
212 static const WCHAR prop_processidW[] =
213 {'P','r','o','c','e','s','s','I','D',0};
214 static const WCHAR prop_processoridW[] =
215 {'P','r','o','c','e','s','s','o','r','I','d',0};
216 static const WCHAR prop_productnameW[] =
217 {'P','r','o','d','u','c','t','N','a','m','e',0};
218 static const WCHAR prop_releasedateW[] =
219 {'R','e','l','e','a','s','e','D','a','t','e',0};
220 static const WCHAR prop_serialnumberW[] =
221 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
222 static const WCHAR prop_servicepackmajorW[] =
223 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
224 static const WCHAR prop_servicepackminorW[] =
225 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
226 static const WCHAR prop_servicetypeW[] =
227 {'S','e','r','v','i','c','e','T','y','p','e',0};
228 static const WCHAR prop_smbiosbiosversionW[] =
229 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
230 static const WCHAR prop_startmodeW[] =
231 {'S','t','a','r','t','M','o','d','e',0};
232 static const WCHAR prop_sizeW[] =
233 {'S','i','z','e',0};
234 static const WCHAR prop_speedW[] =
235 {'S','p','e','e','d',0};
236 static const WCHAR prop_startingoffsetW[] =
237 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
238 static const WCHAR prop_stateW[] =
239 {'S','t','a','t','e',0};
240 static const WCHAR prop_strvalueW[] =
241 {'S','t','r','i','n','g','V','a','l','u','e',0};
242 static const WCHAR prop_suitemaskW[] =
243 {'S','u','i','t','e','M','a','s','k',0};
244 static const WCHAR prop_systemdirectoryW[] =
245 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
246 static const WCHAR prop_systemnameW[] =
247 {'S','y','s','t','e','m','N','a','m','e',0};
248 static const WCHAR prop_tagW[] =
249 {'T','a','g',0};
250 static const WCHAR prop_threadcountW[] =
251 {'T','h','r','e','a','d','C','o','u','n','t',0};
252 static const WCHAR prop_totalphysicalmemoryW[] =
253 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
254 static const WCHAR prop_typeW[] =
255 {'T','y','p','e',0};
256 static const WCHAR prop_uniqueidW[] =
257 {'U','n','i','q','u','e','I','d',0};
258 static const WCHAR prop_varianttypeW[] =
259 {'V','a','r','i','a','n','t','T','y','p','e',0};
260 static const WCHAR prop_versionW[] =
261 {'V','e','r','s','i','o','n',0};
263 /* column definitions must be kept in sync with record structures below */
264 static const struct column col_baseboard[] =
266 { prop_manufacturerW, CIM_STRING },
267 { prop_modelW, CIM_STRING },
268 { prop_nameW, CIM_STRING },
269 { prop_serialnumberW, CIM_STRING },
270 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
272 static const struct column col_bios[] =
274 { prop_descriptionW, CIM_STRING },
275 { prop_identificationcodeW, CIM_STRING },
276 { prop_manufacturerW, CIM_STRING },
277 { prop_releasedateW, CIM_DATETIME },
278 { prop_serialnumberW, CIM_STRING },
279 { prop_smbiosbiosversionW, CIM_STRING },
280 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
282 static const struct column col_cdromdrive[] =
284 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
285 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
286 { prop_nameW, CIM_STRING },
287 { prop_pnpdeviceidW, CIM_STRING }
289 static const struct column col_compsys[] =
291 { prop_descriptionW, CIM_STRING },
292 { prop_domainW, CIM_STRING },
293 { prop_domainroleW, CIM_UINT16 },
294 { prop_manufacturerW, CIM_STRING },
295 { prop_modelW, CIM_STRING },
296 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
297 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
298 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
299 { prop_totalphysicalmemoryW, CIM_UINT64 }
301 static const struct column col_datafile[] =
303 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
304 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
306 static const struct column col_directory[] =
308 { prop_accessmaskW, CIM_UINT32 },
309 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
311 static const struct column col_diskdrive[] =
313 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
314 { prop_indexW, CIM_UINT32, VT_I4 },
315 { prop_manufacturerW, CIM_STRING },
316 { prop_modelW, CIM_STRING },
317 { prop_serialnumberW, CIM_STRING }
319 static const struct column col_diskpartition[] =
321 { prop_bootableW, CIM_BOOLEAN },
322 { prop_bootpartitionW, CIM_BOOLEAN },
323 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
324 { prop_diskindexW, CIM_UINT32, VT_I4 },
325 { prop_indexW, CIM_UINT32, VT_I4 },
326 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
327 { prop_sizeW, CIM_UINT64 },
328 { prop_startingoffsetW, CIM_UINT64 },
329 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
331 static const struct column col_logicaldisk[] =
333 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
334 { prop_drivetypeW, CIM_UINT32, VT_I4 },
335 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
336 { prop_freespaceW, CIM_UINT64 },
337 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
338 { prop_sizeW, CIM_UINT64 }
340 static const struct column col_networkadapter[] =
342 { prop_adaptertypeW, CIM_STRING },
343 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
344 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
345 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
346 { prop_manufacturerW, CIM_STRING },
347 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
348 { prop_physicaladapterW, CIM_BOOLEAN },
349 { prop_pnpdeviceidW, CIM_STRING },
350 { prop_speedW, CIM_UINT64 }
352 static const struct column col_networkadapterconfig[] =
354 { prop_indexW, CIM_UINT32|COL_FLAG_KEY },
355 { prop_ipenabledW, CIM_BOOLEAN },
356 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
358 static const struct column col_os[] =
360 { prop_captionW, CIM_STRING },
361 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
362 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
363 { prop_csdversionW, CIM_STRING },
364 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
365 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
366 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
367 { prop_osarchitectureW, CIM_STRING },
368 { prop_oslanguageW, CIM_UINT32, VT_I4 },
369 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
370 { prop_ostypeW, CIM_UINT16, VT_I4 },
371 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
372 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
373 { prop_suitemaskW, CIM_UINT32, VT_I4 },
374 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
375 { prop_versionW, CIM_STRING }
377 static const struct column col_param[] =
379 { prop_classW, CIM_STRING },
380 { prop_methodW, CIM_STRING },
381 { prop_directionW, CIM_SINT32 },
382 { prop_parameterW, CIM_STRING },
383 { prop_typeW, CIM_UINT32 },
384 { prop_varianttypeW, CIM_UINT32 },
385 { prop_defaultvalueW, CIM_UINT32 }
387 static const struct column col_physicalmedia[] =
389 { prop_serialnumberW, CIM_STRING }
391 static const struct column col_process[] =
393 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
394 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
395 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
396 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
397 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
398 { prop_pprocessidW, CIM_UINT32, VT_I4 },
399 { prop_processidW, CIM_UINT32, VT_I4 },
400 { prop_threadcountW, CIM_UINT32, VT_I4 },
401 /* methods */
402 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
404 static const struct column col_processor[] =
406 { prop_addresswidthW, CIM_UINT16, VT_I4 },
407 { prop_cpustatusW, CIM_UINT16 },
408 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
409 { prop_familyW, CIM_UINT16, VT_I4 },
410 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
411 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
412 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
413 { prop_numcoresW, CIM_UINT32, VT_I4 },
414 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
415 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
416 { prop_uniqueidW, CIM_STRING }
418 static const struct column col_qualifier[] =
420 { prop_classW, CIM_STRING },
421 { prop_memberW, CIM_STRING },
422 { prop_typeW, CIM_UINT32 },
423 { prop_flavorW, CIM_SINT32 },
424 { prop_nameW, CIM_STRING },
425 { prop_intvalueW, CIM_SINT32 },
426 { prop_strvalueW, CIM_STRING }
428 static const struct column col_service[] =
430 { prop_acceptpauseW, CIM_BOOLEAN },
431 { prop_acceptstopW, CIM_BOOLEAN },
432 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
433 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
434 { prop_processidW, CIM_UINT32 },
435 { prop_servicetypeW, CIM_STRING },
436 { prop_startmodeW, CIM_STRING },
437 { prop_stateW, CIM_STRING },
438 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
439 /* methods */
440 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
441 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
442 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
443 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
445 static const struct column col_sounddevice[] =
447 { prop_nameW, CIM_STRING },
448 { prop_productnameW, CIM_STRING }
450 static const struct column col_stdregprov[] =
452 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
453 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
454 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
456 static const struct column col_videocontroller[] =
458 { prop_adapterdactypeW, CIM_STRING },
459 { prop_adapterramW, CIM_UINT32, VT_I4 },
460 { prop_currentbitsperpixelW, CIM_UINT32 },
461 { prop_currenthorizontalresW, CIM_UINT32 },
462 { prop_currentverticalresW, CIM_UINT32 },
463 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
464 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
465 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
466 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
469 static const WCHAR baseboard_manufacturerW[] =
470 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
471 static const WCHAR baseboard_serialnumberW[] =
472 {'N','o','n','e',0};
473 static const WCHAR baseboard_tagW[] =
474 {'B','a','s','e',' ','B','o','a','r','d',0};
475 static const WCHAR bios_descriptionW[] =
476 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
477 static const WCHAR bios_manufacturerW[] =
478 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
479 static const WCHAR bios_releasedateW[] =
480 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
481 static const WCHAR bios_serialnumberW[] =
482 {'0',0};
483 static const WCHAR bios_smbiosbiosversionW[] =
484 {'W','i','n','e',0};
485 static const WCHAR bios_versionW[] =
486 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
487 static const WCHAR cdromdrive_nameW[] =
488 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
489 static const WCHAR cdromdrive_pnpdeviceidW[]=
490 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
491 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
492 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
493 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
494 static const WCHAR compsys_descriptionW[] =
495 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
496 static const WCHAR compsys_domainW[] =
497 {'W','O','R','K','G','R','O','U','P',0};
498 static const WCHAR compsys_manufacturerW[] =
499 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
500 static const WCHAR compsys_modelW[] =
501 {'W','i','n','e',0};
502 static const WCHAR diskdrive_deviceidW[] =
503 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
504 static const WCHAR diskdrive_modelW[] =
505 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
506 static const WCHAR diskdrive_manufacturerW[] =
507 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
508 static const WCHAR diskdrive_serialW[] =
509 {'W','I','N','E','H','D','I','S','K',0};
510 static const WCHAR networkadapter_pnpdeviceidW[]=
511 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
512 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
513 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
514 static const WCHAR os_captionW[] =
515 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
516 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
517 static const WCHAR os_csdversionW[] =
518 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
519 static const WCHAR os_32bitW[] =
520 {'3','2','-','b','i','t',0};
521 static const WCHAR os_64bitW[] =
522 {'6','4','-','b','i','t',0};
523 static const WCHAR os_versionW[] =
524 {'5','.','1','.','2','6','0','0',0};
525 static const WCHAR sounddevice_productnameW[] =
526 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
527 static const WCHAR videocontroller_dactypeW[] =
528 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
529 static const WCHAR videocontroller_deviceidW[] =
530 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
532 #include "pshpack1.h"
533 struct record_baseboard
535 const WCHAR *manufacturer;
536 const WCHAR *model;
537 const WCHAR *name;
538 const WCHAR *serialnumber;
539 const WCHAR *tag;
541 struct record_bios
543 const WCHAR *description;
544 const WCHAR *identificationcode;
545 const WCHAR *manufacturer;
546 const WCHAR *releasedate;
547 const WCHAR *serialnumber;
548 const WCHAR *smbiosbiosversion;
549 const WCHAR *version;
551 struct record_cdromdrive
553 const WCHAR *device_id;
554 const WCHAR *drive;
555 const WCHAR *name;
556 const WCHAR *pnpdevice_id;
558 struct record_computersystem
560 const WCHAR *description;
561 const WCHAR *domain;
562 UINT16 domainrole;
563 const WCHAR *manufacturer;
564 const WCHAR *model;
565 const WCHAR *name;
566 UINT32 num_logical_processors;
567 UINT32 num_processors;
568 UINT64 total_physical_memory;
570 struct record_datafile
572 const WCHAR *name;
573 const WCHAR *version;
575 struct record_directory
577 UINT32 accessmask;
578 const WCHAR *name;
580 struct record_diskdrive
582 const WCHAR *device_id;
583 UINT32 index;
584 const WCHAR *manufacturer;
585 const WCHAR *name;
586 const WCHAR *serialnumber;
588 struct record_diskpartition
590 int bootable;
591 int bootpartition;
592 const WCHAR *device_id;
593 UINT32 diskindex;
594 UINT32 index;
595 const WCHAR *pnpdevice_id;
596 UINT64 size;
597 UINT64 startingoffset;
598 const WCHAR *type;
600 struct record_logicaldisk
602 const WCHAR *device_id;
603 UINT32 drivetype;
604 const WCHAR *filesystem;
605 UINT64 freespace;
606 const WCHAR *name;
607 UINT64 size;
609 struct record_networkadapter
611 const WCHAR *adaptertype;
612 const WCHAR *device_id;
613 INT32 interface_index;
614 const WCHAR *mac_address;
615 const WCHAR *manufacturer;
616 UINT16 netconnection_status;
617 int physicaladapter;
618 const WCHAR *pnpdevice_id;
619 UINT64 speed;
621 struct record_networkadapterconfig
623 UINT32 index;
624 int ipenabled;
625 const WCHAR *mac_address;
627 struct record_operatingsystem
629 const WCHAR *caption;
630 const WCHAR *codeset;
631 const WCHAR *countrycode;
632 const WCHAR *csdversion;
633 const WCHAR *lastbootuptime;
634 const WCHAR *localdatetime;
635 const WCHAR *locale;
636 const WCHAR *osarchitecture;
637 UINT32 oslanguage;
638 UINT32 osproductsuite;
639 UINT16 ostype;
640 UINT16 servicepackmajor;
641 UINT16 servicepackminor;
642 UINT32 suitemask;
643 const WCHAR *systemdirectory;
644 const WCHAR *version;
646 struct record_param
648 const WCHAR *class;
649 const WCHAR *method;
650 INT32 direction;
651 const WCHAR *parameter;
652 UINT32 type;
653 UINT32 varianttype;
654 UINT32 defaultvalue;
656 struct record_physicalmedia
658 const WCHAR *serialnumber;
660 struct record_process
662 const WCHAR *caption;
663 const WCHAR *commandline;
664 const WCHAR *description;
665 const WCHAR *handle;
666 const WCHAR *name;
667 UINT32 pprocess_id;
668 UINT32 process_id;
669 UINT32 thread_count;
670 /* methods */
671 class_method *get_owner;
673 struct record_processor
675 UINT16 addresswidth;
676 UINT16 cpu_status;
677 const WCHAR *device_id;
678 UINT16 family;
679 const WCHAR *manufacturer;
680 UINT32 maxclockspeed;
681 const WCHAR *name;
682 UINT32 num_cores;
683 UINT32 num_logical_processors;
684 const WCHAR *processor_id;
685 const WCHAR *unique_id;
687 struct record_qualifier
689 const WCHAR *class;
690 const WCHAR *member;
691 UINT32 type;
692 INT32 flavor;
693 const WCHAR *name;
694 INT32 intvalue;
695 const WCHAR *strvalue;
697 struct record_service
699 int accept_pause;
700 int accept_stop;
701 const WCHAR *displayname;
702 const WCHAR *name;
703 UINT32 process_id;
704 const WCHAR *servicetype;
705 const WCHAR *startmode;
706 const WCHAR *state;
707 const WCHAR *systemname;
708 /* methods */
709 class_method *pause_service;
710 class_method *resume_service;
711 class_method *start_service;
712 class_method *stop_service;
714 struct record_sounddevice
716 const WCHAR *name;
717 const WCHAR *productname;
719 struct record_stdregprov
721 class_method *enumkey;
722 class_method *enumvalues;
723 class_method *getstringvalue;
725 struct record_videocontroller
727 const WCHAR *adapter_dactype;
728 UINT32 adapter_ram;
729 UINT32 current_bitsperpixel;
730 UINT32 current_horizontalres;
731 UINT32 current_verticalres;
732 const WCHAR *description;
733 const WCHAR *device_id;
734 const WCHAR *name;
735 const WCHAR *pnpdevice_id;
737 #include "poppack.h"
739 static const struct record_baseboard data_baseboard[] =
741 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
743 static const struct record_bios data_bios[] =
745 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
746 bios_smbiosbiosversionW, bios_versionW }
748 static const struct record_diskdrive data_diskdrive[] =
750 { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
752 static const struct record_param data_param[] =
754 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
755 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
756 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
757 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
758 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
759 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
760 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
761 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
762 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
763 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
764 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
765 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
766 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
767 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
768 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
769 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
770 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
771 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
772 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
773 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
774 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
777 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
778 WBEM_FLAVOR_ORIGIN_PROPAGATED)
780 static const struct record_physicalmedia data_physicalmedia[] =
782 { diskdrive_serialW }
784 static const struct record_qualifier data_qualifier[] =
786 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
787 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
789 static const struct record_sounddevice data_sounddevice[] =
791 { sounddevice_productnameW, sounddevice_productnameW }
793 static const struct record_stdregprov data_stdregprov[] =
795 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
798 /* check if row matches condition and update status */
799 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
801 LONGLONG val;
802 if (!cond)
804 *status = FILL_STATUS_UNFILTERED;
805 return TRUE;
807 if (eval_cond( table, row, cond, &val ) != S_OK)
809 *status = FILL_STATUS_FAILED;
810 return FALSE;
812 *status = FILL_STATUS_FILTERED;
813 return val != 0;
816 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
818 if (!table->num_rows_allocated)
820 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
821 table->num_rows_allocated = row_count;
822 return TRUE;
824 if (row_count >= table->num_rows_allocated)
826 BYTE *data;
827 UINT count = table->num_rows_allocated * 2;
828 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
829 table->data = data;
830 table->num_rows_allocated = count;
832 return TRUE;
835 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
837 static const WCHAR fmtW[] = {'%','c',':',0};
838 WCHAR drive[3], root[] = {'A',':','\\',0};
839 struct record_cdromdrive *rec;
840 UINT i, row = 0, offset = 0;
841 DWORD drives = GetLogicalDrives();
842 enum fill_status status = FILL_STATUS_UNFILTERED;
844 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
846 for (i = 0; i < sizeof(drives); i++)
848 if (drives & (1 << i))
850 root[0] = 'A' + i;
851 if (GetDriveTypeW( root ) != DRIVE_CDROM)
852 continue;
854 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
856 rec = (struct record_cdromdrive *)(table->data + offset);
857 rec->device_id = cdromdrive_pnpdeviceidW;
858 sprintfW( drive, fmtW, 'A' + i );
859 rec->drive = heap_strdupW( drive );
860 rec->name = cdromdrive_nameW;
861 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
862 if (!match_row( table, row, cond, &status ))
864 free_row_values( table, row );
865 continue;
867 offset += sizeof(*rec);
868 row++;
871 TRACE("created %u rows\n", row);
872 table->num_rows = row;
873 return status;
876 static UINT get_processor_count(void)
878 SYSTEM_BASIC_INFORMATION info;
880 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
881 return info.NumberOfProcessors;
884 static UINT get_logical_processor_count( UINT *num_cores )
886 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
887 UINT i, j, count = 0;
888 NTSTATUS status;
889 ULONG len;
891 if (num_cores) *num_cores = get_processor_count();
892 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
893 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
895 if (!(info = heap_alloc( len ))) return get_processor_count();
896 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
897 if (status != STATUS_SUCCESS)
899 heap_free( info );
900 return get_processor_count();
902 if (num_cores) *num_cores = 0;
903 for (i = 0; i < len / sizeof(*info); i++)
905 if (info[i].Relationship == RelationProcessorCore)
907 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
909 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
911 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
914 heap_free( info );
915 return count;
918 static UINT64 get_total_physical_memory(void)
920 MEMORYSTATUSEX status;
922 status.dwLength = sizeof(status);
923 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
924 return status.ullTotalPhys;
927 static WCHAR *get_computername(void)
929 WCHAR *ret;
930 DWORD size = MAX_COMPUTERNAME_LENGTH;
932 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
933 GetComputerNameW( ret, &size );
934 return ret;
937 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
939 struct record_computersystem *rec;
940 enum fill_status status = FILL_STATUS_UNFILTERED;
941 UINT row = 0;
943 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
945 rec = (struct record_computersystem *)table->data;
946 rec->description = compsys_descriptionW;
947 rec->domain = compsys_domainW;
948 rec->domainrole = 0; /* standalone workstation */
949 rec->manufacturer = compsys_manufacturerW;
950 rec->model = compsys_modelW;
951 rec->name = get_computername();
952 rec->num_logical_processors = get_logical_processor_count( NULL );
953 rec->num_processors = get_processor_count();
954 rec->total_physical_memory = get_total_physical_memory();
955 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
956 else row++;
958 TRACE("created %u rows\n", row);
959 table->num_rows = row;
960 return status;
963 struct dirstack
965 WCHAR **dirs;
966 UINT *len_dirs;
967 UINT num_dirs;
968 UINT num_allocated;
971 static struct dirstack *alloc_dirstack( UINT size )
973 struct dirstack *dirstack;
975 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
976 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
978 heap_free( dirstack );
979 return NULL;
981 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
983 heap_free( dirstack->dirs );
984 heap_free( dirstack );
985 return NULL;
987 dirstack->num_dirs = 0;
988 dirstack->num_allocated = size;
989 return dirstack;
992 static void clear_dirstack( struct dirstack *dirstack )
994 UINT i;
995 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
996 dirstack->num_dirs = 0;
999 static void free_dirstack( struct dirstack *dirstack )
1001 clear_dirstack( dirstack );
1002 heap_free( dirstack->dirs );
1003 heap_free( dirstack->len_dirs );
1004 heap_free( dirstack );
1007 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
1009 UINT size, i = dirstack->num_dirs;
1011 if (!dir) return FALSE;
1013 if (i == dirstack->num_allocated)
1015 WCHAR **tmp;
1016 UINT *len_tmp;
1018 size = dirstack->num_allocated * 2;
1019 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1020 dirstack->dirs = tmp;
1021 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1022 dirstack->len_dirs = len_tmp;
1023 dirstack->num_allocated = size;
1025 dirstack->dirs[i] = dir;
1026 dirstack->len_dirs[i] = len;
1027 dirstack->num_dirs++;
1028 return TRUE;
1031 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1033 if (!dirstack->num_dirs)
1035 *len = 0;
1036 return NULL;
1038 dirstack->num_dirs--;
1039 *len = dirstack->len_dirs[dirstack->num_dirs];
1040 return dirstack->dirs[dirstack->num_dirs];
1043 static const WCHAR *peek_dir( struct dirstack *dirstack )
1045 if (!dirstack->num_dirs) return NULL;
1046 return dirstack->dirs[dirstack->num_dirs - 1];
1049 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1051 UINT i = 0;
1052 WCHAR *ret;
1054 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1055 ret[i++] = drive;
1056 ret[i++] = ':';
1057 ret[i++] = '\\';
1058 if (path && len)
1060 memcpy( ret + i, path, len * sizeof(WCHAR) );
1061 i += len;
1062 ret[i++] = '\\';
1064 ret[i++] = '*';
1065 ret[i] = 0;
1066 return ret;
1069 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1071 UINT i = 0, len = 0;
1072 const WCHAR *p;
1073 WCHAR *ret;
1075 for (p = path; *p; p++)
1077 if (*p == '\\') len += 2;
1078 else len++;
1080 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1081 ret[i++] = drive;
1082 ret[i++] = ':';
1083 ret[i++] = '\\';
1084 ret[i++] = '\\';
1085 for (p = path; *p; p++)
1087 if (*p != '\\') ret[i++] = *p;
1088 else
1090 ret[i++] = '\\';
1091 ret[i++] = '\\';
1094 ret[i] = 0;
1095 return ret;
1098 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1100 const WCHAR *p = path, *start;
1101 UINT len, i;
1102 WCHAR *ret;
1104 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1105 start = path + 4;
1106 len = strlenW( start );
1107 p = start + len - 1;
1108 if (*p == '\\') return NULL;
1110 while (p >= start && *p != '\\') { len--; p--; };
1111 while (p >= start && *p == '\\') { len--; p--; };
1113 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1114 for (i = 0, p = start; p < start + len; p++)
1116 if (p[0] == '\\' && p[1] == '\\')
1118 ret[i++] = '\\';
1119 p++;
1121 else ret[i++] = *p;
1123 ret[i] = 0;
1124 *ret_len = i;
1125 return ret;
1128 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1130 UINT i;
1131 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1132 return FALSE;
1135 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1136 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1138 const struct expr *left, *right;
1140 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1142 left = cond->u.expr.left;
1143 right = cond->u.expr.right;
1144 if (cond->u.expr.op == OP_EQ)
1146 UINT len;
1147 WCHAR *path;
1148 const WCHAR *str = NULL;
1150 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1151 !strcmpW( left->u.propval->name, prop_nameW ) &&
1152 toupperW( right->u.sval[0] ) == toupperW( root ))
1154 str = right->u.sval;
1156 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1157 !strcmpW( right->u.propval->name, prop_nameW ) &&
1158 toupperW( left->u.sval[0] ) == toupperW( root ))
1160 str = left->u.sval;
1162 if (str && (path = build_dirname( str, &len )))
1164 if (seen_dir( dirstack, path ))
1166 heap_free( path );
1167 return ++*count;
1169 else if (push_dir( dirstack, path, len )) return ++*count;
1170 heap_free( path );
1171 return *count = 0;
1174 else if (cond->u.expr.op == OP_OR)
1176 UINT left_count = 0, right_count = 0;
1178 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1179 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1180 return *count += left_count + right_count;
1182 return *count = 0;
1185 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1187 UINT len_path = 0, len_segment = strlenW( segment );
1188 WCHAR *ret;
1190 *len = 0;
1191 if (path) len_path = strlenW( path );
1192 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1193 if (path && len_path)
1195 memcpy( ret, path, len_path * sizeof(WCHAR) );
1196 ret[len_path] = '\\';
1197 *len += len_path + 1;
1199 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1200 *len += len_segment;
1201 ret[*len] = 0;
1202 return ret;
1205 static WCHAR *get_file_version( const WCHAR *filename )
1207 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1208 VS_FIXEDFILEINFO *info;
1209 DWORD size;
1210 void *block;
1211 WCHAR *ret;
1213 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1214 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1216 heap_free( ret );
1217 return NULL;
1219 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1220 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1222 heap_free( block );
1223 heap_free( ret );
1224 return NULL;
1226 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1227 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1228 heap_free( block );
1229 return ret;
1232 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1234 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1235 struct record_datafile *rec;
1236 UINT i, len, row = 0, offset = 0, num_expected_rows;
1237 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1238 DWORD drives = GetLogicalDrives();
1239 WIN32_FIND_DATAW data;
1240 HANDLE handle;
1241 struct dirstack *dirstack = alloc_dirstack(2);
1242 enum fill_status status = FILL_STATUS_UNFILTERED;
1244 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1246 for (i = 0; i < sizeof(drives); i++)
1248 if (!(drives & (1 << i))) continue;
1250 root[0] = 'A' + i;
1251 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1253 num_expected_rows = 0;
1254 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1256 for (;;)
1258 path = pop_dir( dirstack, &len );
1259 if (!(glob = build_glob( root[0], path, len )))
1261 status = FILL_STATUS_FAILED;
1262 goto done;
1264 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1268 if (!resize_table( table, row + 1, sizeof(*rec) ))
1270 status = FILL_STATUS_FAILED;
1271 goto done;
1273 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1274 new_path = append_path( path, data.cFileName, &len );
1276 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1278 if (push_dir( dirstack, new_path, len )) continue;
1279 heap_free( new_path );
1280 status = FILL_STATUS_FAILED;
1281 goto done;
1283 rec = (struct record_datafile *)(table->data + offset);
1284 rec->name = build_name( root[0], new_path );
1285 rec->version = get_file_version( rec->name );
1286 if (!match_row( table, row, cond, &status ))
1288 free_row_values( table, row );
1289 continue;
1291 else if (num_expected_rows && row == num_expected_rows - 1)
1293 row++;
1294 FindClose( handle );
1295 status = FILL_STATUS_FILTERED;
1296 goto done;
1298 offset += sizeof(*rec);
1299 row++;
1301 while (FindNextFileW( handle, &data ));
1302 FindClose( handle );
1304 if (!peek_dir( dirstack )) break;
1305 heap_free( glob );
1306 heap_free( path );
1310 done:
1311 free_dirstack( dirstack );
1312 heap_free( glob );
1313 heap_free( path );
1315 TRACE("created %u rows\n", row);
1316 table->num_rows = row;
1317 return status;
1320 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1322 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1323 struct record_directory *rec;
1324 UINT i, len, row = 0, offset = 0, num_expected_rows;
1325 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1326 DWORD drives = GetLogicalDrives();
1327 WIN32_FIND_DATAW data;
1328 HANDLE handle;
1329 struct dirstack *dirstack;
1330 enum fill_status status = FILL_STATUS_UNFILTERED;
1332 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1334 dirstack = alloc_dirstack(2);
1336 for (i = 0; i < sizeof(drives); i++)
1338 if (!(drives & (1 << i))) continue;
1340 root[0] = 'A' + i;
1341 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1343 num_expected_rows = 0;
1344 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1346 for (;;)
1348 path = pop_dir( dirstack, &len );
1349 if (!(glob = build_glob( root[0], path, len )))
1351 status = FILL_STATUS_FAILED;
1352 goto done;
1354 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1358 if (!resize_table( table, row + 1, sizeof(*rec) ))
1360 FindClose( handle );
1361 status = FILL_STATUS_FAILED;
1362 goto done;
1364 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1365 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1366 continue;
1368 new_path = append_path( path, data.cFileName, &len );
1369 if (!(push_dir( dirstack, new_path, len )))
1371 heap_free( new_path );
1372 FindClose( handle );
1373 status = FILL_STATUS_FAILED;
1374 goto done;
1376 rec = (struct record_directory *)(table->data + offset);
1377 rec->accessmask = FILE_ALL_ACCESS;
1378 rec->name = build_name( root[0], new_path );
1379 if (!match_row( table, row, cond, &status ))
1381 free_row_values( table, row );
1382 continue;
1384 else if (num_expected_rows && row == num_expected_rows - 1)
1386 row++;
1387 FindClose( handle );
1388 status = FILL_STATUS_FILTERED;
1389 goto done;
1391 offset += sizeof(*rec);
1392 row++;
1394 while (FindNextFileW( handle, &data ));
1395 FindClose( handle );
1397 if (!peek_dir( dirstack )) break;
1398 heap_free( glob );
1399 heap_free( path );
1403 done:
1404 free_dirstack( dirstack );
1405 heap_free( glob );
1406 heap_free( path );
1408 TRACE("created %u rows\n", row);
1409 table->num_rows = row;
1410 return status;
1413 static WCHAR *get_filesystem( const WCHAR *root )
1415 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1416 WCHAR buffer[MAX_PATH + 1];
1418 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1419 return heap_strdupW( buffer );
1420 return heap_strdupW( ntfsW );
1423 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1425 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1426 ULARGE_INTEGER free;
1427 DISK_GEOMETRY_EX info;
1428 HANDLE handle;
1430 free.QuadPart = 512 * 1024 * 1024;
1431 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1433 root[4] = dir[0];
1434 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1435 if (handle != INVALID_HANDLE_VALUE)
1437 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1438 *disksize = info.DiskSize.QuadPart;
1439 CloseHandle( handle );
1441 return free.QuadPart;
1444 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1446 static const WCHAR fmtW[] =
1447 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1448 WCHAR device_id[32], root[] = {'A',':','\\',0};
1449 struct record_diskpartition *rec;
1450 UINT i, row = 0, offset = 0, type, index = 0;
1451 UINT64 size = 1024 * 1024 * 1024;
1452 DWORD drives = GetLogicalDrives();
1453 enum fill_status status = FILL_STATUS_UNFILTERED;
1455 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1457 for (i = 0; i < sizeof(drives); i++)
1459 if (drives & (1 << i))
1461 root[0] = 'A' + i;
1462 type = GetDriveTypeW( root );
1463 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1464 continue;
1466 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1468 rec = (struct record_diskpartition *)(table->data + offset);
1469 rec->bootable = (i == 2) ? -1 : 0;
1470 rec->bootpartition = (i == 2) ? -1 : 0;
1471 sprintfW( device_id, fmtW, index );
1472 rec->device_id = heap_strdupW( device_id );
1473 rec->diskindex = index;
1474 rec->index = 0;
1475 rec->pnpdevice_id = heap_strdupW( device_id );
1476 get_freespace( root, &size );
1477 rec->size = size;
1478 rec->startingoffset = 0;
1479 rec->type = get_filesystem( root );
1480 if (!match_row( table, row, cond, &status ))
1482 free_row_values( table, row );
1483 continue;
1485 offset += sizeof(*rec);
1486 row++;
1487 index++;
1490 TRACE("created %u rows\n", row);
1491 table->num_rows = row;
1492 return status;
1495 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1497 static const WCHAR fmtW[] = {'%','c',':',0};
1498 WCHAR device_id[3], root[] = {'A',':','\\',0};
1499 struct record_logicaldisk *rec;
1500 UINT i, row = 0, offset = 0, type;
1501 UINT64 size = 1024 * 1024 * 1024;
1502 DWORD drives = GetLogicalDrives();
1503 enum fill_status status = FILL_STATUS_UNFILTERED;
1505 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1507 for (i = 0; i < sizeof(drives); i++)
1509 if (drives & (1 << i))
1511 root[0] = 'A' + i;
1512 type = GetDriveTypeW( root );
1513 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1514 continue;
1516 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1518 rec = (struct record_logicaldisk *)(table->data + offset);
1519 sprintfW( device_id, fmtW, 'A' + i );
1520 rec->device_id = heap_strdupW( device_id );
1521 rec->drivetype = type;
1522 rec->filesystem = get_filesystem( root );
1523 rec->freespace = get_freespace( root, &size );
1524 rec->name = heap_strdupW( device_id );
1525 rec->size = size;
1526 if (!match_row( table, row, cond, &status ))
1528 free_row_values( table, row );
1529 continue;
1531 offset += sizeof(*rec);
1532 row++;
1535 TRACE("created %u rows\n", row);
1536 table->num_rows = row;
1537 return status;
1540 static UINT16 get_connection_status( IF_OPER_STATUS status )
1542 switch (status)
1544 case IfOperStatusDown:
1545 return 0; /* Disconnected */
1546 case IfOperStatusUp:
1547 return 2; /* Connected */
1548 default:
1549 ERR("unhandled status %u\n", status);
1550 break;
1552 return 0;
1554 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1556 static const WCHAR fmtW[] =
1557 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1558 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1559 WCHAR *ret;
1561 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1562 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1563 return ret;
1565 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1567 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1568 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1569 static const WCHAR firewireW[] = {'1','3','9','4',0};
1570 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1572 switch (type)
1574 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1575 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1576 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1577 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1578 default: *physical = 0; return NULL;
1582 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1584 static const WCHAR fmtW[] = {'%','u',0};
1585 WCHAR device_id[11];
1586 struct record_networkadapter *rec;
1587 IP_ADAPTER_ADDRESSES *aa, *buffer;
1588 UINT row = 0, offset = 0, count = 0;
1589 DWORD size = 0, ret;
1590 int physical;
1591 enum fill_status status = FILL_STATUS_UNFILTERED;
1593 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1594 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1596 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1597 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1599 heap_free( buffer );
1600 return FILL_STATUS_FAILED;
1602 for (aa = buffer; aa; aa = aa->Next) count++;
1603 if (!resize_table( table, count, sizeof(*rec) ))
1605 heap_free( buffer );
1606 return FILL_STATUS_FAILED;
1608 for (aa = buffer; aa; aa = aa->Next)
1610 rec = (struct record_networkadapter *)(table->data + offset);
1611 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1612 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1613 rec->device_id = heap_strdupW( device_id );
1614 rec->interface_index = aa->u.s.IfIndex;
1615 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1616 rec->manufacturer = compsys_manufacturerW;
1617 rec->netconnection_status = get_connection_status( aa->OperStatus );
1618 rec->physicaladapter = physical;
1619 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1620 rec->speed = 1000000;
1621 if (!match_row( table, row, cond, &status ))
1623 free_row_values( table, row );
1624 continue;
1626 offset += sizeof(*rec);
1627 row++;
1629 TRACE("created %u rows\n", row);
1630 table->num_rows = row;
1632 heap_free( buffer );
1633 return status;
1636 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1638 struct record_networkadapterconfig *rec;
1639 IP_ADAPTER_ADDRESSES *aa, *buffer;
1640 UINT row = 0, offset = 0, count = 0;
1641 DWORD size = 0, ret;
1642 enum fill_status status = FILL_STATUS_UNFILTERED;
1644 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1645 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1647 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1648 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1650 heap_free( buffer );
1651 return FILL_STATUS_FAILED;
1653 for (aa = buffer; aa; aa = aa->Next) count++;
1654 if (!resize_table( table, count, sizeof(*rec) ))
1656 heap_free( buffer );
1657 return FILL_STATUS_FAILED;
1659 for (aa = buffer; aa; aa = aa->Next)
1661 rec = (struct record_networkadapterconfig *)(table->data + offset);
1662 rec->index = aa->u.s.IfIndex;
1663 rec->ipenabled = -1;
1664 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1665 if (!match_row( table, row, cond, &status ))
1667 free_row_values( table, row );
1668 continue;
1670 offset += sizeof(*rec);
1671 row++;
1673 TRACE("created %u rows\n", row);
1674 table->num_rows = row;
1676 heap_free( buffer );
1677 return status;
1680 static WCHAR *get_cmdline( DWORD process_id )
1682 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1683 return NULL; /* FIXME handle different process case */
1686 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1688 static const WCHAR fmtW[] = {'%','u',0};
1689 WCHAR handle[11];
1690 struct record_process *rec;
1691 PROCESSENTRY32W entry;
1692 HANDLE snap;
1693 enum fill_status status = FILL_STATUS_FAILED;
1694 UINT row = 0, offset = 0;
1696 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1697 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1699 entry.dwSize = sizeof(entry);
1700 if (!Process32FirstW( snap, &entry )) goto done;
1701 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1705 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1707 rec = (struct record_process *)(table->data + offset);
1708 rec->caption = heap_strdupW( entry.szExeFile );
1709 rec->commandline = get_cmdline( entry.th32ProcessID );
1710 rec->description = heap_strdupW( entry.szExeFile );
1711 sprintfW( handle, fmtW, entry.th32ProcessID );
1712 rec->handle = heap_strdupW( handle );
1713 rec->name = heap_strdupW( entry.szExeFile );
1714 rec->process_id = entry.th32ProcessID;
1715 rec->pprocess_id = entry.th32ParentProcessID;
1716 rec->thread_count = entry.cntThreads;
1717 rec->get_owner = process_get_owner;
1718 if (!match_row( table, row, cond, &status ))
1720 free_row_values( table, row );
1721 continue;
1723 offset += sizeof(*rec);
1724 row++;
1725 } while (Process32NextW( snap, &entry ));
1727 TRACE("created %u rows\n", row);
1728 table->num_rows = row;
1729 status = FILL_STATUS_UNFILTERED;
1731 done:
1732 CloseHandle( snap );
1733 return status;
1736 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1738 #ifdef __i386__
1739 __asm__("pushl %%ebx\n\t"
1740 "cpuid\n\t"
1741 "movl %%ebx, %%esi\n\t"
1742 "popl %%ebx"
1743 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1744 : "0" (ax));
1745 #endif
1748 static void get_processor_id( WCHAR *processor_id )
1750 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1751 unsigned int regs[4] = {0, 0, 0, 0};
1753 do_cpuid( 1, regs );
1754 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1756 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1758 unsigned int i;
1759 unsigned char *p = (unsigned char *)regs;
1761 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1762 buffer[i] = 0;
1764 static void get_processor_manufacturer( WCHAR *manufacturer )
1766 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1768 do_cpuid( 0, regs );
1769 tmp = regs[2]; /* swap edx and ecx */
1770 regs[2] = regs[3];
1771 regs[3] = tmp;
1773 regs_to_str( regs + 1, 12, manufacturer );
1775 static void get_processor_name( WCHAR *name )
1777 unsigned int regs[4] = {0, 0, 0, 0};
1779 do_cpuid( 0x80000000, regs );
1780 if (regs[0] >= 0x80000004)
1782 do_cpuid( 0x80000002, regs );
1783 regs_to_str( regs, 16, name );
1784 do_cpuid( 0x80000003, regs );
1785 regs_to_str( regs, 16, name + 16 );
1786 do_cpuid( 0x80000004, regs );
1787 regs_to_str( regs, 16, name + 32 );
1790 static UINT get_processor_maxclockspeed( void )
1792 PROCESSOR_POWER_INFORMATION *info;
1793 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1794 NTSTATUS status;
1796 if ((info = heap_alloc( size )))
1798 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1799 if (!status) ret = info[0].MaxMhz;
1800 heap_free( info );
1802 return ret;
1804 static const WCHAR *get_osarchitecture(void)
1806 SYSTEM_INFO info;
1807 GetNativeSystemInfo( &info );
1808 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1809 return os_32bitW;
1812 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
1814 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1815 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1816 struct record_processor *rec;
1817 UINT i, offset = 0, maxclockspeed, num_cores, num_logical_processors, count = get_processor_count();
1818 enum fill_status status = FILL_STATUS_UNFILTERED;
1820 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
1822 get_processor_id( processor_id );
1823 get_processor_manufacturer( manufacturer );
1824 get_processor_name( name );
1826 maxclockspeed = get_processor_maxclockspeed();
1827 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
1828 num_cores /= count;
1830 for (i = 0; i < count; i++)
1832 rec = (struct record_processor *)(table->data + offset);
1833 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
1834 rec->cpu_status = 1; /* CPU Enabled */
1835 sprintfW( device_id, fmtW, i );
1836 rec->device_id = heap_strdupW( device_id );
1837 rec->family = 2; /* Unknown */
1838 rec->manufacturer = heap_strdupW( manufacturer );
1839 rec->maxclockspeed = maxclockspeed;
1840 rec->name = heap_strdupW( name );
1841 rec->num_cores = num_cores;
1842 rec->num_logical_processors = num_logical_processors;
1843 rec->processor_id = heap_strdupW( processor_id );
1844 rec->unique_id = NULL;
1845 if (!match_row( table, i, cond, &status ))
1847 free_row_values( table, i );
1848 continue;
1850 offset += sizeof(*rec);
1853 TRACE("created %u rows\n", count);
1854 table->num_rows = count;
1855 return status;
1858 static WCHAR *get_lastbootuptime(void)
1860 static const WCHAR fmtW[] =
1861 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1862 '.','%','0','6','u','+','0','0','0',0};
1863 SYSTEM_TIMEOFDAY_INFORMATION ti;
1864 TIME_FIELDS tf;
1865 WCHAR *ret;
1867 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1869 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1870 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1871 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1872 return ret;
1874 static WCHAR *get_localdatetime(void)
1876 static const WCHAR fmtW[] =
1877 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1878 '.','%','0','6','u','%','+','0','3','d',0};
1879 TIME_ZONE_INFORMATION tzi;
1880 SYSTEMTIME st;
1881 WCHAR *ret;
1882 DWORD Status;
1883 LONG Bias;
1885 Status = GetTimeZoneInformation(&tzi);
1887 if(Status == TIME_ZONE_ID_INVALID) return NULL;
1888 Bias = tzi.Bias;
1889 if(Status == TIME_ZONE_ID_DAYLIGHT)
1890 Bias+= tzi.DaylightBias;
1891 else
1892 Bias+= tzi.StandardBias;
1893 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1895 GetLocalTime(&st);
1896 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
1897 return ret;
1899 static WCHAR *get_systemdirectory(void)
1901 void *redir;
1902 WCHAR *ret;
1904 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1905 Wow64DisableWow64FsRedirection( &redir );
1906 GetSystemDirectoryW( ret, MAX_PATH );
1907 Wow64RevertWow64FsRedirection( redir );
1908 return ret;
1910 static WCHAR *get_codeset(void)
1912 static const WCHAR fmtW[] = {'%','u',0};
1913 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
1914 if (ret) sprintfW( ret, fmtW, GetACP() );
1915 return ret;
1917 static WCHAR *get_countrycode(void)
1919 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
1920 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
1921 return ret;
1923 static WCHAR *get_locale(void)
1925 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
1926 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
1927 return ret;
1930 static enum fill_status fill_os( struct table *table, const struct expr *cond )
1932 struct record_operatingsystem *rec;
1933 enum fill_status status = FILL_STATUS_UNFILTERED;
1934 UINT row = 0;
1936 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1938 rec = (struct record_operatingsystem *)table->data;
1939 rec->caption = os_captionW;
1940 rec->codeset = get_codeset();
1941 rec->countrycode = get_countrycode();
1942 rec->csdversion = os_csdversionW;
1943 rec->lastbootuptime = get_lastbootuptime();
1944 rec->localdatetime = get_localdatetime();
1945 rec->locale = get_locale();
1946 rec->osarchitecture = get_osarchitecture();
1947 rec->oslanguage = GetSystemDefaultLangID();
1948 rec->osproductsuite = 2461140; /* Windows XP Professional */
1949 rec->ostype = 18; /* WINNT */
1950 rec->servicepackmajor = 3;
1951 rec->servicepackminor = 0;
1952 rec->suitemask = 272; /* Single User + Terminal */
1953 rec->systemdirectory = get_systemdirectory();
1954 rec->version = os_versionW;
1955 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1956 else row++;
1958 TRACE("created %u rows\n", row);
1959 table->num_rows = row;
1960 return status;
1963 static const WCHAR *get_service_type( DWORD type )
1965 static const WCHAR filesystem_driverW[] =
1966 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1967 static const WCHAR kernel_driverW[] =
1968 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1969 static const WCHAR own_processW[] =
1970 {'O','w','n',' ','P','r','o','c','e','s','s',0};
1971 static const WCHAR share_processW[] =
1972 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1974 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
1975 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
1976 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
1977 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1978 else ERR("unhandled type 0x%08x\n", type);
1979 return NULL;
1981 static const WCHAR *get_service_state( DWORD state )
1983 static const WCHAR runningW[] =
1984 {'R','u','n','n','i','n','g',0};
1985 static const WCHAR start_pendingW[] =
1986 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1987 static const WCHAR stop_pendingW[] =
1988 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1989 static const WCHAR stoppedW[] =
1990 {'S','t','o','p','p','e','d',0};
1991 static const WCHAR unknownW[] =
1992 {'U','n','k','n','o','w','n',0};
1994 switch (state)
1996 case SERVICE_STOPPED: return stoppedW;
1997 case SERVICE_START_PENDING: return start_pendingW;
1998 case SERVICE_STOP_PENDING: return stop_pendingW;
1999 case SERVICE_RUNNING: return runningW;
2000 default:
2001 ERR("unknown state %u\n", state);
2002 return unknownW;
2005 static const WCHAR *get_service_startmode( DWORD mode )
2007 static const WCHAR bootW[] = {'B','o','o','t',0};
2008 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
2009 static const WCHAR autoW[] = {'A','u','t','o',0};
2010 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
2011 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
2012 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2014 switch (mode)
2016 case SERVICE_BOOT_START: return bootW;
2017 case SERVICE_SYSTEM_START: return systemW;
2018 case SERVICE_AUTO_START: return autoW;
2019 case SERVICE_DEMAND_START: return manualW;
2020 case SERVICE_DISABLED: return disabledW;
2021 default:
2022 ERR("unknown mode 0x%x\n", mode);
2023 return unknownW;
2026 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2028 QUERY_SERVICE_CONFIGW *config = NULL;
2029 SC_HANDLE service;
2030 DWORD size;
2032 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2033 QueryServiceConfigW( service, NULL, 0, &size );
2034 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2035 if (!(config = heap_alloc( size ))) goto done;
2036 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2037 heap_free( config );
2038 config = NULL;
2040 done:
2041 CloseServiceHandle( service );
2042 return config;
2045 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2047 struct record_service *rec;
2048 SC_HANDLE manager;
2049 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2050 SERVICE_STATUS_PROCESS *status;
2051 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2052 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2053 UINT i, row = 0, offset = 0, size = 256, needed, count;
2054 enum fill_status fill_status = FILL_STATUS_FAILED;
2055 BOOL ret;
2057 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2058 if (!(services = heap_alloc( size ))) goto done;
2060 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2061 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2062 &count, NULL, NULL );
2063 if (!ret)
2065 if (GetLastError() != ERROR_MORE_DATA) goto done;
2066 size = needed;
2067 if (!(tmp = heap_realloc( services, size ))) goto done;
2068 services = tmp;
2069 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2070 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2071 &count, NULL, NULL );
2072 if (!ret) goto done;
2074 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2076 GetComputerNameW( sysnameW, &len );
2077 fill_status = FILL_STATUS_UNFILTERED;
2079 for (i = 0; i < count; i++)
2081 QUERY_SERVICE_CONFIGW *config;
2083 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2085 status = &services[i].ServiceStatusProcess;
2086 rec = (struct record_service *)(table->data + offset);
2087 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2088 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2089 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2090 rec->name = heap_strdupW( services[i].lpServiceName );
2091 rec->process_id = status->dwProcessId;
2092 rec->servicetype = get_service_type( status->dwServiceType );
2093 rec->startmode = get_service_startmode( config->dwStartType );
2094 rec->state = get_service_state( status->dwCurrentState );
2095 rec->systemname = heap_strdupW( sysnameW );
2096 rec->pause_service = service_pause_service;
2097 rec->resume_service = service_resume_service;
2098 rec->start_service = service_start_service;
2099 rec->stop_service = service_stop_service;
2100 heap_free( config );
2101 if (!match_row( table, row, cond, &fill_status ))
2103 free_row_values( table, row );
2104 continue;
2106 offset += sizeof(*rec);
2107 row++;
2110 TRACE("created %u rows\n", row);
2111 table->num_rows = row;
2113 done:
2114 CloseServiceHandle( manager );
2115 heap_free( services );
2116 return fill_status;
2119 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2121 HDC hdc = GetDC( NULL );
2122 UINT32 ret;
2124 if (!hdc) return 32;
2125 ret = GetDeviceCaps( hdc, BITSPIXEL );
2126 *hres = GetDeviceCaps( hdc, HORZRES );
2127 *vres = GetDeviceCaps( hdc, VERTRES );
2128 ReleaseDC( NULL, hdc );
2129 return ret;
2131 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2133 static const WCHAR fmtW[] =
2134 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2135 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2136 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2137 WCHAR *ret;
2139 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2140 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2141 return ret;
2144 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2147 struct record_videocontroller *rec;
2148 HRESULT hr;
2149 IDXGIFactory *factory = NULL;
2150 IDXGIAdapter *adapter = NULL;
2151 DXGI_ADAPTER_DESC desc;
2152 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2153 const WCHAR *name = videocontroller_deviceidW;
2154 enum fill_status status = FILL_STATUS_UNFILTERED;
2155 UINT row = 0;
2157 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2159 memset (&desc, 0, sizeof(desc));
2160 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2161 if (FAILED(hr)) goto done;
2163 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2164 if (FAILED(hr)) goto done;
2166 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2167 if (SUCCEEDED(hr))
2169 vidmem = desc.DedicatedVideoMemory;
2170 name = desc.Description;
2173 done:
2174 rec = (struct record_videocontroller *)table->data;
2175 rec->adapter_dactype = videocontroller_dactypeW;
2176 rec->adapter_ram = vidmem;
2177 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2178 rec->current_horizontalres = hres;
2179 rec->current_verticalres = vres;
2180 rec->description = heap_strdupW( name );
2181 rec->device_id = videocontroller_deviceidW;
2182 rec->name = heap_strdupW( name );
2183 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2184 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2185 else row++;
2187 TRACE("created %u rows\n", row);
2188 table->num_rows = row;
2190 if (adapter) IDXGIAdapter_Release( adapter );
2191 if (factory) IDXGIFactory_Release( factory );
2192 return status;
2195 static struct table builtin_classes[] =
2197 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2198 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2199 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2200 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2201 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2202 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2203 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), 0, (BYTE *)data_diskdrive },
2204 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2205 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2206 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2207 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2208 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2209 fill_networkadapterconfig },
2210 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2211 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2212 { class_physicalmediaW, SIZEOF(col_physicalmedia), col_physicalmedia, SIZEOF(data_physicalmedia), 0, (BYTE *)data_physicalmedia },
2213 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2214 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2215 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2216 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2217 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2218 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2219 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2222 void init_table_list( void )
2224 static struct list tables = LIST_INIT( tables );
2225 UINT i;
2227 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2228 table_list = &tables;