opengl32: Update the extension list.
[wine] / dlls / 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 COBJMACROS
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
22
23 #include "config.h"
24 #include <stdarg.h>
25
26 #include "ntstatus.h"
27 #define WIN32_NO_STATUS
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wbemcli.h"
31 #include "winsock2.h"
32 #include "iphlpapi.h"
33 #include "tlhelp32.h"
34 #include "initguid.h"
35 #include "d3d10.h"
36 #include "winternl.h"
37 #include "winioctl.h"
38 #include "winsvc.h"
39
40 #include "wine/debug.h"
41 #include "wbemprox_private.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
44
45 static const WCHAR class_baseboardW[] =
46     {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
47 static const WCHAR class_biosW[] =
48     {'W','i','n','3','2','_','B','I','O','S',0};
49 static const WCHAR class_compsysW[] =
50     {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
51 static const WCHAR class_logicaldiskW[] =
52     {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
53 static const WCHAR class_networkadapterW[] =
54     {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
55 static const WCHAR class_osW[] =
56     {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
57 static const WCHAR class_paramsW[] =
58     {'_','_','P','A','R','A','M','E','T','E','R','S',0};
59 static const WCHAR class_processW[] =
60     {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
61 static const WCHAR class_processorW[] =
62     {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
63 static const WCHAR class_serviceW[] =
64     {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
65 static const WCHAR class_stdregprovW[] =
66     {'S','t','d','R','e','g','P','r','o','v',0};
67 static const WCHAR class_videocontrollerW[] =
68     {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
69
70 static const WCHAR prop_acceptpauseW[] =
71     {'A','c','c','e','p','t','P','a','u','s','e',0};
72 static const WCHAR prop_acceptstopW[] =
73     {'A','c','c','e','p','t','S','t','o','p',0};
74 static const WCHAR prop_adapterramW[] =
75     {'A','d','a','p','t','e','r','R','A','M',0};
76 static const WCHAR prop_captionW[] =
77     {'C','a','p','t','i','o','n',0};
78 static const WCHAR prop_classW[] =
79     {'C','l','a','s','s',0};
80 static const WCHAR prop_commandlineW[] =
81     {'C','o','m','m','a','n','d','L','i','n','e',0};
82 static const WCHAR prop_cpustatusW[] =
83     {'C','p','u','S','t','a','t','u','s',0};
84 static const WCHAR prop_csdversionW[] =
85     {'C','S','D','V','e','r','s','i','o','n',0};
86 static const WCHAR prop_currentbitsperpixelW[] =
87     {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
88 static const WCHAR prop_currenthorizontalresW[] =
89     {'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};
90 static const WCHAR prop_currentverticalresW[] =
91     {'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};
92 static const WCHAR prop_defaultvalueW[] =
93     {'D','e','f','a','u','l','t','V','a','l','u','e',0};
94 static const WCHAR prop_descriptionW[] =
95     {'D','e','s','c','r','i','p','t','i','o','n',0};
96 static const WCHAR prop_deviceidW[] =
97     {'D','e','v','i','c','e','I','d',0};
98 static const WCHAR prop_directionW[] =
99     {'D','i','r','e','c','t','i','o','n',0};
100 static const WCHAR prop_displaynameW[] =
101     {'D','i','s','p','l','a','y','N','a','m','e',0};
102 static const WCHAR prop_domainroleW[] =
103     {'D','o','m','a','i','n','R','o','l','e',0};
104 static const WCHAR prop_drivetypeW[] =
105     {'D','r','i','v','e','T','y','p','e',0};
106 static const WCHAR prop_filesystemW[] =
107     {'F','i','l','e','S','y','s','t','e','m',0};
108 static const WCHAR prop_freespaceW[] =
109     {'F','r','e','e','S','p','a','c','e',0};
110 static const WCHAR prop_handleW[] =
111     {'H','a','n','d','l','e',0};
112 static const WCHAR prop_interfaceindexW[] =
113     {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
114 static const WCHAR prop_macaddressW[] =
115     {'M','A','C','A','d','d','r','e','s','s',0};
116 static const WCHAR prop_manufacturerW[] =
117     {'M','a','n','u','f','a','c','t','u','r','e','r',0};
118 static const WCHAR prop_maxclockspeedW[] =
119     {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
120 static const WCHAR prop_methodW[] =
121     {'M','e','t','h','o','d',0};
122 static const WCHAR prop_modelW[] =
123     {'M','o','d','e','l',0};
124 static const WCHAR prop_nameW[] =
125     {'N','a','m','e',0};
126 static const WCHAR prop_netconnectionstatusW[] =
127     {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
128 static const WCHAR prop_numlogicalprocessorsW[] =
129     {'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};
130 static const WCHAR prop_numprocessorsW[] =
131     {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
132 static const WCHAR prop_osarchitectureW[] =
133     {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
134 static const WCHAR prop_oslanguageW[] =
135     {'O','S','L','a','n','g','u','a','g','e',0};
136 static const WCHAR prop_parameterW[] =
137     {'P','a','r','a','m','e','t','e','r',0};
138 static const WCHAR prop_pnpdeviceidW[] =
139     {'P','N','P','D','e','v','i','c','e','I','D',0};
140 static const WCHAR prop_pprocessidW[] =
141     {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
142 static const WCHAR prop_processidW[] =
143     {'P','r','o','c','e','s','s','I','D',0};
144 static const WCHAR prop_processoridW[] =
145     {'P','r','o','c','e','s','s','o','r','I','d',0};
146 static const WCHAR prop_releasedateW[] =
147     {'R','e','l','e','a','s','e','D','a','t','e',0};
148 static const WCHAR prop_serialnumberW[] =
149     {'S','e','r','i','a','l','N','u','m','b','e','r',0};
150 static const WCHAR prop_servicetypeW[] =
151     {'S','e','r','v','i','c','e','T','y','p','e',0};
152 static const WCHAR prop_startmodeW[] =
153     {'S','t','a','r','t','M','o','d','e',0};
154 static const WCHAR prop_sizeW[] =
155     {'S','i','z','e',0};
156 static const WCHAR prop_speedW[] =
157     {'S','p','e','e','d',0};
158 static const WCHAR prop_stateW[] =
159     {'S','t','a','t','e',0};
160 static const WCHAR prop_systemdirectoryW[] =
161     {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
162 static const WCHAR prop_systemnameW[] =
163     {'S','y','s','t','e','m','N','a','m','e',0};
164 static const WCHAR prop_tagW[] =
165     {'T','a','g',0};
166 static const WCHAR prop_threadcountW[] =
167     {'T','h','r','e','a','d','C','o','u','n','t',0};
168 static const WCHAR prop_totalphysicalmemoryW[] =
169     {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
170 static const WCHAR prop_typeW[] =
171     {'T','y','p','e',0};
172
173 static const WCHAR method_enumkeyW[] =
174     {'E','n','u','m','K','e','y',0};
175 static const WCHAR method_enumvaluesW[] =
176     {'E','n','u','m','V','a','l','u','e','s',0};
177
178 static const WCHAR param_defkeyW[] =
179     {'h','D','e','f','K','e','y',0};
180 static const WCHAR param_namesW[] =
181     {'N','a','m','e','s',0};
182 static const WCHAR param_returnvalueW[] =
183     {'R','e','t','u','r','n','V','a','l','u','e',0};
184 static const WCHAR param_subkeynameW[] =
185     {'s','S','u','b','K','e','y','N','a','m','e',0};
186 static const WCHAR param_typesW[] =
187     {'T','y','p','e','s',0};
188
189 /* column definitions must be kept in sync with record structures below */
190 static const struct column col_baseboard[] =
191 {
192     { prop_manufacturerW,  CIM_STRING },
193     { prop_serialnumberW,  CIM_STRING },
194     { prop_tagW,           CIM_STRING|COL_FLAG_KEY }
195 };
196 static const struct column col_bios[] =
197 {
198     { prop_descriptionW,  CIM_STRING },
199     { prop_manufacturerW, CIM_STRING },
200     { prop_releasedateW,  CIM_DATETIME },
201     { prop_serialnumberW, CIM_STRING }
202 };
203 static const struct column col_compsys[] =
204 {
205     { prop_descriptionW,          CIM_STRING },
206     { prop_domainroleW,           CIM_UINT16 },
207     { prop_manufacturerW,         CIM_STRING },
208     { prop_modelW,                CIM_STRING },
209     { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
210     { prop_numprocessorsW,        CIM_UINT32, VT_I4 },
211     { prop_totalphysicalmemoryW,  CIM_UINT64 }
212 };
213 static const struct column col_logicaldisk[] =
214 {
215     { prop_deviceidW,   CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
216     { prop_drivetypeW,  CIM_UINT32, VT_I4 },
217     { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
218     { prop_freespaceW,  CIM_UINT64 },
219     { prop_sizeW,       CIM_UINT64 }
220 };
221 static const struct column col_networkadapter[] =
222 {
223     { prop_deviceidW,            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
224     { prop_interfaceindexW,      CIM_UINT32, VT_I4 },
225     { prop_macaddressW,          CIM_STRING|COL_FLAG_DYNAMIC },
226     { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
227     { prop_pnpdeviceidW,         CIM_STRING },
228     { prop_speedW,               CIM_UINT64 }
229 };
230 static const struct column col_os[] =
231 {
232     { prop_captionW,         CIM_STRING },
233     { prop_csdversionW,      CIM_STRING },
234     { prop_osarchitectureW,  CIM_STRING },
235     { prop_oslanguageW,      CIM_UINT32, VT_I4 },
236     { prop_systemdirectoryW, CIM_STRING }
237 };
238 static const struct column col_params[] =
239 {
240     { prop_classW,        CIM_STRING },
241     { prop_methodW,       CIM_STRING },
242     { prop_directionW,    CIM_SINT32 },
243     { prop_parameterW,    CIM_STRING },
244     { prop_typeW,         CIM_UINT32 },
245     { prop_defaultvalueW, CIM_UINT32 }
246 };
247 static const struct column col_process[] =
248 {
249     { prop_captionW,     CIM_STRING|COL_FLAG_DYNAMIC },
250     { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
251     { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
252     { prop_handleW,      CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
253     { prop_pprocessidW,  CIM_UINT32, VT_I4 },
254     { prop_processidW,   CIM_UINT32, VT_I4 },
255     { prop_threadcountW, CIM_UINT32, VT_I4 }
256 };
257 static const struct column col_processor[] =
258 {
259     { prop_cpustatusW,            CIM_UINT16 },
260     { prop_deviceidW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
261     { prop_manufacturerW,         CIM_STRING|COL_FLAG_DYNAMIC },
262     { prop_maxclockspeedW,        CIM_UINT32 },
263     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
264     { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
265     { prop_processoridW,          CIM_STRING|COL_FLAG_DYNAMIC }
266 };
267 static const struct column col_service[] =
268 {
269     { prop_acceptpauseW,      CIM_BOOLEAN },
270     { prop_acceptstopW,       CIM_BOOLEAN },
271     { prop_displaynameW,      CIM_STRING|COL_FLAG_DYNAMIC },
272     { prop_nameW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
273     { prop_processidW,        CIM_UINT32 },
274     { prop_servicetypeW,      CIM_STRING },
275     { prop_startmodeW,        CIM_STRING },
276     { prop_stateW,            CIM_STRING },
277     { prop_systemnameW,       CIM_STRING|COL_FLAG_DYNAMIC }
278 };
279 static const struct column col_stdregprov[] =
280 {
281     { method_enumkeyW,    CIM_OBJECT|COL_FLAG_METHOD },
282     { method_enumvaluesW, CIM_OBJECT|COL_FLAG_METHOD }
283 };
284 static const struct column col_videocontroller[] =
285 {
286     { prop_adapterramW,           CIM_UINT32 },
287     { prop_currentbitsperpixelW,  CIM_UINT32 },
288     { prop_currenthorizontalresW, CIM_UINT32 },
289     { prop_currentverticalresW,   CIM_UINT32 },
290     { prop_deviceidW,             CIM_STRING|COL_FLAG_KEY },
291     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC }
292 };
293
294 static const WCHAR baseboard_manufacturerW[] =
295     {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
296 static const WCHAR baseboard_serialnumberW[] =
297     {'N','o','n','e',0};
298 static const WCHAR baseboard_tagW[] =
299     {'B','a','s','e',' ','B','o','a','r','d',0};
300 static const WCHAR bios_descriptionW[] =
301     {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
302 static const WCHAR bios_manufacturerW[] =
303     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
304 static const WCHAR bios_releasedateW[] =
305     {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
306 static const WCHAR bios_serialnumberW[] =
307     {'0',0};
308 static const WCHAR compsys_descriptionW[] =
309     {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
310 static const WCHAR compsys_manufacturerW[] =
311     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
312 static const WCHAR compsys_modelW[] =
313     {'W','i','n','e',0};
314 static const WCHAR networkadapter_pnpdeviceidW[]=
315     {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
316      'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
317      '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
318 static const WCHAR os_captionW[] =
319     {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
320      'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
321 static const WCHAR os_csdversionW[] =
322     {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
323 static const WCHAR os_32bitW[] =
324     {'3','2','-','b','i','t',0};
325 static const WCHAR os_64bitW[] =
326     {'6','4','-','b','i','t',0};
327 static const WCHAR videocontroller_deviceidW[] =
328     {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
329
330 #include "pshpack1.h"
331 struct record_baseboard
332 {
333     const WCHAR *manufacturer;
334     const WCHAR *serialnumber;
335     const WCHAR *tag;
336 };
337 struct record_bios
338 {
339     const WCHAR *description;
340     const WCHAR *manufacturer;
341     const WCHAR *releasedate;
342     const WCHAR *serialnumber;
343 };
344 struct record_computersystem
345 {
346     const WCHAR *description;
347     UINT16       domainrole;
348     const WCHAR *manufacturer;
349     const WCHAR *model;
350     UINT32       num_logical_processors;
351     UINT32       num_processors;
352     UINT64       total_physical_memory;
353 };
354 struct record_logicaldisk
355 {
356     const WCHAR *device_id;
357     UINT32       drivetype;
358     const WCHAR *filesystem;
359     UINT64       freespace;
360     UINT64       size;
361 };
362 struct record_networkadapter
363 {
364     const WCHAR *device_id;
365     INT32        interface_index;
366     const WCHAR *mac_address;
367     UINT16       netconnection_status;
368     const WCHAR *pnpdevice_id;
369     UINT64       speed;
370 };
371 struct record_operatingsystem
372 {
373     const WCHAR *caption;
374     const WCHAR *csdversion;
375     const WCHAR *osarchitecture;
376     UINT32       oslanguage;
377     const WCHAR *systemdirectory;
378 };
379 struct record_params
380 {
381     const WCHAR *class;
382     const WCHAR *method;
383     INT32        direction;
384     const WCHAR *parameter;
385     UINT32       type;
386     UINT32       defaultvalue;
387 };
388 struct record_process
389 {
390     const WCHAR *caption;
391     const WCHAR *commandline;
392     const WCHAR *description;
393     const WCHAR *handle;
394     UINT32       pprocess_id;
395     UINT32       process_id;
396     UINT32       thread_count;
397 };
398 struct record_processor
399 {
400     UINT16       cpu_status;
401     const WCHAR *device_id;
402     const WCHAR *manufacturer;
403     UINT32       maxclockspeed;
404     const WCHAR *name;
405     UINT32       num_logical_processors;
406     const WCHAR *processor_id;
407 };
408 struct record_service
409 {
410     int          accept_pause;
411     int          accept_stop;
412     const WCHAR *displayname;
413     const WCHAR *name;
414     UINT32       process_id;
415     const WCHAR *servicetype;
416     const WCHAR *startmode;
417     const WCHAR *state;
418     const WCHAR *systemname;
419 };
420 struct record_stdregprov
421 {
422     class_method *enumkey;
423     class_method *enumvalues;
424 };
425 struct record_videocontroller
426 {
427     UINT32       adapter_ram;
428     UINT32       current_bitsperpixel;
429     UINT32       current_horizontalres;
430     UINT32       current_verticalres;
431     const WCHAR *device_id;
432     const WCHAR *name;
433 };
434 #include "poppack.h"
435
436 static HRESULT reg_enumkey( IWbemClassObject *in, IWbemClassObject **out )
437 {
438     FIXME("\n");
439     return E_NOTIMPL;
440 }
441 static HRESULT reg_enumvalues( IWbemClassObject *in, IWbemClassObject **out )
442 {
443     FIXME("\n");
444     return E_NOTIMPL;
445 }
446
447 static const struct record_baseboard data_baseboard[] =
448 {
449     { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
450 };
451 static const struct record_bios data_bios[] =
452 {
453     { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW }
454 };
455 static const struct record_params data_params[] =
456 {
457     { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
458     { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
459     { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32 },
460     { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
461     { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_UINT32, 0x80000002 },
462     { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
463     { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32 },
464     { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
465     { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY }
466 };
467 static const struct record_stdregprov data_stdregprov[] =
468 {
469     { reg_enumkey, reg_enumvalues }
470 };
471
472 static UINT get_processor_count(void)
473 {
474     SYSTEM_BASIC_INFORMATION info;
475
476     if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
477     return info.NumberOfProcessors;
478 }
479
480 static UINT get_logical_processor_count(void)
481 {
482     SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
483     UINT i, j, count = 0;
484     NTSTATUS status;
485     ULONG len;
486
487     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
488     if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
489
490     if (!(info = heap_alloc( len ))) return get_processor_count();
491     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
492     if (status != STATUS_SUCCESS)
493     {
494         heap_free( info );
495         return get_processor_count();
496     }
497     for (i = 0; i < len / sizeof(*info); i++)
498     {
499         if (info[i].Relationship != RelationProcessorCore) continue;
500         for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
501     }
502     heap_free( info );
503     return count;
504 }
505
506 static UINT64 get_total_physical_memory(void)
507 {
508     MEMORYSTATUSEX status;
509
510     status.dwLength = sizeof(status);
511     if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
512     return status.ullTotalPhys;
513 }
514
515 static void fill_compsys( struct table *table )
516 {
517     struct record_computersystem *rec;
518
519     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
520
521     rec = (struct record_computersystem *)table->data;
522     rec->description            = compsys_descriptionW;
523     rec->domainrole             = 0; /* standalone workstation */
524     rec->manufacturer           = compsys_manufacturerW;
525     rec->model                  = compsys_modelW;
526     rec->num_logical_processors = get_logical_processor_count();
527     rec->num_processors         = get_processor_count();
528     rec->total_physical_memory  = get_total_physical_memory();
529
530     TRACE("created 1 row\n");
531     table->num_rows = 1;
532 }
533
534 static WCHAR *get_filesystem( const WCHAR *root )
535 {
536     static const WCHAR ntfsW[] = {'N','T','F','S',0};
537     WCHAR buffer[MAX_PATH + 1];
538
539     if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
540         return heap_strdupW( buffer );
541     return heap_strdupW( ntfsW );
542 }
543
544 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
545 {
546     WCHAR root[] = {'\\','\\','.','\\','A',':',0};
547     ULARGE_INTEGER free;
548     DISK_GEOMETRY_EX info;
549     HANDLE handle;
550
551     free.QuadPart = 512 * 1024 * 1024;
552     GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
553
554     root[4] = dir[0];
555     handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
556     if (handle != INVALID_HANDLE_VALUE)
557     {
558         if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
559             *disksize = info.DiskSize.QuadPart;
560         CloseHandle( handle );
561     }
562     return free.QuadPart;
563 }
564
565 static void fill_logicaldisk( struct table *table )
566 {
567     static const WCHAR fmtW[] = {'%','c',':',0};
568     WCHAR device_id[3], root[] = {'A',':','\\',0};
569     struct record_logicaldisk *rec;
570     UINT i, num_rows = 0, offset = 0, count = 4, type;
571     UINT64 size = 1024 * 1024 * 1024;
572     DWORD drives = GetLogicalDrives();
573
574     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
575
576     for (i = 0; i < sizeof(drives); i++)
577     {
578         if (drives & (1 << i))
579         {
580             root[0] = 'A' + i;
581             type = GetDriveTypeW( root );
582             if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
583                 continue;
584
585             if (num_rows > count)
586             {
587                 BYTE *data;
588                 count *= 2;
589                 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
590                 table->data = data;
591             }
592             rec = (struct record_logicaldisk *)(table->data + offset);
593             sprintfW( device_id, fmtW, 'A' + i );
594             rec->device_id  = heap_strdupW( device_id );
595             rec->drivetype  = type;
596             rec->filesystem = get_filesystem( root );
597             rec->freespace  = get_freespace( root, &size );
598             rec->size       = size;
599             offset += sizeof(*rec);
600             num_rows++;
601         }
602     }
603     TRACE("created %u rows\n", num_rows);
604     table->num_rows = num_rows;
605 }
606
607 static UINT16 get_connection_status( IF_OPER_STATUS status )
608 {
609     switch (status)
610     {
611     case IfOperStatusDown:
612         return 0; /* Disconnected */
613     case IfOperStatusUp:
614         return 2; /* Connected */
615     default:
616         ERR("unhandled status %u\n", status);
617         break;
618     }
619     return 0;
620 }
621 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
622 {
623     static const WCHAR fmtW[] =
624         {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
625          '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
626     WCHAR *ret;
627
628     if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
629     sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
630     return ret;
631 }
632
633 static void fill_networkadapter( struct table *table )
634 {
635     static const WCHAR fmtW[] = {'%','u',0};
636     WCHAR device_id[11];
637     struct record_networkadapter *rec;
638     IP_ADAPTER_ADDRESSES *aa, *buffer;
639     UINT num_rows = 0, offset = 0;
640     DWORD size = 0, ret;
641
642     ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
643     if (ret != ERROR_BUFFER_OVERFLOW) return;
644
645     if (!(buffer = heap_alloc( size ))) return;
646     if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
647     {
648         heap_free( buffer );
649         return;
650     }
651     for (aa = buffer; aa; aa = aa->Next) num_rows++;
652     if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
653     {
654         heap_free( buffer );
655         return;
656     }
657     for (aa = buffer; aa; aa = aa->Next)
658     {
659         rec = (struct record_networkadapter *)(table->data + offset);
660         sprintfW( device_id, fmtW, aa->u.s.IfIndex );
661         rec->device_id            = heap_strdupW( device_id );
662         rec->interface_index      = aa->u.s.IfIndex;
663         rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
664         rec->netconnection_status = get_connection_status( aa->OperStatus );
665         rec->pnpdevice_id         = networkadapter_pnpdeviceidW;
666         rec->speed                = 1000000;
667         offset += sizeof(*rec);
668     }
669     TRACE("created %u rows\n", num_rows);
670     table->num_rows = num_rows;
671
672     heap_free( buffer );
673 }
674
675 static WCHAR *get_cmdline( DWORD process_id )
676 {
677     if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
678     return NULL; /* FIXME handle different process case */
679 }
680
681 static void fill_process( struct table *table )
682 {
683     static const WCHAR fmtW[] = {'%','u',0};
684     WCHAR handle[11];
685     struct record_process *rec;
686     PROCESSENTRY32W entry;
687     HANDLE snap;
688     UINT num_rows = 0, offset = 0, count = 8;
689
690     snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
691     if (snap == INVALID_HANDLE_VALUE) return;
692
693     entry.dwSize = sizeof(entry);
694     if (!Process32FirstW( snap, &entry )) goto done;
695     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
696
697     do
698     {
699         if (num_rows > count)
700         {
701             BYTE *data;
702             count *= 2;
703             if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
704             table->data = data;
705         }
706         rec = (struct record_process *)(table->data + offset);
707         rec->caption      = heap_strdupW( entry.szExeFile );
708         rec->commandline  = get_cmdline( entry.th32ProcessID );
709         rec->description  = heap_strdupW( entry.szExeFile );
710         sprintfW( handle, fmtW, entry.th32ProcessID );
711         rec->handle       = heap_strdupW( handle );
712         rec->process_id   = entry.th32ProcessID;
713         rec->pprocess_id  = entry.th32ParentProcessID;
714         rec->thread_count = entry.cntThreads;
715         offset += sizeof(*rec);
716         num_rows++;
717     } while (Process32NextW( snap, &entry ));
718
719     TRACE("created %u rows\n", num_rows);
720     table->num_rows = num_rows;
721
722 done:
723     CloseHandle( snap );
724 }
725
726 static inline void do_cpuid( unsigned int ax, unsigned int *p )
727 {
728 #ifdef __i386__
729     __asm__("pushl %%ebx\n\t"
730                 "cpuid\n\t"
731                 "movl %%ebx, %%esi\n\t"
732                 "popl %%ebx"
733                 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
734                 :  "0" (ax));
735 #endif
736 }
737
738 static void get_processor_id( WCHAR *processor_id )
739 {
740     static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
741     unsigned int regs[4] = {0, 0, 0, 0};
742
743     do_cpuid( 1, regs );
744     sprintfW( processor_id, fmtW, regs[3], regs[0] );
745 }
746 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
747 {
748     unsigned int i;
749     unsigned char *p = (unsigned char *)regs;
750
751     for (i = 0; i < len; i++)
752     {
753         buffer[i] = *p++;
754     }
755     buffer[i] = 0;
756 }
757 static void get_processor_manufacturer( WCHAR *manufacturer )
758 {
759     unsigned int tmp, regs[4] = {0, 0, 0, 0};
760
761     do_cpuid( 0, regs );
762     tmp = regs[2];      /* swap edx and ecx */
763     regs[2] = regs[3];
764     regs[3] = tmp;
765
766     regs_to_str( regs + 1, 12, manufacturer );
767 }
768 static void get_processor_name( WCHAR *name )
769 {
770     unsigned int regs[4] = {0, 0, 0, 0};
771
772     do_cpuid( 0x80000000, regs );
773     if (regs[0] >= 0x80000004)
774     {
775         do_cpuid( 0x80000002, regs );
776         regs_to_str( regs, 16, name );
777         do_cpuid( 0x80000003, regs );
778         regs_to_str( regs, 16, name + 16 );
779         do_cpuid( 0x80000004, regs );
780         regs_to_str( regs, 16, name + 32 );
781     }
782 }
783 static UINT get_processor_maxclockspeed( void )
784 {
785     PROCESSOR_POWER_INFORMATION info;
786     if (!NtPowerInformation( ProcessorInformation, NULL, 0, &info, sizeof(info) )) return info.MaxMhz;
787     return 1000000;
788 }
789
790 static void fill_processor( struct table *table )
791 {
792     static const WCHAR fmtW[] = {'C','P','U','%','u',0};
793     WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
794     struct record_processor *rec;
795     UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
796
797     if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
798
799     get_processor_id( processor_id );
800     get_processor_manufacturer( manufacturer );
801     get_processor_name( name );
802
803     maxclockspeed = get_processor_maxclockspeed();
804     num_logical_processors = get_logical_processor_count() / count;
805
806     for (i = 0; i < count; i++)
807     {
808         rec = (struct record_processor *)(table->data + offset);
809         rec->cpu_status             = 1; /* CPU Enabled */
810         sprintfW( device_id, fmtW, i );
811         rec->device_id              = heap_strdupW( device_id );
812         rec->manufacturer           = heap_strdupW( manufacturer );
813         rec->maxclockspeed          = maxclockspeed;
814         rec->name                   = heap_strdupW( name );
815         rec->num_logical_processors = num_logical_processors;
816         rec->processor_id           = heap_strdupW( processor_id );
817         offset += sizeof(*rec);
818     }
819
820     TRACE("created %u rows\n", count);
821     table->num_rows = count;
822 }
823
824 static void fill_os( struct table *table )
825 {
826     struct record_operatingsystem *rec;
827     WCHAR path[MAX_PATH];
828     SYSTEM_INFO info;
829     void *redir;
830
831     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
832
833     rec = (struct record_operatingsystem *)table->data;
834     rec->caption    = os_captionW;
835     rec->csdversion = os_csdversionW;
836
837     GetNativeSystemInfo( &info );
838     if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64)
839         rec->osarchitecture = os_64bitW;
840     else
841         rec->osarchitecture = os_32bitW;
842
843     rec->oslanguage = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
844
845     Wow64DisableWow64FsRedirection( &redir );
846     GetSystemDirectoryW( path, MAX_PATH );
847     Wow64RevertWow64FsRedirection( redir );
848     rec->systemdirectory = heap_strdupW( path );
849
850     TRACE("created 1 row\n");
851     table->num_rows = 1;
852 }
853
854 static const WCHAR *get_service_type( DWORD type )
855 {
856     static const WCHAR filesystem_driverW[] =
857         {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
858     static const WCHAR kernel_driverW[] =
859         {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
860     static const WCHAR own_processW[] =
861         {'O','w','n',' ','P','r','o','c','e','s','s',0};
862     static const WCHAR share_processW[] =
863         {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
864
865     if (type & SERVICE_KERNEL_DRIVER)            return kernel_driverW;
866     else if (type & SERVICE_FILE_SYSTEM_DRIVER)  return filesystem_driverW;
867     else if (type & SERVICE_WIN32_OWN_PROCESS)   return own_processW;
868     else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
869     else ERR("unhandled type 0x%08x\n", type);
870     return NULL;
871 }
872 static const WCHAR *get_service_state( DWORD state )
873 {
874     static const WCHAR runningW[] =
875         {'R','u','n','n','i','n','g',0};
876     static const WCHAR start_pendingW[] =
877         {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
878     static const WCHAR stop_pendingW[] =
879         {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
880     static const WCHAR stoppedW[] =
881         {'S','t','o','p','p','e','d',0};
882     static const WCHAR unknownW[] =
883         {'U','n','k','n','o','w','n',0};
884
885     switch (state)
886     {
887     case SERVICE_STOPPED:       return stoppedW;
888     case SERVICE_START_PENDING: return start_pendingW;
889     case SERVICE_STOP_PENDING:  return stop_pendingW;
890     case SERVICE_RUNNING:       return runningW;
891     default:
892         ERR("unknown state %u\n", state);
893         return unknownW;
894     }
895 }
896
897 static const WCHAR *get_service_startmode( DWORD mode )
898 {
899     static const WCHAR bootW[] = {'B','o','o','t',0};
900     static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
901     static const WCHAR autoW[] = {'A','u','t','o',0};
902     static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
903     static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
904     static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
905
906     switch (mode)
907     {
908     case SERVICE_BOOT_START:   return bootW;
909     case SERVICE_SYSTEM_START: return systemW;
910     case SERVICE_AUTO_START:   return autoW;
911     case SERVICE_DEMAND_START: return manualW;
912     case SERVICE_DISABLED:     return disabledW;
913     default:
914         ERR("unknown mode 0x%x\n", mode);
915         return unknownW;
916     }
917 }
918
919 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
920 {
921     QUERY_SERVICE_CONFIGW *config = NULL;
922     SC_HANDLE service;
923     DWORD size;
924
925     if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
926     QueryServiceConfigW( service, NULL, 0, &size );
927     if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
928     if (!(config = heap_alloc( size ))) goto done;
929     if (QueryServiceConfigW( service, config, size, &size )) goto done;
930     heap_free( config );
931     config = NULL;
932
933 done:
934     CloseServiceHandle( service );
935     return config;
936 }
937
938 static void fill_service( struct table *table )
939 {
940     struct record_service *rec;
941     SC_HANDLE manager;
942     ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
943     SERVICE_STATUS_PROCESS *status;
944     WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
945     DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
946     UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
947     BOOL ret;
948
949     if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
950     if (!(services = heap_alloc( size ))) goto done;
951
952     ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
953                                  SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
954                                  &count, NULL, NULL );
955     if (!ret)
956     {
957         if (GetLastError() != ERROR_MORE_DATA) goto done;
958         size = needed;
959         if (!(tmp = heap_realloc( services, size ))) goto done;
960         services = tmp;
961         ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
962                                      SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
963                                      &count, NULL, NULL );
964         if (!ret) goto done;
965     }
966     if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
967
968     GetComputerNameW( sysnameW, &len );
969
970     for (i = 0; i < count; i++)
971     {
972         QUERY_SERVICE_CONFIGW *config;
973
974         if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
975
976         status = &services[i].ServiceStatusProcess;
977         rec = (struct record_service *)(table->data + offset);
978         rec->accept_pause = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
979         rec->accept_stop  = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
980         rec->displayname  = heap_strdupW( services[i].lpDisplayName );
981         rec->name         = heap_strdupW( services[i].lpServiceName );
982         rec->process_id   = status->dwProcessId;
983         rec->servicetype  = get_service_type( status->dwServiceType );
984         rec->startmode    = get_service_startmode( config->dwStartType );
985         rec->state        = get_service_state( status->dwCurrentState );
986         rec->systemname   = heap_strdupW( sysnameW );
987         heap_free( config );
988         offset += sizeof(*rec);
989         num_rows++;
990     }
991
992     TRACE("created %u rows\n", num_rows);
993     table->num_rows = num_rows;
994
995 done:
996     CloseServiceHandle( manager );
997     heap_free( services );
998 }
999
1000 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1001 {
1002     HDC hdc = GetDC( NULL );
1003     UINT32 ret;
1004
1005     if (!hdc) return 32;
1006     ret = GetDeviceCaps( hdc, BITSPIXEL );
1007     *hres = GetDeviceCaps( hdc, HORZRES );
1008     *vres = GetDeviceCaps( hdc, VERTRES );
1009     ReleaseDC( NULL, hdc );
1010     return ret;
1011 }
1012
1013 static void fill_videocontroller( struct table *table )
1014 {
1015
1016     struct record_videocontroller *rec;
1017     HRESULT hr;
1018     IDXGIFactory *factory = NULL;
1019     IDXGIAdapter *adapter = NULL;
1020     DXGI_ADAPTER_DESC desc;
1021     UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1022     const WCHAR *name = videocontroller_deviceidW;
1023
1024     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1025
1026     hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1027     if (FAILED(hr)) goto done;
1028
1029     hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1030     if (FAILED(hr)) goto done;
1031
1032     hr = IDXGIAdapter_GetDesc( adapter, &desc );
1033     if (SUCCEEDED(hr))
1034     {
1035         vidmem = desc.DedicatedVideoMemory;
1036         name   = desc.Description;
1037     }
1038
1039 done:
1040     rec = (struct record_videocontroller *)table->data;
1041     rec->adapter_ram           = vidmem;
1042     rec->current_bitsperpixel  = get_bits_per_pixel( &hres, &vres );
1043     rec->current_horizontalres = hres;
1044     rec->current_verticalres   = vres;
1045     rec->device_id             = videocontroller_deviceidW;
1046     rec->name                  = heap_strdupW( name );
1047
1048     TRACE("created 1 row\n");
1049     table->num_rows = 1;
1050
1051     if (adapter) IDXGIAdapter_Release( adapter );
1052     if (factory) IDXGIFactory_Release( factory );
1053 }
1054
1055 static struct table builtin_classes[] =
1056 {
1057     { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1058     { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1059     { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1060     { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1061     { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1062     { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1063     { class_paramsW, SIZEOF(col_params), col_params, SIZEOF(data_params), (BYTE *)data_params },
1064     { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1065     { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1066     { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1067     { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1068     { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1069 };
1070
1071 void init_table_list( void )
1072 {
1073     static struct list tables = LIST_INIT( tables );
1074     UINT i;
1075
1076     for (i = 0; i < SIZEOF(builtin_classes); i++)
1077     {
1078         list_add_tail( &tables, &builtin_classes[i].entry );
1079     }
1080     table_list = &tables;
1081 }