wbemprox: Add a partial implementation of Win32_NetworkAdapterConfiguration.
[wine/wine-gecko.git] / dlls / wbemprox / builtin.c
blob4efb17bb21ea22d7fbac5e709601abab4c180921
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_qualifiersW[] =
77 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
78 static const WCHAR class_process_getowner_outW[] =
79 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
80 'N','E','R','_','O','U','T',0};
81 static const WCHAR class_processorW[] =
82 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
83 static const WCHAR class_sounddeviceW[] =
84 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
85 static const WCHAR class_videocontrollerW[] =
86 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
88 static const WCHAR prop_acceptpauseW[] =
89 {'A','c','c','e','p','t','P','a','u','s','e',0};
90 static const WCHAR prop_acceptstopW[] =
91 {'A','c','c','e','p','t','S','t','o','p',0};
92 static const WCHAR prop_accessmaskW[] =
93 {'A','c','c','e','s','s','M','a','s','k',0};
94 static const WCHAR prop_adapterdactypeW[] =
95 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
96 static const WCHAR prop_adapterramW[] =
97 {'A','d','a','p','t','e','r','R','A','M',0};
98 static const WCHAR prop_adaptertypeW[] =
99 {'A','d','a','p','t','e','r','T','y','p','e',0};
100 static const WCHAR prop_addresswidthW[] =
101 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
102 static const WCHAR prop_bootableW[] =
103 {'B','o','o','t','a','b','l','e',0};
104 static const WCHAR prop_bootpartitionW[] =
105 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
106 static const WCHAR prop_captionW[] =
107 {'C','a','p','t','i','o','n',0};
108 static const WCHAR prop_classW[] =
109 {'C','l','a','s','s',0};
110 static const WCHAR prop_codesetW[] =
111 {'C','o','d','e','S','e','t',0};
112 static const WCHAR prop_commandlineW[] =
113 {'C','o','m','m','a','n','d','L','i','n','e',0};
114 static const WCHAR prop_countrycodeW[] =
115 {'C','o','u','n','t','r','y','C','o','d','e',0};
116 static const WCHAR prop_cpustatusW[] =
117 {'C','p','u','S','t','a','t','u','s',0};
118 static const WCHAR prop_csdversionW[] =
119 {'C','S','D','V','e','r','s','i','o','n',0};
120 static const WCHAR prop_currentbitsperpixelW[] =
121 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
122 static const WCHAR prop_currenthorizontalresW[] =
123 {'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};
124 static const WCHAR prop_currentverticalresW[] =
125 {'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};
126 static const WCHAR prop_defaultvalueW[] =
127 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
128 static const WCHAR prop_descriptionW[] =
129 {'D','e','s','c','r','i','p','t','i','o','n',0};
130 static const WCHAR prop_deviceidW[] =
131 {'D','e','v','i','c','e','I','d',0};
132 static const WCHAR prop_directionW[] =
133 {'D','i','r','e','c','t','i','o','n',0};
134 static const WCHAR prop_displaynameW[] =
135 {'D','i','s','p','l','a','y','N','a','m','e',0};
136 static const WCHAR prop_diskindexW[] =
137 {'D','i','s','k','I','n','d','e','x',0};
138 static const WCHAR prop_domainW[] =
139 {'D','o','m','a','i','n',0};
140 static const WCHAR prop_domainroleW[] =
141 {'D','o','m','a','i','n','R','o','l','e',0};
142 static const WCHAR prop_driveW[] =
143 {'D','r','i','v','e',0};
144 static const WCHAR prop_drivetypeW[] =
145 {'D','r','i','v','e','T','y','p','e',0};
146 static const WCHAR prop_familyW[] =
147 {'F','a','m','i','l','y',0};
148 static const WCHAR prop_filesystemW[] =
149 {'F','i','l','e','S','y','s','t','e','m',0};
150 static const WCHAR prop_flavorW[] =
151 {'F','l','a','v','o','r',0};
152 static const WCHAR prop_freespaceW[] =
153 {'F','r','e','e','S','p','a','c','e',0};
154 static const WCHAR prop_handleW[] =
155 {'H','a','n','d','l','e',0};
156 static const WCHAR prop_idW[] =
157 {'I','D',0};
158 static const WCHAR prop_identificationcodeW[] =
159 {'I','d','e','n','t','i','f','i','c','a','t','i','o','n','C','o','d','e',0};
160 static const WCHAR prop_indexW[] =
161 {'I','n','d','e','x',0};
162 static const WCHAR prop_interfaceindexW[] =
163 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
164 static const WCHAR prop_intvalueW[] =
165 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
166 static const WCHAR prop_ipenabledW[] =
167 {'I','P','E','n','a','b','l','e','d',0};
168 static const WCHAR prop_lastbootuptimeW[] =
169 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
170 static const WCHAR prop_localdatetimeW[] =
171 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
172 static const WCHAR prop_localeW[] =
173 {'L','o','c','a','l','e',0};
174 static const WCHAR prop_macaddressW[] =
175 {'M','A','C','A','d','d','r','e','s','s',0};
176 static const WCHAR prop_manufacturerW[] =
177 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
178 static const WCHAR prop_maxclockspeedW[] =
179 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
180 static const WCHAR prop_memberW[] =
181 {'M','e','m','b','e','r',0};
182 static const WCHAR prop_methodW[] =
183 {'M','e','t','h','o','d',0};
184 static const WCHAR prop_modelW[] =
185 {'M','o','d','e','l',0};
186 static const WCHAR prop_netconnectionstatusW[] =
187 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
188 static const WCHAR prop_numcoresW[] =
189 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
190 static const WCHAR prop_numlogicalprocessorsW[] =
191 {'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};
192 static const WCHAR prop_numprocessorsW[] =
193 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
194 static const WCHAR prop_osarchitectureW[] =
195 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
196 static const WCHAR prop_oslanguageW[] =
197 {'O','S','L','a','n','g','u','a','g','e',0};
198 static const WCHAR prop_osproductsuiteW[] =
199 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
200 static const WCHAR prop_ostypeW[] =
201 {'O','S','T','y','p','e',0};
202 static const WCHAR prop_parameterW[] =
203 {'P','a','r','a','m','e','t','e','r',0};
204 static const WCHAR prop_physicaladapterW[] =
205 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
206 static const WCHAR prop_pnpdeviceidW[] =
207 {'P','N','P','D','e','v','i','c','e','I','D',0};
208 static const WCHAR prop_pprocessidW[] =
209 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
210 static const WCHAR prop_processidW[] =
211 {'P','r','o','c','e','s','s','I','D',0};
212 static const WCHAR prop_processoridW[] =
213 {'P','r','o','c','e','s','s','o','r','I','d',0};
214 static const WCHAR prop_productnameW[] =
215 {'P','r','o','d','u','c','t','N','a','m','e',0};
216 static const WCHAR prop_releasedateW[] =
217 {'R','e','l','e','a','s','e','D','a','t','e',0};
218 static const WCHAR prop_serialnumberW[] =
219 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
220 static const WCHAR prop_servicepackmajorW[] =
221 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
222 static const WCHAR prop_servicepackminorW[] =
223 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
224 static const WCHAR prop_servicetypeW[] =
225 {'S','e','r','v','i','c','e','T','y','p','e',0};
226 static const WCHAR prop_smbiosbiosversionW[] =
227 {'S','M','B','I','O','S','B','I','O','S','V','e','r','s','i','o','n',0};
228 static const WCHAR prop_startmodeW[] =
229 {'S','t','a','r','t','M','o','d','e',0};
230 static const WCHAR prop_sizeW[] =
231 {'S','i','z','e',0};
232 static const WCHAR prop_speedW[] =
233 {'S','p','e','e','d',0};
234 static const WCHAR prop_startingoffsetW[] =
235 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
236 static const WCHAR prop_stateW[] =
237 {'S','t','a','t','e',0};
238 static const WCHAR prop_strvalueW[] =
239 {'S','t','r','i','n','g','V','a','l','u','e',0};
240 static const WCHAR prop_suitemaskW[] =
241 {'S','u','i','t','e','M','a','s','k',0};
242 static const WCHAR prop_systemdirectoryW[] =
243 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
244 static const WCHAR prop_systemnameW[] =
245 {'S','y','s','t','e','m','N','a','m','e',0};
246 static const WCHAR prop_tagW[] =
247 {'T','a','g',0};
248 static const WCHAR prop_threadcountW[] =
249 {'T','h','r','e','a','d','C','o','u','n','t',0};
250 static const WCHAR prop_totalphysicalmemoryW[] =
251 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
252 static const WCHAR prop_typeW[] =
253 {'T','y','p','e',0};
254 static const WCHAR prop_uniqueidW[] =
255 {'U','n','i','q','u','e','I','d',0};
256 static const WCHAR prop_varianttypeW[] =
257 {'V','a','r','i','a','n','t','T','y','p','e',0};
258 static const WCHAR prop_versionW[] =
259 {'V','e','r','s','i','o','n',0};
261 /* column definitions must be kept in sync with record structures below */
262 static const struct column col_baseboard[] =
264 { prop_manufacturerW, CIM_STRING },
265 { prop_modelW, CIM_STRING },
266 { prop_nameW, CIM_STRING },
267 { prop_serialnumberW, CIM_STRING },
268 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
270 static const struct column col_bios[] =
272 { prop_descriptionW, CIM_STRING },
273 { prop_identificationcodeW, CIM_STRING },
274 { prop_manufacturerW, CIM_STRING },
275 { prop_releasedateW, CIM_DATETIME },
276 { prop_serialnumberW, CIM_STRING },
277 { prop_smbiosbiosversionW, CIM_STRING },
278 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
280 static const struct column col_cdromdrive[] =
282 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
283 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
284 { prop_nameW, CIM_STRING },
285 { prop_pnpdeviceidW, CIM_STRING }
287 static const struct column col_compsys[] =
289 { prop_descriptionW, CIM_STRING },
290 { prop_domainW, CIM_STRING },
291 { prop_domainroleW, CIM_UINT16 },
292 { prop_manufacturerW, CIM_STRING },
293 { prop_modelW, CIM_STRING },
294 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
295 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
296 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
297 { prop_totalphysicalmemoryW, CIM_UINT64 }
299 static const struct column col_datafile[] =
301 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
302 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
304 static const struct column col_directory[] =
306 { prop_accessmaskW, CIM_UINT32 },
307 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
309 static const struct column col_diskdrive[] =
311 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
312 { prop_indexW, CIM_UINT32, VT_I4 },
313 { prop_manufacturerW, CIM_STRING },
314 { prop_modelW, CIM_STRING },
315 { prop_serialnumberW, CIM_STRING }
317 static const struct column col_diskpartition[] =
319 { prop_bootableW, CIM_BOOLEAN },
320 { prop_bootpartitionW, CIM_BOOLEAN },
321 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
322 { prop_diskindexW, CIM_UINT32, VT_I4 },
323 { prop_indexW, CIM_UINT32, VT_I4 },
324 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
325 { prop_sizeW, CIM_UINT64 },
326 { prop_startingoffsetW, CIM_UINT64 },
327 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
329 static const struct column col_logicaldisk[] =
331 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
332 { prop_drivetypeW, CIM_UINT32, VT_I4 },
333 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
334 { prop_freespaceW, CIM_UINT64 },
335 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
336 { prop_sizeW, CIM_UINT64 }
338 static const struct column col_networkadapter[] =
340 { prop_adaptertypeW, CIM_STRING },
341 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
342 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
343 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
344 { prop_manufacturerW, CIM_STRING },
345 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
346 { prop_physicaladapterW, CIM_BOOLEAN },
347 { prop_pnpdeviceidW, CIM_STRING },
348 { prop_speedW, CIM_UINT64 }
350 static const struct column col_networkadapterconfig[] =
352 { prop_indexW, CIM_UINT32|COL_FLAG_KEY },
353 { prop_ipenabledW, CIM_BOOLEAN },
354 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC }
356 static const struct column col_os[] =
358 { prop_captionW, CIM_STRING },
359 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
360 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
361 { prop_csdversionW, CIM_STRING },
362 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
363 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
364 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
365 { prop_osarchitectureW, CIM_STRING },
366 { prop_oslanguageW, CIM_UINT32, VT_I4 },
367 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
368 { prop_ostypeW, CIM_UINT16, VT_I4 },
369 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
370 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
371 { prop_suitemaskW, CIM_UINT32, VT_I4 },
372 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
373 { prop_versionW, CIM_STRING }
375 static const struct column col_param[] =
377 { prop_classW, CIM_STRING },
378 { prop_methodW, CIM_STRING },
379 { prop_directionW, CIM_SINT32 },
380 { prop_parameterW, CIM_STRING },
381 { prop_typeW, CIM_UINT32 },
382 { prop_varianttypeW, CIM_UINT32 },
383 { prop_defaultvalueW, CIM_UINT32 }
385 static const struct column col_process[] =
387 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
388 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
389 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
390 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
391 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
392 { prop_pprocessidW, CIM_UINT32, VT_I4 },
393 { prop_processidW, CIM_UINT32, VT_I4 },
394 { prop_threadcountW, CIM_UINT32, VT_I4 },
395 /* methods */
396 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
398 static const struct column col_processor[] =
400 { prop_addresswidthW, CIM_UINT16, VT_I4 },
401 { prop_cpustatusW, CIM_UINT16 },
402 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
403 { prop_familyW, CIM_UINT16, VT_I4 },
404 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
405 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
406 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
407 { prop_numcoresW, CIM_UINT32, VT_I4 },
408 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
409 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
410 { prop_uniqueidW, CIM_STRING }
412 static const struct column col_qualifier[] =
414 { prop_classW, CIM_STRING },
415 { prop_memberW, CIM_STRING },
416 { prop_typeW, CIM_UINT32 },
417 { prop_flavorW, CIM_SINT32 },
418 { prop_nameW, CIM_STRING },
419 { prop_intvalueW, CIM_SINT32 },
420 { prop_strvalueW, CIM_STRING }
422 static const struct column col_service[] =
424 { prop_acceptpauseW, CIM_BOOLEAN },
425 { prop_acceptstopW, CIM_BOOLEAN },
426 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
427 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
428 { prop_processidW, CIM_UINT32 },
429 { prop_servicetypeW, CIM_STRING },
430 { prop_startmodeW, CIM_STRING },
431 { prop_stateW, CIM_STRING },
432 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
433 /* methods */
434 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
435 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
436 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
437 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
439 static const struct column col_sounddevice[] =
441 { prop_nameW, CIM_STRING },
442 { prop_productnameW, CIM_STRING }
444 static const struct column col_stdregprov[] =
446 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
447 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
448 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
450 static const struct column col_videocontroller[] =
452 { prop_adapterdactypeW, CIM_STRING },
453 { prop_adapterramW, CIM_UINT32, VT_I4 },
454 { prop_currentbitsperpixelW, CIM_UINT32 },
455 { prop_currenthorizontalresW, CIM_UINT32 },
456 { prop_currentverticalresW, CIM_UINT32 },
457 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
458 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
459 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
460 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
463 static const WCHAR baseboard_manufacturerW[] =
464 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
465 static const WCHAR baseboard_serialnumberW[] =
466 {'N','o','n','e',0};
467 static const WCHAR baseboard_tagW[] =
468 {'B','a','s','e',' ','B','o','a','r','d',0};
469 static const WCHAR bios_descriptionW[] =
470 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
471 static const WCHAR bios_manufacturerW[] =
472 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
473 static const WCHAR bios_releasedateW[] =
474 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
475 static const WCHAR bios_serialnumberW[] =
476 {'0',0};
477 static const WCHAR bios_smbiosbiosversionW[] =
478 {'W','i','n','e',0};
479 static const WCHAR bios_versionW[] =
480 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
481 static const WCHAR cdromdrive_nameW[] =
482 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
483 static const WCHAR cdromdrive_pnpdeviceidW[]=
484 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
485 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
486 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
487 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
488 static const WCHAR compsys_descriptionW[] =
489 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
490 static const WCHAR compsys_domainW[] =
491 {'W','O','R','K','G','R','O','U','P',0};
492 static const WCHAR compsys_manufacturerW[] =
493 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
494 static const WCHAR compsys_modelW[] =
495 {'W','i','n','e',0};
496 static const WCHAR diskdrive_deviceidW[] =
497 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
498 static const WCHAR diskdrive_modelW[] =
499 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
500 static const WCHAR diskdrive_manufacturerW[] =
501 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
502 static const WCHAR diskdrive_serialW[] =
503 {'W','I','N','E','H','D','I','S','K',0};
504 static const WCHAR networkadapter_pnpdeviceidW[]=
505 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
506 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
507 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
508 static const WCHAR os_captionW[] =
509 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
510 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
511 static const WCHAR os_csdversionW[] =
512 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
513 static const WCHAR os_32bitW[] =
514 {'3','2','-','b','i','t',0};
515 static const WCHAR os_64bitW[] =
516 {'6','4','-','b','i','t',0};
517 static const WCHAR os_versionW[] =
518 {'5','.','1','.','2','6','0','0',0};
519 static const WCHAR sounddevice_productnameW[] =
520 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
521 static const WCHAR videocontroller_dactypeW[] =
522 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
523 static const WCHAR videocontroller_deviceidW[] =
524 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
526 #include "pshpack1.h"
527 struct record_baseboard
529 const WCHAR *manufacturer;
530 const WCHAR *model;
531 const WCHAR *name;
532 const WCHAR *serialnumber;
533 const WCHAR *tag;
535 struct record_bios
537 const WCHAR *description;
538 const WCHAR *identificationcode;
539 const WCHAR *manufacturer;
540 const WCHAR *releasedate;
541 const WCHAR *serialnumber;
542 const WCHAR *smbiosbiosversion;
543 const WCHAR *version;
545 struct record_cdromdrive
547 const WCHAR *device_id;
548 const WCHAR *drive;
549 const WCHAR *name;
550 const WCHAR *pnpdevice_id;
552 struct record_computersystem
554 const WCHAR *description;
555 const WCHAR *domain;
556 UINT16 domainrole;
557 const WCHAR *manufacturer;
558 const WCHAR *model;
559 const WCHAR *name;
560 UINT32 num_logical_processors;
561 UINT32 num_processors;
562 UINT64 total_physical_memory;
564 struct record_datafile
566 const WCHAR *name;
567 const WCHAR *version;
569 struct record_directory
571 UINT32 accessmask;
572 const WCHAR *name;
574 struct record_diskdrive
576 const WCHAR *device_id;
577 UINT32 index;
578 const WCHAR *manufacturer;
579 const WCHAR *name;
580 const WCHAR *serialnumber;
582 struct record_diskpartition
584 int bootable;
585 int bootpartition;
586 const WCHAR *device_id;
587 UINT32 diskindex;
588 UINT32 index;
589 const WCHAR *pnpdevice_id;
590 UINT64 size;
591 UINT64 startingoffset;
592 const WCHAR *type;
594 struct record_logicaldisk
596 const WCHAR *device_id;
597 UINT32 drivetype;
598 const WCHAR *filesystem;
599 UINT64 freespace;
600 const WCHAR *name;
601 UINT64 size;
603 struct record_networkadapter
605 const WCHAR *adaptertype;
606 const WCHAR *device_id;
607 INT32 interface_index;
608 const WCHAR *mac_address;
609 const WCHAR *manufacturer;
610 UINT16 netconnection_status;
611 int physicaladapter;
612 const WCHAR *pnpdevice_id;
613 UINT64 speed;
615 struct record_networkadapterconfig
617 UINT32 index;
618 int ipenabled;
619 const WCHAR *mac_address;
621 struct record_operatingsystem
623 const WCHAR *caption;
624 const WCHAR *codeset;
625 const WCHAR *countrycode;
626 const WCHAR *csdversion;
627 const WCHAR *lastbootuptime;
628 const WCHAR *localdatetime;
629 const WCHAR *locale;
630 const WCHAR *osarchitecture;
631 UINT32 oslanguage;
632 UINT32 osproductsuite;
633 UINT16 ostype;
634 UINT16 servicepackmajor;
635 UINT16 servicepackminor;
636 UINT32 suitemask;
637 const WCHAR *systemdirectory;
638 const WCHAR *version;
640 struct record_param
642 const WCHAR *class;
643 const WCHAR *method;
644 INT32 direction;
645 const WCHAR *parameter;
646 UINT32 type;
647 UINT32 varianttype;
648 UINT32 defaultvalue;
650 struct record_process
652 const WCHAR *caption;
653 const WCHAR *commandline;
654 const WCHAR *description;
655 const WCHAR *handle;
656 const WCHAR *name;
657 UINT32 pprocess_id;
658 UINT32 process_id;
659 UINT32 thread_count;
660 /* methods */
661 class_method *get_owner;
663 struct record_processor
665 UINT16 addresswidth;
666 UINT16 cpu_status;
667 const WCHAR *device_id;
668 UINT16 family;
669 const WCHAR *manufacturer;
670 UINT32 maxclockspeed;
671 const WCHAR *name;
672 UINT32 num_cores;
673 UINT32 num_logical_processors;
674 const WCHAR *processor_id;
675 const WCHAR *unique_id;
677 struct record_qualifier
679 const WCHAR *class;
680 const WCHAR *member;
681 UINT32 type;
682 INT32 flavor;
683 const WCHAR *name;
684 INT32 intvalue;
685 const WCHAR *strvalue;
687 struct record_service
689 int accept_pause;
690 int accept_stop;
691 const WCHAR *displayname;
692 const WCHAR *name;
693 UINT32 process_id;
694 const WCHAR *servicetype;
695 const WCHAR *startmode;
696 const WCHAR *state;
697 const WCHAR *systemname;
698 /* methods */
699 class_method *pause_service;
700 class_method *resume_service;
701 class_method *start_service;
702 class_method *stop_service;
704 struct record_sounddevice
706 const WCHAR *name;
707 const WCHAR *productname;
709 struct record_stdregprov
711 class_method *enumkey;
712 class_method *enumvalues;
713 class_method *getstringvalue;
715 struct record_videocontroller
717 const WCHAR *adapter_dactype;
718 UINT32 adapter_ram;
719 UINT32 current_bitsperpixel;
720 UINT32 current_horizontalres;
721 UINT32 current_verticalres;
722 const WCHAR *description;
723 const WCHAR *device_id;
724 const WCHAR *name;
725 const WCHAR *pnpdevice_id;
727 #include "poppack.h"
729 static const struct record_baseboard data_baseboard[] =
731 { baseboard_manufacturerW, baseboard_tagW, baseboard_tagW, baseboard_serialnumberW, baseboard_tagW }
733 static const struct record_bios data_bios[] =
735 { bios_descriptionW, bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW,
736 bios_smbiosbiosversionW, bios_versionW }
738 static const struct record_diskdrive data_diskdrive[] =
740 { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
742 static const struct record_param data_param[] =
744 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
745 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
746 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
747 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
748 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
749 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
750 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
751 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
752 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
753 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
754 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
755 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
756 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
757 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
758 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
759 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
760 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
761 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
762 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
763 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
764 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
767 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
768 WBEM_FLAVOR_ORIGIN_PROPAGATED)
770 static const struct record_qualifier data_qualifier[] =
772 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
773 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
775 static const struct record_sounddevice data_sounddevice[] =
777 { sounddevice_productnameW, sounddevice_productnameW }
779 static const struct record_stdregprov data_stdregprov[] =
781 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
784 /* check if row matches condition and update status */
785 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
787 LONGLONG val;
788 if (!cond)
790 *status = FILL_STATUS_UNFILTERED;
791 return TRUE;
793 if (eval_cond( table, row, cond, &val ) != S_OK)
795 *status = FILL_STATUS_FAILED;
796 return FALSE;
798 *status = FILL_STATUS_FILTERED;
799 return val != 0;
802 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
804 if (!table->num_rows_allocated)
806 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
807 table->num_rows_allocated = row_count;
808 return TRUE;
810 if (row_count >= table->num_rows_allocated)
812 BYTE *data;
813 UINT count = table->num_rows_allocated * 2;
814 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
815 table->data = data;
816 table->num_rows_allocated = count;
818 return TRUE;
821 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
823 static const WCHAR fmtW[] = {'%','c',':',0};
824 WCHAR drive[3], root[] = {'A',':','\\',0};
825 struct record_cdromdrive *rec;
826 UINT i, row = 0, offset = 0;
827 DWORD drives = GetLogicalDrives();
828 enum fill_status status = FILL_STATUS_UNFILTERED;
830 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
832 for (i = 0; i < sizeof(drives); i++)
834 if (drives & (1 << i))
836 root[0] = 'A' + i;
837 if (GetDriveTypeW( root ) != DRIVE_CDROM)
838 continue;
840 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
842 rec = (struct record_cdromdrive *)(table->data + offset);
843 rec->device_id = cdromdrive_pnpdeviceidW;
844 sprintfW( drive, fmtW, 'A' + i );
845 rec->drive = heap_strdupW( drive );
846 rec->name = cdromdrive_nameW;
847 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
848 if (!match_row( table, row, cond, &status ))
850 free_row_values( table, row );
851 continue;
853 offset += sizeof(*rec);
854 row++;
857 TRACE("created %u rows\n", row);
858 table->num_rows = row;
859 return status;
862 static UINT get_processor_count(void)
864 SYSTEM_BASIC_INFORMATION info;
866 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
867 return info.NumberOfProcessors;
870 static UINT get_logical_processor_count( UINT *num_cores )
872 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
873 UINT i, j, count = 0;
874 NTSTATUS status;
875 ULONG len;
877 if (num_cores) *num_cores = get_processor_count();
878 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
879 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
881 if (!(info = heap_alloc( len ))) return get_processor_count();
882 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
883 if (status != STATUS_SUCCESS)
885 heap_free( info );
886 return get_processor_count();
888 if (num_cores) *num_cores = 0;
889 for (i = 0; i < len / sizeof(*info); i++)
891 if (info[i].Relationship == RelationProcessorCore)
893 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
895 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
897 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
900 heap_free( info );
901 return count;
904 static UINT64 get_total_physical_memory(void)
906 MEMORYSTATUSEX status;
908 status.dwLength = sizeof(status);
909 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
910 return status.ullTotalPhys;
913 static WCHAR *get_computername(void)
915 WCHAR *ret;
916 DWORD size = MAX_COMPUTERNAME_LENGTH;
918 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
919 GetComputerNameW( ret, &size );
920 return ret;
923 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
925 struct record_computersystem *rec;
926 enum fill_status status = FILL_STATUS_UNFILTERED;
927 UINT row = 0;
929 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
931 rec = (struct record_computersystem *)table->data;
932 rec->description = compsys_descriptionW;
933 rec->domain = compsys_domainW;
934 rec->domainrole = 0; /* standalone workstation */
935 rec->manufacturer = compsys_manufacturerW;
936 rec->model = compsys_modelW;
937 rec->name = get_computername();
938 rec->num_logical_processors = get_logical_processor_count( NULL );
939 rec->num_processors = get_processor_count();
940 rec->total_physical_memory = get_total_physical_memory();
941 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
942 else row++;
944 TRACE("created %u rows\n", row);
945 table->num_rows = row;
946 return status;
949 struct dirstack
951 WCHAR **dirs;
952 UINT *len_dirs;
953 UINT num_dirs;
954 UINT num_allocated;
957 static struct dirstack *alloc_dirstack( UINT size )
959 struct dirstack *dirstack;
961 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
962 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
964 heap_free( dirstack );
965 return NULL;
967 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
969 heap_free( dirstack->dirs );
970 heap_free( dirstack );
971 return NULL;
973 dirstack->num_dirs = 0;
974 dirstack->num_allocated = size;
975 return dirstack;
978 static void clear_dirstack( struct dirstack *dirstack )
980 UINT i;
981 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
982 dirstack->num_dirs = 0;
985 static void free_dirstack( struct dirstack *dirstack )
987 clear_dirstack( dirstack );
988 heap_free( dirstack->dirs );
989 heap_free( dirstack->len_dirs );
990 heap_free( dirstack );
993 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
995 UINT size, i = dirstack->num_dirs;
997 if (!dir) return FALSE;
999 if (i == dirstack->num_allocated)
1001 WCHAR **tmp;
1002 UINT *len_tmp;
1004 size = dirstack->num_allocated * 2;
1005 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
1006 dirstack->dirs = tmp;
1007 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
1008 dirstack->len_dirs = len_tmp;
1009 dirstack->num_allocated = size;
1011 dirstack->dirs[i] = dir;
1012 dirstack->len_dirs[i] = len;
1013 dirstack->num_dirs++;
1014 return TRUE;
1017 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
1019 if (!dirstack->num_dirs)
1021 *len = 0;
1022 return NULL;
1024 dirstack->num_dirs--;
1025 *len = dirstack->len_dirs[dirstack->num_dirs];
1026 return dirstack->dirs[dirstack->num_dirs];
1029 static const WCHAR *peek_dir( struct dirstack *dirstack )
1031 if (!dirstack->num_dirs) return NULL;
1032 return dirstack->dirs[dirstack->num_dirs - 1];
1035 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1037 UINT i = 0;
1038 WCHAR *ret;
1040 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1041 ret[i++] = drive;
1042 ret[i++] = ':';
1043 ret[i++] = '\\';
1044 if (path && len)
1046 memcpy( ret + i, path, len * sizeof(WCHAR) );
1047 i += len;
1048 ret[i++] = '\\';
1050 ret[i++] = '*';
1051 ret[i] = 0;
1052 return ret;
1055 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1057 UINT i = 0, len = 0;
1058 const WCHAR *p;
1059 WCHAR *ret;
1061 for (p = path; *p; p++)
1063 if (*p == '\\') len += 2;
1064 else len++;
1066 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1067 ret[i++] = drive;
1068 ret[i++] = ':';
1069 ret[i++] = '\\';
1070 ret[i++] = '\\';
1071 for (p = path; *p; p++)
1073 if (*p != '\\') ret[i++] = *p;
1074 else
1076 ret[i++] = '\\';
1077 ret[i++] = '\\';
1080 ret[i] = 0;
1081 return ret;
1084 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1086 const WCHAR *p = path, *start;
1087 UINT len, i;
1088 WCHAR *ret;
1090 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1091 start = path + 4;
1092 len = strlenW( start );
1093 p = start + len - 1;
1094 if (*p == '\\') return NULL;
1096 while (p >= start && *p != '\\') { len--; p--; };
1097 while (p >= start && *p == '\\') { len--; p--; };
1099 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1100 for (i = 0, p = start; p < start + len; p++)
1102 if (p[0] == '\\' && p[1] == '\\')
1104 ret[i++] = '\\';
1105 p++;
1107 else ret[i++] = *p;
1109 ret[i] = 0;
1110 *ret_len = i;
1111 return ret;
1114 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1116 UINT i;
1117 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1118 return FALSE;
1121 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1122 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1124 const struct expr *left, *right;
1126 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1128 left = cond->u.expr.left;
1129 right = cond->u.expr.right;
1130 if (cond->u.expr.op == OP_EQ)
1132 UINT len;
1133 WCHAR *path;
1134 const WCHAR *str = NULL;
1136 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1137 !strcmpW( left->u.propval->name, prop_nameW ) &&
1138 toupperW( right->u.sval[0] ) == toupperW( root ))
1140 str = right->u.sval;
1142 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1143 !strcmpW( right->u.propval->name, prop_nameW ) &&
1144 toupperW( left->u.sval[0] ) == toupperW( root ))
1146 str = left->u.sval;
1148 if (str && (path = build_dirname( str, &len )))
1150 if (seen_dir( dirstack, path ))
1152 heap_free( path );
1153 return ++*count;
1155 else if (push_dir( dirstack, path, len )) return ++*count;
1156 heap_free( path );
1157 return *count = 0;
1160 else if (cond->u.expr.op == OP_OR)
1162 UINT left_count = 0, right_count = 0;
1164 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1165 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1166 return *count += left_count + right_count;
1168 return *count = 0;
1171 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1173 UINT len_path = 0, len_segment = strlenW( segment );
1174 WCHAR *ret;
1176 *len = 0;
1177 if (path) len_path = strlenW( path );
1178 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1179 if (path && len_path)
1181 memcpy( ret, path, len_path * sizeof(WCHAR) );
1182 ret[len_path] = '\\';
1183 *len += len_path + 1;
1185 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1186 *len += len_segment;
1187 ret[*len] = 0;
1188 return ret;
1191 static WCHAR *get_file_version( const WCHAR *filename )
1193 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1194 VS_FIXEDFILEINFO *info;
1195 DWORD size;
1196 void *block;
1197 WCHAR *ret;
1199 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1200 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1202 heap_free( ret );
1203 return NULL;
1205 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1206 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1208 heap_free( block );
1209 heap_free( ret );
1210 return NULL;
1212 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1213 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1214 heap_free( block );
1215 return ret;
1218 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1220 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1221 struct record_datafile *rec;
1222 UINT i, len, row = 0, offset = 0, num_expected_rows;
1223 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1224 DWORD drives = GetLogicalDrives();
1225 WIN32_FIND_DATAW data;
1226 HANDLE handle;
1227 struct dirstack *dirstack = alloc_dirstack(2);
1228 enum fill_status status = FILL_STATUS_UNFILTERED;
1230 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1232 for (i = 0; i < sizeof(drives); i++)
1234 if (!(drives & (1 << i))) continue;
1236 root[0] = 'A' + i;
1237 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1239 num_expected_rows = 0;
1240 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1242 for (;;)
1244 path = pop_dir( dirstack, &len );
1245 if (!(glob = build_glob( root[0], path, len )))
1247 status = FILL_STATUS_FAILED;
1248 goto done;
1250 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1254 if (!resize_table( table, row + 1, sizeof(*rec) ))
1256 status = FILL_STATUS_FAILED;
1257 goto done;
1259 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1260 new_path = append_path( path, data.cFileName, &len );
1262 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1264 if (push_dir( dirstack, new_path, len )) continue;
1265 heap_free( new_path );
1266 status = FILL_STATUS_FAILED;
1267 goto done;
1269 rec = (struct record_datafile *)(table->data + offset);
1270 rec->name = build_name( root[0], new_path );
1271 rec->version = get_file_version( rec->name );
1272 if (!match_row( table, row, cond, &status ))
1274 free_row_values( table, row );
1275 continue;
1277 else if (num_expected_rows && row == num_expected_rows - 1)
1279 row++;
1280 FindClose( handle );
1281 status = FILL_STATUS_FILTERED;
1282 goto done;
1284 offset += sizeof(*rec);
1285 row++;
1287 while (FindNextFileW( handle, &data ));
1288 FindClose( handle );
1290 if (!peek_dir( dirstack )) break;
1291 heap_free( glob );
1292 heap_free( path );
1296 done:
1297 free_dirstack( dirstack );
1298 heap_free( glob );
1299 heap_free( path );
1301 TRACE("created %u rows\n", row);
1302 table->num_rows = row;
1303 return status;
1306 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1308 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1309 struct record_directory *rec;
1310 UINT i, len, row = 0, offset = 0, num_expected_rows;
1311 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1312 DWORD drives = GetLogicalDrives();
1313 WIN32_FIND_DATAW data;
1314 HANDLE handle;
1315 struct dirstack *dirstack;
1316 enum fill_status status = FILL_STATUS_UNFILTERED;
1318 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1320 dirstack = alloc_dirstack(2);
1322 for (i = 0; i < sizeof(drives); i++)
1324 if (!(drives & (1 << i))) continue;
1326 root[0] = 'A' + i;
1327 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1329 num_expected_rows = 0;
1330 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1332 for (;;)
1334 path = pop_dir( dirstack, &len );
1335 if (!(glob = build_glob( root[0], path, len )))
1337 status = FILL_STATUS_FAILED;
1338 goto done;
1340 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1344 if (!resize_table( table, row + 1, sizeof(*rec) ))
1346 FindClose( handle );
1347 status = FILL_STATUS_FAILED;
1348 goto done;
1350 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1351 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1352 continue;
1354 new_path = append_path( path, data.cFileName, &len );
1355 if (!(push_dir( dirstack, new_path, len )))
1357 heap_free( new_path );
1358 FindClose( handle );
1359 status = FILL_STATUS_FAILED;
1360 goto done;
1362 rec = (struct record_directory *)(table->data + offset);
1363 rec->accessmask = FILE_ALL_ACCESS;
1364 rec->name = build_name( root[0], new_path );
1365 if (!match_row( table, row, cond, &status ))
1367 free_row_values( table, row );
1368 continue;
1370 else if (num_expected_rows && row == num_expected_rows - 1)
1372 row++;
1373 FindClose( handle );
1374 status = FILL_STATUS_FILTERED;
1375 goto done;
1377 offset += sizeof(*rec);
1378 row++;
1380 while (FindNextFileW( handle, &data ));
1381 FindClose( handle );
1383 if (!peek_dir( dirstack )) break;
1384 heap_free( glob );
1385 heap_free( path );
1389 done:
1390 free_dirstack( dirstack );
1391 heap_free( glob );
1392 heap_free( path );
1394 TRACE("created %u rows\n", row);
1395 table->num_rows = row;
1396 return status;
1399 static WCHAR *get_filesystem( const WCHAR *root )
1401 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1402 WCHAR buffer[MAX_PATH + 1];
1404 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1405 return heap_strdupW( buffer );
1406 return heap_strdupW( ntfsW );
1409 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1411 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1412 ULARGE_INTEGER free;
1413 DISK_GEOMETRY_EX info;
1414 HANDLE handle;
1416 free.QuadPart = 512 * 1024 * 1024;
1417 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1419 root[4] = dir[0];
1420 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1421 if (handle != INVALID_HANDLE_VALUE)
1423 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1424 *disksize = info.DiskSize.QuadPart;
1425 CloseHandle( handle );
1427 return free.QuadPart;
1430 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1432 static const WCHAR fmtW[] =
1433 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1434 WCHAR device_id[32], root[] = {'A',':','\\',0};
1435 struct record_diskpartition *rec;
1436 UINT i, row = 0, offset = 0, type, index = 0;
1437 UINT64 size = 1024 * 1024 * 1024;
1438 DWORD drives = GetLogicalDrives();
1439 enum fill_status status = FILL_STATUS_UNFILTERED;
1441 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1443 for (i = 0; i < sizeof(drives); i++)
1445 if (drives & (1 << i))
1447 root[0] = 'A' + i;
1448 type = GetDriveTypeW( root );
1449 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1450 continue;
1452 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1454 rec = (struct record_diskpartition *)(table->data + offset);
1455 rec->bootable = (i == 2) ? -1 : 0;
1456 rec->bootpartition = (i == 2) ? -1 : 0;
1457 sprintfW( device_id, fmtW, index );
1458 rec->device_id = heap_strdupW( device_id );
1459 rec->diskindex = index;
1460 rec->index = 0;
1461 rec->pnpdevice_id = heap_strdupW( device_id );
1462 get_freespace( root, &size );
1463 rec->size = size;
1464 rec->startingoffset = 0;
1465 rec->type = get_filesystem( root );
1466 if (!match_row( table, row, cond, &status ))
1468 free_row_values( table, row );
1469 continue;
1471 offset += sizeof(*rec);
1472 row++;
1473 index++;
1476 TRACE("created %u rows\n", row);
1477 table->num_rows = row;
1478 return status;
1481 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1483 static const WCHAR fmtW[] = {'%','c',':',0};
1484 WCHAR device_id[3], root[] = {'A',':','\\',0};
1485 struct record_logicaldisk *rec;
1486 UINT i, row = 0, offset = 0, type;
1487 UINT64 size = 1024 * 1024 * 1024;
1488 DWORD drives = GetLogicalDrives();
1489 enum fill_status status = FILL_STATUS_UNFILTERED;
1491 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1493 for (i = 0; i < sizeof(drives); i++)
1495 if (drives & (1 << i))
1497 root[0] = 'A' + i;
1498 type = GetDriveTypeW( root );
1499 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1500 continue;
1502 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1504 rec = (struct record_logicaldisk *)(table->data + offset);
1505 sprintfW( device_id, fmtW, 'A' + i );
1506 rec->device_id = heap_strdupW( device_id );
1507 rec->drivetype = type;
1508 rec->filesystem = get_filesystem( root );
1509 rec->freespace = get_freespace( root, &size );
1510 rec->name = heap_strdupW( device_id );
1511 rec->size = size;
1512 if (!match_row( table, row, cond, &status ))
1514 free_row_values( table, row );
1515 continue;
1517 offset += sizeof(*rec);
1518 row++;
1521 TRACE("created %u rows\n", row);
1522 table->num_rows = row;
1523 return status;
1526 static UINT16 get_connection_status( IF_OPER_STATUS status )
1528 switch (status)
1530 case IfOperStatusDown:
1531 return 0; /* Disconnected */
1532 case IfOperStatusUp:
1533 return 2; /* Connected */
1534 default:
1535 ERR("unhandled status %u\n", status);
1536 break;
1538 return 0;
1540 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1542 static const WCHAR fmtW[] =
1543 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1544 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1545 WCHAR *ret;
1547 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1548 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1549 return ret;
1551 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1553 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1554 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1555 static const WCHAR firewireW[] = {'1','3','9','4',0};
1556 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1558 switch (type)
1560 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1561 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1562 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1563 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1564 default: *physical = 0; return NULL;
1568 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1570 static const WCHAR fmtW[] = {'%','u',0};
1571 WCHAR device_id[11];
1572 struct record_networkadapter *rec;
1573 IP_ADAPTER_ADDRESSES *aa, *buffer;
1574 UINT row = 0, offset = 0, count = 0;
1575 DWORD size = 0, ret;
1576 int physical;
1577 enum fill_status status = FILL_STATUS_UNFILTERED;
1579 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1580 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1582 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1583 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1585 heap_free( buffer );
1586 return FILL_STATUS_FAILED;
1588 for (aa = buffer; aa; aa = aa->Next) count++;
1589 if (!resize_table( table, count, sizeof(*rec) ))
1591 heap_free( buffer );
1592 return FILL_STATUS_FAILED;
1594 for (aa = buffer; aa; aa = aa->Next)
1596 rec = (struct record_networkadapter *)(table->data + offset);
1597 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1598 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1599 rec->device_id = heap_strdupW( device_id );
1600 rec->interface_index = aa->u.s.IfIndex;
1601 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1602 rec->manufacturer = compsys_manufacturerW;
1603 rec->netconnection_status = get_connection_status( aa->OperStatus );
1604 rec->physicaladapter = physical;
1605 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1606 rec->speed = 1000000;
1607 if (!match_row( table, row, cond, &status ))
1609 free_row_values( table, row );
1610 continue;
1612 offset += sizeof(*rec);
1613 row++;
1615 TRACE("created %u rows\n", row);
1616 table->num_rows = row;
1618 heap_free( buffer );
1619 return status;
1622 static enum fill_status fill_networkadapterconfig( struct table *table, const struct expr *cond )
1624 struct record_networkadapterconfig *rec;
1625 IP_ADAPTER_ADDRESSES *aa, *buffer;
1626 UINT row = 0, offset = 0, count = 0;
1627 DWORD size = 0, ret;
1628 enum fill_status status = FILL_STATUS_UNFILTERED;
1630 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1631 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1633 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1634 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1636 heap_free( buffer );
1637 return FILL_STATUS_FAILED;
1639 for (aa = buffer; aa; aa = aa->Next) count++;
1640 if (!resize_table( table, count, sizeof(*rec) ))
1642 heap_free( buffer );
1643 return FILL_STATUS_FAILED;
1645 for (aa = buffer; aa; aa = aa->Next)
1647 rec = (struct record_networkadapterconfig *)(table->data + offset);
1648 rec->index = aa->u.s.IfIndex;
1649 rec->ipenabled = -1;
1650 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1651 if (!match_row( table, row, cond, &status ))
1653 free_row_values( table, row );
1654 continue;
1656 offset += sizeof(*rec);
1657 row++;
1659 TRACE("created %u rows\n", row);
1660 table->num_rows = row;
1662 heap_free( buffer );
1663 return status;
1666 static WCHAR *get_cmdline( DWORD process_id )
1668 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1669 return NULL; /* FIXME handle different process case */
1672 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1674 static const WCHAR fmtW[] = {'%','u',0};
1675 WCHAR handle[11];
1676 struct record_process *rec;
1677 PROCESSENTRY32W entry;
1678 HANDLE snap;
1679 enum fill_status status = FILL_STATUS_FAILED;
1680 UINT row = 0, offset = 0;
1682 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1683 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1685 entry.dwSize = sizeof(entry);
1686 if (!Process32FirstW( snap, &entry )) goto done;
1687 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1691 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1693 rec = (struct record_process *)(table->data + offset);
1694 rec->caption = heap_strdupW( entry.szExeFile );
1695 rec->commandline = get_cmdline( entry.th32ProcessID );
1696 rec->description = heap_strdupW( entry.szExeFile );
1697 sprintfW( handle, fmtW, entry.th32ProcessID );
1698 rec->handle = heap_strdupW( handle );
1699 rec->name = heap_strdupW( entry.szExeFile );
1700 rec->process_id = entry.th32ProcessID;
1701 rec->pprocess_id = entry.th32ParentProcessID;
1702 rec->thread_count = entry.cntThreads;
1703 rec->get_owner = process_get_owner;
1704 if (!match_row( table, row, cond, &status ))
1706 free_row_values( table, row );
1707 continue;
1709 offset += sizeof(*rec);
1710 row++;
1711 } while (Process32NextW( snap, &entry ));
1713 TRACE("created %u rows\n", row);
1714 table->num_rows = row;
1715 status = FILL_STATUS_UNFILTERED;
1717 done:
1718 CloseHandle( snap );
1719 return status;
1722 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1724 #ifdef __i386__
1725 __asm__("pushl %%ebx\n\t"
1726 "cpuid\n\t"
1727 "movl %%ebx, %%esi\n\t"
1728 "popl %%ebx"
1729 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1730 : "0" (ax));
1731 #endif
1734 static void get_processor_id( WCHAR *processor_id )
1736 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1737 unsigned int regs[4] = {0, 0, 0, 0};
1739 do_cpuid( 1, regs );
1740 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1742 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1744 unsigned int i;
1745 unsigned char *p = (unsigned char *)regs;
1747 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1748 buffer[i] = 0;
1750 static void get_processor_manufacturer( WCHAR *manufacturer )
1752 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1754 do_cpuid( 0, regs );
1755 tmp = regs[2]; /* swap edx and ecx */
1756 regs[2] = regs[3];
1757 regs[3] = tmp;
1759 regs_to_str( regs + 1, 12, manufacturer );
1761 static void get_processor_name( WCHAR *name )
1763 unsigned int regs[4] = {0, 0, 0, 0};
1765 do_cpuid( 0x80000000, regs );
1766 if (regs[0] >= 0x80000004)
1768 do_cpuid( 0x80000002, regs );
1769 regs_to_str( regs, 16, name );
1770 do_cpuid( 0x80000003, regs );
1771 regs_to_str( regs, 16, name + 16 );
1772 do_cpuid( 0x80000004, regs );
1773 regs_to_str( regs, 16, name + 32 );
1776 static UINT get_processor_maxclockspeed( void )
1778 PROCESSOR_POWER_INFORMATION *info;
1779 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1780 NTSTATUS status;
1782 if ((info = heap_alloc( size )))
1784 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1785 if (!status) ret = info[0].MaxMhz;
1786 heap_free( info );
1788 return ret;
1790 static const WCHAR *get_osarchitecture(void)
1792 SYSTEM_INFO info;
1793 GetNativeSystemInfo( &info );
1794 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1795 return os_32bitW;
1798 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
1800 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1801 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1802 struct record_processor *rec;
1803 UINT i, offset = 0, maxclockspeed, num_cores, num_logical_processors, count = get_processor_count();
1804 enum fill_status status = FILL_STATUS_UNFILTERED;
1806 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
1808 get_processor_id( processor_id );
1809 get_processor_manufacturer( manufacturer );
1810 get_processor_name( name );
1812 maxclockspeed = get_processor_maxclockspeed();
1813 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
1814 num_cores /= count;
1816 for (i = 0; i < count; i++)
1818 rec = (struct record_processor *)(table->data + offset);
1819 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
1820 rec->cpu_status = 1; /* CPU Enabled */
1821 sprintfW( device_id, fmtW, i );
1822 rec->device_id = heap_strdupW( device_id );
1823 rec->family = 2; /* Unknown */
1824 rec->manufacturer = heap_strdupW( manufacturer );
1825 rec->maxclockspeed = maxclockspeed;
1826 rec->name = heap_strdupW( name );
1827 rec->num_cores = num_cores;
1828 rec->num_logical_processors = num_logical_processors;
1829 rec->processor_id = heap_strdupW( processor_id );
1830 rec->unique_id = NULL;
1831 if (!match_row( table, i, cond, &status ))
1833 free_row_values( table, i );
1834 continue;
1836 offset += sizeof(*rec);
1839 TRACE("created %u rows\n", count);
1840 table->num_rows = count;
1841 return status;
1844 static WCHAR *get_lastbootuptime(void)
1846 static const WCHAR fmtW[] =
1847 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1848 '.','%','0','6','u','+','0','0','0',0};
1849 SYSTEM_TIMEOFDAY_INFORMATION ti;
1850 TIME_FIELDS tf;
1851 WCHAR *ret;
1853 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1855 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1856 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1857 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1858 return ret;
1860 static WCHAR *get_localdatetime(void)
1862 static const WCHAR fmtW[] =
1863 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1864 '.','%','0','6','u','%','+','0','3','d',0};
1865 TIME_ZONE_INFORMATION tzi;
1866 SYSTEMTIME st;
1867 WCHAR *ret;
1868 DWORD Status;
1869 LONG Bias;
1871 Status = GetTimeZoneInformation(&tzi);
1873 if(Status == TIME_ZONE_ID_INVALID) return NULL;
1874 Bias = tzi.Bias;
1875 if(Status == TIME_ZONE_ID_DAYLIGHT)
1876 Bias+= tzi.DaylightBias;
1877 else
1878 Bias+= tzi.StandardBias;
1879 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1881 GetLocalTime(&st);
1882 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
1883 return ret;
1885 static WCHAR *get_systemdirectory(void)
1887 void *redir;
1888 WCHAR *ret;
1890 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1891 Wow64DisableWow64FsRedirection( &redir );
1892 GetSystemDirectoryW( ret, MAX_PATH );
1893 Wow64RevertWow64FsRedirection( redir );
1894 return ret;
1896 static WCHAR *get_codeset(void)
1898 static const WCHAR fmtW[] = {'%','u',0};
1899 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
1900 if (ret) sprintfW( ret, fmtW, GetACP() );
1901 return ret;
1903 static WCHAR *get_countrycode(void)
1905 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
1906 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
1907 return ret;
1909 static WCHAR *get_locale(void)
1911 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
1912 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
1913 return ret;
1916 static enum fill_status fill_os( struct table *table, const struct expr *cond )
1918 struct record_operatingsystem *rec;
1919 enum fill_status status = FILL_STATUS_UNFILTERED;
1920 UINT row = 0;
1922 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1924 rec = (struct record_operatingsystem *)table->data;
1925 rec->caption = os_captionW;
1926 rec->codeset = get_codeset();
1927 rec->countrycode = get_countrycode();
1928 rec->csdversion = os_csdversionW;
1929 rec->lastbootuptime = get_lastbootuptime();
1930 rec->localdatetime = get_localdatetime();
1931 rec->locale = get_locale();
1932 rec->osarchitecture = get_osarchitecture();
1933 rec->oslanguage = GetSystemDefaultLangID();
1934 rec->osproductsuite = 2461140; /* Windows XP Professional */
1935 rec->ostype = 18; /* WINNT */
1936 rec->servicepackmajor = 3;
1937 rec->servicepackminor = 0;
1938 rec->suitemask = 272; /* Single User + Terminal */
1939 rec->systemdirectory = get_systemdirectory();
1940 rec->version = os_versionW;
1941 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1942 else row++;
1944 TRACE("created %u rows\n", row);
1945 table->num_rows = row;
1946 return status;
1949 static const WCHAR *get_service_type( DWORD type )
1951 static const WCHAR filesystem_driverW[] =
1952 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1953 static const WCHAR kernel_driverW[] =
1954 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1955 static const WCHAR own_processW[] =
1956 {'O','w','n',' ','P','r','o','c','e','s','s',0};
1957 static const WCHAR share_processW[] =
1958 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1960 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
1961 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
1962 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
1963 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1964 else ERR("unhandled type 0x%08x\n", type);
1965 return NULL;
1967 static const WCHAR *get_service_state( DWORD state )
1969 static const WCHAR runningW[] =
1970 {'R','u','n','n','i','n','g',0};
1971 static const WCHAR start_pendingW[] =
1972 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1973 static const WCHAR stop_pendingW[] =
1974 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1975 static const WCHAR stoppedW[] =
1976 {'S','t','o','p','p','e','d',0};
1977 static const WCHAR unknownW[] =
1978 {'U','n','k','n','o','w','n',0};
1980 switch (state)
1982 case SERVICE_STOPPED: return stoppedW;
1983 case SERVICE_START_PENDING: return start_pendingW;
1984 case SERVICE_STOP_PENDING: return stop_pendingW;
1985 case SERVICE_RUNNING: return runningW;
1986 default:
1987 ERR("unknown state %u\n", state);
1988 return unknownW;
1991 static const WCHAR *get_service_startmode( DWORD mode )
1993 static const WCHAR bootW[] = {'B','o','o','t',0};
1994 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
1995 static const WCHAR autoW[] = {'A','u','t','o',0};
1996 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
1997 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
1998 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
2000 switch (mode)
2002 case SERVICE_BOOT_START: return bootW;
2003 case SERVICE_SYSTEM_START: return systemW;
2004 case SERVICE_AUTO_START: return autoW;
2005 case SERVICE_DEMAND_START: return manualW;
2006 case SERVICE_DISABLED: return disabledW;
2007 default:
2008 ERR("unknown mode 0x%x\n", mode);
2009 return unknownW;
2012 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
2014 QUERY_SERVICE_CONFIGW *config = NULL;
2015 SC_HANDLE service;
2016 DWORD size;
2018 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
2019 QueryServiceConfigW( service, NULL, 0, &size );
2020 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
2021 if (!(config = heap_alloc( size ))) goto done;
2022 if (QueryServiceConfigW( service, config, size, &size )) goto done;
2023 heap_free( config );
2024 config = NULL;
2026 done:
2027 CloseServiceHandle( service );
2028 return config;
2031 static enum fill_status fill_service( struct table *table, const struct expr *cond )
2033 struct record_service *rec;
2034 SC_HANDLE manager;
2035 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
2036 SERVICE_STATUS_PROCESS *status;
2037 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
2038 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
2039 UINT i, row = 0, offset = 0, size = 256, needed, count;
2040 enum fill_status fill_status = FILL_STATUS_FAILED;
2041 BOOL ret;
2043 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
2044 if (!(services = heap_alloc( size ))) goto done;
2046 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2047 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2048 &count, NULL, NULL );
2049 if (!ret)
2051 if (GetLastError() != ERROR_MORE_DATA) goto done;
2052 size = needed;
2053 if (!(tmp = heap_realloc( services, size ))) goto done;
2054 services = tmp;
2055 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
2056 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
2057 &count, NULL, NULL );
2058 if (!ret) goto done;
2060 if (!resize_table( table, count, sizeof(*rec) )) goto done;
2062 GetComputerNameW( sysnameW, &len );
2063 fill_status = FILL_STATUS_UNFILTERED;
2065 for (i = 0; i < count; i++)
2067 QUERY_SERVICE_CONFIGW *config;
2069 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2071 status = &services[i].ServiceStatusProcess;
2072 rec = (struct record_service *)(table->data + offset);
2073 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2074 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2075 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2076 rec->name = heap_strdupW( services[i].lpServiceName );
2077 rec->process_id = status->dwProcessId;
2078 rec->servicetype = get_service_type( status->dwServiceType );
2079 rec->startmode = get_service_startmode( config->dwStartType );
2080 rec->state = get_service_state( status->dwCurrentState );
2081 rec->systemname = heap_strdupW( sysnameW );
2082 rec->pause_service = service_pause_service;
2083 rec->resume_service = service_resume_service;
2084 rec->start_service = service_start_service;
2085 rec->stop_service = service_stop_service;
2086 heap_free( config );
2087 if (!match_row( table, row, cond, &fill_status ))
2089 free_row_values( table, row );
2090 continue;
2092 offset += sizeof(*rec);
2093 row++;
2096 TRACE("created %u rows\n", row);
2097 table->num_rows = row;
2099 done:
2100 CloseServiceHandle( manager );
2101 heap_free( services );
2102 return fill_status;
2105 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2107 HDC hdc = GetDC( NULL );
2108 UINT32 ret;
2110 if (!hdc) return 32;
2111 ret = GetDeviceCaps( hdc, BITSPIXEL );
2112 *hres = GetDeviceCaps( hdc, HORZRES );
2113 *vres = GetDeviceCaps( hdc, VERTRES );
2114 ReleaseDC( NULL, hdc );
2115 return ret;
2117 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2119 static const WCHAR fmtW[] =
2120 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2121 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2122 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2123 WCHAR *ret;
2125 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2126 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2127 return ret;
2130 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2133 struct record_videocontroller *rec;
2134 HRESULT hr;
2135 IDXGIFactory *factory = NULL;
2136 IDXGIAdapter *adapter = NULL;
2137 DXGI_ADAPTER_DESC desc;
2138 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2139 const WCHAR *name = videocontroller_deviceidW;
2140 enum fill_status status = FILL_STATUS_UNFILTERED;
2141 UINT row = 0;
2143 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2145 memset (&desc, 0, sizeof(desc));
2146 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2147 if (FAILED(hr)) goto done;
2149 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2150 if (FAILED(hr)) goto done;
2152 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2153 if (SUCCEEDED(hr))
2155 vidmem = desc.DedicatedVideoMemory;
2156 name = desc.Description;
2159 done:
2160 rec = (struct record_videocontroller *)table->data;
2161 rec->adapter_dactype = videocontroller_dactypeW;
2162 rec->adapter_ram = vidmem;
2163 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2164 rec->current_horizontalres = hres;
2165 rec->current_verticalres = vres;
2166 rec->description = heap_strdupW( name );
2167 rec->device_id = videocontroller_deviceidW;
2168 rec->name = heap_strdupW( name );
2169 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2170 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2171 else row++;
2173 TRACE("created %u rows\n", row);
2174 table->num_rows = row;
2176 if (adapter) IDXGIAdapter_Release( adapter );
2177 if (factory) IDXGIFactory_Release( factory );
2178 return status;
2181 static struct table builtin_classes[] =
2183 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2184 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2185 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2186 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2187 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2188 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2189 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), 0, (BYTE *)data_diskdrive },
2190 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2191 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2192 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2193 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2194 { class_networkadapterconfigW, SIZEOF(col_networkadapterconfig), col_networkadapterconfig, 0, 0, NULL,
2195 fill_networkadapterconfig },
2196 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2197 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2198 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2199 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2200 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2201 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2202 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2203 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2204 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2207 void init_table_list( void )
2209 static struct list tables = LIST_INIT( tables );
2210 UINT i;
2212 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2213 table_list = &tables;