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