Skip to content

Commit

Permalink
Added activation filter.
Browse files Browse the repository at this point in the history
  • Loading branch information
tyranid committed Jun 12, 2017
1 parent 02e496a commit 679566c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
10 changes: 10 additions & 0 deletions OleViewDotNet/COMInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,14 @@ public interface IDispatch
void Invoke(int dispIdMember, ref Guid riid, uint lcid, ushort wFlags, System.Runtime.InteropServices.ComTypes.DISPPARAMS[] pDispParams,
out VariantWrapper pVarResult, ref System.Runtime.InteropServices.ComTypes.EXCEPINFO pExcepInfo, out uint puArgErr);
}

[Guid("00000017-0000-0000-C000-000000000046"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IActivationFilter
{
void HandleActivation(
uint dwActivationType,
ref Guid rclsid,
out Guid pReplacementClsId);
};
}
3 changes: 3 additions & 0 deletions OleViewDotNet/COMUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,9 @@ public static extern object CoUnmarshalInterface(
ref Guid riid
);

[DllImport("ole32.dll", CallingConvention = CallingConvention.StdCall, CharSet = CharSet.Unicode)]
public static extern int CoRegisterActivationFilter(IActivationFilter pActivationFilter);

private static Dictionary<Guid, Assembly> m_typelibs;
private static Dictionary<string, Assembly> m_typelibsname;
private static Dictionary<Guid, Type> m_iidtypes;
Expand Down
19 changes: 17 additions & 2 deletions OleViewDotNet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,15 @@ protected override void OnMainFormClosed(object sender, EventArgs e)
}
}

class ActivationFilter : IActivationFilter
{
public void HandleActivation(uint dwActivationType, ref Guid rclsid, out Guid pReplacementClsId)
{
pReplacementClsId = rclsid;
System.Diagnostics.Trace.WriteLine(String.Format("{0:X} {1}", dwActivationType, rclsid));
}
}

static IEnumerable<COMServerType> ParseServerTypes(string servers)
{
string[] ss = servers.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
Expand All @@ -144,6 +153,7 @@ public static void Main(string[] args)
bool query_interfaces = false;
int concurrent_queries = Environment.ProcessorCount;
bool refresh_interfaces = false;
bool enable_activation_filter = false;
COMRegistryMode mode = COMRegistryMode.Merged;
IEnumerable<COMServerType> server_types = new COMServerType[] { COMServerType.InProcHandler32, COMServerType.InProcServer32, COMServerType.LocalServer32 };

Expand All @@ -155,8 +165,9 @@ public static void Main(string[] args)
{ "c|conn=", "Number of concurrent interface queries", v => concurrent_queries = int.Parse(v) },
{ "s|server=", "Specify server types for query", v => server_types = ParseServerTypes(v) },
{ "refresh", "Refresh interfaces in query", v => refresh_interfaces = v != null },
{ "m", "Loading mode is machine only.", v => mode = COMRegistryMode.MachineOnly },
{ "u", "Loading mode is user only.", v => mode = COMRegistryMode.UserOnly },
{ "m", "Loading mode is machine only.", v => mode = COMRegistryMode.MachineOnly },
{ "u", "Loading mode is user only.", v => mode = COMRegistryMode.UserOnly },
{ "a", "Enable activation filter.", v => enable_activation_filter = v != null },
{ "h|help", "Show this message and exit.", v => show_help = v != null },
};

Expand Down Expand Up @@ -219,6 +230,10 @@ public static void Main(string[] args)
}

_appContext = new MultiApplicationContext(new MainForm(registry));
if (enable_activation_filter)
{
COMUtilities.CoRegisterActivationFilter(new ActivationFilter());
}
Application.Run(_appContext);
}
catch (Exception ex)
Expand Down

0 comments on commit 679566c

Please sign in to comment.