Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add and forward server type param from Get-ComClassInterface cmdlet to OOP interface querying #37

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion OleViewDotNet.Main/COMUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2214,7 +2214,7 @@ private static bool QueryAllInterfaces(IEnumerable<COMCLSIDEntry> clsids, IProgr
try
{
query_progress.Report();
clsid.LoadSupportedInterfaces(false, null);
clsid.LoadSupportedInterfaces(false, null, COMServerType.UnknownServer);
}
catch
{
Expand Down
53 changes: 31 additions & 22 deletions OleViewDotNet.Main/Database/COMCLSIDEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,18 +457,20 @@ public interface ICOMClassEntry
/// </summary>
/// <param name="refresh">Force the supported interface list to refresh</param>
/// <param name="token">Token to use when querying for the interfaces.</param>
/// <param name="serverType">Server type to use when creating the object.</param>
/// <returns>Returns true if supported interfaces were refreshed.</returns>
/// <exception cref="Win32Exception">Thrown on error.</exception>
Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token);
Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token, COMServerType serverType);

/// <summary>
/// Get list of supported Interface IIDs Synchronously
/// </summary>
/// <param name="refresh">Force the supported interface list to refresh</param>
/// <param name="token">Token to use when querying for the interfaces.</param>
/// <param name="serverType">Server type to use when creating the object.</param>
/// <returns>Returns true if supported interfaces were refreshed.</returns>
/// <exception cref="Win32Exception">Thrown on error.</exception>
bool LoadSupportedInterfaces(bool refresh, NtToken token);
bool LoadSupportedInterfaces(bool refresh, NtToken token, COMServerType serverType);

/// <summary>
/// Indicates that the class' interface list has been loaded.
Expand Down Expand Up @@ -1030,11 +1032,11 @@ public override int GetHashCode()
^ Source.GetHashCode() ^ PackageId.GetSafeHashCode();
}

