Beispiel #1
0
        /// <summary>
        /// Handler method of on loading assembly event from app manager
        /// </summary>
        /// <param name="name">name of assembly</param>
        /// <param name="assembly">associate assembly</param>
        internal static void OnLoad(string name, Assembly assembly)
        {
            if (name != "System.Management.Automation")
            {
                return;
            }

            // retrieve method info of target function
            var target = assembly
                         .GetType("System.Management.Automation.ScriptBlock")
                         .GetMethod(
                "InvokeWithPipe",
                BindingFlags.Instance | BindingFlags.NonPublic,
                null,
                new Type[] {
                typeof(bool),
                typeof(bool),
                typeof(object),
                typeof(object),
                typeof(object),
                assembly.GetType("System.Management.Automation.Internal.Pipe"),
                typeof(ArrayList).MakeByRefType(),
                typeof(object[])
            },
                null
                );

            var handler = typeof(ScriptBlock)
                          .GetMethod(
                "Handler",
                BindingFlags.Static | BindingFlags.NonPublic
                );


            var trampoline = typeof(ScriptBlock)
                             .GetMethod(
                "Trampoline",
                BindingFlags.Instance | BindingFlags.NonPublic
                );

            MinHook.Hook(target, handler, trampoline);
        }
Beispiel #2
0
        /// <summary>
        /// On load assembly event from app manager
        /// </summary>
        /// <param name="name">name of assembly</param>
        /// <param name="assembly">associate assembly</param>
        /// <returns></returns>
        internal static void OnLoad(string name, Assembly assembly)
        {
            if (name != "System.Management.Automation")
            {
                return;
            }

            // retrieve method info of target function
            var target = assembly
                         .GetType("System.Management.Automation.Runspaces.Pipeline")
                         .GetMethod(
                "Invoke",
                BindingFlags.Instance | BindingFlags.Public,
                null,
                new Type[] { },
                null
                );

            if (target == null)
            {
                throw new Exception("unable to locate InvokeWithPipe method in System.Management.Automation.Runspaces.Pipeline assembly");
            }

            var handler = typeof(Pipeline)
                          .GetMethod(
                "Handler",
                BindingFlags.Static | BindingFlags.NonPublic
                );


            var trampoline = typeof(Pipeline)
                             .GetMethod(
                "Trampoline",
                BindingFlags.Instance | BindingFlags.NonPublic
                );

            MinHook.Hook(target, handler, trampoline);
        }