2 * Copyright 2012 Hans Leidekker for CodeWeavers
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.
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.
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
20 #define NONAMELESSUNION
21 #define NONAMELESSSTRUCT
38 #include "wine/debug.h"
39 #include "wbemprox_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
43 static const WCHAR class_baseboardW
[] =
44 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
45 static const WCHAR class_biosW
[] =
46 {'W','i','n','3','2','_','B','I','O','S',0};
47 static const WCHAR class_compsysW
[] =
48 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
49 static const WCHAR class_logicaldiskW
[] =
50 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
51 static const WCHAR class_networkadapterW
[] =
52 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
53 static const WCHAR class_osW
[] =
54 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
55 static const WCHAR class_paramsW
[] =
56 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
57 static const WCHAR class_processW
[] =
58 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
59 static const WCHAR class_processorW
[] =
60 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
61 static const WCHAR class_serviceW
[] =
62 {'W','i','n','3','2','_','S','e','r','v','i','c','e',0};
63 static const WCHAR class_stdregprovW
[] =
64 {'S','t','d','R','e','g','P','r','o','v',0};
65 static const WCHAR class_videocontrollerW
[] =
66 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
68 static const WCHAR prop_acceptpauseW
[] =
69 {'A','c','c','e','p','t','P','a','u','s','e',0};
70 static const WCHAR prop_acceptstopW
[] =
71 {'A','c','c','e','p','t','S','t','o','p',0};
72 static const WCHAR prop_adapterramW
[] =
73 {'A','d','a','p','t','e','r','R','A','M',0};
74 static const WCHAR prop_captionW
[] =
75 {'C','a','p','t','i','o','n',0};
76 static const WCHAR prop_classW
[] =
77 {'C','l','a','s','s',0};
78 static const WCHAR prop_commandlineW
[] =
79 {'C','o','m','m','a','n','d','L','i','n','e',0};
80 static const WCHAR prop_cpustatusW
[] =
81 {'C','p','u','S','t','a','t','u','s',0};
82 static const WCHAR prop_csdversionW
[] =
83 {'C','S','D','V','e','r','s','i','o','n',0};
84 static const WCHAR prop_currentbitsperpixelW
[] =
85 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
86 static const WCHAR prop_currenthorizontalresW
[] =
87 {'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};
88 static const WCHAR prop_currentverticalresW
[] =
89 {'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};
90 static const WCHAR prop_defaultvalueW
[] =
91 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
92 static const WCHAR prop_descriptionW
[] =
93 {'D','e','s','c','r','i','p','t','i','o','n',0};
94 static const WCHAR prop_deviceidW
[] =
95 {'D','e','v','i','c','e','I','d',0};
96 static const WCHAR prop_directionW
[] =
97 {'D','i','r','e','c','t','i','o','n',0};
98 static const WCHAR prop_displaynameW
[] =
99 {'D','i','s','p','l','a','y','N','a','m','e',0};
100 static const WCHAR prop_drivetypeW
[] =
101 {'D','r','i','v','e','T','y','p','e',0};
102 static const WCHAR prop_filesystemW
[] =
103 {'F','i','l','e','S','y','s','t','e','m',0};
104 static const WCHAR prop_freespaceW
[] =
105 {'F','r','e','e','S','p','a','c','e',0};
106 static const WCHAR prop_handleW
[] =
107 {'H','a','n','d','l','e',0};
108 static const WCHAR prop_interfaceindexW
[] =
109 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
110 static const WCHAR prop_macaddressW
[] =
111 {'M','A','C','A','d','d','r','e','s','s',0};
112 static const WCHAR prop_manufacturerW
[] =
113 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
114 static const WCHAR prop_methodW
[] =
115 {'M','e','t','h','o','d',0};
116 static const WCHAR prop_modelW
[] =
117 {'M','o','d','e','l',0};
118 static const WCHAR prop_nameW
[] =
120 static const WCHAR prop_netconnectionstatusW
[] =
121 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
122 static const WCHAR prop_numlogicalprocessorsW
[] =
123 {'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};
124 static const WCHAR prop_numprocessorsW
[] =
125 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
126 static const WCHAR prop_osarchitectureW
[] =
127 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
128 static const WCHAR prop_oslanguageW
[] =
129 {'O','S','L','a','n','g','u','a','g','e',0};
130 static const WCHAR prop_parameterW
[] =
131 {'P','a','r','a','m','e','t','e','r',0};
132 static const WCHAR prop_pnpdeviceidW
[] =
133 {'P','N','P','D','e','v','i','c','e','I','D',0};
134 static const WCHAR prop_pprocessidW
[] =
135 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
136 static const WCHAR prop_processidW
[] =
137 {'P','r','o','c','e','s','s','I','D',0};
138 static const WCHAR prop_processoridW
[] =
139 {'P','r','o','c','e','s','s','o','r','I','d',0};
140 static const WCHAR prop_releasedateW
[] =
141 {'R','e','l','e','a','s','e','D','a','t','e',0};
142 static const WCHAR prop_serialnumberW
[] =
143 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
144 static const WCHAR prop_servicetypeW
[] =
145 {'S','e','r','v','i','c','e','T','y','p','e',0};
146 static const WCHAR prop_sizeW
[] =
148 static const WCHAR prop_speedW
[] =
149 {'S','p','e','e','d',0};
150 static const WCHAR prop_stateW
[] =
151 {'S','t','a','t','e',0};
152 static const WCHAR prop_systemdirectoryW
[] =
153 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
154 static const WCHAR prop_tagW
[] =
156 static const WCHAR prop_threadcountW
[] =
157 {'T','h','r','e','a','d','C','o','u','n','t',0};
158 static const WCHAR prop_totalphysicalmemoryW
[] =
159 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
160 static const WCHAR prop_typeW
[] =
163 static const WCHAR method_enumkeyW
[] =
164 {'E','n','u','m','K','e','y',0};
165 static const WCHAR method_enumvaluesW
[] =
166 {'E','n','u','m','V','a','l','u','e','s',0};
168 static const WCHAR param_defkeyW
[] =
169 {'h','D','e','f','K','e','y',0};
170 static const WCHAR param_namesW
[] =
171 {'N','a','m','e','s',0};
172 static const WCHAR param_returnvalueW
[] =
173 {'R','e','t','u','r','n','V','a','l','u','e',0};
174 static const WCHAR param_subkeynameW
[] =
175 {'s','S','u','b','K','e','y','N','a','m','e',0};
176 static const WCHAR param_typesW
[] =
177 {'T','y','p','e','s',0};
179 /* column definitions must be kept in sync with record structures below */
180 static const struct column col_baseboard
[] =
182 { prop_manufacturerW
, CIM_STRING
},
183 { prop_serialnumberW
, CIM_STRING
},
184 { prop_tagW
, CIM_STRING
|COL_FLAG_KEY
}
186 static const struct column col_bios
[] =
188 { prop_descriptionW
, CIM_STRING
},
189 { prop_manufacturerW
, CIM_STRING
},
190 { prop_releasedateW
, CIM_DATETIME
},
191 { prop_serialnumberW
, CIM_STRING
}
193 static const struct column col_compsys
[] =
195 { prop_descriptionW
, CIM_STRING
},
196 { prop_manufacturerW
, CIM_STRING
},
197 { prop_modelW
, CIM_STRING
},
198 { prop_numlogicalprocessorsW
, CIM_UINT32
, VT_I4
},
199 { prop_numprocessorsW
, CIM_UINT32
, VT_I4
},
200 { prop_totalphysicalmemoryW
, CIM_UINT64
}
202 static const struct column col_logicaldisk
[] =
204 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
205 { prop_drivetypeW
, CIM_UINT32
, VT_I4
},
206 { prop_filesystemW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
207 { prop_freespaceW
, CIM_UINT64
},
208 { prop_sizeW
, CIM_UINT64
}
210 static const struct column col_networkadapter
[] =
212 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
213 { prop_interfaceindexW
, CIM_UINT32
, VT_I4
},
214 { prop_macaddressW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
215 { prop_netconnectionstatusW
, CIM_UINT16
, VT_I4
},
216 { prop_pnpdeviceidW
, CIM_STRING
},
217 { prop_speedW
, CIM_UINT64
}
219 static const struct column col_os
[] =
221 { prop_captionW
, CIM_STRING
},
222 { prop_csdversionW
, CIM_STRING
},
223 { prop_osarchitectureW
, CIM_STRING
},
224 { prop_oslanguageW
, CIM_UINT32
, VT_I4
},
225 { prop_systemdirectoryW
, CIM_STRING
}
227 static const struct column col_params
[] =
229 { prop_classW
, CIM_STRING
},
230 { prop_methodW
, CIM_STRING
},
231 { prop_directionW
, CIM_SINT32
},
232 { prop_parameterW
, CIM_STRING
},
233 { prop_typeW
, CIM_UINT32
},
234 { prop_defaultvalueW
, CIM_UINT32
}
236 static const struct column col_process
[] =
238 { prop_captionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
239 { prop_commandlineW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
240 { prop_descriptionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
241 { prop_handleW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
242 { prop_pprocessidW
, CIM_UINT32
, VT_I4
},
243 { prop_processidW
, CIM_UINT32
, VT_I4
},
244 { prop_threadcountW
, CIM_UINT32
, VT_I4
}
246 static const struct column col_processor
[] =
248 { prop_cpustatusW
, CIM_UINT16
},
249 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
250 { prop_manufacturerW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
251 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
252 { prop_processoridW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
254 static const struct column col_service
[] =
256 { prop_acceptpauseW
, CIM_BOOLEAN
},
257 { prop_acceptstopW
, CIM_BOOLEAN
},
258 { prop_displaynameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
259 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
260 { prop_processidW
, CIM_UINT32
},
261 { prop_servicetypeW
, CIM_STRING
},
262 { prop_stateW
, CIM_STRING
}
264 static const struct column col_stdregprov
[] =
266 { method_enumkeyW
, CIM_OBJECT
|COL_FLAG_METHOD
},
267 { method_enumvaluesW
, CIM_OBJECT
|COL_FLAG_METHOD
}
269 static const struct column col_videocontroller
[] =
271 { prop_adapterramW
, CIM_UINT32
},
272 { prop_currentbitsperpixelW
, CIM_UINT32
},
273 { prop_currenthorizontalresW
, CIM_UINT32
},
274 { prop_currentverticalresW
, CIM_UINT32
},
275 { prop_deviceidW
, CIM_STRING
|COL_FLAG_KEY
},
276 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
279 static const WCHAR baseboard_manufacturerW
[] =
280 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
281 static const WCHAR baseboard_serialnumberW
[] =
283 static const WCHAR baseboard_tagW
[] =
284 {'B','a','s','e',' ','B','o','a','r','d',0};
285 static const WCHAR bios_descriptionW
[] =
286 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
287 static const WCHAR bios_manufacturerW
[] =
288 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
289 static const WCHAR bios_releasedateW
[] =
290 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
291 static const WCHAR bios_serialnumberW
[] =
293 static const WCHAR compsys_descriptionW
[] =
294 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
295 static const WCHAR compsys_manufacturerW
[] =
296 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
297 static const WCHAR compsys_modelW
[] =
299 static const WCHAR networkadapter_pnpdeviceidW
[]=
300 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
301 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
302 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
303 static const WCHAR os_captionW
[] =
304 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
305 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
306 static const WCHAR os_csdversionW
[] =
307 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
308 static const WCHAR os_32bitW
[] =
309 {'3','2','-','b','i','t',0};
310 static const WCHAR os_64bitW
[] =
311 {'6','4','-','b','i','t',0};
312 static const WCHAR videocontroller_deviceidW
[] =
313 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
315 #include "pshpack1.h"
316 struct record_baseboard
318 const WCHAR
*manufacturer
;
319 const WCHAR
*serialnumber
;
324 const WCHAR
*description
;
325 const WCHAR
*manufacturer
;
326 const WCHAR
*releasedate
;
327 const WCHAR
*serialnumber
;
329 struct record_computersystem
331 const WCHAR
*description
;
332 const WCHAR
*manufacturer
;
334 UINT32 num_logical_processors
;
335 UINT32 num_processors
;
336 UINT64 total_physical_memory
;
338 struct record_logicaldisk
340 const WCHAR
*device_id
;
342 const WCHAR
*filesystem
;
346 struct record_networkadapter
348 const WCHAR
*device_id
;
349 INT32 interface_index
;
350 const WCHAR
*mac_address
;
351 UINT16 netconnection_status
;
352 const WCHAR
*pnpdevice_id
;
355 struct record_operatingsystem
357 const WCHAR
*caption
;
358 const WCHAR
*csdversion
;
359 const WCHAR
*osarchitecture
;
361 const WCHAR
*systemdirectory
;
368 const WCHAR
*parameter
;
372 struct record_process
374 const WCHAR
*caption
;
375 const WCHAR
*commandline
;
376 const WCHAR
*description
;
382 struct record_processor
385 const WCHAR
*device_id
;
386 const WCHAR
*manufacturer
;
388 const WCHAR
*processor_id
;
390 struct record_service
394 const WCHAR
*displayname
;
397 const WCHAR
*servicetype
;
400 struct record_stdregprov
402 class_method
*enumkey
;
403 class_method
*enumvalues
;
405 struct record_videocontroller
408 UINT32 current_bitsperpixel
;
409 UINT32 current_horizontalres
;
410 UINT32 current_verticalres
;
411 const WCHAR
*device_id
;
416 static HRESULT
reg_enumkey( IWbemClassObject
*in
, IWbemClassObject
**out
)
421 static HRESULT
reg_enumvalues( IWbemClassObject
*in
, IWbemClassObject
**out
)
427 static const struct record_baseboard data_baseboard
[] =
429 { baseboard_manufacturerW
, baseboard_serialnumberW
, baseboard_tagW
}
431 static const struct record_bios data_bios
[] =
433 { bios_descriptionW
, bios_manufacturerW
, bios_releasedateW
, bios_serialnumberW
}
435 static const struct record_params data_params
[] =
437 { class_stdregprovW
, method_enumkeyW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
438 { class_stdregprovW
, method_enumkeyW
, 1, param_subkeynameW
, CIM_STRING
},
439 { class_stdregprovW
, method_enumkeyW
, -1, param_returnvalueW
, CIM_UINT32
},
440 { class_stdregprovW
, method_enumkeyW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
441 { class_stdregprovW
, method_enumvaluesW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
442 { class_stdregprovW
, method_enumvaluesW
, 1, param_subkeynameW
, CIM_STRING
},
443 { class_stdregprovW
, method_enumvaluesW
, -1, param_returnvalueW
, CIM_UINT32
},
444 { class_stdregprovW
, method_enumvaluesW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
445 { class_stdregprovW
, method_enumvaluesW
, -1, param_typesW
, CIM_SINT32
|CIM_FLAG_ARRAY
}
447 static const struct record_stdregprov data_stdregprov
[] =
449 { reg_enumkey
, reg_enumvalues
}
452 static UINT
get_processor_count(void)
454 SYSTEM_BASIC_INFORMATION info
;
456 if (NtQuerySystemInformation( SystemBasicInformation
, &info
, sizeof(info
), NULL
)) return 1;
457 return info
.NumberOfProcessors
;
460 static UINT64
get_total_physical_memory(void)
462 MEMORYSTATUSEX status
;
464 status
.dwLength
= sizeof(status
);
465 if (!GlobalMemoryStatusEx( &status
)) return 1024 * 1024 * 1024;
466 return status
.ullTotalPhys
;
469 static void fill_compsys( struct table
*table
)
471 struct record_computersystem
*rec
;
473 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
475 rec
= (struct record_computersystem
*)table
->data
;
476 rec
->description
= compsys_descriptionW
;
477 rec
->manufacturer
= compsys_manufacturerW
;
478 rec
->model
= compsys_modelW
;
479 rec
->num_logical_processors
= get_processor_count();
480 rec
->num_processors
= rec
->num_logical_processors
;
481 rec
->total_physical_memory
= get_total_physical_memory();
483 TRACE("created 1 row\n");
487 static WCHAR
*get_filesystem( const WCHAR
*root
)
489 static const WCHAR ntfsW
[] = {'N','T','F','S',0};
490 WCHAR buffer
[MAX_PATH
+ 1];
492 if (GetVolumeInformationW( root
, NULL
, 0, NULL
, NULL
, NULL
, buffer
, MAX_PATH
+ 1 ))
493 return heap_strdupW( buffer
);
494 return heap_strdupW( ntfsW
);
497 static UINT64
get_freespace( const WCHAR
*dir
, UINT64
*disksize
)
499 WCHAR root
[] = {'\\','\\','.','\\','A',':',0};
501 DISK_GEOMETRY_EX info
;
504 free
.QuadPart
= 512 * 1024 * 1024;
505 GetDiskFreeSpaceExW( dir
, NULL
, NULL
, &free
);
508 handle
= CreateFileW( root
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
509 if (handle
!= INVALID_HANDLE_VALUE
)
511 if (DeviceIoControl( handle
, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
))
512 *disksize
= info
.DiskSize
.QuadPart
;
513 CloseHandle( handle
);
515 return free
.QuadPart
;
518 static void fill_logicaldisk( struct table
*table
)
520 static const WCHAR fmtW
[] = {'%','c',':',0};
521 WCHAR device_id
[3], root
[] = {'A',':','\\',0};
522 struct record_logicaldisk
*rec
;
523 UINT i
, num_rows
= 0, offset
= 0, count
= 4, type
;
524 UINT64 size
= 1024 * 1024 * 1024;
525 DWORD drives
= GetLogicalDrives();
527 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) return;
529 for (i
= 0; i
< sizeof(drives
); i
++)
531 if (drives
& (1 << i
))
534 type
= GetDriveTypeW( root
);
535 if (type
!= DRIVE_FIXED
&& type
!= DRIVE_CDROM
&& type
!= DRIVE_REMOVABLE
)
538 if (num_rows
> count
)
542 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) return;
545 rec
= (struct record_logicaldisk
*)(table
->data
+ offset
);
546 sprintfW( device_id
, fmtW
, 'A' + i
);
547 rec
->device_id
= heap_strdupW( device_id
);
548 rec
->drivetype
= type
;
549 rec
->filesystem
= get_filesystem( root
);
550 rec
->freespace
= get_freespace( root
, &size
);
552 offset
+= sizeof(*rec
);
556 TRACE("created %u rows\n", num_rows
);
557 table
->num_rows
= num_rows
;
560 static UINT16
get_connection_status( IF_OPER_STATUS status
)
564 case IfOperStatusDown
:
565 return 0; /* Disconnected */
567 return 2; /* Connected */
569 ERR("unhandled status %u\n", status
);
574 static WCHAR
*get_mac_address( const BYTE
*addr
, DWORD len
)
576 static const WCHAR fmtW
[] =
577 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
578 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
581 if (len
!= 6 || !(ret
= heap_alloc( 18 * sizeof(WCHAR
) ))) return NULL
;
582 sprintfW( ret
, fmtW
, addr
[0], addr
[1], addr
[2], addr
[3], addr
[4], addr
[5] );
586 static void fill_networkadapter( struct table
*table
)
588 static const WCHAR fmtW
[] = {'%','u',0};
590 struct record_networkadapter
*rec
;
591 IP_ADAPTER_ADDRESSES
*aa
, *buffer
;
592 UINT num_rows
= 0, offset
= 0;
595 ret
= GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, NULL
, &size
);
596 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
598 if (!(buffer
= heap_alloc( size
))) return;
599 if (GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, buffer
, &size
))
604 for (aa
= buffer
; aa
; aa
= aa
->Next
) num_rows
++;
605 if (!(table
->data
= heap_alloc( sizeof(*rec
) * num_rows
)))
610 for (aa
= buffer
; aa
; aa
= aa
->Next
)
612 rec
= (struct record_networkadapter
*)(table
->data
+ offset
);
613 sprintfW( device_id
, fmtW
, aa
->u
.s
.IfIndex
);
614 rec
->device_id
= heap_strdupW( device_id
);
615 rec
->interface_index
= aa
->u
.s
.IfIndex
;
616 rec
->mac_address
= get_mac_address( aa
->PhysicalAddress
, aa
->PhysicalAddressLength
);
617 rec
->netconnection_status
= get_connection_status( aa
->OperStatus
);
618 rec
->pnpdevice_id
= networkadapter_pnpdeviceidW
;
619 rec
->speed
= 1000000;
620 offset
+= sizeof(*rec
);
622 TRACE("created %u rows\n", num_rows
);
623 table
->num_rows
= num_rows
;
628 static WCHAR
*get_cmdline( DWORD process_id
)
630 if (process_id
== GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
631 return NULL
; /* FIXME handle different process case */
634 static void fill_process( struct table
*table
)
636 static const WCHAR fmtW
[] = {'%','u',0};
638 struct record_process
*rec
;
639 PROCESSENTRY32W entry
;
641 UINT num_rows
= 0, offset
= 0, count
= 8;
643 snap
= CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
644 if (snap
== INVALID_HANDLE_VALUE
) return;
646 entry
.dwSize
= sizeof(entry
);
647 if (!Process32FirstW( snap
, &entry
)) goto done
;
648 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) goto done
;
652 if (num_rows
> count
)
656 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) goto done
;
659 rec
= (struct record_process
*)(table
->data
+ offset
);
660 rec
->caption
= heap_strdupW( entry
.szExeFile
);
661 rec
->commandline
= get_cmdline( entry
.th32ProcessID
);
662 rec
->description
= heap_strdupW( entry
.szExeFile
);
663 sprintfW( handle
, fmtW
, entry
.th32ProcessID
);
664 rec
->handle
= heap_strdupW( handle
);
665 rec
->process_id
= entry
.th32ProcessID
;
666 rec
->pprocess_id
= entry
.th32ParentProcessID
;
667 rec
->thread_count
= entry
.cntThreads
;
668 offset
+= sizeof(*rec
);
670 } while (Process32NextW( snap
, &entry
));
672 TRACE("created %u rows\n", num_rows
);
673 table
->num_rows
= num_rows
;
679 static inline void do_cpuid( unsigned int ax
, unsigned int *p
)
682 __asm__("pushl %%ebx\n\t"
684 "movl %%ebx, %%esi\n\t"
686 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
691 static void get_processor_id( WCHAR
*processor_id
)
693 static const WCHAR fmtW
[] = {'%','0','8','X','%','0','8','X',0};
694 unsigned int regs
[4] = {0, 0, 0, 0};
697 sprintfW( processor_id
, fmtW
, regs
[3], regs
[0] );
699 static void regs_to_str( unsigned int *regs
, unsigned int len
, WCHAR
*buffer
)
702 unsigned char *p
= (unsigned char *)regs
;
704 for (i
= 0; i
< len
; i
++)
710 static void get_processor_manufacturer( WCHAR
*manufacturer
)
712 unsigned int tmp
, regs
[4] = {0, 0, 0, 0};
715 tmp
= regs
[2]; /* swap edx and ecx */
719 regs_to_str( regs
+ 1, 12, manufacturer
);
721 static void get_processor_name( WCHAR
*name
)
723 unsigned int regs
[4] = {0, 0, 0, 0};
725 do_cpuid( 0x80000000, regs
);
726 if (regs
[0] >= 0x80000004)
728 do_cpuid( 0x80000002, regs
);
729 regs_to_str( regs
, 16, name
);
730 do_cpuid( 0x80000003, regs
);
731 regs_to_str( regs
, 16, name
+ 16 );
732 do_cpuid( 0x80000004, regs
);
733 regs_to_str( regs
, 16, name
+ 32 );
737 static void fill_processor( struct table
*table
)
739 static const WCHAR fmtW
[] = {'C','P','U','%','u',0};
740 WCHAR device_id
[14], processor_id
[17], manufacturer
[13], name
[49] = {0};
741 struct record_processor
*rec
;
742 UINT i
, offset
= 0, count
= get_processor_count();
744 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) return;
746 get_processor_id( processor_id
);
747 get_processor_manufacturer( manufacturer
);
748 get_processor_name( name
);
750 for (i
= 0; i
< count
; i
++)
752 rec
= (struct record_processor
*)(table
->data
+ offset
);
753 rec
->cpu_status
= 1; /* CPU Enabled */
754 sprintfW( device_id
, fmtW
, i
);
755 rec
->device_id
= heap_strdupW( device_id
);
756 rec
->manufacturer
= heap_strdupW( manufacturer
);
757 rec
->name
= heap_strdupW( name
);
758 rec
->processor_id
= heap_strdupW( processor_id
);
759 offset
+= sizeof(*rec
);
762 TRACE("created %u rows\n", count
);
763 table
->num_rows
= count
;
766 static void fill_os( struct table
*table
)
768 struct record_operatingsystem
*rec
;
769 WCHAR path
[MAX_PATH
];
773 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
775 rec
= (struct record_operatingsystem
*)table
->data
;
776 rec
->caption
= os_captionW
;
777 rec
->csdversion
= os_csdversionW
;
779 GetNativeSystemInfo( &info
);
780 if (info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
781 rec
->osarchitecture
= os_64bitW
;
783 rec
->osarchitecture
= os_32bitW
;
785 rec
->oslanguage
= MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
787 Wow64DisableWow64FsRedirection( &redir
);
788 GetSystemDirectoryW( path
, MAX_PATH
);
789 Wow64RevertWow64FsRedirection( redir
);
790 rec
->systemdirectory
= heap_strdupW( path
);
792 TRACE("created 1 row\n");
796 static const WCHAR
*get_service_type( DWORD type
)
798 static const WCHAR filesystem_driverW
[] =
799 {'F','i','l','e',' ','S','y','s','t','e','m',' ','D','r','i','v','e','r',0};
800 static const WCHAR kernel_driverW
[] =
801 {'K','e','r','n','e','l',' ','D','r','i','v','e','r',0};
802 static const WCHAR own_processW
[] =
803 {'O','w','n',' ','P','r','o','c','e','s','s',0};
804 static const WCHAR share_processW
[] =
805 {'S','h','a','r','e',' ','P','r','o','c','e','s','s',0};
807 if (type
& SERVICE_KERNEL_DRIVER
) return kernel_driverW
;
808 else if (type
& SERVICE_FILE_SYSTEM_DRIVER
) return filesystem_driverW
;
809 else if (type
& SERVICE_WIN32_OWN_PROCESS
) return own_processW
;
810 else if (type
& SERVICE_WIN32_SHARE_PROCESS
) return share_processW
;
811 else ERR("unhandled type 0x%08x\n", type
);
814 static const WCHAR
*get_service_state( DWORD state
)
816 static const WCHAR runningW
[] =
817 {'R','u','n','n','i','n','g',0};
818 static const WCHAR start_pendingW
[] =
819 {'S','t','a','r','t',' ','P','e','n','d','i','n','g',0};
820 static const WCHAR stop_pendingW
[] =
821 {'S','t','o','p',' ','P','e','n','d','i','n','g',0};
822 static const WCHAR stoppedW
[] =
823 {'S','t','o','p','p','e','d',0};
824 static const WCHAR unknownW
[] =
825 {'U','n','k','n','o','w','n',0};
829 case SERVICE_STOPPED
: return stoppedW
;
830 case SERVICE_START_PENDING
: return start_pendingW
;
831 case SERVICE_STOP_PENDING
: return stop_pendingW
;
832 case SERVICE_RUNNING
: return runningW
;
834 ERR("unknown state %u\n", state
);
839 static void fill_service( struct table
*table
)
841 struct record_service
*rec
;
843 ENUM_SERVICE_STATUS_PROCESSW
*tmp
, *services
= NULL
;
844 SERVICE_STATUS_PROCESS
*status
;
845 UINT i
, num_rows
= 0, offset
= 0, size
= 256, needed
, count
;
848 if (!(manager
= OpenSCManagerW( NULL
, NULL
, SC_MANAGER_ENUMERATE_SERVICE
))) return;
849 if (!(services
= heap_alloc( size
))) goto done
;
851 ret
= EnumServicesStatusExW( manager
, SC_ENUM_PROCESS_INFO
, SERVICE_TYPE_ALL
,
852 SERVICE_STATE_ALL
, (BYTE
*)services
, size
, &needed
,
853 &count
, NULL
, NULL
);
856 if (GetLastError() != ERROR_MORE_DATA
) goto done
;
858 if (!(tmp
= heap_realloc( services
, size
))) goto done
;
860 ret
= EnumServicesStatusExW( manager
, SC_ENUM_PROCESS_INFO
, SERVICE_TYPE_ALL
,
861 SERVICE_STATE_ALL
, (BYTE
*)services
, size
, &needed
,
862 &count
, NULL
, NULL
);
865 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) goto done
;
867 for (i
= 0; i
< count
; i
++)
869 status
= &services
[i
].ServiceStatusProcess
;
870 rec
= (struct record_service
*)(table
->data
+ offset
);
871 rec
->accept_pause
= (status
->dwControlsAccepted
& SERVICE_ACCEPT_PAUSE_CONTINUE
) ? -1 : 0;
872 rec
->accept_stop
= (status
->dwControlsAccepted
& SERVICE_ACCEPT_STOP
) ? -1 : 0;
873 rec
->displayname
= heap_strdupW( services
[i
].lpDisplayName
);
874 rec
->name
= heap_strdupW( services
[i
].lpServiceName
);
875 rec
->process_id
= status
->dwProcessId
;
876 rec
->servicetype
= get_service_type( status
->dwServiceType
);
877 rec
->state
= get_service_state( status
->dwCurrentState
);
878 offset
+= sizeof(*rec
);
882 TRACE("created %u rows\n", num_rows
);
883 table
->num_rows
= num_rows
;
886 CloseServiceHandle( manager
);
887 heap_free( services
);
890 static UINT32
get_bits_per_pixel( UINT
*hres
, UINT
*vres
)
892 HDC hdc
= GetDC( NULL
);
896 ret
= GetDeviceCaps( hdc
, BITSPIXEL
);
897 *hres
= GetDeviceCaps( hdc
, HORZRES
);
898 *vres
= GetDeviceCaps( hdc
, VERTRES
);
899 ReleaseDC( NULL
, hdc
);
903 static void fill_videocontroller( struct table
*table
)
906 struct record_videocontroller
*rec
;
908 IDXGIFactory
*factory
= NULL
;
909 IDXGIAdapter
*adapter
= NULL
;
910 DXGI_ADAPTER_DESC desc
;
911 UINT hres
= 1024, vres
= 768, vidmem
= 512 * 1024 * 1024;
912 const WCHAR
*name
= videocontroller_deviceidW
;
914 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
916 hr
= CreateDXGIFactory( &IID_IDXGIFactory
, (void **)&factory
);
917 if (FAILED(hr
)) goto done
;
919 hr
= IDXGIFactory_EnumAdapters( factory
, 0, &adapter
);
920 if (FAILED(hr
)) goto done
;
922 hr
= IDXGIAdapter_GetDesc( adapter
, &desc
);
925 vidmem
= desc
.DedicatedVideoMemory
;
926 name
= desc
.Description
;
930 rec
= (struct record_videocontroller
*)table
->data
;
931 rec
->adapter_ram
= vidmem
;
932 rec
->current_bitsperpixel
= get_bits_per_pixel( &hres
, &vres
);
933 rec
->current_horizontalres
= hres
;
934 rec
->current_verticalres
= vres
;
935 rec
->device_id
= videocontroller_deviceidW
;
936 rec
->name
= heap_strdupW( name
);
938 TRACE("created 1 row\n");
941 if (adapter
) IDXGIAdapter_Release( adapter
);
942 if (factory
) IDXGIFactory_Release( factory
);
945 static struct table builtin_classes
[] =
947 { class_baseboardW
, SIZEOF(col_baseboard
), col_baseboard
, SIZEOF(data_baseboard
), (BYTE
*)data_baseboard
},
948 { class_biosW
, SIZEOF(col_bios
), col_bios
, SIZEOF(data_bios
), (BYTE
*)data_bios
},
949 { class_compsysW
, SIZEOF(col_compsys
), col_compsys
, 0, NULL
, fill_compsys
},
950 { class_logicaldiskW
, SIZEOF(col_logicaldisk
), col_logicaldisk
, 0, NULL
, fill_logicaldisk
},
951 { class_networkadapterW
, SIZEOF(col_networkadapter
), col_networkadapter
, 0, NULL
, fill_networkadapter
},
952 { class_osW
, SIZEOF(col_os
), col_os
, 0, NULL
, fill_os
},
953 { class_paramsW
, SIZEOF(col_params
), col_params
, SIZEOF(data_params
), (BYTE
*)data_params
},
954 { class_processW
, SIZEOF(col_process
), col_process
, 0, NULL
, fill_process
},
955 { class_processorW
, SIZEOF(col_processor
), col_processor
, 0, NULL
, fill_processor
},
956 { class_serviceW
, SIZEOF(col_service
), col_service
, 0, NULL
, fill_service
},
957 { class_stdregprovW
, SIZEOF(col_stdregprov
), col_stdregprov
, SIZEOF(data_stdregprov
), (BYTE
*)data_stdregprov
},
958 { class_videocontrollerW
, SIZEOF(col_videocontroller
), col_videocontroller
, 0, NULL
, fill_videocontroller
}
961 void init_table_list( void )
963 static struct list tables
= LIST_INIT( tables
);
966 for (i
= 0; i
< SIZEOF(builtin_classes
); i
++)
968 list_add_tail( &tables
, &builtin_classes
[i
].entry
);
970 table_list
= &tables
;