private async Task<COMEnumerateInterfaces> GetSupportedInterfacesInternal(NtToken token)
private async Task<COMEnumerateInterfaces> GetSupportedInterfacesInternal(NtToken token, COMServerType serverType)
{
try
{
return await COMEnumerateInterfaces.GetInterfacesOOP(this, Database, token);
return await COMEnumerateInterfaces.GetInterfacesOOP(this, Database, token, serverType);
}
catch (Win32Exception)
{
Expand Down Expand Up @@ -1073,9 +1075,10 @@ private COMCLSIDServerEntry GetDefaultServer()
/// </summary>
/// <param name="refresh">Force the supported interface list to refresh</param>
/// <param name="token">Token to use when checking for the interfaces.</param>
/// <param name="serverType">Server type to use when creating the object.</param>
/// <returns>Returns true if supported interfaces were refreshed.</returns>
/// <exception cref="Win32Exception">Thrown on error.</exception>
public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token)
public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token, COMServerType serverType)
{
if (Clsid == Guid.Empty)
{
Expand All @@ -1084,7 +1087,7 @@ public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token

if (refresh || !InterfacesLoaded)
{
COMEnumerateInterfaces enum_int = await GetSupportedInterfacesInternal(token);
COMEnumerateInterfaces enum_int = await GetSupportedInterfacesInternal(token, serverType);
m_interfaces = new List<COMInterfaceInstance>(enum_int.Interfaces);
m_factory_interfaces = new List<COMInterfaceInstance>(enum_int.FactoryInterfaces);
InterfacesLoaded = true;
Expand All @@ -1098,11 +1101,12 @@ public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token
/// </summary>
/// <param name="refresh">Force the supported interface list to refresh</param>
/// <param name="token">Token to use when querying for the interfaces.</param>
/// <param name="serverType">Server type to use when creating the object.</param>
/// <returns>Returns true if supported interfaces were refreshed.</returns>
/// <exception cref="Win32Exception">Thrown on error.</exception>
public bool LoadSupportedInterfaces(bool refresh, NtToken token)
public bool LoadSupportedInterfaces(bool refresh, NtToken token, COMServerType serverType)
{
Task<bool> result = LoadSupportedInterfacesAsync(refresh, token);
Task<bool> result = LoadSupportedInterfacesAsync(refresh, token, serverType);
try
{
result.Wait();
Expand Down Expand Up @@ -1169,23 +1173,28 @@ public CLSCTX CreateContext
{
get
{
CLSCTX dwContext = CLSCTX.ALL;
return ServerTypeToClsCtx(DefaultServerType);
}
}

if (DefaultServerType == COMServerType.InProcServer32)
{
dwContext = CLSCTX.INPROC_SERVER;
}
else if (DefaultServerType == COMServerType.LocalServer32)
{
dwContext = CLSCTX.LOCAL_SERVER;
}
else if (DefaultServerType == COMServerType.InProcHandler32)
{
dwContext = CLSCTX.INPROC_HANDLER;
}
public static CLSCTX ServerTypeToClsCtx(COMServerType serverType)
{
CLSCTX dwContext = CLSCTX.ALL;

return dwContext;
if (serverType == COMServerType.InProcServer32)
{
dwContext = CLSCTX.INPROC_SERVER;
}
else if (serverType == COMServerType.LocalServer32)
{
dwContext = CLSCTX.LOCAL_SERVER;
}
else if (serverType == COMServerType.InProcHandler32)
{
dwContext = CLSCTX.INPROC_HANDLER;
}

return dwContext;
}

public IntPtr CreateInstance(CLSCTX dwContext, string server)
Expand Down
14 changes: 10 additions & 4 deletions OleViewDotNet.Main/Database/COMEnumerateInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ private COMEnumerateInterfaces(Guid clsid, CLSCTX clsctx, string activatable_cla
_winrt_component = !string.IsNullOrWhiteSpace(_activatable_classid);
}

public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMRuntimeClassEntry ent, COMRegistry registry, NtToken token)
public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMRuntimeClassEntry ent, COMRegistry registry, NtToken token, COMServerType serverType)
{
string apartment = "s";
if (ent.Threading == ThreadingType.Both
Expand Down Expand Up @@ -500,7 +500,7 @@ private async static Task<InterfaceLists> GetInterfacesOOP(string command_line,
}
}

public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMCLSIDEntry ent, COMRegistry registry, NtToken token)
public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMCLSIDEntry ent, COMRegistry registry, NtToken token, COMServerType serverType)
{
string apartment = "s";
if (ent.DefaultThreadingModel == COMThreadingModel.Both
Expand All @@ -509,9 +509,15 @@ public async static Task<COMEnumerateInterfaces> GetInterfacesOOP(COMCLSIDEntry
apartment = "m";
}

string command_line = string.Format("{0} {1} \"{2}\"", ent.Clsid.ToString("B"), apartment, ent.CreateContext);
CLSCTX createCtx;
if (serverType == COMServerType.UnknownServer)
createCtx = ent.CreateContext;
else
createCtx = COMCLSIDEntry.ServerTypeToClsCtx(serverType);

string command_line = string.Format("{0} {1} \"{2}\"", ent.Clsid.ToString("B"), apartment, createCtx);
var interfaces = await GetInterfacesOOP(command_line, false, registry, token);
return new COMEnumerateInterfaces(ent.Clsid, ent.CreateContext, string.Empty, interfaces.Interfaces, interfaces.FactoryInterfaces);
return new COMEnumerateInterfaces(ent.Clsid, createCtx, string.Empty, interfaces.Interfaces, interfaces.FactoryInterfaces);
}
}
}
12 changes: 6 additions & 6 deletions OleViewDotNet.Main/Database/COMRuntimeClassEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,23 +259,23 @@ int IComparable<COMRuntimeClassEntry>.CompareTo(COMRuntimeClassEntry other)
return Server.CompareTo(other.Server);
}

private async Task<COMEnumerateInterfaces> GetSupportedInterfacesInternal(NtToken token)
private async Task<COMEnumerateInterfaces> GetSupportedInterfacesInternal(NtToken token, COMServerType serverType)
{
try
{
return await COMEnumerateInterfaces.GetInterfacesOOP(this, m_registry, token);
return await COMEnumerateInterfaces.GetInterfacesOOP(this, m_registry, token, serverType);
}
catch (Win32Exception)
{
throw;
}
}

