65b09d36fe8f2e2d306aa7113df6071ea54a3b9a
[reactos.git] / reactos / dll / win32 / wbemprox / builtin.c
1 /*
2 * Copyright 2012 Hans Leidekker for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define _INC_WINDOWS
20 #define COM_NO_WINDOWS_H
21
22 #define COBJMACROS
23 #define NONAMELESSUNION
24 #define NONAMELESSSTRUCT
25
26 #include "config.h"
27 #include <stdarg.h>
28
29 #include "ntstatus.h"
30 #define WIN32_NO_STATUS
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "initguid.h"
35 #include "objbase.h"
36 #include "oleauto.h"
37 #include "wbemcli.h"
38 #include "wbemprov.h"
39 #include "winsock2.h"
40 #include "iphlpapi.h"
41 #include "tlhelp32.h"
42 #include "d3d10.h"
43 #include "winternl.h"
44 #include "winioctl.h"
45 #include "winsvc.h"
46 #include "winver.h"
47
48 #include "wine/debug.h"
49 #include "wbemprox_private.h"
50
51 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
52
53 static const WCHAR class_baseboardW[] =
54 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
55 static const WCHAR class_biosW[] =
56 {'W','i','n','3','2','_','B','I','O','S',0};
57 static const WCHAR class_cdromdriveW[] =
58 {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
59 static const WCHAR class_compsysW[] =
60 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
61 static const WCHAR class_datafileW[] =
62 {'C','I','M','_','D','a','t','a','F','i','l','e',0};
63 static const WCHAR class_directoryW[] =
64 {'W','i','n','3','2','_','D','i','r','e','c','t','o','r','y',0};
65 static const WCHAR class_diskdriveW[] =
66 {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
67 static const WCHAR class_diskpartitionW[] =
68 {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
69 static const WCHAR class_logicaldiskW[] =
70 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
71 static const WCHAR class_logicaldisk2W[] =
72 {'C','I','M','_','L','o','g','i','c','a','l','D','i','s','k',0};
73 static const WCHAR class_networkadapterW[] =
74 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
75 static const WCHAR class_osW[] =
76 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
77 static const WCHAR class_paramsW[] =
78 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
79 static const WCHAR class_qualifiersW[] =
80 {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
81 static const WCHAR class_process_getowner_outW[] =
82 {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
83 'N','E','R','_','O','U','T',0};
84 static const WCHAR class_processorW[] =
85 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
86 static const WCHAR class_sounddeviceW[] =
87 {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
88 static const WCHAR class_videocontrollerW[] =
89 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
90
91 static const WCHAR prop_acceptpauseW[] =
92 {'A','c','c','e','p','t','P','a','u','s','e',0};
93 static const WCHAR prop_acceptstopW[] =
94 {'A','c','c','e','p','t','S','t','o','p',0};
95 static const WCHAR prop_accessmaskW[] =
96 {'A','c','c','e','s','s','M','a','s','k',0};
97 static const WCHAR prop_adapterdactypeW[] =
98 {'A','d','a','p','t','e','r','D','A','C','T','y','p','e',0};
99 static const WCHAR prop_adapterramW[] =
100 {'A','d','a','p','t','e','r','R','A','M',0};
101 static const WCHAR prop_adaptertypeW[] =
102 {'A','d','a','p','t','e','r','T','y','p','e',0};
103 static const WCHAR prop_addresswidthW[] =
104 {'A','d','d','r','e','s','s','W','i','d','t','h',0};
105 static const WCHAR prop_bootableW[] =
106 {'B','o','o','t','a','b','l','e',0};
107 static const WCHAR prop_bootpartitionW[] =
108 {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
109 static const WCHAR prop_captionW[] =
110 {'C','a','p','t','i','o','n',0};
111 static const WCHAR prop_classW[] =
112 {'C','l','a','s','s',0};
113 static const WCHAR prop_codesetW[] =
114 {'C','o','d','e','S','e','t',0};
115 static const WCHAR prop_commandlineW[] =
116 {'C','o','m','m','a','n','d','L','i','n','e',0};
117 static const WCHAR prop_countrycodeW[] =
118 {'C','o','u','n','t','r','y','C','o','d','e',0};
119 static const WCHAR prop_cpustatusW[] =
120 {'C','p','u','S','t','a','t','u','s',0};
121 static const WCHAR prop_csdversionW[] =
122 {'C','S','D','V','e','r','s','i','o','n',0};
123 static const WCHAR prop_currentbitsperpixelW[] =
124 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
125 static const WCHAR prop_currenthorizontalresW[] =
126 {'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};
127 static const WCHAR prop_currentverticalresW[] =
128 {'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};
129 static const WCHAR prop_defaultvalueW[] =
130 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
131 static const WCHAR prop_descriptionW[] =
132 {'D','e','s','c','r','i','p','t','i','o','n',0};
133 static const WCHAR prop_deviceidW[] =
134 {'D','e','v','i','c','e','I','d',0};
135 static const WCHAR prop_directionW[] =
136 {'D','i','r','e','c','t','i','o','n',0};
137 static const WCHAR prop_displaynameW[] =
138 {'D','i','s','p','l','a','y','N','a','m','e',0};
139 static const WCHAR prop_diskindexW[] =
140 {'D','i','s','k','I','n','d','e','x',0};
141 static const WCHAR prop_domainW[] =
142 {'D','o','m','a','i','n',0};
143 static const WCHAR prop_domainroleW[] =
144 {'D','o','m','a','i','n','R','o','l','e',0};
145 static const WCHAR prop_driveW[] =
146 {'D','r','i','v','e',0};
147 static const WCHAR prop_drivetypeW[] =
148 {'D','r','i','v','e','T','y','p','e',0};
149 static const WCHAR prop_familyW[] =
150 {'F','a','m','i','l','y',0};
151 static const WCHAR prop_filesystemW[] =
152 {'F','i','l','e','S','y','s','t','e','m',0};
153 static const WCHAR prop_flavorW[] =
154 {'F','l','a','v','o','r',0};
155 static const WCHAR prop_freespaceW[] =
156 {'F','r','e','e','S','p','a','c','e',0};
157 static const WCHAR prop_handleW[] =
158 {'H','a','n','d','l','e',0};
159 static const WCHAR prop_idW[] =
160 {'I','D',0};
161 static const WCHAR prop_indexW[] =
162 {'I','n','d','e','x',0};
163 static const WCHAR prop_interfaceindexW[] =
164 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
165 static const WCHAR prop_intvalueW[] =
166 {'I','n','t','e','g','e','r','V','a','l','u','e',0};
167 static const WCHAR prop_lastbootuptimeW[] =
168 {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
169 static const WCHAR prop_localdatetimeW[] =
170 {'L','o','c','a','l','D','a','t','e','T','i','m','e',0};
171 static const WCHAR prop_localeW[] =
172 {'L','o','c','a','l','e',0};
173 static const WCHAR prop_macaddressW[] =
174 {'M','A','C','A','d','d','r','e','s','s',0};
175 static const WCHAR prop_manufacturerW[] =
176 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
177 static const WCHAR prop_maxclockspeedW[] =
178 {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
179 static const WCHAR prop_memberW[] =
180 {'M','e','m','b','e','r',0};
181 static const WCHAR prop_methodW[] =
182 {'M','e','t','h','o','d',0};
183 static const WCHAR prop_modelW[] =
184 {'M','o','d','e','l',0};
185 static const WCHAR prop_netconnectionstatusW[] =
186 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
187 static const WCHAR prop_numcoresW[] =
188 {'N','u','m','b','e','r','O','f','C','o','r','e','s',0};
189 static const WCHAR prop_numlogicalprocessorsW[] =
190 {'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};
191 static const WCHAR prop_numprocessorsW[] =
192 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
193 static const WCHAR prop_osarchitectureW[] =
194 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
195 static const WCHAR prop_oslanguageW[] =
196 {'O','S','L','a','n','g','u','a','g','e',0};
197 static const WCHAR prop_osproductsuiteW[] =
198 {'O','S','P','r','o','d','u','c','t','S','u','i','t','e',0};
199 static const WCHAR prop_ostypeW[] =
200 {'O','S','T','y','p','e',0};
201 static const WCHAR prop_parameterW[] =
202 {'P','a','r','a','m','e','t','e','r',0};
203 static const WCHAR prop_physicaladapterW[] =
204 {'P','h','y','s','i','c','a','l','A','d','a','p','t','e','r',0};
205 static const WCHAR prop_pnpdeviceidW[] =
206 {'P','N','P','D','e','v','i','c','e','I','D',0};
207 static const WCHAR prop_pprocessidW[] =
208 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
209 static const WCHAR prop_processidW[] =
210 {'P','r','o','c','e','s','s','I','D',0};
211 static const WCHAR prop_processoridW[] =
212 {'P','r','o','c','e','s','s','o','r','I','d',0};
213 static const WCHAR prop_productnameW[] =
214 {'P','r','o','d','u','c','t','N','a','m','e',0};
215 static const WCHAR prop_releasedateW[] =
216 {'R','e','l','e','a','s','e','D','a','t','e',0};
217 static const WCHAR prop_serialnumberW[] =
218 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
219 static const WCHAR prop_servicepackmajorW[] =
220 {'S','e','r','v','i','c','e','P','a','c','k','M','a','j','o','r','V','e','r','s','i','o','n',0};
221 static const WCHAR prop_servicepackminorW[] =
222 {'S','e','r','v','i','c','e','P','a','c','k','M','i','n','o','r','V','e','r','s','i','o','n',0};
223 static const WCHAR prop_servicetypeW[] =
224 {'S','e','r','v','i','c','e','T','y','p','e',0};
225 static const WCHAR prop_startmodeW[] =
226 {'S','t','a','r','t','M','o','d','e',0};
227 static const WCHAR prop_sizeW[] =
228 {'S','i','z','e',0};
229 static const WCHAR prop_speedW[] =
230 {'S','p','e','e','d',0};
231 static const WCHAR prop_startingoffsetW[] =
232 {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
233 static const WCHAR prop_stateW[] =
234 {'S','t','a','t','e',0};
235 static const WCHAR prop_strvalueW[] =
236 {'S','t','r','i','n','g','V','a','l','u','e',0};
237 static const WCHAR prop_suitemaskW[] =
238 {'S','u','i','t','e','M','a','s','k',0};
239 static const WCHAR prop_systemdirectoryW[] =
240 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
241 static const WCHAR prop_systemnameW[] =
242 {'S','y','s','t','e','m','N','a','m','e',0};
243 static const WCHAR prop_tagW[] =
244 {'T','a','g',0};
245 static const WCHAR prop_threadcountW[] =
246 {'T','h','r','e','a','d','C','o','u','n','t',0};
247 static const WCHAR prop_totalphysicalmemoryW[] =
248 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
249 static const WCHAR prop_typeW[] =
250 {'T','y','p','e',0};
251 static const WCHAR prop_uniqueidW[] =
252 {'U','n','i','q','u','e','I','d',0};
253 static const WCHAR prop_varianttypeW[] =
254 {'V','a','r','i','a','n','t','T','y','p','e',0};
255 static const WCHAR prop_versionW[] =
256 {'V','e','r','s','i','o','n',0};
257
258 /* column definitions must be kept in sync with record structures below */
259 static const struct column col_baseboard[] =
260 {
261 { prop_manufacturerW, CIM_STRING },
262 { prop_serialnumberW, CIM_STRING },
263 { prop_tagW, CIM_STRING|COL_FLAG_KEY }
264 };
265 static const struct column col_bios[] =
266 {
267 { prop_descriptionW, CIM_STRING },
268 { prop_manufacturerW, CIM_STRING },
269 { prop_releasedateW, CIM_DATETIME },
270 { prop_serialnumberW, CIM_STRING },
271 { prop_versionW, CIM_STRING|COL_FLAG_KEY }
272 };
273 static const struct column col_cdromdrive[] =
274 {
275 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
276 { prop_driveW, CIM_STRING|COL_FLAG_DYNAMIC },
277 { prop_nameW, CIM_STRING },
278 { prop_pnpdeviceidW, CIM_STRING }
279 };
280 static const struct column col_compsys[] =
281 {
282 { prop_descriptionW, CIM_STRING },
283 { prop_domainW, CIM_STRING },
284 { prop_domainroleW, CIM_UINT16 },
285 { prop_manufacturerW, CIM_STRING },
286 { prop_modelW, CIM_STRING },
287 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
288 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
289 { prop_numprocessorsW, CIM_UINT32, VT_I4 },
290 { prop_totalphysicalmemoryW, CIM_UINT64 }
291 };
292 static const struct column col_datafile[] =
293 {
294 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
295 { prop_versionW, CIM_STRING|COL_FLAG_DYNAMIC }
296 };
297 static const struct column col_directory[] =
298 {
299 { prop_accessmaskW, CIM_UINT32 },
300 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY }
301 };
302 static const struct column col_diskdrive[] =
303 {
304 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
305 { prop_indexW, CIM_UINT32, VT_I4 },
306 { prop_manufacturerW, CIM_STRING },
307 { prop_modelW, CIM_STRING },
308 { prop_serialnumberW, CIM_STRING }
309 };
310 static const struct column col_diskpartition[] =
311 {
312 { prop_bootableW, CIM_BOOLEAN },
313 { prop_bootpartitionW, CIM_BOOLEAN },
314 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
315 { prop_diskindexW, CIM_UINT32, VT_I4 },
316 { prop_indexW, CIM_UINT32, VT_I4 },
317 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC },
318 { prop_sizeW, CIM_UINT64 },
319 { prop_startingoffsetW, CIM_UINT64 },
320 { prop_typeW, CIM_STRING|COL_FLAG_DYNAMIC }
321 };
322 static const struct column col_logicaldisk[] =
323 {
324 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
325 { prop_drivetypeW, CIM_UINT32, VT_I4 },
326 { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
327 { prop_freespaceW, CIM_UINT64 },
328 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
329 { prop_sizeW, CIM_UINT64 }
330 };
331 static const struct column col_networkadapter[] =
332 {
333 { prop_adaptertypeW, CIM_STRING },
334 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
335 { prop_interfaceindexW, CIM_UINT32, VT_I4 },
336 { prop_macaddressW, CIM_STRING|COL_FLAG_DYNAMIC },
337 { prop_manufacturerW, CIM_STRING },
338 { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
339 { prop_physicaladapterW, CIM_BOOLEAN },
340 { prop_pnpdeviceidW, CIM_STRING },
341 { prop_speedW, CIM_UINT64 }
342 };
343 static const struct column col_os[] =
344 {
345 { prop_captionW, CIM_STRING },
346 { prop_codesetW, CIM_STRING|COL_FLAG_DYNAMIC },
347 { prop_countrycodeW, CIM_STRING|COL_FLAG_DYNAMIC },
348 { prop_csdversionW, CIM_STRING },
349 { prop_lastbootuptimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
350 { prop_localdatetimeW, CIM_DATETIME|COL_FLAG_DYNAMIC },
351 { prop_localeW, CIM_STRING|COL_FLAG_DYNAMIC },
352 { prop_osarchitectureW, CIM_STRING },
353 { prop_oslanguageW, CIM_UINT32, VT_I4 },
354 { prop_osproductsuiteW, CIM_UINT32, VT_I4 },
355 { prop_ostypeW, CIM_UINT16, VT_I4 },
356 { prop_servicepackmajorW, CIM_UINT16, VT_I4 },
357 { prop_servicepackminorW, CIM_UINT16, VT_I4 },
358 { prop_suitemaskW, CIM_UINT32, VT_I4 },
359 { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC },
360 { prop_versionW, CIM_STRING }
361 };
362 static const struct column col_param[] =
363 {
364 { prop_classW, CIM_STRING },
365 { prop_methodW, CIM_STRING },
366 { prop_directionW, CIM_SINT32 },
367 { prop_parameterW, CIM_STRING },
368 { prop_typeW, CIM_UINT32 },
369 { prop_varianttypeW, CIM_UINT32 },
370 { prop_defaultvalueW, CIM_UINT32 }
371 };
372 static const struct column col_process[] =
373 {
374 { prop_captionW, CIM_STRING|COL_FLAG_DYNAMIC },
375 { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
376 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
377 { prop_handleW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
378 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
379 { prop_pprocessidW, CIM_UINT32, VT_I4 },
380 { prop_processidW, CIM_UINT32, VT_I4 },
381 { prop_threadcountW, CIM_UINT32, VT_I4 },
382 /* methods */
383 { method_getownerW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
384 };
385 static const struct column col_processor[] =
386 {
387 { prop_addresswidthW, CIM_UINT16, VT_I4 },
388 { prop_cpustatusW, CIM_UINT16 },
389 { prop_deviceidW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
390 { prop_familyW, CIM_UINT16, VT_I4 },
391 { prop_manufacturerW, CIM_STRING|COL_FLAG_DYNAMIC },
392 { prop_maxclockspeedW, CIM_UINT32, VT_I4 },
393 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
394 { prop_numcoresW, CIM_UINT32, VT_I4 },
395 { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
396 { prop_processoridW, CIM_STRING|COL_FLAG_DYNAMIC },
397 { prop_uniqueidW, CIM_STRING }
398 };
399 static const struct column col_qualifier[] =
400 {
401 { prop_classW, CIM_STRING },
402 { prop_memberW, CIM_STRING },
403 { prop_typeW, CIM_UINT32 },
404 { prop_flavorW, CIM_SINT32 },
405 { prop_nameW, CIM_STRING },
406 { prop_intvalueW, CIM_SINT32 },
407 { prop_strvalueW, CIM_STRING }
408 };
409 static const struct column col_service[] =
410 {
411 { prop_acceptpauseW, CIM_BOOLEAN },
412 { prop_acceptstopW, CIM_BOOLEAN },
413 { prop_displaynameW, CIM_STRING|COL_FLAG_DYNAMIC },
414 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
415 { prop_processidW, CIM_UINT32 },
416 { prop_servicetypeW, CIM_STRING },
417 { prop_startmodeW, CIM_STRING },
418 { prop_stateW, CIM_STRING },
419 { prop_systemnameW, CIM_STRING|COL_FLAG_DYNAMIC },
420 /* methods */
421 { method_pauseserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
422 { method_resumeserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
423 { method_startserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
424 { method_stopserviceW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
425 };
426 static const struct column col_sounddevice[] =
427 {
428 { prop_nameW, CIM_STRING },
429 { prop_productnameW, CIM_STRING }
430 };
431 static const struct column col_stdregprov[] =
432 {
433 { method_enumkeyW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
434 { method_enumvaluesW, CIM_FLAG_ARRAY|COL_FLAG_METHOD },
435 { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
436 };
437 static const struct column col_videocontroller[] =
438 {
439 { prop_adapterdactypeW, CIM_STRING },
440 { prop_adapterramW, CIM_UINT32, VT_I4 },
441 { prop_currentbitsperpixelW, CIM_UINT32 },
442 { prop_currenthorizontalresW, CIM_UINT32 },
443 { prop_currentverticalresW, CIM_UINT32 },
444 { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
445 { prop_deviceidW, CIM_STRING|COL_FLAG_KEY },
446 { prop_nameW, CIM_STRING|COL_FLAG_DYNAMIC },
447 { prop_pnpdeviceidW, CIM_STRING|COL_FLAG_DYNAMIC }
448 };
449
450 static const WCHAR baseboard_manufacturerW[] =
451 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
452 static const WCHAR baseboard_serialnumberW[] =
453 {'N','o','n','e',0};
454 static const WCHAR baseboard_tagW[] =
455 {'B','a','s','e',' ','B','o','a','r','d',0};
456 static const WCHAR bios_descriptionW[] =
457 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
458 static const WCHAR bios_manufacturerW[] =
459 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
460 static const WCHAR bios_releasedateW[] =
461 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
462 static const WCHAR bios_serialnumberW[] =
463 {'0',0};
464 static const WCHAR bios_versionW[] =
465 {'W','I','N','E',' ',' ',' ','-',' ','1',0};
466 static const WCHAR cdromdrive_nameW[] =
467 {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
468 static const WCHAR cdromdrive_pnpdeviceidW[]=
469 {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
470 '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
471 '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
472 'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
473 static const WCHAR compsys_descriptionW[] =
474 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
475 static const WCHAR compsys_domainW[] =
476 {'W','O','R','K','G','R','O','U','P',0};
477 static const WCHAR compsys_manufacturerW[] =
478 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
479 static const WCHAR compsys_modelW[] =
480 {'W','i','n','e',0};
481 static const WCHAR diskdrive_deviceidW[] =
482 {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
483 static const WCHAR diskdrive_modelW[] =
484 {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
485 static const WCHAR diskdrive_manufacturerW[] =
486 {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
487 static const WCHAR diskdrive_serialW[] =
488 {'W','I','N','E','H','D','I','S','K',0};
489 static const WCHAR networkadapter_pnpdeviceidW[]=
490 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
491 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
492 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
493 static const WCHAR os_captionW[] =
494 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
495 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
496 static const WCHAR os_csdversionW[] =
497 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
498 static const WCHAR os_32bitW[] =
499 {'3','2','-','b','i','t',0};
500 static const WCHAR os_64bitW[] =
501 {'6','4','-','b','i','t',0};
502 static const WCHAR os_versionW[] =
503 {'5','.','1','.','2','6','0','0',0};
504 static const WCHAR sounddevice_productnameW[] =
505 {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
506 static const WCHAR videocontroller_dactypeW[] =
507 {'I','n','t','e','g','r','a','t','e','d',' ','R','A','M','D','A','C',0};
508 static const WCHAR videocontroller_deviceidW[] =
509 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
510
511 #include "pshpack1.h"
512 struct record_baseboard
513 {
514 const WCHAR *manufacturer;
515 const WCHAR *serialnumber;
516 const WCHAR *tag;
517 };
518 struct record_bios
519 {
520 const WCHAR *description;
521 const WCHAR *manufacturer;
522 const WCHAR *releasedate;
523 const WCHAR *serialnumber;
524 const WCHAR *version;
525 };
526 struct record_cdromdrive
527 {
528 const WCHAR *device_id;
529 const WCHAR *drive;
530 const WCHAR *name;
531 const WCHAR *pnpdevice_id;
532 };
533 struct record_computersystem
534 {
535 const WCHAR *description;
536 const WCHAR *domain;
537 UINT16 domainrole;
538 const WCHAR *manufacturer;
539 const WCHAR *model;
540 const WCHAR *name;
541 UINT32 num_logical_processors;
542 UINT32 num_processors;
543 UINT64 total_physical_memory;
544 };
545 struct record_datafile
546 {
547 const WCHAR *name;
548 const WCHAR *version;
549 };
550 struct record_directory
551 {
552 UINT32 accessmask;
553 const WCHAR *name;
554 };
555 struct record_diskdrive
556 {
557 const WCHAR *device_id;
558 UINT32 index;
559 const WCHAR *manufacturer;
560 const WCHAR *name;
561 const WCHAR *serialnumber;
562 };
563 struct record_diskpartition
564 {
565 int bootable;
566 int bootpartition;
567 const WCHAR *device_id;
568 UINT32 diskindex;
569 UINT32 index;
570 const WCHAR *pnpdevice_id;
571 UINT64 size;
572 UINT64 startingoffset;
573 const WCHAR *type;
574 };
575 struct record_logicaldisk
576 {
577 const WCHAR *device_id;
578 UINT32 drivetype;
579 const WCHAR *filesystem;
580 UINT64 freespace;
581 const WCHAR *name;
582 UINT64 size;
583 };
584 struct record_networkadapter
585 {
586 const WCHAR *adaptertype;
587 const WCHAR *device_id;
588 INT32 interface_index;
589 const WCHAR *mac_address;
590 const WCHAR *manufacturer;
591 UINT16 netconnection_status;
592 int physicaladapter;
593 const WCHAR *pnpdevice_id;
594 UINT64 speed;
595 };
596 struct record_operatingsystem
597 {
598 const WCHAR *caption;
599 const WCHAR *codeset;
600 const WCHAR *countrycode;
601 const WCHAR *csdversion;
602 const WCHAR *lastbootuptime;
603 const WCHAR *localdatetime;
604 const WCHAR *locale;
605 const WCHAR *osarchitecture;
606 UINT32 oslanguage;
607 UINT32 osproductsuite;
608 UINT16 ostype;
609 UINT16 servicepackmajor;
610 UINT16 servicepackminor;
611 UINT32 suitemask;
612 const WCHAR *systemdirectory;
613 const WCHAR *version;
614 };
615 struct record_param
616 {
617 const WCHAR *class;
618 const WCHAR *method;
619 INT32 direction;
620 const WCHAR *parameter;
621 UINT32 type;
622 UINT32 varianttype;
623 UINT32 defaultvalue;
624 };
625 struct record_process
626 {
627 const WCHAR *caption;
628 const WCHAR *commandline;
629 const WCHAR *description;
630 const WCHAR *handle;
631 const WCHAR *name;
632 UINT32 pprocess_id;
633 UINT32 process_id;
634 UINT32 thread_count;
635 /* methods */
636 class_method *get_owner;
637 };
638 struct record_processor
639 {
640 UINT16 addresswidth;
641 UINT16 cpu_status;
642 const WCHAR *device_id;
643 UINT16 family;
644 const WCHAR *manufacturer;
645 UINT32 maxclockspeed;
646 const WCHAR *name;
647 UINT32 num_cores;
648 UINT32 num_logical_processors;
649 const WCHAR *processor_id;
650 const WCHAR *unique_id;
651 };
652 struct record_qualifier
653 {
654 const WCHAR *class;
655 const WCHAR *member;
656 UINT32 type;
657 INT32 flavor;
658 const WCHAR *name;
659 INT32 intvalue;
660 const WCHAR *strvalue;
661 };
662 struct record_service
663 {
664 int accept_pause;
665 int accept_stop;
666 const WCHAR *displayname;
667 const WCHAR *name;
668 UINT32 process_id;
669 const WCHAR *servicetype;
670 const WCHAR *startmode;
671 const WCHAR *state;
672 const WCHAR *systemname;
673 /* methods */
674 class_method *pause_service;
675 class_method *resume_service;
676 class_method *start_service;
677 class_method *stop_service;
678 };
679 struct record_sounddevice
680 {
681 const WCHAR *name;
682 const WCHAR *productname;
683 };
684 struct record_stdregprov
685 {
686 class_method *enumkey;
687 class_method *enumvalues;
688 class_method *getstringvalue;
689 };
690 struct record_videocontroller
691 {
692 const WCHAR *adapter_dactype;
693 UINT32 adapter_ram;
694 UINT32 current_bitsperpixel;
695 UINT32 current_horizontalres;
696 UINT32 current_verticalres;
697 const WCHAR *description;
698 const WCHAR *device_id;
699 const WCHAR *name;
700 const WCHAR *pnpdevice_id;
701 };
702 #include "poppack.h"
703
704 static const struct record_baseboard data_baseboard[] =
705 {
706 { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
707 };
708 static const struct record_bios data_bios[] =
709 {
710 { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW, bios_versionW }
711 };
712 static const struct record_diskdrive data_diskdrive[] =
713 {
714 { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
715 };
716 static const struct record_param data_param[] =
717 {
718 { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
719 { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
720 { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
721 { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
722 { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
723 { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
724 { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
725 { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
726 { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
727 { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
728 { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
729 { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
730 { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
731 { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
732 { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
733 { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
734 { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
735 { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
736 { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
737 { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
738 { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
739 };
740
741 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
742 WBEM_FLAVOR_ORIGIN_PROPAGATED)
743
744 static const struct record_qualifier data_qualifier[] =
745 {
746 { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
747 { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
748 };
749 static const struct record_sounddevice data_sounddevice[] =
750 {
751 { sounddevice_productnameW, sounddevice_productnameW }
752 };
753 static const struct record_stdregprov data_stdregprov[] =
754 {
755 { reg_enum_key, reg_enum_values, reg_get_stringvalue }
756 };
757
758 /* check if row matches condition and update status */
759 static BOOL match_row( const struct table *table, UINT row, const struct expr *cond, enum fill_status *status )
760 {
761 LONGLONG val;
762 if (!cond)
763 {
764 *status = FILL_STATUS_UNFILTERED;
765 return TRUE;
766 }
767 if (eval_cond( table, row, cond, &val ) != S_OK)
768 {
769 *status = FILL_STATUS_FAILED;
770 return FALSE;
771 }
772 *status = FILL_STATUS_FILTERED;
773 return val != 0;
774 }
775
776 static BOOL resize_table( struct table *table, UINT row_count, UINT row_size )
777 {
778 if (!table->num_rows_allocated)
779 {
780 if (!(table->data = heap_alloc( row_count * row_size ))) return FALSE;
781 table->num_rows_allocated = row_count;
782 return TRUE;
783 }
784 if (row_count >= table->num_rows_allocated)
785 {
786 BYTE *data;
787 UINT count = table->num_rows_allocated * 2;
788 if (!(data = heap_realloc( table->data, count * row_size ))) return FALSE;
789 table->data = data;
790 table->num_rows_allocated = count;
791 }
792 return TRUE;
793 }
794
795 static enum fill_status fill_cdromdrive( struct table *table, const struct expr *cond )
796 {
797 static const WCHAR fmtW[] = {'%','c',':',0};
798 WCHAR drive[3], root[] = {'A',':','\\',0};
799 struct record_cdromdrive *rec;
800 UINT i, row = 0, offset = 0;
801 DWORD drives = GetLogicalDrives();
802 enum fill_status status = FILL_STATUS_UNFILTERED;
803
804 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
805
806 for (i = 0; i < sizeof(drives); i++)
807 {
808 if (drives & (1 << i))
809 {
810 root[0] = 'A' + i;
811 if (GetDriveTypeW( root ) != DRIVE_CDROM)
812 continue;
813
814 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
815
816 rec = (struct record_cdromdrive *)(table->data + offset);
817 rec->device_id = cdromdrive_pnpdeviceidW;
818 sprintfW( drive, fmtW, 'A' + i );
819 rec->drive = heap_strdupW( drive );
820 rec->name = cdromdrive_nameW;
821 rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
822 if (!match_row( table, row, cond, &status ))
823 {
824 free_row_values( table, row );
825 continue;
826 }
827 offset += sizeof(*rec);
828 row++;
829 }
830 }
831 TRACE("created %u rows\n", row);
832 table->num_rows = row;
833 return status;
834 }
835
836 static UINT get_processor_count(void)
837 {
838 SYSTEM_BASIC_INFORMATION info;
839
840 if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
841 return info.NumberOfProcessors;
842 }
843
844 static UINT get_logical_processor_count( UINT *num_cores )
845 {
846 SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
847 UINT i, j, count = 0;
848 NTSTATUS status;
849 ULONG len;
850
851 if (num_cores) *num_cores = get_processor_count();
852 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
853 if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
854
855 if (!(info = heap_alloc( len ))) return get_processor_count();
856 status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
857 if (status != STATUS_SUCCESS)
858 {
859 heap_free( info );
860 return get_processor_count();
861 }
862 if (num_cores) *num_cores = 0;
863 for (i = 0; i < len / sizeof(*info); i++)
864 {
865 if (info[i].Relationship == RelationProcessorCore)
866 {
867 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
868 }
869 else if (info[i].Relationship == RelationProcessorPackage && num_cores)
870 {
871 for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) (*num_cores)++;
872 }
873 }
874 heap_free( info );
875 return count;
876 }
877
878 static UINT64 get_total_physical_memory(void)
879 {
880 MEMORYSTATUSEX status;
881
882 status.dwLength = sizeof(status);
883 if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
884 return status.ullTotalPhys;
885 }
886
887 static WCHAR *get_computername(void)
888 {
889 WCHAR *ret;
890 DWORD size = MAX_COMPUTERNAME_LENGTH;
891
892 if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
893 GetComputerNameW( ret, &size );
894 return ret;
895 }
896
897 static enum fill_status fill_compsys( struct table *table, const struct expr *cond )
898 {
899 struct record_computersystem *rec;
900 enum fill_status status = FILL_STATUS_UNFILTERED;
901 UINT row = 0;
902
903 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
904
905 rec = (struct record_computersystem *)table->data;
906 rec->description = compsys_descriptionW;
907 rec->domain = compsys_domainW;
908 rec->domainrole = 0; /* standalone workstation */
909 rec->manufacturer = compsys_manufacturerW;
910 rec->model = compsys_modelW;
911 rec->name = get_computername();
912 rec->num_logical_processors = get_logical_processor_count( NULL );
913 rec->num_processors = get_processor_count();
914 rec->total_physical_memory = get_total_physical_memory();
915 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
916 else row++;
917
918 TRACE("created %u rows\n", row);
919 table->num_rows = row;
920 return status;
921 }
922
923 struct dirstack
924 {
925 WCHAR **dirs;
926 UINT *len_dirs;
927 UINT num_dirs;
928 UINT num_allocated;
929 };
930
931 static struct dirstack *alloc_dirstack( UINT size )
932 {
933 struct dirstack *dirstack;
934
935 if (!(dirstack = heap_alloc( sizeof(*dirstack) ))) return NULL;
936 if (!(dirstack->dirs = heap_alloc( sizeof(WCHAR *) * size )))
937 {
938 heap_free( dirstack );
939 return NULL;
940 }
941 if (!(dirstack->len_dirs = heap_alloc( sizeof(UINT) * size )))
942 {
943 heap_free( dirstack->dirs );
944 heap_free( dirstack );
945 return NULL;
946 }
947 dirstack->num_dirs = 0;
948 dirstack->num_allocated = size;
949 return dirstack;
950 }
951
952 static void clear_dirstack( struct dirstack *dirstack )
953 {
954 UINT i;
955 for (i = 0; i < dirstack->num_dirs; i++) heap_free( dirstack->dirs[i] );
956 dirstack->num_dirs = 0;
957 }
958
959 static void free_dirstack( struct dirstack *dirstack )
960 {
961 clear_dirstack( dirstack );
962 heap_free( dirstack->dirs );
963 heap_free( dirstack->len_dirs );
964 heap_free( dirstack );
965 }
966
967 static BOOL push_dir( struct dirstack *dirstack, WCHAR *dir, UINT len )
968 {
969 UINT size, i = dirstack->num_dirs;
970
971 if (!dir) return FALSE;
972
973 if (i == dirstack->num_allocated)
974 {
975 WCHAR **tmp;
976 UINT *len_tmp;
977
978 size = dirstack->num_allocated * 2;
979 if (!(tmp = heap_realloc( dirstack->dirs, size * sizeof(WCHAR *) ))) return FALSE;
980 dirstack->dirs = tmp;
981 if (!(len_tmp = heap_realloc( dirstack->len_dirs, size * sizeof(UINT) ))) return FALSE;
982 dirstack->len_dirs = len_tmp;
983 dirstack->num_allocated = size;
984 }
985 dirstack->dirs[i] = dir;
986 dirstack->len_dirs[i] = len;
987 dirstack->num_dirs++;
988 return TRUE;
989 }
990
991 static WCHAR *pop_dir( struct dirstack *dirstack, UINT *len )
992 {
993 if (!dirstack->num_dirs)
994 {
995 *len = 0;
996 return NULL;
997 }
998 dirstack->num_dirs--;
999 *len = dirstack->len_dirs[dirstack->num_dirs];
1000 return dirstack->dirs[dirstack->num_dirs];
1001 }
1002
1003 static const WCHAR *peek_dir( struct dirstack *dirstack )
1004 {
1005 if (!dirstack->num_dirs) return NULL;
1006 return dirstack->dirs[dirstack->num_dirs - 1];
1007 }
1008
1009 static WCHAR *build_glob( WCHAR drive, const WCHAR *path, UINT len )
1010 {
1011 UINT i = 0;
1012 WCHAR *ret;
1013
1014 if (!(ret = heap_alloc( (len + 6) * sizeof(WCHAR) ))) return NULL;
1015 ret[i++] = drive;
1016 ret[i++] = ':';
1017 ret[i++] = '\\';
1018 if (path && len)
1019 {
1020 memcpy( ret + i, path, len * sizeof(WCHAR) );
1021 i += len;
1022 ret[i++] = '\\';
1023 }
1024 ret[i++] = '*';
1025 ret[i] = 0;
1026 return ret;
1027 }
1028
1029 static WCHAR *build_name( WCHAR drive, const WCHAR *path )
1030 {
1031 UINT i = 0, len = 0;
1032 const WCHAR *p;
1033 WCHAR *ret;
1034
1035 for (p = path; *p; p++)
1036 {
1037 if (*p == '\\') len += 2;
1038 else len++;
1039 };
1040 if (!(ret = heap_alloc( (len + 5) * sizeof(WCHAR) ))) return NULL;
1041 ret[i++] = drive;
1042 ret[i++] = ':';
1043 ret[i++] = '\\';
1044 ret[i++] = '\\';
1045 for (p = path; *p; p++)
1046 {
1047 if (*p != '\\') ret[i++] = *p;
1048 else
1049 {
1050 ret[i++] = '\\';
1051 ret[i++] = '\\';
1052 }
1053 }
1054 ret[i] = 0;
1055 return ret;
1056 }
1057
1058 static WCHAR *build_dirname( const WCHAR *path, UINT *ret_len )
1059 {
1060 const WCHAR *p = path, *start;
1061 UINT len, i;
1062 WCHAR *ret;
1063
1064 if (!isalphaW( p[0] ) || p[1] != ':' || p[2] != '\\' || p[3] != '\\' || !p[4]) return NULL;
1065 start = path + 4;
1066 len = strlenW( start );
1067 p = start + len - 1;
1068 if (*p == '\\') return NULL;
1069
1070 while (p >= start && *p != '\\') { len--; p--; };
1071 while (p >= start && *p == '\\') { len--; p--; };
1072
1073 if (!(ret = heap_alloc( (len + 1) * sizeof(WCHAR) ))) return NULL;
1074 for (i = 0, p = start; p < start + len; p++)
1075 {
1076 if (p[0] == '\\' && p[1] == '\\')
1077 {
1078 ret[i++] = '\\';
1079 p++;
1080 }
1081 else ret[i++] = *p;
1082 }
1083 ret[i] = 0;
1084 *ret_len = i;
1085 return ret;
1086 }
1087
1088 static BOOL seen_dir( struct dirstack *dirstack, const WCHAR *path )
1089 {
1090 UINT i;
1091 for (i = 0; i < dirstack->num_dirs; i++) if (!strcmpW( dirstack->dirs[i], path )) return TRUE;
1092 return FALSE;
1093 }
1094
1095 /* optimize queries of the form WHERE Name='...' [OR Name='...']* */
1096 static UINT seed_dirs( struct dirstack *dirstack, const struct expr *cond, WCHAR root, UINT *count )
1097 {
1098 const struct expr *left, *right;
1099
1100 if (!cond || cond->type != EXPR_COMPLEX) return *count = 0;
1101
1102 left = cond->u.expr.left;
1103 right = cond->u.expr.right;
1104 if (cond->u.expr.op == OP_EQ)
1105 {
1106 UINT len;
1107 WCHAR *path;
1108 const WCHAR *str = NULL;
1109
1110 if (left->type == EXPR_PROPVAL && right->type == EXPR_SVAL &&
1111 !strcmpW( left->u.propval->name, prop_nameW ) &&
1112 toupperW( right->u.sval[0] ) == toupperW( root ))
1113 {
1114 str = right->u.sval;
1115 }
1116 else if (left->type == EXPR_SVAL && right->type == EXPR_PROPVAL &&
1117 !strcmpW( right->u.propval->name, prop_nameW ) &&
1118 toupperW( left->u.sval[0] ) == toupperW( root ))
1119 {
1120 str = left->u.sval;
1121 }
1122 if (str && (path = build_dirname( str, &len )))
1123 {
1124 if (seen_dir( dirstack, path ))
1125 {
1126 heap_free( path );
1127 return ++*count;
1128 }
1129 else if (push_dir( dirstack, path, len )) return ++*count;
1130 heap_free( path );
1131 return *count = 0;
1132 }
1133 }
1134 else if (cond->u.expr.op == OP_OR)
1135 {
1136 UINT left_count = 0, right_count = 0;
1137
1138 if (!(seed_dirs( dirstack, left, root, &left_count ))) return *count = 0;
1139 if (!(seed_dirs( dirstack, right, root, &right_count ))) return *count = 0;
1140 return *count += left_count + right_count;
1141 }
1142 return *count = 0;
1143 }
1144
1145 static WCHAR *append_path( const WCHAR *path, const WCHAR *segment, UINT *len )
1146 {
1147 UINT len_path = 0, len_segment = strlenW( segment );
1148 WCHAR *ret;
1149
1150 *len = 0;
1151 if (path) len_path = strlenW( path );
1152 if (!(ret = heap_alloc( (len_path + len_segment + 2) * sizeof(WCHAR) ))) return NULL;
1153 if (path && len_path)
1154 {
1155 memcpy( ret, path, len_path * sizeof(WCHAR) );
1156 ret[len_path] = '\\';
1157 *len += len_path + 1;
1158 }
1159 memcpy( ret + *len, segment, len_segment * sizeof(WCHAR) );
1160 *len += len_segment;
1161 ret[*len] = 0;
1162 return ret;
1163 }
1164
1165 static WCHAR *get_file_version( const WCHAR *filename )
1166 {
1167 static const WCHAR slashW[] = {'\\',0}, fmtW[] = {'%','u','.','%','u','.','%','u','.','%','u',0};
1168 VS_FIXEDFILEINFO *info;
1169 DWORD size;
1170 void *block;
1171 WCHAR *ret;
1172
1173 if (!(ret = heap_alloc( (4 * 5 + sizeof(fmtW) / sizeof(fmtW[0])) * sizeof(WCHAR) ))) return NULL;
1174 if (!(size = GetFileVersionInfoSizeW( filename, NULL )) || !(block = heap_alloc( size )))
1175 {
1176 heap_free( ret );
1177 return NULL;
1178 }
1179 if (!GetFileVersionInfoW( filename, 0, size, block ) ||
1180 !VerQueryValueW( block, slashW, (void **)&info, &size ))
1181 {
1182 heap_free( block );
1183 heap_free( ret );
1184 return NULL;
1185 }
1186 sprintfW( ret, fmtW, info->dwFileVersionMS >> 16, info->dwFileVersionMS & 0xffff,
1187 info->dwFileVersionLS >> 16, info->dwFileVersionLS & 0xffff );
1188 heap_free( block );
1189 return ret;
1190 }
1191
1192 static enum fill_status fill_datafile( struct table *table, const struct expr *cond )
1193 {
1194 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1195 struct record_datafile *rec;
1196 UINT i, len, row = 0, offset = 0, num_expected_rows;
1197 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1198 DWORD drives = GetLogicalDrives();
1199 WIN32_FIND_DATAW data;
1200 HANDLE handle;
1201 struct dirstack *dirstack = alloc_dirstack(2);
1202 enum fill_status status = FILL_STATUS_UNFILTERED;
1203
1204 if (!resize_table( table, 8, sizeof(*rec) )) return FILL_STATUS_FAILED;
1205
1206 for (i = 0; i < sizeof(drives); i++)
1207 {
1208 if (!(drives & (1 << i))) continue;
1209
1210 root[0] = 'A' + i;
1211 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1212
1213 num_expected_rows = 0;
1214 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1215
1216 for (;;)
1217 {
1218 path = pop_dir( dirstack, &len );
1219 if (!(glob = build_glob( root[0], path, len )))
1220 {
1221 status = FILL_STATUS_FAILED;
1222 goto done;
1223 }
1224 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1225 {
1226 do
1227 {
1228 if (!resize_table( table, row + 1, sizeof(*rec) ))
1229 {
1230 status = FILL_STATUS_FAILED;
1231 goto done;
1232 }
1233 if (!strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW )) continue;
1234 new_path = append_path( path, data.cFileName, &len );
1235
1236 if (data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
1237 {
1238 if (push_dir( dirstack, new_path, len )) continue;
1239 heap_free( new_path );
1240 status = FILL_STATUS_FAILED;
1241 goto done;
1242 }
1243 rec = (struct record_datafile *)(table->data + offset);
1244 rec->name = build_name( root[0], new_path );
1245 rec->version = get_file_version( rec->name );
1246 if (!match_row( table, row, cond, &status ))
1247 {
1248 free_row_values( table, row );
1249 continue;
1250 }
1251 else if (num_expected_rows && row == num_expected_rows - 1)
1252 {
1253 row++;
1254 FindClose( handle );
1255 status = FILL_STATUS_FILTERED;
1256 goto done;
1257 }
1258 offset += sizeof(*rec);
1259 row++;
1260 }
1261 while (FindNextFileW( handle, &data ));
1262 FindClose( handle );
1263 }
1264 if (!peek_dir( dirstack )) break;
1265 heap_free( glob );
1266 heap_free( path );
1267 }
1268 }
1269
1270 done:
1271 free_dirstack( dirstack );
1272 heap_free( glob );
1273 heap_free( path );
1274
1275 TRACE("created %u rows\n", row);
1276 table->num_rows = row;
1277 return status;
1278 }
1279
1280 static enum fill_status fill_directory( struct table *table, const struct expr *cond )
1281 {
1282 static const WCHAR dotW[] = {'.',0}, dotdotW[] = {'.','.',0};
1283 struct record_directory *rec;
1284 UINT i, len, row = 0, offset = 0, num_expected_rows;
1285 WCHAR *glob = NULL, *path = NULL, *new_path, root[] = {'A',':','\\',0};
1286 DWORD drives = GetLogicalDrives();
1287 WIN32_FIND_DATAW data;
1288 HANDLE handle;
1289 struct dirstack *dirstack;
1290 enum fill_status status = FILL_STATUS_UNFILTERED;
1291
1292 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1293
1294 dirstack = alloc_dirstack(2);
1295
1296 for (i = 0; i < sizeof(drives); i++)
1297 {
1298 if (!(drives & (1 << i))) continue;
1299
1300 root[0] = 'A' + i;
1301 if (GetDriveTypeW( root ) != DRIVE_FIXED) continue;
1302
1303 num_expected_rows = 0;
1304 if (!seed_dirs( dirstack, cond, root[0], &num_expected_rows )) clear_dirstack( dirstack );
1305
1306 for (;;)
1307 {
1308 path = pop_dir( dirstack, &len );
1309 if (!(glob = build_glob( root[0], path, len )))
1310 {
1311 status = FILL_STATUS_FAILED;
1312 goto done;
1313 }
1314 if ((handle = FindFirstFileW( glob, &data )) != INVALID_HANDLE_VALUE)
1315 {
1316 do
1317 {
1318 if (!resize_table( table, row + 1, sizeof(*rec) ))
1319 {
1320 FindClose( handle );
1321 status = FILL_STATUS_FAILED;
1322 goto done;
1323 }
1324 if (!(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ||
1325 !strcmpW( data.cFileName, dotW ) || !strcmpW( data.cFileName, dotdotW ))
1326 continue;
1327
1328 new_path = append_path( path, data.cFileName, &len );
1329 if (!(push_dir( dirstack, new_path, len )))
1330 {
1331 heap_free( new_path );
1332 FindClose( handle );
1333 status = FILL_STATUS_FAILED;
1334 goto done;
1335 }
1336 rec = (struct record_directory *)(table->data + offset);
1337 rec->accessmask = FILE_ALL_ACCESS;
1338 rec->name = build_name( root[0], new_path );
1339 if (!match_row( table, row, cond, &status ))
1340 {
1341 free_row_values( table, row );
1342 continue;
1343 }
1344 else if (num_expected_rows && row == num_expected_rows - 1)
1345 {
1346 row++;
1347 FindClose( handle );
1348 status = FILL_STATUS_FILTERED;
1349 goto done;
1350 }
1351 offset += sizeof(*rec);
1352 row++;
1353 }
1354 while (FindNextFileW( handle, &data ));
1355 FindClose( handle );
1356 }
1357 if (!peek_dir( dirstack )) break;
1358 heap_free( glob );
1359 heap_free( path );
1360 }
1361 }
1362
1363 done:
1364 free_dirstack( dirstack );
1365 heap_free( glob );
1366 heap_free( path );
1367
1368 TRACE("created %u rows\n", row);
1369 table->num_rows = row;
1370 return status;
1371 }
1372
1373 static WCHAR *get_filesystem( const WCHAR *root )
1374 {
1375 static const WCHAR ntfsW[] = {'N','T','F','S',0};
1376 WCHAR buffer[MAX_PATH + 1];
1377
1378 if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
1379 return heap_strdupW( buffer );
1380 return heap_strdupW( ntfsW );
1381 }
1382
1383 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
1384 {
1385 WCHAR root[] = {'\\','\\','.','\\','A',':',0};
1386 ULARGE_INTEGER free;
1387 DISK_GEOMETRY_EX info;
1388 HANDLE handle;
1389
1390 free.QuadPart = 512 * 1024 * 1024;
1391 GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
1392
1393 root[4] = dir[0];
1394 handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
1395 if (handle != INVALID_HANDLE_VALUE)
1396 {
1397 if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
1398 *disksize = info.DiskSize.QuadPart;
1399 CloseHandle( handle );
1400 }
1401 return free.QuadPart;
1402 }
1403
1404 static enum fill_status fill_diskpartition( struct table *table, const struct expr *cond )
1405 {
1406 static const WCHAR fmtW[] =
1407 {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
1408 WCHAR device_id[32], root[] = {'A',':','\\',0};
1409 struct record_diskpartition *rec;
1410 UINT i, row = 0, offset = 0, type, index = 0;
1411 UINT64 size = 1024 * 1024 * 1024;
1412 DWORD drives = GetLogicalDrives();
1413 enum fill_status status = FILL_STATUS_UNFILTERED;
1414
1415 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1416
1417 for (i = 0; i < sizeof(drives); i++)
1418 {
1419 if (drives & (1 << i))
1420 {
1421 root[0] = 'A' + i;
1422 type = GetDriveTypeW( root );
1423 if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
1424 continue;
1425
1426 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1427
1428 rec = (struct record_diskpartition *)(table->data + offset);
1429 rec->bootable = (i == 2) ? -1 : 0;
1430 rec->bootpartition = (i == 2) ? -1 : 0;
1431 sprintfW( device_id, fmtW, index );
1432 rec->device_id = heap_strdupW( device_id );
1433 rec->diskindex = index;
1434 rec->index = 0;
1435 rec->pnpdevice_id = heap_strdupW( device_id );
1436 get_freespace( root, &size );
1437 rec->size = size;
1438 rec->startingoffset = 0;
1439 rec->type = get_filesystem( root );
1440 if (!match_row( table, row, cond, &status ))
1441 {
1442 free_row_values( table, row );
1443 continue;
1444 }
1445 offset += sizeof(*rec);
1446 row++;
1447 index++;
1448 }
1449 }
1450 TRACE("created %u rows\n", row);
1451 table->num_rows = row;
1452 return status;
1453 }
1454
1455 static enum fill_status fill_logicaldisk( struct table *table, const struct expr *cond )
1456 {
1457 static const WCHAR fmtW[] = {'%','c',':',0};
1458 WCHAR device_id[3], root[] = {'A',':','\\',0};
1459 struct record_logicaldisk *rec;
1460 UINT i, row = 0, offset = 0, type;
1461 UINT64 size = 1024 * 1024 * 1024;
1462 DWORD drives = GetLogicalDrives();
1463 enum fill_status status = FILL_STATUS_UNFILTERED;
1464
1465 if (!resize_table( table, 4, sizeof(*rec) )) return FILL_STATUS_FAILED;
1466
1467 for (i = 0; i < sizeof(drives); i++)
1468 {
1469 if (drives & (1 << i))
1470 {
1471 root[0] = 'A' + i;
1472 type = GetDriveTypeW( root );
1473 if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
1474 continue;
1475
1476 if (!resize_table( table, row + 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1477
1478 rec = (struct record_logicaldisk *)(table->data + offset);
1479 sprintfW( device_id, fmtW, 'A' + i );
1480 rec->device_id = heap_strdupW( device_id );
1481 rec->drivetype = type;
1482 rec->filesystem = get_filesystem( root );
1483 rec->freespace = get_freespace( root, &size );
1484 rec->name = heap_strdupW( device_id );
1485 rec->size = size;
1486 if (!match_row( table, row, cond, &status ))
1487 {
1488 free_row_values( table, row );
1489 continue;
1490 }
1491 offset += sizeof(*rec);
1492 row++;
1493 }
1494 }
1495 TRACE("created %u rows\n", row);
1496 table->num_rows = row;
1497 return status;
1498 }
1499
1500 static UINT16 get_connection_status( IF_OPER_STATUS status )
1501 {
1502 switch (status)
1503 {
1504 case IfOperStatusDown:
1505 return 0; /* Disconnected */
1506 case IfOperStatusUp:
1507 return 2; /* Connected */
1508 default:
1509 ERR("unhandled status %u\n", status);
1510 break;
1511 }
1512 return 0;
1513 }
1514 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
1515 {
1516 static const WCHAR fmtW[] =
1517 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
1518 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
1519 WCHAR *ret;
1520
1521 if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
1522 sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
1523 return ret;
1524 }
1525 static const WCHAR *get_adaptertype( DWORD type, int *physical )
1526 {
1527 static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
1528 static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
1529 static const WCHAR firewireW[] = {'1','3','9','4',0};
1530 static const WCHAR tunnelW[] = {'T','u','n','n','e','l',0};
1531
1532 switch (type)
1533 {
1534 case IF_TYPE_ETHERNET_CSMACD: *physical = -1; return ethernetW;
1535 case IF_TYPE_IEEE80211: *physical = -1; return wirelessW;
1536 case IF_TYPE_IEEE1394: *physical = -1; return firewireW;
1537 case IF_TYPE_TUNNEL: *physical = 0; return tunnelW;
1538 default: *physical = 0; return NULL;
1539 }
1540 }
1541
1542 static enum fill_status fill_networkadapter( struct table *table, const struct expr *cond )
1543 {
1544 static const WCHAR fmtW[] = {'%','u',0};
1545 WCHAR device_id[11];
1546 struct record_networkadapter *rec;
1547 IP_ADAPTER_ADDRESSES *aa, *buffer;
1548 UINT row = 0, offset = 0, count = 0;
1549 DWORD size = 0, ret;
1550 int physical;
1551 enum fill_status status = FILL_STATUS_UNFILTERED;
1552
1553 ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
1554 if (ret != ERROR_BUFFER_OVERFLOW) return FILL_STATUS_FAILED;
1555
1556 if (!(buffer = heap_alloc( size ))) return FILL_STATUS_FAILED;
1557 if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
1558 {
1559 heap_free( buffer );
1560 return FILL_STATUS_FAILED;
1561 }
1562 for (aa = buffer; aa; aa = aa->Next) count++;
1563 if (!resize_table( table, count, sizeof(*rec) ))
1564 {
1565 heap_free( buffer );
1566 return FILL_STATUS_FAILED;
1567 }
1568 for (aa = buffer; aa; aa = aa->Next)
1569 {
1570 rec = (struct record_networkadapter *)(table->data + offset);
1571 sprintfW( device_id, fmtW, aa->u.s.IfIndex );
1572 rec->adaptertype = get_adaptertype( aa->IfType, &physical );
1573 rec->device_id = heap_strdupW( device_id );
1574 rec->interface_index = aa->u.s.IfIndex;
1575 rec->mac_address = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
1576 rec->manufacturer = compsys_manufacturerW;
1577 rec->netconnection_status = get_connection_status( aa->OperStatus );
1578 rec->physicaladapter = physical;
1579 rec->pnpdevice_id = networkadapter_pnpdeviceidW;
1580 rec->speed = 1000000;
1581 if (!match_row( table, row, cond, &status ))
1582 {
1583 free_row_values( table, row );
1584 continue;
1585 }
1586 offset += sizeof(*rec);
1587 row++;
1588 }
1589 TRACE("created %u rows\n", row);
1590 table->num_rows = row;
1591
1592 heap_free( buffer );
1593 return status;
1594 }
1595
1596 static WCHAR *get_cmdline( DWORD process_id )
1597 {
1598 if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
1599 return NULL; /* FIXME handle different process case */
1600 }
1601
1602 static enum fill_status fill_process( struct table *table, const struct expr *cond )
1603 {
1604 static const WCHAR fmtW[] = {'%','u',0};
1605 WCHAR handle[11];
1606 struct record_process *rec;
1607 PROCESSENTRY32W entry;
1608 HANDLE snap;
1609 enum fill_status status = FILL_STATUS_FAILED;
1610 UINT row = 0, offset = 0;
1611
1612 snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
1613 if (snap == INVALID_HANDLE_VALUE) return FILL_STATUS_FAILED;
1614
1615 entry.dwSize = sizeof(entry);
1616 if (!Process32FirstW( snap, &entry )) goto done;
1617 if (!resize_table( table, 8, sizeof(*rec) )) goto done;
1618
1619 do
1620 {
1621 if (!resize_table( table, row + 1, sizeof(*rec) )) goto done;
1622
1623 rec = (struct record_process *)(table->data + offset);
1624 rec->caption = heap_strdupW( entry.szExeFile );
1625 rec->commandline = get_cmdline( entry.th32ProcessID );
1626 rec->description = heap_strdupW( entry.szExeFile );
1627 sprintfW( handle, fmtW, entry.th32ProcessID );
1628 rec->handle = heap_strdupW( handle );
1629 rec->name = heap_strdupW( entry.szExeFile );
1630 rec->process_id = entry.th32ProcessID;
1631 rec->pprocess_id = entry.th32ParentProcessID;
1632 rec->thread_count = entry.cntThreads;
1633 rec->get_owner = process_get_owner;
1634 if (!match_row( table, row, cond, &status ))
1635 {
1636 free_row_values( table, row );
1637 continue;
1638 }
1639 offset += sizeof(*rec);
1640 row++;
1641 } while (Process32NextW( snap, &entry ));
1642
1643 TRACE("created %u rows\n", row);
1644 table->num_rows = row;
1645 status = FILL_STATUS_UNFILTERED;
1646
1647 done:
1648 CloseHandle( snap );
1649 return status;
1650 }
1651
1652 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1653 {
1654 #ifdef __i386__
1655 #ifdef _MSC_VER
1656 __cpuid(p, ax);
1657 #else
1658 __asm__("pushl %%ebx\n\t"
1659 "cpuid\n\t"
1660 "movl %%ebx, %%esi\n\t"
1661 "popl %%ebx"
1662 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1663 : "0" (ax));
1664 #endif
1665 #endif
1666 }
1667
1668 static void get_processor_id( WCHAR *processor_id )
1669 {
1670 static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1671 unsigned int regs[4] = {0, 0, 0, 0};
1672
1673 do_cpuid( 1, regs );
1674 sprintfW( processor_id, fmtW, regs[3], regs[0] );
1675 }
1676 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1677 {
1678 unsigned int i;
1679 unsigned char *p = (unsigned char *)regs;
1680
1681 for (i = 0; i < len; i++) { buffer[i] = *p++; }
1682 buffer[i] = 0;
1683 }
1684 static void get_processor_manufacturer( WCHAR *manufacturer )
1685 {
1686 unsigned int tmp, regs[4] = {0, 0, 0, 0};
1687
1688 do_cpuid( 0, regs );
1689 tmp = regs[2]; /* swap edx and ecx */
1690 regs[2] = regs[3];
1691 regs[3] = tmp;
1692
1693 regs_to_str( regs + 1, 12, manufacturer );
1694 }
1695 static void get_processor_name( WCHAR *name )
1696 {
1697 unsigned int regs[4] = {0, 0, 0, 0};
1698
1699 do_cpuid( 0x80000000, regs );
1700 if (regs[0] >= 0x80000004)
1701 {
1702 do_cpuid( 0x80000002, regs );
1703 regs_to_str( regs, 16, name );
1704 do_cpuid( 0x80000003, regs );
1705 regs_to_str( regs, 16, name + 16 );
1706 do_cpuid( 0x80000004, regs );
1707 regs_to_str( regs, 16, name + 32 );
1708 }
1709 }
1710 static UINT get_processor_maxclockspeed( void )
1711 {
1712 PROCESSOR_POWER_INFORMATION *info;
1713 UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1714 NTSTATUS status;
1715
1716 if ((info = heap_alloc( size )))
1717 {
1718 status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1719 if (!status) ret = info[0].MaxMhz;
1720 heap_free( info );
1721 }
1722 return ret;
1723 }
1724 static const WCHAR *get_osarchitecture(void)
1725 {
1726 SYSTEM_INFO info;
1727 GetNativeSystemInfo( &info );
1728 if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1729 return os_32bitW;
1730 }
1731
1732 static enum fill_status fill_processor( struct table *table, const struct expr *cond )
1733 {
1734 static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1735 WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1736 struct record_processor *rec;
1737 UINT i, offset = 0, maxclockspeed, num_cores, num_logical_processors, count = get_processor_count();
1738 enum fill_status status = FILL_STATUS_UNFILTERED;
1739
1740 if (!resize_table( table, count, sizeof(*rec) )) return FILL_STATUS_FAILED;
1741
1742 get_processor_id( processor_id );
1743 get_processor_manufacturer( manufacturer );
1744 get_processor_name( name );
1745
1746 maxclockspeed = get_processor_maxclockspeed();
1747 num_logical_processors = get_logical_processor_count( &num_cores ) / count;
1748 num_cores /= count;
1749
1750 for (i = 0; i < count; i++)
1751 {
1752 rec = (struct record_processor *)(table->data + offset);
1753 rec->addresswidth = get_osarchitecture() == os_32bitW ? 32 : 64;
1754 rec->cpu_status = 1; /* CPU Enabled */
1755 sprintfW( device_id, fmtW, i );
1756 rec->device_id = heap_strdupW( device_id );
1757 rec->family = 2; /* Unknown */
1758 rec->manufacturer = heap_strdupW( manufacturer );
1759 rec->maxclockspeed = maxclockspeed;
1760 rec->name = heap_strdupW( name );
1761 rec->num_cores = num_cores;
1762 rec->num_logical_processors = num_logical_processors;
1763 rec->processor_id = heap_strdupW( processor_id );
1764 rec->unique_id = NULL;
1765 if (!match_row( table, i, cond, &status ))
1766 {
1767 free_row_values( table, i );
1768 continue;
1769 }
1770 offset += sizeof(*rec);
1771 }
1772
1773 TRACE("created %u rows\n", count);
1774 table->num_rows = count;
1775 return status;
1776 }
1777
1778 static WCHAR *get_lastbootuptime(void)
1779 {
1780 static const WCHAR fmtW[] =
1781 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1782 '.','%','0','6','u','+','0','0','0',0};
1783 SYSTEM_TIMEOFDAY_INFORMATION ti;
1784 TIME_FIELDS tf;
1785 WCHAR *ret;
1786
1787 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1788
1789 NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1790 RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1791 sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1792 return ret;
1793 }
1794 static WCHAR *get_localdatetime(void)
1795 {
1796 static const WCHAR fmtW[] =
1797 {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1798 '.','%','0','6','u','%','+','0','3','d',0};
1799 TIME_ZONE_INFORMATION tzi;
1800 SYSTEMTIME st;
1801 WCHAR *ret;
1802 DWORD Status;
1803 LONG Bias;
1804
1805 Status = GetTimeZoneInformation(&tzi);
1806
1807 if(Status == TIME_ZONE_ID_INVALID) return NULL;
1808 Bias = tzi.Bias;
1809 if(Status == TIME_ZONE_ID_DAYLIGHT)
1810 Bias+= tzi.DaylightBias;
1811 else
1812 Bias+= tzi.StandardBias;
1813 if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1814
1815 GetLocalTime(&st);
1816 sprintfW( ret, fmtW, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, st.wMilliseconds * 1000, -Bias);
1817 return ret;
1818 }
1819 static WCHAR *get_systemdirectory(void)
1820 {
1821 void *redir;
1822 WCHAR *ret;
1823
1824 if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1825 Wow64DisableWow64FsRedirection( &redir );
1826 GetSystemDirectoryW( ret, MAX_PATH );
1827 Wow64RevertWow64FsRedirection( redir );
1828 return ret;
1829 }
1830 static WCHAR *get_codeset(void)
1831 {
1832 static const WCHAR fmtW[] = {'%','u',0};
1833 WCHAR *ret = heap_alloc( 11 * sizeof(WCHAR) );
1834 if (ret) sprintfW( ret, fmtW, GetACP() );
1835 return ret;
1836 }
1837 static WCHAR *get_countrycode(void)
1838 {
1839 WCHAR *ret = heap_alloc( 6 * sizeof(WCHAR) );
1840 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ICOUNTRY, ret, 6 );
1841 return ret;
1842 }
1843 static WCHAR *get_locale(void)
1844 {
1845 WCHAR *ret = heap_alloc( 5 * sizeof(WCHAR) );
1846 if (ret) GetLocaleInfoW( LOCALE_SYSTEM_DEFAULT, LOCALE_ILANGUAGE, ret, 5 );
1847 return ret;
1848 }
1849
1850 static enum fill_status fill_os( struct table *table, const struct expr *cond )
1851 {
1852 struct record_operatingsystem *rec;
1853 enum fill_status status = FILL_STATUS_UNFILTERED;
1854 UINT row = 0;
1855
1856 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
1857
1858 rec = (struct record_operatingsystem *)table->data;
1859 rec->caption = os_captionW;
1860 rec->codeset = get_codeset();
1861 rec->countrycode = get_countrycode();
1862 rec->csdversion = os_csdversionW;
1863 rec->lastbootuptime = get_lastbootuptime();
1864 rec->localdatetime = get_localdatetime();
1865 rec->locale = get_locale();
1866 rec->osarchitecture = get_osarchitecture();
1867 rec->oslanguage = GetSystemDefaultLangID();
1868 rec->osproductsuite = 2461140; /* Windows XP Professional */
1869 rec->ostype = 18; /* WINNT */
1870 rec->servicepackmajor = 3;
1871 rec->servicepackminor = 0;
1872 rec->suitemask = 272; /* Single User + Terminal */
1873 rec->systemdirectory = get_systemdirectory();
1874 rec->version = os_versionW;
1875 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
1876 else row++;
1877
1878 TRACE("created %u rows\n", row);
1879 table->num_rows = row;
1880 return status;
1881 }
1882
1883 static const WCHAR *get_service_type( DWORD type )
1884 {
1885 static const WCHAR filesystem_driverW[] =
1886 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1887 static const WCHAR kernel_driverW[] =
1888 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1889 static const WCHAR own_processW[] =
1890 {'O','w','n',' ','P','r','o','c','e','s','s',0};
1891 static const WCHAR share_processW[] =
1892 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1893
1894 if (type & SERVICE_KERNEL_DRIVER) return kernel_driverW;
1895 else if (type & SERVICE_FILE_SYSTEM_DRIVER) return filesystem_driverW;
1896 else if (type & SERVICE_WIN32_OWN_PROCESS) return own_processW;
1897 else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1898 else ERR("unhandled type 0x%08x\n", type);
1899 return NULL;
1900 }
1901 static const WCHAR *get_service_state( DWORD state )
1902 {
1903 static const WCHAR runningW[] =
1904 {'R','u','n','n','i','n','g',0};
1905 static const WCHAR start_pendingW[] =
1906 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1907 static const WCHAR stop_pendingW[] =
1908 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1909 static const WCHAR stoppedW[] =
1910 {'S','t','o','p','p','e','d',0};
1911 static const WCHAR unknownW[] =
1912 {'U','n','k','n','o','w','n',0};
1913
1914 switch (state)
1915 {
1916 case SERVICE_STOPPED: return stoppedW;
1917 case SERVICE_START_PENDING: return start_pendingW;
1918 case SERVICE_STOP_PENDING: return stop_pendingW;
1919 case SERVICE_RUNNING: return runningW;
1920 default:
1921 ERR("unknown state %u\n", state);
1922 return unknownW;
1923 }
1924 }
1925 static const WCHAR *get_service_startmode( DWORD mode )
1926 {
1927 static const WCHAR bootW[] = {'B','o','o','t',0};
1928 static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
1929 static const WCHAR autoW[] = {'A','u','t','o',0};
1930 static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
1931 static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
1932 static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
1933
1934 switch (mode)
1935 {
1936 case SERVICE_BOOT_START: return bootW;
1937 case SERVICE_SYSTEM_START: return systemW;
1938 case SERVICE_AUTO_START: return autoW;
1939 case SERVICE_DEMAND_START: return manualW;
1940 case SERVICE_DISABLED: return disabledW;
1941 default:
1942 ERR("unknown mode 0x%x\n", mode);
1943 return unknownW;
1944 }
1945 }
1946 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
1947 {
1948 QUERY_SERVICE_CONFIGW *config = NULL;
1949 SC_HANDLE service;
1950 DWORD size;
1951
1952 if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
1953 QueryServiceConfigW( service, NULL, 0, &size );
1954 if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
1955 if (!(config = heap_alloc( size ))) goto done;
1956 if (QueryServiceConfigW( service, config, size, &size )) goto done;
1957 heap_free( config );
1958 config = NULL;
1959
1960 done:
1961 CloseServiceHandle( service );
1962 return config;
1963 }
1964
1965 static enum fill_status fill_service( struct table *table, const struct expr *cond )
1966 {
1967 struct record_service *rec;
1968 SC_HANDLE manager;
1969 ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
1970 SERVICE_STATUS_PROCESS *status;
1971 WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
1972 DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
1973 UINT i, row = 0, offset = 0, size = 256, needed, count;
1974 enum fill_status fill_status = FILL_STATUS_FAILED;
1975 BOOL ret;
1976
1977 if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return FILL_STATUS_FAILED;
1978 if (!(services = heap_alloc( size ))) goto done;
1979
1980 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1981 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1982 &count, NULL, NULL );
1983 if (!ret)
1984 {
1985 if (GetLastError() != ERROR_MORE_DATA) goto done;
1986 size = needed;
1987 if (!(tmp = heap_realloc( services, size ))) goto done;
1988 services = tmp;
1989 ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1990 SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1991 &count, NULL, NULL );
1992 if (!ret) goto done;
1993 }
1994 if (!resize_table( table, count, sizeof(*rec) )) goto done;
1995
1996 GetComputerNameW( sysnameW, &len );
1997 fill_status = FILL_STATUS_UNFILTERED;
1998
1999 for (i = 0; i < count; i++)
2000 {
2001 QUERY_SERVICE_CONFIGW *config;
2002
2003 if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
2004
2005 status = &services[i].ServiceStatusProcess;
2006 rec = (struct record_service *)(table->data + offset);
2007 rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
2008 rec->accept_stop = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
2009 rec->displayname = heap_strdupW( services[i].lpDisplayName );
2010 rec->name = heap_strdupW( services[i].lpServiceName );
2011 rec->process_id = status->dwProcessId;
2012 rec->servicetype = get_service_type( status->dwServiceType );
2013 rec->startmode = get_service_startmode( config->dwStartType );
2014 rec->state = get_service_state( status->dwCurrentState );
2015 rec->systemname = heap_strdupW( sysnameW );
2016 rec->pause_service = service_pause_service;
2017 rec->resume_service = service_resume_service;
2018 rec->start_service = service_start_service;
2019 rec->stop_service = service_stop_service;
2020 heap_free( config );
2021 if (!match_row( table, row, cond, &fill_status ))
2022 {
2023 free_row_values( table, row );
2024 continue;
2025 }
2026 offset += sizeof(*rec);
2027 row++;
2028 }
2029
2030 TRACE("created %u rows\n", row);
2031 table->num_rows = row;
2032
2033 done:
2034 CloseServiceHandle( manager );
2035 heap_free( services );
2036 return fill_status;
2037 }
2038
2039 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
2040 {
2041 HDC hdc = GetDC( NULL );
2042 UINT32 ret;
2043
2044 if (!hdc) return 32;
2045 ret = GetDeviceCaps( hdc, BITSPIXEL );
2046 *hres = GetDeviceCaps( hdc, HORZRES );
2047 *vres = GetDeviceCaps( hdc, VERTRES );
2048 ReleaseDC( NULL, hdc );
2049 return ret;
2050 }
2051 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
2052 {
2053 static const WCHAR fmtW[] =
2054 {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
2055 '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
2056 '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
2057 WCHAR *ret;
2058
2059 if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
2060 sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
2061 return ret;
2062 }
2063
2064 static enum fill_status fill_videocontroller( struct table *table, const struct expr *cond )
2065 {
2066
2067 struct record_videocontroller *rec;
2068 HRESULT hr;
2069 IDXGIFactory *factory = NULL;
2070 IDXGIAdapter *adapter = NULL;
2071 DXGI_ADAPTER_DESC desc;
2072 UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
2073 const WCHAR *name = videocontroller_deviceidW;
2074 enum fill_status status = FILL_STATUS_UNFILTERED;
2075 UINT row = 0;
2076
2077 if (!resize_table( table, 1, sizeof(*rec) )) return FILL_STATUS_FAILED;
2078
2079 memset (&desc, 0, sizeof(desc));
2080 hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
2081 if (FAILED(hr)) goto done;
2082
2083 hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
2084 if (FAILED(hr)) goto done;
2085
2086 hr = IDXGIAdapter_GetDesc( adapter, &desc );
2087 if (SUCCEEDED(hr))
2088 {
2089 vidmem = desc.DedicatedVideoMemory;
2090 name = desc.Description;
2091 }
2092
2093 done:
2094 rec = (struct record_videocontroller *)table->data;
2095 rec->adapter_dactype = videocontroller_dactypeW;
2096 rec->adapter_ram = vidmem;
2097 rec->current_bitsperpixel = get_bits_per_pixel( &hres, &vres );
2098 rec->current_horizontalres = hres;
2099 rec->current_verticalres = vres;
2100 rec->description = heap_strdupW( name );
2101 rec->device_id = videocontroller_deviceidW;
2102 rec->name = heap_strdupW( name );
2103 rec->pnpdevice_id = get_pnpdeviceid( &desc );
2104 if (!match_row( table, row, cond, &status )) free_row_values( table, row );
2105 else row++;
2106
2107 TRACE("created %u rows\n", row);
2108 table->num_rows = row;
2109
2110 if (adapter) IDXGIAdapter_Release( adapter );
2111 if (factory) IDXGIFactory_Release( factory );
2112 return status;
2113 }
2114
2115 static struct table builtin_classes[] =
2116 {
2117 { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), 0, (BYTE *)data_baseboard },
2118 { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), 0, (BYTE *)data_bios },
2119 { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, 0, NULL, fill_cdromdrive },
2120 { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, 0, NULL, fill_compsys },
2121 { class_datafileW, SIZEOF(col_datafile), col_datafile, 0, 0, NULL, fill_datafile },
2122 { class_directoryW, SIZEOF(col_directory), col_directory, 0, 0, NULL, fill_directory },
2123 { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), 0, (BYTE *)data_diskdrive },
2124 { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, 0, NULL, fill_diskpartition },
2125 { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2126 { class_logicaldisk2W, SIZEOF(col_logicaldisk), col_logicaldisk, 0, 0, NULL, fill_logicaldisk },
2127 { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, 0, NULL, fill_networkadapter },
2128 { class_osW, SIZEOF(col_os), col_os, 0, 0, NULL, fill_os },
2129 { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), 0, (BYTE *)data_param },
2130 { class_processW, SIZEOF(col_process), col_process, 0, 0, NULL, fill_process },
2131 { class_processorW, SIZEOF(col_processor), col_processor, 0, 0, NULL, fill_processor },
2132 { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), 0, (BYTE *)data_qualifier },
2133 { class_serviceW, SIZEOF(col_service), col_service, 0, 0, NULL, fill_service },
2134 { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), 0, (BYTE *)data_sounddevice },
2135 { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), 0, (BYTE *)data_stdregprov },
2136 { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, 0, NULL, fill_videocontroller }
2137 };
2138
2139 void init_table_list( void )
2140 {
2141 static struct list tables = LIST_INIT( tables );
2142 UINT i;
2143
2144 for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
2145 table_list = &tables;
2146 }