-
Notifications
You must be signed in to change notification settings - Fork 0
COM
Suppose you're attempting to develop a Visual Studio extension, and would like to take a peek into where some of Visual Studio's core interfaces such as IVsSolution are implemented. This interface is implemented by some native COM component...but which one, and where?
DebugTools can help you track down the underlying type of a COM object in any system wide process, without needing to attach a debugger.
C:\> Get-ComObject -ProcessId 21356 IVsSolution
Module Symbol RVA LoadedAddress OriginalAddress Interfaces
------ ------ --- ------------- --------------- ----------
msenv.dll CSolution::`vftable' 0xD97B0 0x3DB97B0 0x100D97B0 {IVsDiagnosticsItem, IVsFileChangeEvents, IVsHi...From this information, we can see that asingle RCW within Visual Studio implements the IVsSolution interface, the underlying type of which is msenv!CSolution. In addition, there are a number of other interfaces that this particular RCW has been asked to QueryInterface for, including IVsHierarchy and IVsSolution 2, 3 and 5.
We can do even better than this however: we can also list all of the methods defined on the CSolution vtable
C:\> Get-ComObject -ProcessId 21356 IVsSolution | Get-ComObjectMethod
Module Symbol RVA LoadedAddress OriginalAddress
------ ------ --- ------------- ---------------
msenv.dll CSolution::QueryInterface 0xD9E74 0x38D9E74 0x100D9E74
msenv.dll CSolution::AddRef 0xD988C 0x38D988C 0x100D988C
msenv.dll CSolution::Release 0xD9850 0x38D9850 0x100D9850
msenv.dll CSolution::GetProjectEnum 0x20190E 0x3A0190E 0x1020190E
msenv.dll CSolution::CreateProject 0x1AEA80 0x39AEA80 0x101AEA80
...Using this information you can now easily open up IDA Pro, hit g and paste in the OriginalAddress of the method you want to look at to jump straight to it.
Both the Get-ComObject and Get-ComObjectMethod cmdlets allow specifying wildcard parameters to filter down the list of results.
Get-ComObject can be used to filter either by the name of the interface you're looking for, or the name of the native symbol the interface is implemented in
# Get all COM objects that implement an interface containing "solution"
Get-ComObject *solution*
# Get all COM objects whose native symbol contains "solution"
Get-ComObject -SymbolName *solution*Similarly, Get-ComObjectMethod can also be used to filter for methods matching a specific pattern
# Get all methods on objects that implement the IVsSolution interface containing the word "project"
C:\> Get-ComObject -ProcessId 21356 IVsSolution | Get-ComObjectMethod *project*When using the Get-ComObject cmdlet, there are several ways to specify the process that should be queried
- If a
-ProcessIdis specified, that process will be targeted - Otherwise, DebugTools will attempt to search for a singular active Profiler or SOS session (in that order). In the event multiple active sessions of a given type are found, an error will be thrown and the implicit session search will not continue.