public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token)
public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token, COMServerType serverType)
{
if (refresh || !InterfacesLoaded)
{
COMEnumerateInterfaces enum_int = await GetSupportedInterfacesInternal(token);
COMEnumerateInterfaces enum_int = await GetSupportedInterfacesInternal(token, serverType);
m_interfaces = new List<COMInterfaceInstance>(enum_int.Interfaces);
m_factory_interfaces = new List<COMInterfaceInstance>(enum_int.FactoryInterfaces);
InterfacesLoaded = true;
Expand All @@ -290,9 +290,9 @@ public async Task<bool> LoadSupportedInterfacesAsync(bool refresh, NtToken token
/// <param name="refresh">Force the supported interface list to refresh</param>
/// <returns>Returns true if supported interfaces were refreshed.</returns>
/// <exception cref="Win32Exception">Thrown on error.</exception>
public bool LoadSupportedInterfaces(bool refresh, NtToken token)
public bool LoadSupportedInterfaces(bool refresh, NtToken token, COMServerType serverType)
{
Task<bool> result = LoadSupportedInterfacesAsync(refresh, token);
Task<bool> result = LoadSupportedInterfacesAsync(refresh, token, serverType);
result.Wait();
if (result.IsFaulted)
{
Expand Down
2 changes: 1 addition & 1 deletion OleViewDotNet.Main/Forms/COMRegistryViewer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1047,7 +1047,7 @@ private async Task SetupCLSIDNodeTree(TreeNode node, bool bRefresh)
node.Nodes.Add(wait_node);
try
{
await clsid.LoadSupportedInterfacesAsync(bRefresh, null);
await clsid.LoadSupportedInterfacesAsync(bRefresh, null, COMServerType.UnknownServer);
int interface_count = clsid.Interfaces.Count();
int factory_count = clsid.FactoryInterfaces.Count();
if (interface_count == 0 && factory_count == 0)
Expand Down
6 changes: 3 additions & 3 deletions OleViewDotNet.Main/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public async Task HostObject(ICOMClassEntry ent, object obj, bool factory)

if (!ent.InterfacesLoaded)
{
await ent.LoadSupportedInterfacesAsync(false, null);
await ent.LoadSupportedInterfacesAsync(false, null, COMServerType.UnknownServer);
}

IEnumerable<COMInterfaceInstance> intfs = factory ? ent.FactoryInterfaces : ent.Interfaces;
Expand Down Expand Up @@ -226,7 +226,7 @@ public async Task CreateInstanceFromCLSID(Guid clsid, CLSCTX clsctx, bool class_
props.Add("CLSID", ent.Clsid.FormatGuid());
props.Add("Name", ent.Name);
props.Add("Server", ent.DefaultServer);
await ent.LoadSupportedInterfacesAsync(false, null);
await ent.LoadSupportedInterfacesAsync(false, null, COMServerType.UnknownServer);

if (class_factory)
{
Expand Down Expand Up @@ -357,7 +357,7 @@ public async Task OpenObjectInformation(object comObj, string defaultName)
props.Add("CLSID", ent.Clsid.FormatGuid());
props.Add("Name", ent.Name);
props.Add("Server", ent.DefaultServer);
await ent.LoadSupportedInterfacesAsync(false, null);
await ent.LoadSupportedInterfacesAsync(false, null, COMServerType.UnknownServer);
ints = ent.Interfaces.Select(i => m_registry.MapIidToInterface(i.Iid));
}
else
Expand Down
2 changes: 1 addition & 1 deletion OleViewDotNet.Main/Forms/PropertiesControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ private async void btnRefreshInterfaces_Click(object sender, EventArgs e)
try
{
ICOMClassEntry entry = (ICOMClassEntry)tabPageSupportedInterfaces.Tag;
await entry.LoadSupportedInterfacesAsync(true, null);
await entry.LoadSupportedInterfacesAsync(true, null, COMServerType.UnknownServer);
LoadInterfaceList(entry.Interfaces, listViewInterfaces);
LoadInterfaceList(entry.FactoryInterfaces, listViewFactoryInterfaces);
}
Expand Down
5 changes: 4 additions & 1 deletion OleViewDotNet.PowerShell/OleViewDotNet.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -907,6 +907,8 @@ Get a COM class or Runtime class instance interfaces.
This cmdlet enumerates the supported interfaces for a COM class or Runtime class and returns them.
.PARAMETER ClassEntry
The COM or Runtime classes to enumerate.
.PARAMETER ServerType
Specify a type of server to match against. If specified as UnknownServer will search DefaultServerType.
.PARAMETER Refresh
Specify to force the interfaces to be refreshed.
.PARAMETER Factory
Expand Down Expand Up @@ -936,6 +938,7 @@ function Get-ComClassInterface {
Param(
[Parameter(Mandatory, Position = 0, ValueFromPipeline)]
[OleViewDotNet.Database.ICOMClassEntry[]]$ClassEntry,
[OleViewDotNet.Database.COMServerType]$ServerType = "UnknownServer",
[switch]$Refresh,
[switch]$Factory,
[switch]$NoQuery,
Expand All @@ -954,7 +957,7 @@ function Get-ComClassInterface {
$i++
}
}
$class.LoadSupportedInterfaces($Refresh, $Token) | Out-Null
$class.LoadSupportedInterfaces($Refresh, $Token, $ServerType) | Out-Null
}
if ($Factory) {
$class.FactoryInterfaces | Write-Output
Expand Down