kernel32: Add a shared memory test.
[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 "initguid.h"
31 #include "wbemcli.h"
32 #include "wbemprov.h"
33 #include "winsock2.h"
34 #include "iphlpapi.h"
35 #include "tlhelp32.h"
36 #include "d3d10.h"
37 #include "winternl.h"
38 #include "winioctl.h"
39 #include "winsvc.h"
40
41 #include "wine/debug.h"
42 #include "wbemprox_private.h"
43
44 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox);
45
46 static const WCHAR class_baseboardW[] =
47     {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
48 static const WCHAR class_biosW[] =
49     {'W','i','n','3','2','_','B','I','O','S',0};
50 static const WCHAR class_cdromdriveW[] =
51     {'W','i','n','3','2','_','C','D','R','O','M','D','r','i','v','e',0};
52 static const WCHAR class_compsysW[] =
53     {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
54 static const WCHAR class_diskdriveW[] =
55     {'W','i','n','3','2','_','D','i','s','k','D','r','i','v','e',0};
56 static const WCHAR class_diskpartitionW[] =
57     {'W','i','n','3','2','_','D','i','s','k','P','a','r','t','i','t','i','o','n',0};
58 static const WCHAR class_logicaldiskW[] =
59     {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
60 static const WCHAR class_networkadapterW[] =
61     {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
62 static const WCHAR class_osW[] =
63     {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
64 static const WCHAR class_paramsW[] =
65     {'_','_','P','A','R','A','M','E','T','E','R','S',0};
66 static const WCHAR class_qualifiersW[] =
67     {'_','_','Q','U','A','L','I','F','I','E','R','S',0};
68 static const WCHAR class_process_getowner_outW[] =
69     {'_','_','W','I','N','3','2','_','P','R','O','C','E','S','S','_','G','E','T','O','W',
70      'N','E','R','_','O','U','T',0};
71 static const WCHAR class_processorW[] =
72     {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
73 static const WCHAR class_sounddeviceW[] =
74     {'W','i','n','3','2','_','S','o','u','n','d','D','e','v','i','c','e',0};
75 static const WCHAR class_videocontrollerW[] =
76     {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
77
78 static const WCHAR prop_adaptertypeW[] =
79     {'A','d','a','p','t','e','r','T','y','p','e',0};
80 static const WCHAR prop_acceptpauseW[] =
81     {'A','c','c','e','p','t','P','a','u','s','e',0};
82 static const WCHAR prop_acceptstopW[] =
83     {'A','c','c','e','p','t','S','t','o','p',0};
84 static const WCHAR prop_adapterramW[] =
85     {'A','d','a','p','t','e','r','R','A','M',0};
86 static const WCHAR prop_bootableW[] =
87     {'B','o','o','t','a','b','l','e',0};
88 static const WCHAR prop_bootpartitionW[] =
89     {'B','o','o','t','P','a','r','t','i','t','i','o','n',0};
90 static const WCHAR prop_captionW[] =
91     {'C','a','p','t','i','o','n',0};
92 static const WCHAR prop_classW[] =
93     {'C','l','a','s','s',0};
94 static const WCHAR prop_commandlineW[] =
95     {'C','o','m','m','a','n','d','L','i','n','e',0};
96 static const WCHAR prop_cpustatusW[] =
97     {'C','p','u','S','t','a','t','u','s',0};
98 static const WCHAR prop_csdversionW[] =
99     {'C','S','D','V','e','r','s','i','o','n',0};
100 static const WCHAR prop_currentbitsperpixelW[] =
101     {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
102 static const WCHAR prop_currenthorizontalresW[] =
103     {'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};
104 static const WCHAR prop_currentverticalresW[] =
105     {'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};
106 static const WCHAR prop_defaultvalueW[] =
107     {'D','e','f','a','u','l','t','V','a','l','u','e',0};
108 static const WCHAR prop_descriptionW[] =
109     {'D','e','s','c','r','i','p','t','i','o','n',0};
110 static const WCHAR prop_deviceidW[] =
111     {'D','e','v','i','c','e','I','d',0};
112 static const WCHAR prop_directionW[] =
113     {'D','i','r','e','c','t','i','o','n',0};
114 static const WCHAR prop_displaynameW[] =
115     {'D','i','s','p','l','a','y','N','a','m','e',0};
116 static const WCHAR prop_diskindexW[] =
117     {'D','i','s','k','I','n','d','e','x',0};
118 static const WCHAR prop_domainW[] =
119     {'D','o','m','a','i','n',0};
120 static const WCHAR prop_domainroleW[] =
121     {'D','o','m','a','i','n','R','o','l','e',0};
122 static const WCHAR prop_driveW[] =
123     {'D','r','i','v','e',0};
124 static const WCHAR prop_drivetypeW[] =
125     {'D','r','i','v','e','T','y','p','e',0};
126 static const WCHAR prop_filesystemW[] =
127     {'F','i','l','e','S','y','s','t','e','m',0};
128 static const WCHAR prop_flavorW[] =
129     {'F','l','a','v','o','r',0};
130 static const WCHAR prop_freespaceW[] =
131     {'F','r','e','e','S','p','a','c','e',0};
132 static const WCHAR prop_handleW[] =
133     {'H','a','n','d','l','e',0};
134 static const WCHAR prop_idW[] =
135     {'I','D',0};
136 static const WCHAR prop_indexW[] =
137     {'I','n','d','e','x',0};
138 static const WCHAR prop_interfaceindexW[] =
139     {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
140 static const WCHAR prop_intvalueW[] =
141     {'I','n','t','e','g','e','r','V','a','l','u','e',0};
142 static const WCHAR prop_lastbootuptimeW[] =
143     {'L','a','s','t','B','o','o','t','U','p','T','i','m','e',0};
144 static const WCHAR prop_macaddressW[] =
145     {'M','A','C','A','d','d','r','e','s','s',0};
146 static const WCHAR prop_manufacturerW[] =
147     {'M','a','n','u','f','a','c','t','u','r','e','r',0};
148 static const WCHAR prop_maxclockspeedW[] =
149     {'M','a','x','C','l','o','c','k','S','p','e','e','d',0};
150 static const WCHAR prop_memberW[] =
151     {'M','e','m','b','e','r',0};
152 static const WCHAR prop_methodW[] =
153     {'M','e','t','h','o','d',0};
154 static const WCHAR prop_modelW[] =
155     {'M','o','d','e','l',0};
156 static const WCHAR prop_netconnectionstatusW[] =
157     {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
158 static const WCHAR prop_numlogicalprocessorsW[] =
159     {'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};
160 static const WCHAR prop_numprocessorsW[] =
161     {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
162 static const WCHAR prop_osarchitectureW[] =
163     {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
164 static const WCHAR prop_oslanguageW[] =
165     {'O','S','L','a','n','g','u','a','g','e',0};
166 static const WCHAR prop_parameterW[] =
167     {'P','a','r','a','m','e','t','e','r',0};
168 static const WCHAR prop_pnpdeviceidW[] =
169     {'P','N','P','D','e','v','i','c','e','I','D',0};
170 static const WCHAR prop_pprocessidW[] =
171     {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
172 static const WCHAR prop_processidW[] =
173     {'P','r','o','c','e','s','s','I','D',0};
174 static const WCHAR prop_processoridW[] =
175     {'P','r','o','c','e','s','s','o','r','I','d',0};
176 static const WCHAR prop_productnameW[] =
177     {'P','r','o','d','u','c','t','N','a','m','e',0};
178 static const WCHAR prop_releasedateW[] =
179     {'R','e','l','e','a','s','e','D','a','t','e',0};
180 static const WCHAR prop_serialnumberW[] =
181     {'S','e','r','i','a','l','N','u','m','b','e','r',0};
182 static const WCHAR prop_servicetypeW[] =
183     {'S','e','r','v','i','c','e','T','y','p','e',0};
184 static const WCHAR prop_startmodeW[] =
185     {'S','t','a','r','t','M','o','d','e',0};
186 static const WCHAR prop_sizeW[] =
187     {'S','i','z','e',0};
188 static const WCHAR prop_speedW[] =
189     {'S','p','e','e','d',0};
190 static const WCHAR prop_startingoffsetW[] =
191     {'S','t','a','r','t','i','n','g','O','f','f','s','e','t',0};
192 static const WCHAR prop_stateW[] =
193     {'S','t','a','t','e',0};
194 static const WCHAR prop_strvalueW[] =
195     {'S','t','r','i','n','g','V','a','l','u','e',0};
196 static const WCHAR prop_systemdirectoryW[] =
197     {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
198 static const WCHAR prop_systemnameW[] =
199     {'S','y','s','t','e','m','N','a','m','e',0};
200 static const WCHAR prop_tagW[] =
201     {'T','a','g',0};
202 static const WCHAR prop_threadcountW[] =
203     {'T','h','r','e','a','d','C','o','u','n','t',0};
204 static const WCHAR prop_totalphysicalmemoryW[] =
205     {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
206 static const WCHAR prop_typeW[] =
207     {'T','y','p','e',0};
208 static const WCHAR prop_uniqueidW[] =
209     {'U','n','i','q','u','e','I','d',0};
210 static const WCHAR prop_varianttypeW[] =
211     {'V','a','r','i','a','n','t','T','y','p','e',0};
212 static const WCHAR prop_versionW[] =
213     {'V','e','r','s','i','o','n',0};
214
215 /* column definitions must be kept in sync with record structures below */
216 static const struct column col_baseboard[] =
217 {
218     { prop_manufacturerW,  CIM_STRING },
219     { prop_serialnumberW,  CIM_STRING },
220     { prop_tagW,           CIM_STRING|COL_FLAG_KEY }
221 };
222 static const struct column col_bios[] =
223 {
224     { prop_descriptionW,  CIM_STRING },
225     { prop_manufacturerW, CIM_STRING },
226     { prop_releasedateW,  CIM_DATETIME },
227     { prop_serialnumberW, CIM_STRING },
228     { prop_versionW,      CIM_STRING|COL_FLAG_KEY }
229 };
230 static const struct column col_cdromdrive[] =
231 {
232     { prop_deviceidW,    CIM_STRING|COL_FLAG_KEY },
233     { prop_driveW,       CIM_STRING|COL_FLAG_DYNAMIC },
234     { prop_nameW,        CIM_STRING },
235     { prop_pnpdeviceidW, CIM_STRING }
236 };
237 static const struct column col_compsys[] =
238 {
239     { prop_descriptionW,          CIM_STRING },
240     { prop_domainW,               CIM_STRING },
241     { prop_domainroleW,           CIM_UINT16 },
242     { prop_manufacturerW,         CIM_STRING },
243     { prop_modelW,                CIM_STRING },
244     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
245     { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
246     { prop_numprocessorsW,        CIM_UINT32, VT_I4 },
247     { prop_totalphysicalmemoryW,  CIM_UINT64 }
248 };
249 static const struct column col_diskdrive[] =
250 {
251     { prop_deviceidW,     CIM_STRING|COL_FLAG_KEY },
252     { prop_indexW,        CIM_UINT32, VT_I4 },
253     { prop_manufacturerW, CIM_STRING },
254     { prop_modelW,        CIM_STRING },
255     { prop_serialnumberW, CIM_STRING }
256 };
257 static const struct column col_diskpartition[] =
258 {
259     { prop_bootableW,       CIM_BOOLEAN },
260     { prop_bootpartitionW,  CIM_BOOLEAN },
261     { prop_deviceidW,       CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
262     { prop_diskindexW,      CIM_UINT32, VT_I4 },
263     { prop_indexW,          CIM_UINT32, VT_I4 },
264     { prop_pnpdeviceidW,    CIM_STRING|COL_FLAG_DYNAMIC },
265     { prop_sizeW,           CIM_UINT64 },
266     { prop_startingoffsetW, CIM_UINT64 },
267     { prop_typeW,           CIM_STRING|COL_FLAG_DYNAMIC }
268 };
269 static const struct column col_logicaldisk[] =
270 {
271     { prop_deviceidW,   CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
272     { prop_drivetypeW,  CIM_UINT32, VT_I4 },
273     { prop_filesystemW, CIM_STRING|COL_FLAG_DYNAMIC },
274     { prop_freespaceW,  CIM_UINT64 },
275     { prop_nameW,       CIM_STRING|COL_FLAG_DYNAMIC },
276     { prop_sizeW,       CIM_UINT64 }
277 };
278 static const struct column col_networkadapter[] =
279 {
280     { prop_adaptertypeW,         CIM_STRING },
281     { prop_deviceidW,            CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
282     { prop_interfaceindexW,      CIM_UINT32, VT_I4 },
283     { prop_macaddressW,          CIM_STRING|COL_FLAG_DYNAMIC },
284     { prop_manufacturerW,        CIM_STRING },
285     { prop_netconnectionstatusW, CIM_UINT16, VT_I4 },
286     { prop_pnpdeviceidW,         CIM_STRING },
287     { prop_speedW,               CIM_UINT64 }
288 };
289 static const struct column col_os[] =
290 {
291     { prop_captionW,         CIM_STRING },
292     { prop_csdversionW,      CIM_STRING },
293     { prop_lastbootuptimeW,  CIM_DATETIME|COL_FLAG_DYNAMIC },
294     { prop_osarchitectureW,  CIM_STRING },
295     { prop_oslanguageW,      CIM_UINT32, VT_I4 },
296     { prop_systemdirectoryW, CIM_STRING|COL_FLAG_DYNAMIC }
297 };
298 static const struct column col_param[] =
299 {
300     { prop_classW,        CIM_STRING },
301     { prop_methodW,       CIM_STRING },
302     { prop_directionW,    CIM_SINT32 },
303     { prop_parameterW,    CIM_STRING },
304     { prop_typeW,         CIM_UINT32 },
305     { prop_varianttypeW,  CIM_UINT32 },
306     { prop_defaultvalueW, CIM_UINT32 }
307 };
308 static const struct column col_process[] =
309 {
310     { prop_captionW,     CIM_STRING|COL_FLAG_DYNAMIC },
311     { prop_commandlineW, CIM_STRING|COL_FLAG_DYNAMIC },
312     { prop_descriptionW, CIM_STRING|COL_FLAG_DYNAMIC },
313     { prop_handleW,      CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
314     { prop_pprocessidW,  CIM_UINT32, VT_I4 },
315     { prop_processidW,   CIM_UINT32, VT_I4 },
316     { prop_threadcountW, CIM_UINT32, VT_I4 },
317     /* methods */
318     { method_getownerW,  CIM_FLAG_ARRAY|COL_FLAG_METHOD }
319 };
320 static const struct column col_processor[] =
321 {
322     { prop_cpustatusW,            CIM_UINT16 },
323     { prop_deviceidW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
324     { prop_manufacturerW,         CIM_STRING|COL_FLAG_DYNAMIC },
325     { prop_maxclockspeedW,        CIM_UINT32, VT_I4 },
326     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
327     { prop_numlogicalprocessorsW, CIM_UINT32, VT_I4 },
328     { prop_processoridW,          CIM_STRING|COL_FLAG_DYNAMIC },
329     { prop_uniqueidW,             CIM_STRING }
330 };
331 static const struct column col_qualifier[] =
332 {
333     { prop_classW,    CIM_STRING },
334     { prop_memberW,   CIM_STRING },
335     { prop_typeW,     CIM_UINT32 },
336     { prop_flavorW,   CIM_SINT32 },
337     { prop_nameW,     CIM_STRING },
338     { prop_intvalueW, CIM_SINT32 },
339     { prop_strvalueW, CIM_STRING }
340 };
341 static const struct column col_service[] =
342 {
343     { prop_acceptpauseW,      CIM_BOOLEAN },
344     { prop_acceptstopW,       CIM_BOOLEAN },
345     { prop_displaynameW,      CIM_STRING|COL_FLAG_DYNAMIC },
346     { prop_nameW,             CIM_STRING|COL_FLAG_DYNAMIC|COL_FLAG_KEY },
347     { prop_processidW,        CIM_UINT32 },
348     { prop_servicetypeW,      CIM_STRING },
349     { prop_startmodeW,        CIM_STRING },
350     { prop_stateW,            CIM_STRING },
351     { prop_systemnameW,       CIM_STRING|COL_FLAG_DYNAMIC },
352     /* methods */
353     { method_pauseserviceW,   CIM_FLAG_ARRAY|COL_FLAG_METHOD },
354     { method_resumeserviceW,  CIM_FLAG_ARRAY|COL_FLAG_METHOD },
355     { method_startserviceW,   CIM_FLAG_ARRAY|COL_FLAG_METHOD },
356     { method_stopserviceW,    CIM_FLAG_ARRAY|COL_FLAG_METHOD }
357 };
358 static const struct column col_sounddevice[] =
359 {
360     { prop_productnameW, CIM_STRING }
361 };
362 static const struct column col_stdregprov[] =
363 {
364     { method_enumkeyW,        CIM_FLAG_ARRAY|COL_FLAG_METHOD },
365     { method_enumvaluesW,     CIM_FLAG_ARRAY|COL_FLAG_METHOD },
366     { method_getstringvalueW, CIM_FLAG_ARRAY|COL_FLAG_METHOD }
367 };
368 static const struct column col_videocontroller[] =
369 {
370     { prop_adapterramW,           CIM_UINT32 },
371     { prop_currentbitsperpixelW,  CIM_UINT32 },
372     { prop_currenthorizontalresW, CIM_UINT32 },
373     { prop_currentverticalresW,   CIM_UINT32 },
374     { prop_descriptionW,          CIM_STRING|COL_FLAG_DYNAMIC },
375     { prop_deviceidW,             CIM_STRING|COL_FLAG_KEY },
376     { prop_nameW,                 CIM_STRING|COL_FLAG_DYNAMIC },
377     { prop_pnpdeviceidW,          CIM_STRING|COL_FLAG_DYNAMIC }
378 };
379
380 static const WCHAR baseboard_manufacturerW[] =
381     {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
382 static const WCHAR baseboard_serialnumberW[] =
383     {'N','o','n','e',0};
384 static const WCHAR baseboard_tagW[] =
385     {'B','a','s','e',' ','B','o','a','r','d',0};
386 static const WCHAR bios_descriptionW[] =
387     {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
388 static const WCHAR bios_manufacturerW[] =
389     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
390 static const WCHAR bios_releasedateW[] =
391     {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
392 static const WCHAR bios_serialnumberW[] =
393     {'0',0};
394 static const WCHAR bios_versionW[] =
395     {'W','I','N','E',' ',' ',' ','-',' ','1',0};
396 static const WCHAR cdromdrive_nameW[] =
397     {'W','i','n','e',' ','C','D','-','R','O','M',' ','A','T','A',' ','D','e','v','i','c','e',0};
398 static const WCHAR cdromdrive_pnpdeviceidW[]=
399     {'I','D','E','\\','C','D','R','O','M','W','I','N','E','_','C','D','-','R','O','M',
400      '_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_','_',
401      '_','_','_','_','_','_','_','1','.','0','_','_','_','_','_','\\','5','&','3','A','2',
402      'A','5','8','5','4','&','0','&','1','.','0','.','0',0};
403 static const WCHAR compsys_descriptionW[] =
404     {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
405 static const WCHAR compsys_domainW[] =
406     {'W','O','R','K','G','R','O','U','P',0};
407 static const WCHAR compsys_manufacturerW[] =
408     {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
409 static const WCHAR compsys_modelW[] =
410     {'W','i','n','e',0};
411 static const WCHAR diskdrive_deviceidW[] =
412     {'\\','\\','\\','\\','.','\\','\\','P','H','Y','S','I','C','A','L','D','R','I','V','E','0',0};
413 static const WCHAR diskdrive_modelW[] =
414     {'W','i','n','e',' ','D','i','s','k',' ','D','r','i','v','e',0};
415 static const WCHAR diskdrive_manufacturerW[] =
416     {'(','S','t','a','n','d','a','r','d',' ','d','i','s','k',' ','d','r','i','v','e','s',')',0};
417 static const WCHAR diskdrive_serialW[] =
418     {'W','I','N','E','H','D','I','S','K',0};
419 static const WCHAR networkadapter_pnpdeviceidW[]=
420     {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
421      'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
422      '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
423 static const WCHAR os_captionW[] =
424     {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
425      'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
426 static const WCHAR os_csdversionW[] =
427     {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
428 static const WCHAR os_32bitW[] =
429     {'3','2','-','b','i','t',0};
430 static const WCHAR os_64bitW[] =
431     {'6','4','-','b','i','t',0};
432 static const WCHAR sounddevice_productnameW[] =
433     {'W','i','n','e',' ','A','u','d','i','o',' ','D','e','v','i','c','e',0};
434 static const WCHAR videocontroller_deviceidW[] =
435     {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
436
437 #include "pshpack1.h"
438 struct record_baseboard
439 {
440     const WCHAR *manufacturer;
441     const WCHAR *serialnumber;
442     const WCHAR *tag;
443 };
444 struct record_bios
445 {
446     const WCHAR *description;
447     const WCHAR *manufacturer;
448     const WCHAR *releasedate;
449     const WCHAR *serialnumber;
450     const WCHAR *version;
451 };
452 struct record_cdromdrive
453 {
454     const WCHAR *device_id;
455     const WCHAR *drive;
456     const WCHAR *name;
457     const WCHAR *pnpdevice_id;
458 };
459 struct record_computersystem
460 {
461     const WCHAR *description;
462     const WCHAR *domain;
463     UINT16       domainrole;
464     const WCHAR *manufacturer;
465     const WCHAR *model;
466     const WCHAR *name;
467     UINT32       num_logical_processors;
468     UINT32       num_processors;
469     UINT64       total_physical_memory;
470 };
471 struct record_diskdrive
472 {
473     const WCHAR *device_id;
474     UINT32       index;
475     const WCHAR *manufacturer;
476     const WCHAR *name;
477     const WCHAR *serialnumber;
478 };
479 struct record_diskpartition
480 {
481     int          bootable;
482     int          bootpartition;
483     const WCHAR *device_id;
484     UINT32       diskindex;
485     UINT32       index;
486     const WCHAR *pnpdevice_id;
487     UINT64       size;
488     UINT64       startingoffset;
489     const WCHAR *type;
490 };
491 struct record_logicaldisk
492 {
493     const WCHAR *device_id;
494     UINT32       drivetype;
495     const WCHAR *filesystem;
496     UINT64       freespace;
497     const WCHAR *name;
498     UINT64       size;
499 };
500 struct record_networkadapter
501 {
502     const WCHAR *adaptertype;
503     const WCHAR *device_id;
504     INT32        interface_index;
505     const WCHAR *mac_address;
506     const WCHAR *manufacturer;
507     UINT16       netconnection_status;
508     const WCHAR *pnpdevice_id;
509     UINT64       speed;
510 };
511 struct record_operatingsystem
512 {
513     const WCHAR *caption;
514     const WCHAR *csdversion;
515     const WCHAR *lastbootuptime;
516     const WCHAR *osarchitecture;
517     UINT32       oslanguage;
518     const WCHAR *systemdirectory;
519 };
520 struct record_param
521 {
522     const WCHAR *class;
523     const WCHAR *method;
524     INT32        direction;
525     const WCHAR *parameter;
526     UINT32       type;
527     UINT32       varianttype;
528     UINT32       defaultvalue;
529 };
530 struct record_process
531 {
532     const WCHAR *caption;
533     const WCHAR *commandline;
534     const WCHAR *description;
535     const WCHAR *handle;
536     UINT32       pprocess_id;
537     UINT32       process_id;
538     UINT32       thread_count;
539     /* methods */
540     class_method *get_owner;
541 };
542 struct record_processor
543 {
544     UINT16       cpu_status;
545     const WCHAR *device_id;
546     const WCHAR *manufacturer;
547     UINT32       maxclockspeed;
548     const WCHAR *name;
549     UINT32       num_logical_processors;
550     const WCHAR *processor_id;
551     const WCHAR *unique_id;
552 };
553 struct record_qualifier
554 {
555     const WCHAR *class;
556     const WCHAR *member;
557     UINT32       type;
558     INT32        flavor;
559     const WCHAR *name;
560     INT32        intvalue;
561     const WCHAR *strvalue;
562 };
563 struct record_service
564 {
565     int          accept_pause;
566     int          accept_stop;
567     const WCHAR *displayname;
568     const WCHAR *name;
569     UINT32       process_id;
570     const WCHAR *servicetype;
571     const WCHAR *startmode;
572     const WCHAR *state;
573     const WCHAR *systemname;
574     /* methods */
575     class_method *pause_service;
576     class_method *resume_service;
577     class_method *start_service;
578     class_method *stop_service;
579 };
580 struct record_sounddevice
581 {
582     const WCHAR *productname;
583 };
584 struct record_stdregprov
585 {
586     class_method *enumkey;
587     class_method *enumvalues;
588     class_method *getstringvalue;
589 };
590 struct record_videocontroller
591 {
592     UINT32       adapter_ram;
593     UINT32       current_bitsperpixel;
594     UINT32       current_horizontalres;
595     UINT32       current_verticalres;
596     const WCHAR *description;
597     const WCHAR *device_id;
598     const WCHAR *name;
599     const WCHAR *pnpdevice_id;
600 };
601 #include "poppack.h"
602
603 static const struct record_baseboard data_baseboard[] =
604 {
605     { baseboard_manufacturerW, baseboard_serialnumberW, baseboard_tagW }
606 };
607 static const struct record_bios data_bios[] =
608 {
609     { bios_descriptionW, bios_manufacturerW, bios_releasedateW, bios_serialnumberW, bios_versionW }
610 };
611 static const struct record_diskdrive data_diskdrive[] =
612 {
613     { diskdrive_deviceidW, 0, diskdrive_manufacturerW, diskdrive_modelW, diskdrive_serialW }
614 };
615 static const struct record_param data_param[] =
616 {
617     { class_processW, method_getownerW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
618     { class_processW, method_getownerW, -1, param_userW, CIM_STRING },
619     { class_processW, method_getownerW, -1, param_domainW, CIM_STRING },
620     { class_serviceW, method_pauseserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
621     { class_serviceW, method_resumeserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
622     { class_serviceW, method_startserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
623     { class_serviceW, method_stopserviceW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
624     { class_stdregprovW, method_enumkeyW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
625     { class_stdregprovW, method_enumkeyW, 1, param_subkeynameW, CIM_STRING },
626     { class_stdregprovW, method_enumkeyW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
627     { class_stdregprovW, method_enumkeyW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
628     { class_stdregprovW, method_enumvaluesW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
629     { class_stdregprovW, method_enumvaluesW, 1, param_subkeynameW, CIM_STRING },
630     { class_stdregprovW, method_enumvaluesW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
631     { class_stdregprovW, method_enumvaluesW, -1, param_namesW, CIM_STRING|CIM_FLAG_ARRAY },
632     { class_stdregprovW, method_enumvaluesW, -1, param_typesW, CIM_SINT32|CIM_FLAG_ARRAY },
633     { class_stdregprovW, method_getstringvalueW, 1, param_defkeyW, CIM_SINT32, 0, 0x80000002 },
634     { class_stdregprovW, method_getstringvalueW, 1, param_subkeynameW, CIM_STRING },
635     { class_stdregprovW, method_getstringvalueW, 1, param_valuenameW, CIM_STRING },
636     { class_stdregprovW, method_getstringvalueW, -1, param_returnvalueW, CIM_UINT32, VT_I4 },
637     { class_stdregprovW, method_getstringvalueW, -1, param_valueW, CIM_STRING }
638 };
639
640 #define FLAVOR_ID (WBEM_FLAVOR_FLAG_PROPAGATE_TO_INSTANCE | WBEM_FLAVOR_NOT_OVERRIDABLE |\
641                    WBEM_FLAVOR_ORIGIN_PROPAGATED)
642
643 static const struct record_qualifier data_qualifier[] =
644 {
645     { class_process_getowner_outW, param_userW, CIM_SINT32, FLAVOR_ID, prop_idW, 0 },
646     { class_process_getowner_outW, param_domainW, CIM_SINT32, FLAVOR_ID, prop_idW, 1 }
647 };
648 static const struct record_sounddevice data_sounddevice[] =
649 {
650     { sounddevice_productnameW }
651 };
652 static const struct record_stdregprov data_stdregprov[] =
653 {
654     { reg_enum_key, reg_enum_values, reg_get_stringvalue }
655 };
656
657 static void fill_cdromdrive( struct table *table )
658 {
659     static const WCHAR fmtW[] = {'%','c',':',0};
660     WCHAR drive[3], root[] = {'A',':','\\',0};
661     struct record_cdromdrive *rec;
662     UINT i, num_rows = 0, offset = 0, count = 1;
663     DWORD drives = GetLogicalDrives();
664
665     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
666
667     for (i = 0; i < sizeof(drives); i++)
668     {
669         if (drives & (1 << i))
670         {
671             root[0] = 'A' + i;
672             if (GetDriveTypeW( root ) != DRIVE_CDROM)
673                 continue;
674
675             if (num_rows > count)
676             {
677                 BYTE *data;
678                 count *= 2;
679                 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
680                 table->data = data;
681             }
682             rec = (struct record_cdromdrive *)(table->data + offset);
683             rec->device_id    = cdromdrive_pnpdeviceidW;
684             sprintfW( drive, fmtW, 'A' + i );
685             rec->drive        = heap_strdupW( drive );
686             rec->name         = cdromdrive_nameW;
687             rec->pnpdevice_id = cdromdrive_pnpdeviceidW;
688             offset += sizeof(*rec);
689             num_rows++;
690         }
691     }
692     TRACE("created %u rows\n", num_rows);
693     table->num_rows = num_rows;
694 }
695
696 static UINT get_processor_count(void)
697 {
698     SYSTEM_BASIC_INFORMATION info;
699
700     if (NtQuerySystemInformation( SystemBasicInformation, &info, sizeof(info), NULL )) return 1;
701     return info.NumberOfProcessors;
702 }
703
704 static UINT get_logical_processor_count(void)
705 {
706     SYSTEM_LOGICAL_PROCESSOR_INFORMATION *info;
707     UINT i, j, count = 0;
708     NTSTATUS status;
709     ULONG len;
710
711     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, NULL, 0, &len );
712     if (status != STATUS_INFO_LENGTH_MISMATCH) return get_processor_count();
713
714     if (!(info = heap_alloc( len ))) return get_processor_count();
715     status = NtQuerySystemInformation( SystemLogicalProcessorInformation, info, len, &len );
716     if (status != STATUS_SUCCESS)
717     {
718         heap_free( info );
719         return get_processor_count();
720     }
721     for (i = 0; i < len / sizeof(*info); i++)
722     {
723         if (info[i].Relationship != RelationProcessorCore) continue;
724         for (j = 0; j < sizeof(ULONG_PTR); j++) if (info[i].ProcessorMask & (1 << j)) count++;
725     }
726     heap_free( info );
727     return count;
728 }
729
730 static UINT64 get_total_physical_memory(void)
731 {
732     MEMORYSTATUSEX status;
733
734     status.dwLength = sizeof(status);
735     if (!GlobalMemoryStatusEx( &status )) return 1024 * 1024 * 1024;
736     return status.ullTotalPhys;
737 }
738
739 static WCHAR *get_computername(void)
740 {
741     WCHAR *ret;
742     DWORD size=MAX_COMPUTERNAME_LENGTH;
743
744     if (!(ret = heap_alloc( size * sizeof(WCHAR) ))) return NULL;
745     GetComputerNameW( ret, &size );
746     return ret;
747 }
748
749 static void fill_compsys( struct table *table )
750 {
751     struct record_computersystem *rec;
752
753     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
754
755     rec = (struct record_computersystem *)table->data;
756     rec->description            = compsys_descriptionW;
757     rec->domain                 = compsys_domainW;
758     rec->domainrole             = 0; /* standalone workstation */
759     rec->manufacturer           = compsys_manufacturerW;
760     rec->model                  = compsys_modelW;
761     rec->name                   = get_computername();
762     rec->num_logical_processors = get_logical_processor_count();
763     rec->num_processors         = get_processor_count();
764     rec->total_physical_memory  = get_total_physical_memory();
765
766     TRACE("created 1 row\n");
767     table->num_rows = 1;
768 }
769
770 static WCHAR *get_filesystem( const WCHAR *root )
771 {
772     static const WCHAR ntfsW[] = {'N','T','F','S',0};
773     WCHAR buffer[MAX_PATH + 1];
774
775     if (GetVolumeInformationW( root, NULL, 0, NULL, NULL, NULL, buffer, MAX_PATH + 1 ))
776         return heap_strdupW( buffer );
777     return heap_strdupW( ntfsW );
778 }
779
780 static UINT64 get_freespace( const WCHAR *dir, UINT64 *disksize )
781 {
782     WCHAR root[] = {'\\','\\','.','\\','A',':',0};
783     ULARGE_INTEGER free;
784     DISK_GEOMETRY_EX info;
785     HANDLE handle;
786
787     free.QuadPart = 512 * 1024 * 1024;
788     GetDiskFreeSpaceExW( dir, NULL, NULL, &free );
789
790     root[4] = dir[0];
791     handle = CreateFileW( root, GENERIC_READ, FILE_SHARE_READ|FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, 0 );
792     if (handle != INVALID_HANDLE_VALUE)
793     {
794         if (DeviceIoControl( handle, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX, NULL, 0, &info, sizeof(info), NULL, NULL ))
795             *disksize = info.DiskSize.QuadPart;
796         CloseHandle( handle );
797     }
798     return free.QuadPart;
799 }
800
801 static void fill_diskpartition( struct table *table )
802 {
803     static const WCHAR fmtW[] =
804         {'D','i','s','k',' ','#','%','u',',',' ','P','a','r','t','i','t','i','o','n',' ','#','0',0};
805     WCHAR device_id[32], root[] = {'A',':','\\',0};
806     struct record_diskpartition *rec;
807     UINT i, num_rows = 0, offset = 0, count = 4, type, index = 0;
808     UINT64 size = 1024 * 1024 * 1024;
809     DWORD drives = GetLogicalDrives();
810
811     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
812
813     for (i = 0; i < sizeof(drives); i++)
814     {
815         if (drives & (1 << i))
816         {
817             root[0] = 'A' + i;
818             type = GetDriveTypeW( root );
819             if (type != DRIVE_FIXED && type != DRIVE_REMOVABLE)
820                 continue;
821
822             if (num_rows > count)
823             {
824                 BYTE *data;
825                 count *= 2;
826                 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
827                 table->data = data;
828             }
829             rec = (struct record_diskpartition *)(table->data + offset);
830             rec->bootable       = (i == 2) ? -1 : 0;
831             rec->bootpartition  = (i == 2) ? -1 : 0;
832             sprintfW( device_id, fmtW, index );
833             rec->device_id      = heap_strdupW( device_id );
834             rec->diskindex      = index;
835             rec->index          = 0;
836             rec->pnpdevice_id   = heap_strdupW( device_id );
837             get_freespace( root, &size );
838             rec->size           = size;
839             rec->startingoffset = 0;
840             rec->type           = get_filesystem( root );
841             offset += sizeof(*rec);
842             num_rows++;
843             index++;
844         }
845     }
846     TRACE("created %u rows\n", num_rows);
847     table->num_rows = num_rows;
848 }
849
850 static void fill_logicaldisk( struct table *table )
851 {
852     static const WCHAR fmtW[] = {'%','c',':',0};
853     WCHAR device_id[3], root[] = {'A',':','\\',0};
854     struct record_logicaldisk *rec;
855     UINT i, num_rows = 0, offset = 0, count = 4, type;
856     UINT64 size = 1024 * 1024 * 1024;
857     DWORD drives = GetLogicalDrives();
858
859     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) return;
860
861     for (i = 0; i < sizeof(drives); i++)
862     {
863         if (drives & (1 << i))
864         {
865             root[0] = 'A' + i;
866             type = GetDriveTypeW( root );
867             if (type != DRIVE_FIXED && type != DRIVE_CDROM && type != DRIVE_REMOVABLE)
868                 continue;
869
870             if (num_rows > count)
871             {
872                 BYTE *data;
873                 count *= 2;
874                 if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) return;
875                 table->data = data;
876             }
877             rec = (struct record_logicaldisk *)(table->data + offset);
878             sprintfW( device_id, fmtW, 'A' + i );
879             rec->device_id  = heap_strdupW( device_id );
880             rec->drivetype  = type;
881             rec->filesystem = get_filesystem( root );
882             rec->freespace  = get_freespace( root, &size );
883             rec->name       = heap_strdupW( device_id );
884             rec->size       = size;
885             offset += sizeof(*rec);
886             num_rows++;
887         }
888     }
889     TRACE("created %u rows\n", num_rows);
890     table->num_rows = num_rows;
891 }
892
893 static UINT16 get_connection_status( IF_OPER_STATUS status )
894 {
895     switch (status)
896     {
897     case IfOperStatusDown:
898         return 0; /* Disconnected */
899     case IfOperStatusUp:
900         return 2; /* Connected */
901     default:
902         ERR("unhandled status %u\n", status);
903         break;
904     }
905     return 0;
906 }
907 static WCHAR *get_mac_address( const BYTE *addr, DWORD len )
908 {
909     static const WCHAR fmtW[] =
910         {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
911          '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
912     WCHAR *ret;
913
914     if (len != 6 || !(ret = heap_alloc( 18 * sizeof(WCHAR) ))) return NULL;
915     sprintfW( ret, fmtW, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5] );
916     return ret;
917 }
918 static const WCHAR *get_adaptertype( DWORD type )
919 {
920     static const WCHAR ethernetW[] = {'E','t','h','e','r','n','e','t',' ','8','0','2','.','3',0};
921     static const WCHAR wirelessW[] = {'W','i','r','e','l','e','s','s',0};
922     static const WCHAR firewireW[] = {'1','3','9','4',0};
923     static const WCHAR tunnelW[]   = {'T','u','n','n','e','l',0};
924
925     switch (type)
926     {
927     case IF_TYPE_ETHERNET_CSMACD: return ethernetW;
928     case IF_TYPE_IEEE80211:       return wirelessW;
929     case IF_TYPE_IEEE1394:        return firewireW;
930     case IF_TYPE_TUNNEL:          return tunnelW;
931     default: break;
932     }
933     return NULL;
934 }
935
936 static void fill_networkadapter( struct table *table )
937 {
938     static const WCHAR fmtW[] = {'%','u',0};
939     WCHAR device_id[11];
940     struct record_networkadapter *rec;
941     IP_ADAPTER_ADDRESSES *aa, *buffer;
942     UINT num_rows = 0, offset = 0;
943     DWORD size = 0, ret;
944
945     ret = GetAdaptersAddresses( AF_UNSPEC, 0, NULL, NULL, &size );
946     if (ret != ERROR_BUFFER_OVERFLOW) return;
947
948     if (!(buffer = heap_alloc( size ))) return;
949     if (GetAdaptersAddresses( AF_UNSPEC, 0, NULL, buffer, &size ))
950     {
951         heap_free( buffer );
952         return;
953     }
954     for (aa = buffer; aa; aa = aa->Next) num_rows++;
955     if (!(table->data = heap_alloc( sizeof(*rec) * num_rows )))
956     {
957         heap_free( buffer );
958         return;
959     }
960     for (aa = buffer; aa; aa = aa->Next)
961     {
962         rec = (struct record_networkadapter *)(table->data + offset);
963         sprintfW( device_id, fmtW, aa->u.s.IfIndex );
964         rec->adaptertype          = get_adaptertype( aa->IfType );
965         rec->device_id            = heap_strdupW( device_id );
966         rec->interface_index      = aa->u.s.IfIndex;
967         rec->mac_address          = get_mac_address( aa->PhysicalAddress, aa->PhysicalAddressLength );
968         rec->manufacturer         = compsys_manufacturerW;
969         rec->netconnection_status = get_connection_status( aa->OperStatus );
970         rec->pnpdevice_id         = networkadapter_pnpdeviceidW;
971         rec->speed                = 1000000;
972         offset += sizeof(*rec);
973     }
974     TRACE("created %u rows\n", num_rows);
975     table->num_rows = num_rows;
976
977     heap_free( buffer );
978 }
979
980 static WCHAR *get_cmdline( DWORD process_id )
981 {
982     if (process_id == GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
983     return NULL; /* FIXME handle different process case */
984 }
985
986 static void fill_process( struct table *table )
987 {
988     static const WCHAR fmtW[] = {'%','u',0};
989     WCHAR handle[11];
990     struct record_process *rec;
991     PROCESSENTRY32W entry;
992     HANDLE snap;
993     UINT num_rows = 0, offset = 0, count = 8;
994
995     snap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
996     if (snap == INVALID_HANDLE_VALUE) return;
997
998     entry.dwSize = sizeof(entry);
999     if (!Process32FirstW( snap, &entry )) goto done;
1000     if (!(table->data = heap_alloc( count * sizeof(*rec) ))) goto done;
1001
1002     do
1003     {
1004         if (num_rows > count)
1005         {
1006             BYTE *data;
1007             count *= 2;
1008             if (!(data = heap_realloc( table->data, count * sizeof(*rec) ))) goto done;
1009             table->data = data;
1010         }
1011         rec = (struct record_process *)(table->data + offset);
1012         rec->caption      = heap_strdupW( entry.szExeFile );
1013         rec->commandline  = get_cmdline( entry.th32ProcessID );
1014         rec->description  = heap_strdupW( entry.szExeFile );
1015         sprintfW( handle, fmtW, entry.th32ProcessID );
1016         rec->handle       = heap_strdupW( handle );
1017         rec->process_id   = entry.th32ProcessID;
1018         rec->pprocess_id  = entry.th32ParentProcessID;
1019         rec->thread_count = entry.cntThreads;
1020         rec->get_owner    = process_get_owner;
1021         offset += sizeof(*rec);
1022         num_rows++;
1023     } while (Process32NextW( snap, &entry ));
1024
1025     TRACE("created %u rows\n", num_rows);
1026     table->num_rows = num_rows;
1027
1028 done:
1029     CloseHandle( snap );
1030 }
1031
1032 static inline void do_cpuid( unsigned int ax, unsigned int *p )
1033 {
1034 #ifdef __i386__
1035     __asm__("pushl %%ebx\n\t"
1036                 "cpuid\n\t"
1037                 "movl %%ebx, %%esi\n\t"
1038                 "popl %%ebx"
1039                 : "=a" (p[0]), "=S" (p[1]), "=c" (p[2]), "=d" (p[3])
1040                 :  "0" (ax));
1041 #endif
1042 }
1043
1044 static void get_processor_id( WCHAR *processor_id )
1045 {
1046     static const WCHAR fmtW[] = {'%','0','8','X','%','0','8','X',0};
1047     unsigned int regs[4] = {0, 0, 0, 0};
1048
1049     do_cpuid( 1, regs );
1050     sprintfW( processor_id, fmtW, regs[3], regs[0] );
1051 }
1052 static void regs_to_str( unsigned int *regs, unsigned int len, WCHAR *buffer )
1053 {
1054     unsigned int i;
1055     unsigned char *p = (unsigned char *)regs;
1056
1057     for (i = 0; i < len; i++)
1058     {
1059         buffer[i] = *p++;
1060     }
1061     buffer[i] = 0;
1062 }
1063 static void get_processor_manufacturer( WCHAR *manufacturer )
1064 {
1065     unsigned int tmp, regs[4] = {0, 0, 0, 0};
1066
1067     do_cpuid( 0, regs );
1068     tmp = regs[2];      /* swap edx and ecx */
1069     regs[2] = regs[3];
1070     regs[3] = tmp;
1071
1072     regs_to_str( regs + 1, 12, manufacturer );
1073 }
1074 static void get_processor_name( WCHAR *name )
1075 {
1076     unsigned int regs[4] = {0, 0, 0, 0};
1077
1078     do_cpuid( 0x80000000, regs );
1079     if (regs[0] >= 0x80000004)
1080     {
1081         do_cpuid( 0x80000002, regs );
1082         regs_to_str( regs, 16, name );
1083         do_cpuid( 0x80000003, regs );
1084         regs_to_str( regs, 16, name + 16 );
1085         do_cpuid( 0x80000004, regs );
1086         regs_to_str( regs, 16, name + 32 );
1087     }
1088 }
1089 static UINT get_processor_maxclockspeed( void )
1090 {
1091     PROCESSOR_POWER_INFORMATION *info;
1092     UINT ret = 1000, size = get_processor_count() * sizeof(PROCESSOR_POWER_INFORMATION);
1093     NTSTATUS status;
1094
1095     if ((info = heap_alloc( size )))
1096     {
1097         status = NtPowerInformation( ProcessorInformation, NULL, 0, info, size );
1098         if (!status) ret = info[0].MaxMhz;
1099         heap_free( info );
1100     }
1101     return ret;
1102 }
1103
1104 static void fill_processor( struct table *table )
1105 {
1106     static const WCHAR fmtW[] = {'C','P','U','%','u',0};
1107     WCHAR device_id[14], processor_id[17], manufacturer[13], name[49] = {0};
1108     struct record_processor *rec;
1109     UINT i, offset = 0, maxclockspeed, num_logical_processors, count = get_processor_count();
1110
1111     if (!(table->data = heap_alloc( sizeof(*rec) * count ))) return;
1112
1113     get_processor_id( processor_id );
1114     get_processor_manufacturer( manufacturer );
1115     get_processor_name( name );
1116
1117     maxclockspeed = get_processor_maxclockspeed();
1118     num_logical_processors = get_logical_processor_count() / count;
1119
1120     for (i = 0; i < count; i++)
1121     {
1122         rec = (struct record_processor *)(table->data + offset);
1123         rec->cpu_status             = 1; /* CPU Enabled */
1124         sprintfW( device_id, fmtW, i );
1125         rec->device_id              = heap_strdupW( device_id );
1126         rec->manufacturer           = heap_strdupW( manufacturer );
1127         rec->maxclockspeed          = maxclockspeed;
1128         rec->name                   = heap_strdupW( name );
1129         rec->num_logical_processors = num_logical_processors;
1130         rec->processor_id           = heap_strdupW( processor_id );
1131         rec->unique_id              = NULL;
1132         offset += sizeof(*rec);
1133     }
1134
1135     TRACE("created %u rows\n", count);
1136     table->num_rows = count;
1137 }
1138
1139 static WCHAR *get_lastbootuptime(void)
1140 {
1141     static const WCHAR fmtW[] =
1142         {'%','0','4','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u','%','0','2','u',
1143          '.','%','0','6','u','+','0','0','0',0};
1144     SYSTEM_TIMEOFDAY_INFORMATION ti;
1145     TIME_FIELDS tf;
1146     WCHAR *ret;
1147
1148     if (!(ret = heap_alloc( 26 * sizeof(WCHAR) ))) return NULL;
1149
1150     NtQuerySystemInformation( SystemTimeOfDayInformation, &ti, sizeof(ti), NULL );
1151     RtlTimeToTimeFields( &ti.liKeBootTime, &tf );
1152     sprintfW( ret, fmtW, tf.Year, tf.Month, tf.Day, tf.Hour, tf.Minute, tf.Second, tf.Milliseconds * 1000 );
1153     return ret;
1154 }
1155 static const WCHAR *get_osarchitecture(void)
1156 {
1157     SYSTEM_INFO info;
1158     GetNativeSystemInfo( &info );
1159     if (info.u.s.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_AMD64) return os_64bitW;
1160     return os_32bitW;
1161 }
1162 static WCHAR *get_systemdirectory(void)
1163 {
1164     void *redir;
1165     WCHAR *ret;
1166
1167     if (!(ret = heap_alloc( MAX_PATH * sizeof(WCHAR) ))) return NULL;
1168     Wow64DisableWow64FsRedirection( &redir );
1169     GetSystemDirectoryW( ret, MAX_PATH );
1170     Wow64RevertWow64FsRedirection( redir );
1171     return ret;
1172 }
1173
1174 static void fill_os( struct table *table )
1175 {
1176     struct record_operatingsystem *rec;
1177
1178     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1179
1180     rec = (struct record_operatingsystem *)table->data;
1181     rec->caption         = os_captionW;
1182     rec->csdversion      = os_csdversionW;
1183     rec->lastbootuptime  = get_lastbootuptime();
1184     rec->osarchitecture  = get_osarchitecture();
1185     rec->oslanguage      = MAKELANGID( LANG_ENGLISH, SUBLANG_ENGLISH_US );
1186     rec->systemdirectory = get_systemdirectory();
1187
1188     TRACE("created 1 row\n");
1189     table->num_rows = 1;
1190 }
1191
1192 static const WCHAR *get_service_type( DWORD type )
1193 {
1194     static const WCHAR filesystem_driverW[] =
1195         {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
1196     static const WCHAR kernel_driverW[] =
1197         {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
1198     static const WCHAR own_processW[] =
1199         {'O','w','n',' ','P','r','o','c','e','s','s',0};
1200     static const WCHAR share_processW[] =
1201         {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
1202
1203     if (type & SERVICE_KERNEL_DRIVER)            return kernel_driverW;
1204     else if (type & SERVICE_FILE_SYSTEM_DRIVER)  return filesystem_driverW;
1205     else if (type & SERVICE_WIN32_OWN_PROCESS)   return own_processW;
1206     else if (type & SERVICE_WIN32_SHARE_PROCESS) return share_processW;
1207     else ERR("unhandled type 0x%08x\n", type);
1208     return NULL;
1209 }
1210 static const WCHAR *get_service_state( DWORD state )
1211 {
1212     static const WCHAR runningW[] =
1213         {'R','u','n','n','i','n','g',0};
1214     static const WCHAR start_pendingW[] =
1215         {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
1216     static const WCHAR stop_pendingW[] =
1217         {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
1218     static const WCHAR stoppedW[] =
1219         {'S','t','o','p','p','e','d',0};
1220     static const WCHAR unknownW[] =
1221         {'U','n','k','n','o','w','n',0};
1222
1223     switch (state)
1224     {
1225     case SERVICE_STOPPED:       return stoppedW;
1226     case SERVICE_START_PENDING: return start_pendingW;
1227     case SERVICE_STOP_PENDING:  return stop_pendingW;
1228     case SERVICE_RUNNING:       return runningW;
1229     default:
1230         ERR("unknown state %u\n", state);
1231         return unknownW;
1232     }
1233 }
1234
1235 static const WCHAR *get_service_startmode( DWORD mode )
1236 {
1237     static const WCHAR bootW[] = {'B','o','o','t',0};
1238     static const WCHAR systemW[] = {'S','y','s','t','e','m',0};
1239     static const WCHAR autoW[] = {'A','u','t','o',0};
1240     static const WCHAR manualW[] = {'M','a','n','u','a','l',0};
1241     static const WCHAR disabledW[] = {'D','i','s','a','b','l','e','d',0};
1242     static const WCHAR unknownW[] = {'U','n','k','n','o','w','n',0};
1243
1244     switch (mode)
1245     {
1246     case SERVICE_BOOT_START:   return bootW;
1247     case SERVICE_SYSTEM_START: return systemW;
1248     case SERVICE_AUTO_START:   return autoW;
1249     case SERVICE_DEMAND_START: return manualW;
1250     case SERVICE_DISABLED:     return disabledW;
1251     default:
1252         ERR("unknown mode 0x%x\n", mode);
1253         return unknownW;
1254     }
1255 }
1256
1257 static QUERY_SERVICE_CONFIGW *query_service_config( SC_HANDLE manager, const WCHAR *name )
1258 {
1259     QUERY_SERVICE_CONFIGW *config = NULL;
1260     SC_HANDLE service;
1261     DWORD size;
1262
1263     if (!(service = OpenServiceW( manager, name, SERVICE_QUERY_CONFIG ))) return NULL;
1264     QueryServiceConfigW( service, NULL, 0, &size );
1265     if (GetLastError() != ERROR_INSUFFICIENT_BUFFER) goto done;
1266     if (!(config = heap_alloc( size ))) goto done;
1267     if (QueryServiceConfigW( service, config, size, &size )) goto done;
1268     heap_free( config );
1269     config = NULL;
1270
1271 done:
1272     CloseServiceHandle( service );
1273     return config;
1274 }
1275
1276 static void fill_service( struct table *table )
1277 {
1278     struct record_service *rec;
1279     SC_HANDLE manager;
1280     ENUM_SERVICE_STATUS_PROCESSW *tmp, *services = NULL;
1281     SERVICE_STATUS_PROCESS *status;
1282     WCHAR sysnameW[MAX_COMPUTERNAME_LENGTH + 1];
1283     DWORD len = sizeof(sysnameW) / sizeof(sysnameW[0]);
1284     UINT i, num_rows = 0, offset = 0, size = 256, needed, count;
1285     BOOL ret;
1286
1287     if (!(manager = OpenSCManagerW( NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE ))) return;
1288     if (!(services = heap_alloc( size ))) goto done;
1289
1290     ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1291                                  SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1292                                  &count, NULL, NULL );
1293     if (!ret)
1294     {
1295         if (GetLastError() != ERROR_MORE_DATA) goto done;
1296         size = needed;
1297         if (!(tmp = heap_realloc( services, size ))) goto done;
1298         services = tmp;
1299         ret = EnumServicesStatusExW( manager, SC_ENUM_PROCESS_INFO, SERVICE_TYPE_ALL,
1300                                      SERVICE_STATE_ALL, (BYTE *)services, size, &needed,
1301                                      &count, NULL, NULL );
1302         if (!ret) goto done;
1303     }
1304     if (!(table->data = heap_alloc( sizeof(*rec) * count ))) goto done;
1305
1306     GetComputerNameW( sysnameW, &len );
1307
1308     for (i = 0; i < count; i++)
1309     {
1310         QUERY_SERVICE_CONFIGW *config;
1311
1312         if (!(config = query_service_config( manager, services[i].lpServiceName ))) continue;
1313
1314         status = &services[i].ServiceStatusProcess;
1315         rec = (struct record_service *)(table->data + offset);
1316         rec->accept_pause   = (status->dwControlsAccepted & SERVICE_ACCEPT_PAUSE_CONTINUE) ? -1 : 0;
1317         rec->accept_stop    = (status->dwControlsAccepted & SERVICE_ACCEPT_STOP) ? -1 : 0;
1318         rec->displayname    = heap_strdupW( services[i].lpDisplayName );
1319         rec->name           = heap_strdupW( services[i].lpServiceName );
1320         rec->process_id     = status->dwProcessId;
1321         rec->servicetype    = get_service_type( status->dwServiceType );
1322         rec->startmode      = get_service_startmode( config->dwStartType );
1323         rec->state          = get_service_state( status->dwCurrentState );
1324         rec->systemname     = heap_strdupW( sysnameW );
1325         rec->pause_service  = service_pause_service;
1326         rec->resume_service = service_resume_service;
1327         rec->start_service  = service_start_service;
1328         rec->stop_service   = service_stop_service;
1329         heap_free( config );
1330         offset += sizeof(*rec);
1331         num_rows++;
1332     }
1333
1334     TRACE("created %u rows\n", num_rows);
1335     table->num_rows = num_rows;
1336
1337 done:
1338     CloseServiceHandle( manager );
1339     heap_free( services );
1340 }
1341
1342 static UINT32 get_bits_per_pixel( UINT *hres, UINT *vres )
1343 {
1344     HDC hdc = GetDC( NULL );
1345     UINT32 ret;
1346
1347     if (!hdc) return 32;
1348     ret = GetDeviceCaps( hdc, BITSPIXEL );
1349     *hres = GetDeviceCaps( hdc, HORZRES );
1350     *vres = GetDeviceCaps( hdc, VERTRES );
1351     ReleaseDC( NULL, hdc );
1352     return ret;
1353 }
1354
1355 static WCHAR *get_pnpdeviceid( DXGI_ADAPTER_DESC *desc )
1356 {
1357     static const WCHAR fmtW[] =
1358         {'P','C','I','\\','V','E','N','_','%','0','4','X','&','D','E','V','_','%','0','4','X',
1359          '&','S','U','B','S','Y','S','_','%','0','8','X','&','R','E','V','_','%','0','2','X','\\',
1360          '0','&','D','E','A','D','B','E','E','F','&','0','&','D','E','A','D',0};
1361     WCHAR *ret;
1362
1363     if (!(ret = heap_alloc( sizeof(fmtW) + 2 * sizeof(WCHAR) ))) return NULL;
1364     sprintfW( ret, fmtW, desc->VendorId, desc->DeviceId, desc->SubSysId, desc->Revision );
1365     return ret;
1366 }
1367
1368 static void fill_videocontroller( struct table *table )
1369 {
1370
1371     struct record_videocontroller *rec;
1372     HRESULT hr;
1373     IDXGIFactory *factory = NULL;
1374     IDXGIAdapter *adapter = NULL;
1375     DXGI_ADAPTER_DESC desc;
1376     UINT hres = 1024, vres = 768, vidmem = 512 * 1024 * 1024;
1377     const WCHAR *name = videocontroller_deviceidW;
1378
1379     if (!(table->data = heap_alloc( sizeof(*rec) ))) return;
1380
1381     hr = CreateDXGIFactory( &IID_IDXGIFactory, (void **)&factory );
1382     if (FAILED(hr)) goto done;
1383
1384     hr = IDXGIFactory_EnumAdapters( factory, 0, &adapter );
1385     if (FAILED(hr)) goto done;
1386
1387     hr = IDXGIAdapter_GetDesc( adapter, &desc );
1388     if (SUCCEEDED(hr))
1389     {
1390         vidmem = desc.DedicatedVideoMemory;
1391         name   = desc.Description;
1392     }
1393
1394 done:
1395     rec = (struct record_videocontroller *)table->data;
1396     rec->adapter_ram           = vidmem;
1397     rec->current_bitsperpixel  = get_bits_per_pixel( &hres, &vres );
1398     rec->current_horizontalres = hres;
1399     rec->current_verticalres   = vres;
1400     rec->description           = heap_strdupW( name );
1401     rec->device_id             = videocontroller_deviceidW;
1402     rec->name                  = heap_strdupW( name );
1403     rec->pnpdevice_id          = get_pnpdeviceid( &desc );
1404
1405     TRACE("created 1 row\n");
1406     table->num_rows = 1;
1407
1408     if (adapter) IDXGIAdapter_Release( adapter );
1409     if (factory) IDXGIFactory_Release( factory );
1410 }
1411
1412 static struct table builtin_classes[] =
1413 {
1414     { class_baseboardW, SIZEOF(col_baseboard), col_baseboard, SIZEOF(data_baseboard), (BYTE *)data_baseboard },
1415     { class_biosW, SIZEOF(col_bios), col_bios, SIZEOF(data_bios), (BYTE *)data_bios },
1416     { class_cdromdriveW, SIZEOF(col_cdromdrive), col_cdromdrive, 0, NULL, fill_cdromdrive },
1417     { class_compsysW, SIZEOF(col_compsys), col_compsys, 0, NULL, fill_compsys },
1418     { class_diskdriveW, SIZEOF(col_diskdrive), col_diskdrive, SIZEOF(data_diskdrive), (BYTE *)data_diskdrive },
1419     { class_diskpartitionW, SIZEOF(col_diskpartition), col_diskpartition, 0, NULL, fill_diskpartition },
1420     { class_logicaldiskW, SIZEOF(col_logicaldisk), col_logicaldisk, 0, NULL, fill_logicaldisk },
1421     { class_networkadapterW, SIZEOF(col_networkadapter), col_networkadapter, 0, NULL, fill_networkadapter },
1422     { class_osW, SIZEOF(col_os), col_os, 0, NULL, fill_os },
1423     { class_paramsW, SIZEOF(col_param), col_param, SIZEOF(data_param), (BYTE *)data_param },
1424     { class_processW, SIZEOF(col_process), col_process, 0, NULL, fill_process },
1425     { class_processorW, SIZEOF(col_processor), col_processor, 0, NULL, fill_processor },
1426     { class_qualifiersW, SIZEOF(col_qualifier), col_qualifier, SIZEOF(data_qualifier), (BYTE *)data_qualifier },
1427     { class_serviceW, SIZEOF(col_service), col_service, 0, NULL, fill_service },
1428     { class_sounddeviceW, SIZEOF(col_sounddevice), col_sounddevice, SIZEOF(data_sounddevice), (BYTE *)data_sounddevice },
1429     { class_stdregprovW, SIZEOF(col_stdregprov), col_stdregprov, SIZEOF(data_stdregprov), (BYTE *)data_stdregprov },
1430     { class_videocontrollerW, SIZEOF(col_videocontroller), col_videocontroller, 0, NULL, fill_videocontroller }
1431 };
1432
1433 void init_table_list( void )
1434 {
1435     static struct list tables = LIST_INIT( tables );
1436     UINT i;
1437
1438     for (i = 0; i < SIZEOF(builtin_classes); i++) list_add_tail( &tables, &builtin_classes[i].entry );
1439     table_list = &tables;
1440 }