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
36 #include "wine/debug.h"
37 #include "wbemprox_private.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wbemprox
);
41 static const WCHAR class_biosW
[] =
42 {'W','i','n','3','2','_','B','I','O','S',0};
43 static const WCHAR class_compsysW
[] =
44 {'W','i','n','3','2','_','C','o','m','p','u','t','e','r','S','y','s','t','e','m',0};
45 static const WCHAR class_networkadapterW
[] =
46 {'W','i','n','3','2','_','N','e','t','w','o','r','k','A','d','a','p','t','e','r',0};
47 static const WCHAR class_osW
[] =
48 {'W','i','n','3','2','_','O','p','e','r','a','t','i','n','g','S','y','s','t','e','m',0};
49 static const WCHAR class_processW
[] =
50 {'W','i','n','3','2','_','P','r','o','c','e','s','s',0};
51 static const WCHAR class_processorW
[] =
52 {'W','i','n','3','2','_','P','r','o','c','e','s','s','o','r',0};
53 static const WCHAR class_videocontrollerW
[] =
54 {'W','i','n','3','2','_','V','i','d','e','o','C','o','n','t','r','o','l','l','e','r',0};
56 static const WCHAR prop_adapterramW
[] =
57 {'A','d','a','p','t','e','r','R','A','M',0};
58 static const WCHAR prop_captionW
[] =
59 {'C','a','p','t','i','o','n',0};
60 static const WCHAR prop_commandlineW
[] =
61 {'C','o','m','m','a','n','d','L','i','n','e',0};
62 static const WCHAR prop_cpustatusW
[] =
63 {'C','p','u','S','t','a','t','u','s',0};
64 static const WCHAR prop_descriptionW
[] =
65 {'D','e','s','c','r','i','p','t','i','o','n',0};
66 static const WCHAR prop_deviceidW
[] =
67 {'D','e','v','i','c','e','I','d',0};
68 static const WCHAR prop_handleW
[] =
69 {'H','a','n','d','l','e',0};
70 static const WCHAR prop_interfaceindexW
[] =
71 {'I','n','t','e','r','f','a','c','e','I','n','d','e','x',0};
72 static const WCHAR prop_manufacturerW
[] =
73 {'M','a','n','u','f','a','c','t','u','r','e','r',0};
74 static const WCHAR prop_modelW
[] =
75 {'M','o','d','e','l',0};
76 static const WCHAR prop_netconnectionstatusW
[] =
77 {'N','e','t','C','o','n','n','e','c','t','i','o','n','S','t','a','t','u','s',0};
78 static const WCHAR prop_numlogicalprocessorsW
[] =
79 {'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};
80 static const WCHAR prop_numprocessorsW
[] =
81 {'N','u','m','b','e','r','O','f','P','r','o','c','e','s','s','o','r','s',0};
82 static const WCHAR prop_osarchitectureW
[] =
83 {'O','S','A','r','c','h','i','t','e','c','t','u','r','e',0};
84 static const WCHAR prop_oslanguageW
[] =
85 {'O','S','L','a','n','g','u','a','g','e',0};
86 static const WCHAR prop_pprocessidW
[] =
87 {'P','a','r','e','n','t','P','r','o','c','e','s','s','I','D',0};
88 static const WCHAR prop_processidW
[] =
89 {'P','r','o','c','e','s','s','I','D',0};
90 static const WCHAR prop_releasedateW
[] =
91 {'R','e','l','e','a','s','e','D','a','t','e',0};
92 static const WCHAR prop_serialnumberW
[] =
93 {'S','e','r','i','a','l','N','u','m','b','e','r',0};
94 static const WCHAR prop_speedW
[] =
95 {'S','p','e','e','d',0};
96 static const WCHAR prop_systemdirectoryW
[] =
97 {'S','y','s','t','e','m','D','i','r','e','c','t','o','r','y',0};
98 static const WCHAR prop_threadcountW
[] =
99 {'T','h','r','e','a','d','C','o','u','n','t',0};
101 static const struct column col_bios
[] =
103 { prop_descriptionW
, CIM_STRING
},
104 { prop_manufacturerW
, CIM_STRING
},
105 { prop_releasedateW
, CIM_DATETIME
},
106 { prop_serialnumberW
, CIM_STRING
}
108 static const struct column col_compsys
[] =
110 { prop_descriptionW
, CIM_STRING
},
111 { prop_manufacturerW
, CIM_STRING
},
112 { prop_modelW
, CIM_STRING
},
113 { prop_numlogicalprocessorsW
, CIM_UINT32
},
114 { prop_numprocessorsW
, CIM_UINT32
}
116 static const struct column col_networkadapter
[] =
118 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
119 { prop_interfaceindexW
, CIM_SINT32
},
120 { prop_netconnectionstatusW
, CIM_UINT16
},
121 { prop_speedW
, CIM_UINT64
}
123 static const struct column col_os
[] =
125 { prop_captionW
, CIM_STRING
},
126 { prop_osarchitectureW
, CIM_STRING
},
127 { prop_oslanguageW
, CIM_UINT32
},
128 { prop_systemdirectoryW
, CIM_STRING
}
130 static const struct column col_process
[] =
132 { prop_captionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
133 { prop_commandlineW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
134 { prop_descriptionW
, CIM_STRING
|COL_FLAG_DYNAMIC
},
135 { prop_handleW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
136 { prop_pprocessidW
, CIM_UINT32
},
137 { prop_processidW
, CIM_UINT32
},
138 { prop_threadcountW
, CIM_UINT32
}
140 static const struct column col_processor
[] =
142 { prop_cpustatusW
, CIM_UINT16
},
143 { prop_deviceidW
, CIM_STRING
|COL_FLAG_DYNAMIC
|COL_FLAG_KEY
},
144 { prop_manufacturerW
, CIM_STRING
}
146 static const struct column col_videocontroller
[] =
148 { prop_adapterramW
, CIM_UINT32
},
149 { prop_deviceidW
, CIM_STRING
|COL_FLAG_KEY
}
152 static const WCHAR bios_descriptionW
[] =
153 {'D','e','f','a','u','l','t',' ','S','y','s','t','e','m',' ','B','I','O','S',0};
154 static const WCHAR bios_manufacturerW
[] =
155 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
156 static const WCHAR bios_releasedateW
[] =
157 {'2','0','1','2','0','6','0','8','0','0','0','0','0','0','.','0','0','0','0','0','0','+','0','0','0',0};
158 static const WCHAR bios_serialnumberW
[] =
160 static const WCHAR compsys_descriptionW
[] =
161 {'A','T','/','A','T',' ','C','O','M','P','A','T','I','B','L','E',0};
162 static const WCHAR compsys_manufacturerW
[] =
163 {'T','h','e',' ','W','i','n','e',' ','P','r','o','j','e','c','t',0};
164 static const WCHAR compsys_modelW
[] =
166 static const WCHAR os_captionW
[] =
168 static const WCHAR os_32bitW
[] =
169 {'3','2','-','b','i','t',0};
170 static const WCHAR os_64bitW
[] =
171 {'6','4','-','b','i','t',0};
172 static const WCHAR processor_manufacturerW
[] =
173 {'G','e','n','u','i','n','e','I','n','t','e','l',0};
174 static const WCHAR videocontroller_deviceidW
[] =
175 {'V','i','d','e','o','C','o','n','t','r','o','l','l','e','r','1',0};
177 #include "pshpack1.h"
180 const WCHAR
*description
;
181 const WCHAR
*manufacturer
;
182 const WCHAR
*releasedate
;
183 const WCHAR
*serialnumber
;
185 struct record_computersystem
187 const WCHAR
*description
;
188 const WCHAR
*manufacturer
;
190 UINT32 num_logical_processors
;
191 UINT32 num_processors
;
193 struct record_networkadapter
195 const WCHAR
*device_id
;
196 INT32 interface_index
;
197 UINT16 netconnection_status
;
200 struct record_operatingsystem
202 const WCHAR
*caption
;
203 const WCHAR
*osarchitecture
;
205 const WCHAR
*systemdirectory
;
207 struct record_process
209 const WCHAR
*caption
;
210 const WCHAR
*commandline
;
211 const WCHAR
*description
;
217 struct record_processor
220 const WCHAR
*device_id
;
221 const WCHAR
*manufacturer
;
223 struct record_videocontroller
226 const WCHAR
*device_id
;
230 static const struct record_bios data_bios
[] =
232 { bios_descriptionW
, bios_manufacturerW
, bios_releasedateW
, bios_serialnumberW
}
235 static UINT
get_processor_count(void)
237 SYSTEM_BASIC_INFORMATION info
;
239 if (NtQuerySystemInformation( SystemBasicInformation
, &info
, sizeof(info
), NULL
)) return 1;
240 return info
.NumberOfProcessors
;
243 static void fill_compsys( struct table
*table
)
245 struct record_computersystem
*rec
;
247 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
249 rec
= (struct record_computersystem
*)table
->data
;
250 rec
->description
= compsys_descriptionW
;
251 rec
->manufacturer
= compsys_manufacturerW
;
252 rec
->model
= compsys_modelW
;
253 rec
->num_logical_processors
= get_processor_count();
254 rec
->num_processors
= rec
->num_logical_processors
;
256 TRACE("created 1 row\n");
260 static UINT16
get_connection_status( IF_OPER_STATUS status
)
264 case IfOperStatusDown
:
265 return 0; /* Disconnected */
267 return 2; /* Connected */
269 ERR("unhandled status %u\n", status
);
275 static void fill_networkadapter( struct table
*table
)
277 static const WCHAR fmtW
[] = {'%','u',0};
279 struct record_networkadapter
*rec
;
280 IP_ADAPTER_ADDRESSES
*aa
, *buffer
;
281 UINT num_rows
= 0, offset
= 0;
284 ret
= GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, NULL
, &size
);
285 if (ret
!= ERROR_BUFFER_OVERFLOW
) return;
287 if (!(buffer
= heap_alloc( size
))) return;
288 if (GetAdaptersAddresses( AF_UNSPEC
, 0, NULL
, buffer
, &size
))
293 for (aa
= buffer
; aa
; aa
= aa
->Next
) num_rows
++;
294 if (!(table
->data
= heap_alloc( sizeof(*rec
) * num_rows
)))
299 for (aa
= buffer
; aa
; aa
= aa
->Next
)
301 rec
= (struct record_networkadapter
*)(table
->data
+ offset
);
302 sprintfW( device_id
, fmtW
, aa
->u
.s
.IfIndex
);
303 rec
->device_id
= heap_strdupW( device_id
);
304 rec
->interface_index
= aa
->u
.s
.IfIndex
;
305 rec
->netconnection_status
= get_connection_status( aa
->OperStatus
);
306 rec
->speed
= 1000000;
307 offset
+= sizeof(*rec
);
309 TRACE("created %u rows\n", num_rows
);
310 table
->num_rows
= num_rows
;
315 static WCHAR
*get_cmdline( DWORD process_id
)
317 if (process_id
== GetCurrentProcessId()) return heap_strdupW( GetCommandLineW() );
318 return NULL
; /* FIXME handle different process case */
321 static void fill_process( struct table
*table
)
323 static const WCHAR fmtW
[] = {'%','u',0};
325 struct record_process
*rec
;
326 PROCESSENTRY32W entry
;
328 UINT num_rows
= 0, offset
= 0, count
= 8;
330 snap
= CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS
, 0 );
331 if (snap
== INVALID_HANDLE_VALUE
) return;
333 entry
.dwSize
= sizeof(entry
);
334 if (!Process32FirstW( snap
, &entry
)) goto done
;
335 if (!(table
->data
= heap_alloc( count
* sizeof(*rec
) ))) goto done
;
339 if (num_rows
> count
)
343 if (!(data
= heap_realloc( table
->data
, count
* sizeof(*rec
) ))) goto done
;
346 rec
= (struct record_process
*)(table
->data
+ offset
);
347 rec
->caption
= heap_strdupW( entry
.szExeFile
);
348 rec
->commandline
= get_cmdline( entry
.th32ProcessID
);
349 rec
->description
= heap_strdupW( entry
.szExeFile
);
350 sprintfW( handle
, fmtW
, entry
.th32ProcessID
);
351 rec
->handle
= heap_strdupW( handle
);
352 rec
->process_id
= entry
.th32ProcessID
;
353 rec
->pprocess_id
= entry
.th32ParentProcessID
;
354 rec
->thread_count
= entry
.cntThreads
;
355 offset
+= sizeof(*rec
);
357 } while (Process32NextW( snap
, &entry
));
359 TRACE("created %u rows\n", num_rows
);
360 table
->num_rows
= num_rows
;
366 static void fill_processor( struct table
*table
)
368 static const WCHAR fmtW
[] = {'C','P','U','%','u',0};
370 struct record_processor
*rec
;
371 UINT i
, offset
= 0, count
= get_processor_count();
373 if (!(table
->data
= heap_alloc( sizeof(*rec
) * count
))) return;
375 for (i
= 0; i
< count
; i
++)
377 rec
= (struct record_processor
*)(table
->data
+ offset
);
378 rec
->cpu_status
= 1; /* CPU Enabled */
379 rec
->manufacturer
= processor_manufacturerW
;
380 sprintfW( device_id
, fmtW
, i
);
381 rec
->device_id
= heap_strdupW( device_id
);
382 offset
+= sizeof(*rec
);
385 TRACE("created %u rows\n", count
);
386 table
->num_rows
= count
;
389 static void fill_os( struct table
*table
)
391 struct record_operatingsystem
*rec
;
392 WCHAR path
[MAX_PATH
];
396 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
398 rec
= (struct record_operatingsystem
*)table
->data
;
399 rec
->caption
= os_captionW
;
401 GetNativeSystemInfo( &info
);
402 if (info
.u
.s
.wProcessorArchitecture
== PROCESSOR_ARCHITECTURE_AMD64
)
403 rec
->osarchitecture
= os_64bitW
;
405 rec
->osarchitecture
= os_32bitW
;
407 rec
->oslanguage
= MAKELANGID( LANG_ENGLISH
, SUBLANG_ENGLISH_US
);
409 Wow64DisableWow64FsRedirection( &redir
);
410 GetSystemDirectoryW( path
, MAX_PATH
);
411 Wow64RevertWow64FsRedirection( redir
);
412 rec
->systemdirectory
= heap_strdupW( path
);
414 TRACE("created 1 row\n");
418 static void fill_videocontroller( struct table
*table
)
421 struct record_videocontroller
*rec
;
423 IDXGIFactory
*factory
= NULL
;
424 IDXGIAdapter
*adapter
= NULL
;
425 DXGI_ADAPTER_DESC desc
;
426 UINT vidmem
= 512 * 1024 * 1024;
428 if (!(table
->data
= heap_alloc( sizeof(*rec
) ))) return;
430 hr
= CreateDXGIFactory( &IID_IDXGIFactory
, (void **)&factory
);
431 if (FAILED(hr
)) goto done
;
433 hr
= IDXGIFactory_EnumAdapters( factory
, 0, &adapter
);
434 if (FAILED(hr
)) goto done
;
436 hr
= IDXGIAdapter_GetDesc( adapter
, &desc
);
437 if (SUCCEEDED(hr
)) vidmem
= desc
.DedicatedVideoMemory
;
440 rec
= (struct record_videocontroller
*)table
->data
;
441 rec
->device_id
= videocontroller_deviceidW
;
442 rec
->adapter_ram
= vidmem
;
444 TRACE("created 1 row\n");
447 if (adapter
) IDXGIAdapter_Release( adapter
);
448 if (factory
) IDXGIFactory_Release( factory
);
451 static struct table classtable
[] =
453 { class_biosW
, SIZEOF(col_bios
), col_bios
, SIZEOF(data_bios
), (BYTE
*)data_bios
, NULL
},
454 { class_compsysW
, SIZEOF(col_compsys
), col_compsys
, 0, NULL
, fill_compsys
},
455 { class_networkadapterW
, SIZEOF(col_networkadapter
), col_networkadapter
, 0, NULL
, fill_networkadapter
},
456 { class_osW
, SIZEOF(col_os
), col_os
, 0, NULL
, fill_os
},
457 { class_processW
, SIZEOF(col_process
), col_process
, 0, NULL
, fill_process
},
458 { class_processorW
, SIZEOF(col_processor
), col_processor
, 0, NULL
, fill_processor
},
459 { class_videocontrollerW
, SIZEOF(col_videocontroller
), col_videocontroller
, 0, NULL
, fill_videocontroller
}
462 struct table
*get_table( const WCHAR
*name
)
465 struct table
*table
= NULL
;
467 for (i
= 0; i
< SIZEOF(classtable
); i
++)
469 if (!strcmpiW( classtable
[i
].name
, name
))
471 table
= &classtable
[i
];
472 if (table
->fill
&& !table
->data
) table
->fill( table
);