コード例 #1
0
        protected override void WndProc(ref Message m)
        {
            if (m.Msg == (int)NativeMethods.Msgs.WM_COPYDATA)
            {
                // message was sended by ProcessViewer.Hooks.dll from the Hooked application when
                // a new message comes to that window

                // LPARAM of this message contains a COPYDATASTRUCT which has HOOK_MSG struct in it
                NativeMethods.COPYDATASTRUCT cdata =
                    (NativeMethods.COPYDATASTRUCT)m.GetLParam(typeof(NativeMethods.COPYDATASTRUCT));
                // This is the information of the message which is sended to the hooked window
                NativeMethods.HOOK_MSG msg = (NativeMethods.HOOK_MSG)Marshal.PtrToStructure(cdata.lpData,
                                                                                            typeof(NativeMethods.HOOK_MSG));

                // process message and set its result (0 ignore, 1 do nothing, other values replace parameters)
                m.Result = _subClass.ProcessMessage(m.WParam, ref msg);
                Marshal.DestroyStructure(m.LParam, typeof(NativeMethods.COPYDATASTRUCT));
            }
            else if (m.Msg == HM_MESSAGE_RESULT)
            //&& Properties.Settings.Default.HandleMessageResults)
            {
                // this message sended by hooked window to give information about the result of a message
                _subClass.ProcessMessageResult(m.WParam.ToInt32(), m.LParam);
            }
            else
            {
                base.WndProc(ref m);
            }
        }
コード例 #2
0
        /// <summary>
        ///  Process message which belongs to the hooked window
        /// </summary>
        /// <param name="hWnd"></param>
        /// <param name="hookedMessage"></param>
        /// <returns>
        ///		This return value will be sended to the Hooked window by our Listener Control
        ///
        ///		Return value might be;
        ///		0 : which means ignore this message (Hooked window will ignore this message)
        ///		1 : Do nothing (Hooked window will do its original action for this message)
        ///		<Other Values> : We are going to change the wParam and lParam for this message
        ///		here the return value indicates an adress in the target process memory which contains
        ///		the new values of the wParam and lParam
        ///		By passing this address to the Hooked window, we make it read the new values
        ///		from this address and replace original wParam and lParam with the new values
        ///		and process message according to this new parameters
        /// </returns>
        internal IntPtr ProcessMessage(IntPtr hWnd, ref NativeMethods.HOOK_MSG hookedMessage)
        {
            lock (this)
            {
                IntPtr             result = IntPtr.Zero;
                NativeMethods.Msgs msg    = (NativeMethods.Msgs)hookedMessage.msg;
                switch (msg)
                {
                case NativeMethods.Msgs.WM_MOVE:
                    _wm.OnMove();
                    break;

                case NativeMethods.Msgs.WM_SIZE:
                    _wm.OnResize();
                    break;
                }
                //if (Enabled && Breakpoints.ContainsKey(msg))
                //{
                //    // if Breakpoints enabled and if we have a breakpoint for the
                //    // given message then do our action
                //    MessageBreakpoint watch = Breakpoints[msg];
                //    switch (watch.Action)
                //    {
                //        case BreakpointAction.IgnoreMessage:
                //            result = new IntPtr(1);
                //            break;
                //        case BreakpointAction.ManuelEditParameters:
                //            FormEditMessage em = new FormEditMessage(hWnd, msg, hookedMessage.wParam, hookedMessage.lParam);
                //            em.ShowDialog(FormMain.Instance);
                //            if (!em.Ignore)
                //                result = WriteToTargetProcessMemory(em.WParam, em.LParam, em.ModifiedMsg);
                //            else
                //                result = new IntPtr(1);
                //            break;
                //        case BreakpointAction.AutoChangeParameters:
                //            NativeMethods.Msgs modifiedMsg = (NativeMethods.Msgs)hookedMessage.msg;
                //            IntPtr wParam = hookedMessage.wParam;
                //            IntPtr lParam = hookedMessage.lParam;

                //            if ((watch.Modifications & ModifiyingSections.Message) == ModifiyingSections.Message
                //                && watch.ModifiedMsg != NativeMethods.Msgs.WM_NULL)
                //                modifiedMsg = watch.ModifiedMsg;

                //            if ((watch.Modifications & ModifiyingSections.WParam) == ModifiyingSections.WParam)
                //                wParam = new IntPtr(watch.WParam.Value);

                //            if ((watch.Modifications & ModifiyingSections.LParam) == ModifiyingSections.LParam)
                //                lParam = new IntPtr(watch.LParam.Value);


                //            result = WriteToTargetProcessMemory(wParam, lParam, modifiedMsg);
                //            break;
                //    }
                //}

                if (ShowMessages)
                {
                    //StringBuilder text = new StringBuilder();
                    //text.AppendFormat("0x{0:X8}", hWnd.ToInt32());
                    //text.Append("  ");
                    //if (msgValues.ContainsKey(msg))
                    //    text.Append(msgValues[msg]);
                    //else
                    //    text.Append(msg);

                    //text.Append("  ");
                    //text.AppendFormat("wParam:{0}", hookedMessage.wParam);
                    //text.AppendFormat(" lParam:{0}", hookedMessage.lParam);
                    //if (result == (IntPtr)1)
                    //    text.Append(Properties.Resources.Hook_Ignored);
                    //text.AppendLine();

                    //FormMain.Instance.txtMessages.AppendText(text.ToString());
                }

                return(result);
            }
        }