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
37 #include "wine/debug.h"
38 #include "wbemprox_private.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
42 static const WCHAR class_baseboardW
[] =
43 {'W','i','n','3','2','_','B','a','s','e','B','o','a','r','d',0};
44 static const WCHAR class_biosW
[] =
45 {'W','i','n','3','2','_','B','I','O','S',0};
46 static const WCHAR class_compsysW
[] =
47 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
48 static const WCHAR class_logicaldiskW
[] =
49 {'W','i','n','3','2','_','L','o','g','i','c','a','l','D','i','s','k',0};
50 static const WCHAR class_networkadapterW
[] =
51 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
52 static const WCHAR class_osW
[] =
53 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
54 static const WCHAR class_paramsW
[] =
55 {'_','_','P','A','R','A','M','E','T','E','R','S',0};
56 static const WCHAR class_processW
[] =
57 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
58 static const WCHAR class_processorW
[] =
59 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
60 static const WCHAR class_stdregprovW
[] =
61 {'S','t','d','R','e','g','P','r','o','v',0};
62 static const WCHAR class_videocontrollerW
[] =
63 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
65 static const WCHAR prop_adapterramW
[] =
66 {'A','d','a','p','t','e','r','R','A','M',0};
67 static const WCHAR prop_captionW
[] =
68 {'C','a','p','t','i','o','n',0};
69 static const WCHAR prop_classW
[] =
70 {'C','l','a','s','s',0};
71 static const WCHAR prop_commandlineW
[] =
72 {'C','o','m','m','a','n','d','L','i','n','e',0};
73 static const WCHAR prop_cpustatusW
[] =
74 {'C','p','u','S','t','a','t','u','s',0};
75 static const WCHAR prop_csdversionW
[] =
76 {'C','S','D','V','e','r','s','i','o','n',0};
77 static const WCHAR prop_currentbitsperpixelW
[] =
78 {'C','u','r','r','e','n','t','B','i','t','s','P','e','r','P','i','x','e','l',0};
79 static const WCHAR prop_currenthorizontalresW
[] =
80 {'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};
81 static const WCHAR prop_currentverticalresW
[] =
82 {'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};
83 static const WCHAR prop_defaultvalueW
[] =
84 {'D','e','f','a','u','l','t','V','a','l','u','e',0};
85 static const WCHAR prop_descriptionW
[] =
86 {'D','e','s','c','r','i','p','t','i','o','n',0};
87 static const WCHAR prop_deviceidW
[] =
88 {'D','e','v','i','c','e','I','d',0};
89 static const WCHAR prop_directionW
[] =
90 {'D','i','r','e','c','t','i','o','n',0};
91 static const WCHAR prop_drivetypeW
[] =
92 {'D','r','i','v','e','T','y','p','e',0};
93 static const WCHAR prop_filesystemW
[] =
94 {'F','i','l','e','S','y','s','t','e','m',0};
95 static const WCHAR prop_freespaceW
[] =
96 {'F','r','e','e','S','p','a','c','e',0};
97 static const WCHAR prop_handleW
[] =
98 {'H','a','n','d','l','e',0};
99 static const WCHAR prop_interfaceindexW
[] =
100 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
101 static const WCHAR prop_macaddressW
[] =
102 {'M','A','C','A','d','d','r','e','s','s',0};
103 static const WCHAR prop_manufacturerW
[] =
104 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
105 static const WCHAR prop_methodW
[] =
106 {'M','e','t','h','o','d',0};
107 static const WCHAR prop_modelW
[] =
108 {'M','o','d','e','l',0};
109 static const WCHAR prop_nameW
[] =
111 static const WCHAR prop_netconnectionstatusW
[] =
112 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
113 static const WCHAR prop_numlogicalprocessorsW
[] =
114 {'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};
115 static const WCHAR prop_numprocessorsW
[] =
116 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
117 static const WCHAR prop_osarchitectureW
[] =
118 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
119 static const WCHAR prop_oslanguageW
[] =
120 {'O','S','L','a','n','g','u','a','g','e',0};
121 static const WCHAR prop_parameterW
[] =
122 {'P','a','r','a','m','e','t','e','r',0};
123 static const WCHAR prop_pnpdeviceidW
[] =
124 {'P','N','P','D','e','v','i','c','e','I','D',0};
125 static const WCHAR prop_pprocessidW
[] =
126 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
127 static const WCHAR prop_processidW
[] =
128 {'P','r','o','c','e','s','s','I','D',0};
129 static const WCHAR prop_processoridW
[] =
130 {'P','r','o','c','e','s','s','o','r','I','d',0};
131 static const WCHAR prop_releasedateW
[] =
132 {'R','e','l','e','a','s','e','D','a','t','e',0};
133 static const WCHAR prop_serialnumberW
[] =
134 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
135 static const WCHAR prop_sizeW
[] =
137 static const WCHAR prop_speedW
[] =
138 {'S','p','e','e','d',0};
139 static const WCHAR prop_systemdirectoryW
[] =
140 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
141 static const WCHAR prop_tagW
[] =
143 static const WCHAR prop_threadcountW
[] =
144 {'T','h','r','e','a','d','C','o','u','n','t',0};
145 static const WCHAR prop_totalphysicalmemoryW
[] =
146 {'T','o','t','a','l','P','h','y','s','i','c','a','l','M','e','m','o','r','y',0};
147 static const WCHAR prop_typeW
[] =
150 static const WCHAR method_enumkeyW
[] =
151 {'E','n','u','m','K','e','y',0};
152 static const WCHAR method_enumvaluesW
[] =
153 {'E','n','u','m','V','a','l','u','e','s',0};
155 static const WCHAR param_defkeyW
[] =
156 {'h','D','e','f','K','e','y',0};
157 static const WCHAR param_namesW
[] =
158 {'N','a','m','e','s',0};
159 static const WCHAR param_returnvalueW
[] =
160 {'R','e','t','u','r','n','V','a','l','u','e',0};
161 static const WCHAR param_subkeynameW
[] =
162 {'s','S','u','b','K','e','y','N','a','m','e',0};
163 static const WCHAR param_typesW
[] =
164 {'T','y','p','e','s',0};
166 /* column definitions must be kept in sync with record structures below */
167 static const struct column col_baseboard
[] =
169 { prop_manufacturerW
, CIM_STRING
},
170 { prop_serialnumberW
, CIM_STRING
},
171 { prop_tagW
, CIM_STRING
|COL_FLAG_KEY
}
173 static const struct column col_bios
[] =
175 { prop_descriptionW
, CIM_STRING
},
176 { prop_manufacturerW
, CIM_STRING
},
177 { prop_releasedateW
, CIM_DATETIME
},
178 { prop_serialnumberW
, CIM_STRING
}
180 static const struct column col_compsys
[] =
182 { prop_descriptionW
, CIM_STRING
},
183 { prop_manufacturerW
, CIM_STRING
},
184 { prop_modelW
, CIM_STRING
},
185 { prop_numlogicalprocessorsW
, CIM_UINT32
, VT_I4
},
186 { prop_numprocessorsW
, CIM_UINT32
, VT_I4
},
187 { prop_totalphysicalmemoryW
, CIM_UINT64
}
189 static const struct column col_logicaldisk
[] =
191 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
192 { prop_drivetypeW
, CIM_UINT32
, VT_I4
},
193 { prop_filesystemW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
194 { prop_freespaceW
, CIM_UINT64
},
195 { prop_sizeW
, CIM_UINT64
}
197 static const struct column col_networkadapter
[] =
199 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
200 { prop_interfaceindexW
, CIM_UINT32
, VT_I4
},
201 { prop_macaddressW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
202 { prop_netconnectionstatusW
, CIM_UINT16
, VT_I4
},
203 { prop_pnpdeviceidW
, CIM_STRING
},
204 { prop_speedW
, CIM_UINT64
}
206 static const struct column col_os
[] =
208 { prop_captionW
, CIM_STRING
},
209 { prop_csdversionW
, CIM_STRING
},
210 { prop_osarchitectureW
, CIM_STRING
},
211 { prop_oslanguageW
, CIM_UINT32
, VT_I4
},
212 { prop_systemdirectoryW
, CIM_STRING
}
214 static const struct column col_params
[] =
216 { prop_classW
, CIM_STRING
},
217 { prop_methodW
, CIM_STRING
},
218 { prop_directionW
, CIM_SINT32
},
219 { prop_parameterW
, CIM_STRING
},
220 { prop_typeW
, CIM_UINT32
},
221 { prop_defaultvalueW
, CIM_UINT32
}
223 static const struct column col_process
[] =
225 { prop_captionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
226 { prop_commandlineW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
227 { prop_descriptionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
228 { prop_handleW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
229 { prop_pprocessidW
, CIM_UINT32
, VT_I4
},
230 { prop_processidW
, CIM_UINT32
, VT_I4
},
231 { prop_threadcountW
, CIM_UINT32
, VT_I4
}
233 static const struct column col_processor
[] =
235 { prop_cpustatusW
, CIM_UINT16
},
236 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
237 { prop_manufacturerW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
238 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
239 { prop_processoridW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
241 static const struct column col_stdregprov
[] =
243 { method_enumkeyW
, CIM_OBJECT
|COL_FLAG_METHOD
},
244 { method_enumvaluesW
, CIM_OBJECT
|COL_FLAG_METHOD
}
246 static const struct column col_videocontroller
[] =
248 { prop_adapterramW
, CIM_UINT32
},
249 { prop_currentbitsperpixelW
, CIM_UINT32
},
250 { prop_currenthorizontalresW
, CIM_UINT32
},
251 { prop_currentverticalresW
, CIM_UINT32
},
252 { prop_deviceidW
, CIM_STRING
|COL_FLAG_KEY
},
253 { prop_nameW
, CIM_STRING
|COL_FLAG_DYNAMIC
}
256 static const WCHAR baseboard_manufacturerW
[] =
257 {'I','n','t','e','l',' ','C','o','r','p','o','r','a','t','i','o','n',0};
258 static const WCHAR baseboard_serialnumberW
[] =
260 static const WCHAR baseboard_tagW
[] =
261 {'B','a','s','e',' ','B','o','a','r','d',0};
262 static const WCHAR bios_descriptionW
[] =
263 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
264 static const WCHAR bios_manufacturerW
[] =
265 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
266 static const WCHAR bios_releasedateW
[] =
267 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
268 static const WCHAR bios_serialnumberW
[] =
270 static const WCHAR compsys_descriptionW
[] =
271 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
272 static const WCHAR compsys_manufacturerW
[] =
273 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
274 static const WCHAR compsys_modelW
[] =
276 static const WCHAR networkadapter_pnpdeviceidW
[]=
277 {'P','C','I','\\','V','E','N','_','8','0','8','6','&','D','E','V','_','1','0','0','E','&',
278 'S','U','B','S','Y','S','_','0','0','1','E','8','0','8','6','&','R','E','V','_','0','2','\\',
279 '3','&','2','6','7','A','6','1','6','A','&','1','&','1','8',0};
280 static const WCHAR os_captionW
[] =
281 {'M','i','c','r','o','s','o','f','t',' ','W','i','n','d','o','w','s',' ','X','P',' ',
282 'V','e','r','s','i','o','n',' ','=',' ','5','.','1','.','2','6','0','0',0};
283 static const WCHAR os_csdversionW
[] =
284 {'S','e','r','v','i','c','e',' ','P','a','c','k',' ','3',0};
285 static const WCHAR os_32bitW
[] =
286 {'3','2','-','b','i','t',0};
287 static const WCHAR os_64bitW
[] =
288 {'6','4','-','b','i','t',0};
289 static const WCHAR videocontroller_deviceidW
[] =
290 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
292 #include "pshpack1.h"
293 struct record_baseboard
295 const WCHAR
*manufacturer
;
296 const WCHAR
*serialnumber
;
301 const WCHAR
*description
;
302 const WCHAR
*manufacturer
;
303 const WCHAR
*releasedate
;
304 const WCHAR
*serialnumber
;
306 struct record_computersystem
308 const WCHAR
*description
;
309 const WCHAR
*manufacturer
;
311 UINT32 num_logical_processors
;
312 UINT32 num_processors
;
313 UINT64 total_physical_memory
;
315 struct record_logicaldisk
317 const WCHAR
*device_id
;
319 const WCHAR
*filesystem
;
323 struct record_networkadapter
325 const WCHAR
*device_id
;
326 INT32 interface_index
;
327 const WCHAR
*mac_address
;
328 UINT16 netconnection_status
;
329 const WCHAR
*pnpdevice_id
;
332 struct record_operatingsystem
334 const WCHAR
*caption
;
335 const WCHAR
*csdversion
;
336 const WCHAR
*osarchitecture
;
338 const WCHAR
*systemdirectory
;
345 const WCHAR
*parameter
;
349 struct record_process
351 const WCHAR
*caption
;
352 const WCHAR
*commandline
;
353 const WCHAR
*description
;
359 struct record_processor
362 const WCHAR
*device_id
;
363 const WCHAR
*manufacturer
;
365 const WCHAR
*processor_id
;
367 struct record_stdregprov
369 class_method
*enumkey
;
370 class_method
*enumvalues
;
372 struct record_videocontroller
375 UINT32 current_bitsperpixel
;
376 UINT32 current_horizontalres
;
377 UINT32 current_verticalres
;
378 const WCHAR
*device_id
;
383 static HRESULT
reg_enumkey( IWbemClassObject
*in
, IWbemClassObject
**out
)
388 static HRESULT
reg_enumvalues( IWbemClassObject
*in
, IWbemClassObject
**out
)
394 static const struct record_baseboard data_baseboard
[] =
396 { baseboard_manufacturerW
, baseboard_serialnumberW
, baseboard_tagW
}
398 static const struct record_bios data_bios
[] =
400 { bios_descriptionW
, bios_manufacturerW
, bios_releasedateW
, bios_serialnumberW
}
402 static const struct record_params data_params
[] =
404 { class_stdregprovW
, method_enumkeyW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
405 { class_stdregprovW
, method_enumkeyW
, 1, param_subkeynameW
, CIM_STRING
},
406 { class_stdregprovW
, method_enumkeyW
, -1, param_returnvalueW
, CIM_UINT32
},
407 { class_stdregprovW
, method_enumkeyW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
408 { class_stdregprovW
, method_enumvaluesW
, 1, param_defkeyW
, CIM_UINT32
, 0x80000002 },
409 { class_stdregprovW
, method_enumvaluesW
, 1, param_subkeynameW
, CIM_STRING
},
410 { class_stdregprovW
, method_enumvaluesW
, -1, param_returnvalueW
, CIM_UINT32
},
411 { class_stdregprovW
, method_enumvaluesW
, -1, param_namesW
, CIM_STRING
|CIM_FLAG_ARRAY
},
412 { class_stdregprovW
, method_enumvaluesW
, -1, param_typesW
, CIM_SINT32
|CIM_FLAG_ARRAY
}
414 static const struct record_stdregprov data_stdregprov
[] =
416 { reg_enumkey
, reg_enumvalues
}
419 static UINT
get_processor_count(void)
421 SYSTEM_BASIC_INFORMATION info
;
423 if (NtQuerySystemInformation( SystemBasicInformation
, &info
, sizeof(info
), NULL
)) return 1;
424 return info
.NumberOfProcessors
;
427 static UINT64
get_total_physical_memory(void)
429 MEMORYSTATUSEX status
;
431 status
.dwLength
= sizeof(status
);
432 if (!GlobalMemoryStatusEx( &status
)) return 1024 * 1024 * 1024;
433 return status
.ullTotalPhys
;
436 static void fill_compsys( struct table
*table
)
438 struct record_computersystem
*rec
;
440 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
442 rec
= (struct record_computersystem
*)table
->data
;
443 rec
->description
= compsys_descriptionW
;
444 rec
->manufacturer
= compsys_manufacturerW
;
445 rec
->model
= compsys_modelW
;
446 rec
->num_logical_processors
= get_processor_count();
447 rec
->num_processors
= rec
->num_logical_processors
;
448 rec
->total_physical_memory
= get_total_physical_memory();
450 TRACE("created 1 row\n");
454 static WCHAR
*get_filesystem( const WCHAR
*root
)
456 static const WCHAR ntfsW
[] = {'N','T','F','S',0};
457 WCHAR buffer
[MAX_PATH
+ 1];
459 if (GetVolumeInformationW( root
, NULL
, 0, NULL
, NULL
, NULL
, buffer
, MAX_PATH
+ 1 ))
460 return heap_strdupW( buffer
);
461 return heap_strdupW( ntfsW
);
464 static UINT64
get_freespace( const WCHAR
*dir
, UINT64
*disksize
)
466 WCHAR root
[] = {'\\','\\','.','\\','A',':',0};
468 DISK_GEOMETRY_EX info
;
471 free
.QuadPart
= 512 * 1024 * 1024;
472 GetDiskFreeSpaceExW( dir
, NULL
, NULL
, &free
);
475 handle
= CreateFileW( root
, GENERIC_READ
, FILE_SHARE_READ
|FILE_SHARE_WRITE
, NULL
, OPEN_EXISTING
, 0, 0 );
476 if (handle
!= INVALID_HANDLE_VALUE
)
478 if (DeviceIoControl( handle
, IOCTL_DISK_GET_DRIVE_GEOMETRY_EX
, NULL
, 0, &info
, sizeof(info
), NULL
, NULL
))
479 *disksize
= info
.DiskSize
.QuadPart
;
480 CloseHandle( handle
);
482 return free
.QuadPart
;
485 static void fill_logicaldisk( struct table
*table
)
487 static const WCHAR fmtW
[] = {'%','c',':',0};
488 WCHAR device_id
[3], root
[] = {'A',':','\\',0};
489 struct record_logicaldisk
*rec
;
490 UINT i
, num_rows
= 0, offset
= 0, count
= 4, type
;
491 UINT64 size
= 1024 * 1024 * 1024;
492 DWORD drives
= GetLogicalDrives();
494 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) return;
496 for (i
= 0; i
< sizeof(drives
); i
++)
498 if (drives
& (1 << i
))
501 type
= GetDriveTypeW( root
);
502 if (type
!= DRIVE_FIXED
&& type
!= DRIVE_CDROM
&& type
!= DRIVE_REMOVABLE
)
505 if (num_rows
> count
)
509 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) return;
512 rec
= (struct record_logicaldisk
*)(table
->data
+ offset
);
513 sprintfW( device_id
, fmtW
, 'A' + i
);
514 rec
->device_id
= heap_strdupW( device_id
);
515 rec
->drivetype
= type
;
516 rec
->filesystem
= get_filesystem( root
);
517 rec
->freespace
= get_freespace( root
, &size
);
519 offset
+= sizeof(*rec
);
523 TRACE("created %u rows\n", num_rows
);
524 table
->num_rows
= num_rows
;
527 static UINT16
get_connection_status( IF_OPER_STATUS status
)
531 case IfOperStatusDown
:
532 return 0; /* Disconnected */
534 return 2; /* Connected */
536 ERR("unhandled status %u\n", status
);
541 static WCHAR
*get_mac_address( const BYTE
*addr
, DWORD len
)
543 static const WCHAR fmtW
[] =
544 {'%','0','2','x',':','%','0','2','x',':','%','0','2','x',':',
545 '%','0','2','x',':','%','0','2','x',':','%','0','2','x',0};
548 if (len
!= 6 || !(ret
= heap_alloc( 18 * sizeof(WCHAR
) ))) return NULL
;
549 sprintfW( ret
, fmtW
, addr
[0], addr
[1], addr
[2], addr
[3], addr
[4], addr
[5] );
553 static void fill_networkadapter( struct table
*table
)
555 static const WCHAR fmtW
[] = {'%','u',0};
557 struct record_networkadapter
*rec
;
558 IP_ADAPTER_ADDRESSES
*aa
, *buffer
;
559 UINT num_rows
= 0, offset
= 0;
562 ret
= GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, NULL
, &size
);
563 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
565 if (!(buffer
= heap_alloc( size
))) return;
566 if (GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, buffer
, &size
))
571 for (aa
= buffer
; aa
; aa
= aa
->Next
) num_rows
++;
572 if (!(table
->data
= heap_alloc( sizeof(*rec
) * num_rows
)))
577 for (aa
= buffer
; aa
; aa
= aa
->Next
)
579 rec
= (struct record_networkadapter
*)(table
->data
+ offset
);
580 sprintfW( device_id
, fmtW
, aa
->u
.s
.IfIndex
);
581 rec
->device_id
= heap_strdupW( device_id
);
582 rec
->interface_index
= aa
->u
.s
.IfIndex
;
583 rec
->mac_address
= get_mac_address( aa
->PhysicalAddress
, aa
->PhysicalAddressLength
);
584 rec
->netconnection_status
= get_connection_status( aa
->OperStatus
);
585 rec
->pnpdevice_id
= networkadapter_pnpdeviceidW
;
586 rec
->speed
= 1000000;
587 offset
+= sizeof(*rec
);
589 TRACE("created %u rows\n", num_rows
);
590 table
->num_rows
= num_rows
;
595 static WCHAR
*get_cmdline( DWORD process_id
)
597 if (process_id
== GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
598 return NULL
; /* FIXME handle different process case */
601 static void fill_process( struct table
*table
)
603 static const WCHAR fmtW
[] = {'%','u',0};
605 struct record_process
*rec
;
606 PROCESSENTRY32W entry
;
608 UINT num_rows
= 0, offset
= 0, count
= 8;
610 snap
= CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
611 if (snap
== INVALID_HANDLE_VALUE
) return;
613 entry
.dwSize
= sizeof(entry
);
614 if (!Process32FirstW( snap
, &entry
)) goto done
;
615 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) goto done
;
619 if (num_rows
> count
)
623 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) goto done
;
626 rec
= (struct record_process
*)(table
->data
+ offset
);
627 rec
->caption
= heap_strdupW( entry
.szExeFile
);
628 rec
->commandline
= get_cmdline( entry
.th32ProcessID
);
629 rec
->description
= heap_strdupW( entry
.szExeFile
);
630 sprintfW( handle
, fmtW
, entry
.th32ProcessID
);
631 rec
->handle
= heap_strdupW( handle
);
632 rec
->process_id
= entry
.th32ProcessID
;
633 rec
->pprocess_id
= entry
.th32ParentProcessID
;
634 rec
->thread_count
= entry
.cntThreads
;
635 offset
+= sizeof(*rec
);
637 } while (Process32NextW( snap
, &entry
));
639 TRACE("created %u rows\n", num_rows
);
640 table
->num_rows
= num_rows
;
646 static inline void do_cpuid( unsigned int ax
, unsigned int *p
)
649 __asm__("pushl %%ebx\n\t"
651 "movl %%ebx, %%esi\n\t"
653 : "=a" (p
[0]), "=S" (p
[1]), "=c" (p
[2]), "=d" (p
[3])
658 static void get_processor_id( WCHAR
*processor_id
)
660 static const WCHAR fmtW
[] = {'%','0','8','X','%','0','8','X',0};
661 unsigned int regs
[4] = {0, 0, 0, 0};
664 sprintfW( processor_id
, fmtW
, regs
[3], regs
[0] );
666 static void regs_to_str( unsigned int *regs
, unsigned int len
, WCHAR
*buffer
)
669 unsigned char *p
= (unsigned char *)regs
;
671 for (i
= 0; i
< len
; i
++)
677 static void get_processor_manufacturer( WCHAR
*manufacturer
)
679 unsigned int tmp
, regs
[4] = {0, 0, 0, 0};
682 tmp
= regs
[2]; /* swap edx and ecx */
686 regs_to_str( regs
+ 1, 12, manufacturer
);
688 static void get_processor_name( WCHAR
*name
)
690 unsigned int regs
[4] = {0, 0, 0, 0};
692 do_cpuid( 0x80000000, regs
);
693 if (regs
[0] >= 0x80000004)
695 do_cpuid( 0x80000002, regs
);
696 regs_to_str( regs
, 16, name
);
697 do_cpuid( 0x80000003, regs
);
698 regs_to_str( regs
, 16, name
+ 16 );
699 do_cpuid( 0x80000004, regs
);
700 regs_to_str( regs
, 16, name
+ 32 );
704 static void fill_processor( struct table
*table
)
706 static const WCHAR fmtW
[] = {'C','P','U','%','u',0};
707 WCHAR device_id
[14], processor_id
[17], manufacturer
[13], name
[49] = {0};
708 struct record_processor
*rec
;
709 UINT i
, offset
= 0, count
= get_processor_count();
711 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) return;
713 get_processor_id( processor_id
);
714 get_processor_manufacturer( manufacturer
);
715 get_processor_name( name
);
717 for (i
= 0; i
< count
; i
++)
719 rec
= (struct record_processor
*)(table
->data
+ offset
);
720 rec
->cpu_status
= 1; /* CPU Enabled */
721 sprintfW( device_id
, fmtW
, i
);
722 rec
->device_id
= heap_strdupW( device_id
);
723 rec
->manufacturer
= heap_strdupW( manufacturer
);
724 rec
->name
= heap_strdupW( name
);
725 rec
->processor_id
= heap_strdupW( processor_id
);
726 offset
+= sizeof(*rec
);
729 TRACE("created %u rows\n", count
);
730 table
->num_rows
= count
;
733 static void fill_os( struct table
*table
)
735 struct record_operatingsystem
*rec
;
736 WCHAR path
[MAX_PATH
];
740 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
742 rec
= (struct record_operatingsystem
*)table
->data
;
743 rec
->caption
= os_captionW
;
744 rec
->csdversion
= os_csdversionW
;
746 GetNativeSystemInfo( &info
);
747 if (info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
748 rec
->osarchitecture
= os_64bitW
;
750 rec
->osarchitecture
= os_32bitW
;
752 rec
->oslanguage
= MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
754 Wow64DisableWow64FsRedirection( &redir
);
755 GetSystemDirectoryW( path
, MAX_PATH
);
756 Wow64RevertWow64FsRedirection( redir
);
757 rec
->systemdirectory
= heap_strdupW( path
);
759 TRACE("created 1 row\n");
763 static UINT32
get_bits_per_pixel( UINT
*hres
, UINT
*vres
)
765 HDC hdc
= GetDC( NULL
);
769 ret
= GetDeviceCaps( hdc
, BITSPIXEL
);
770 *hres
= GetDeviceCaps( hdc
, HORZRES
);
771 *vres
= GetDeviceCaps( hdc
, VERTRES
);
772 ReleaseDC( NULL
, hdc
);
776 static void fill_videocontroller( struct table
*table
)
779 struct record_videocontroller
*rec
;
781 IDXGIFactory
*factory
= NULL
;
782 IDXGIAdapter
*adapter
= NULL
;
783 DXGI_ADAPTER_DESC desc
;
784 UINT hres
= 1024, vres
= 768, vidmem
= 512 * 1024 * 1024;
785 const WCHAR
*name
= videocontroller_deviceidW
;
787 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
789 hr
= CreateDXGIFactory( &IID_IDXGIFactory
, (void **)&factory
);
790 if (FAILED(hr
)) goto done
;
792 hr
= IDXGIFactory_EnumAdapters( factory
, 0, &adapter
);
793 if (FAILED(hr
)) goto done
;
795 hr
= IDXGIAdapter_GetDesc( adapter
, &desc
);
798 vidmem
= desc
.DedicatedVideoMemory
;
799 name
= desc
.Description
;
803 rec
= (struct record_videocontroller
*)table
->data
;
804 rec
->adapter_ram
= vidmem
;
805 rec
->current_bitsperpixel
= get_bits_per_pixel( &hres
, &vres
);
806 rec
->current_horizontalres
= hres
;
807 rec
->current_verticalres
= vres
;
808 rec
->device_id
= videocontroller_deviceidW
;
809 rec
->name
= heap_strdupW( name
);
811 TRACE("created 1 row\n");
814 if (adapter
) IDXGIAdapter_Release( adapter
);
815 if (factory
) IDXGIFactory_Release( factory
);
818 static struct table builtin_classes
[] =
820 { class_baseboardW
, SIZEOF(col_baseboard
), col_baseboard
, SIZEOF(data_baseboard
), (BYTE
*)data_baseboard
},
821 { class_biosW
, SIZEOF(col_bios
), col_bios
, SIZEOF(data_bios
), (BYTE
*)data_bios
},
822 { class_compsysW
, SIZEOF(col_compsys
), col_compsys
, 0, NULL
, fill_compsys
},
823 { class_logicaldiskW
, SIZEOF(col_logicaldisk
), col_logicaldisk
, 0, NULL
, fill_logicaldisk
},
824 { class_networkadapterW
, SIZEOF(col_networkadapter
), col_networkadapter
, 0, NULL
, fill_networkadapter
},
825 { class_osW
, SIZEOF(col_os
), col_os
, 0, NULL
, fill_os
},
826 { class_paramsW
, SIZEOF(col_params
), col_params
, SIZEOF(data_params
), (BYTE
*)data_params
},
827 { class_processW
, SIZEOF(col_process
), col_process
, 0, NULL
, fill_process
},
828 { class_processorW
, SIZEOF(col_processor
), col_processor
, 0, NULL
, fill_processor
},
829 { class_stdregprovW
, SIZEOF(col_stdregprov
), col_stdregprov
, SIZEOF(data_stdregprov
), (BYTE
*)data_stdregprov
},
830 { class_videocontrollerW
, SIZEOF(col_videocontroller
), col_videocontroller
, 0, NULL
, fill_videocontroller
}
833 void init_table_list( void )
835 static struct list tables
= LIST_INIT( tables
);
838 for (i
= 0; i
< SIZEOF(builtin_classes
); i
++)
840 list_add_tail( &tables
, &builtin_classes
[i
].entry
);
842 table_list
= &tables
;