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