Skip to content

Commit

Permalink
Fix NPD in WinRT name demangling Issue #38
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranid authored and tyranid committed Sep 3, 2023
1 parent 855fc6b commit 9634810
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion OleViewDotNet/COMProxyInterfaceInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class COMProxyInterfaceInstance : IProxyFormatter
/// <summary>
/// The name of the proxy interface.
/// </summary>
public string Name => COMUtilities.DemangleWinRTName(Entry.Name);
public string Name => COMUtilities.DemangleWinRTName(Entry.Name, Iid);
/// <summary>
/// Original name of the interface.
/// </summary>
Expand Down
14 changes: 11 additions & 3 deletions OleViewDotNet/COMUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2029,12 +2029,20 @@ private static string DemangleGenericType(string name)
return ReadType(ref name);
}

// TODO: This isn't exactly correct, but can't find any good documentation.
internal static string DemangleWinRTName(string name)
{
return DemangleWinRTName(name, null);
}

// TODO: This isn't exactly correct, but can't find any good documentation.
internal static string DemangleWinRTName(string name, Guid? iid)
{
if (string.IsNullOrWhiteSpace(name))
{
return iid?.ToString() ?? "IInvalidName";
}
name = name.Trim();
string result;
if (_demangled_names.TryGetValue(name, out result))
if (_demangled_names.TryGetValue(name, out string result))
{
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion OleViewDotNet/Database/COMInterfaceEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ private void LoadFromKey(RegistryKey key)
string name = key.GetValue(null) as string;
if (!string.IsNullOrWhiteSpace(name))
{
Name = COMUtilities.DemangleWinRTName(name.ToString());
Name = COMUtilities.DemangleWinRTName(name);
CacheIidToName(Iid, Name);
}
else
Expand Down
10 changes: 5 additions & 5 deletions OleViewDotNet/Forms/TypeLibControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@ private static IEnumerable<ListViewItemWithGuid> FormatClasses(Assembly typelib,

private static IEnumerable<ListViewItemWithGuid> FormatProxyInstance(COMProxyInstance proxy)
{
foreach (var t in proxy.Entries.OrderBy(t => COMUtilities.DemangleWinRTName(t.Name)))
foreach (var t in proxy.Entries.OrderBy(t => COMUtilities.DemangleWinRTName(t.Name, t.Iid)))
{
ListViewItemWithGuid item = new ListViewItemWithGuid(COMUtilities.DemangleWinRTName(t.Name), t.Iid);
ListViewItemWithGuid item = new ListViewItemWithGuid(COMUtilities.DemangleWinRTName(t.Name, t.Iid), t.Iid);
item.SubItems.Add(t.Iid.FormatGuid());
item.Tag = t;
yield return item;
Expand Down Expand Up @@ -208,16 +208,16 @@ public TypeLibControl(COMRegistry registry, string name, COMProxyInstance proxy,
new ListViewItemWithGuid[0], FormatProxyInstanceComplexTypes(proxy), new ListViewItem[0])
{
// controls on this panel are not enabled by default, activating them in the proxy view only
this.btnDqs.Enabled = true;
this.cbProxyRenderStyle.Enabled = true;
btnDqs.Enabled = true;
cbProxyRenderStyle.Enabled = true;
this.comClassId = comClassId;
this.comClassIdName = comClassIdName;
}

private INdrFormatter GetNdrFormatter(bool useDemangler)
{
DefaultNdrFormatterFlags flags = cbProxyRenderStyle.SelectedIndex % 2 == 0 ? DefaultNdrFormatterFlags.None : DefaultNdrFormatterFlags.RemoveComments;
Func<string, string> demangler = useDemangler ? COMUtilities.DemangleWinRTName : (Func<string, string>)null;
Func<string, string> demangler = useDemangler ? COMUtilities.DemangleWinRTName : null;
bool useNtApiFormatter = this.cbProxyRenderStyle.SelectedIndex < 2;
return useNtApiFormatter ?
DefaultNdrFormatter.Create(m_iids_to_names, demangler, flags) :
Expand Down

0 comments on commit 9634810

Please sign in to comment.