Exemplo n.º 1
0
        /// <summary>
        ///  Modific the websocket message with your rule
        /// </summary>
        /// <param name="oSession"></param>
        /// <param name="webSocketMessage"></param>
        /// <param name="nowFiddlerRequsetChange"></param>
        /// <param name="ShowError"></param>
        /// <param name="ShowMes"></param>
        public static void ModificWebSocketMessage(Session oSession, WebSocketMessage webSocketMessage, IFiddlerHttpTamper nowFiddlerChange, bool isRequest, Action <string> ShowError, Action <string> ShowMes)
        {
            if (nowFiddlerChange.ParameterPickList != null)
            {
                PickSessionParameter(oSession, nowFiddlerChange, ShowError, ShowMes, webSocketMessage.IsOutbound, webSocketMessage);
            }
            ContentModific payLoadModific = null;

            if (isRequest)
            {
                FiddlerRequestChange nowFiddlerRequsetChange = (FiddlerRequestChange)nowFiddlerChange;
                payLoadModific = nowFiddlerRequsetChange.BodyModific;
            }
            else
            {
                FiddlerResponseChange nowFiddlerResponseChange = (FiddlerResponseChange)nowFiddlerChange;
                payLoadModific = nowFiddlerResponseChange.BodyModific;
            }
            //Modific body
            if (payLoadModific != null && payLoadModific.ModificMode != ContentModificMode.NoChange)
            {
                if (payLoadModific.ModificMode == ContentModificMode.HexReplace)
                {
                    try
                    {
                        webSocketMessage.SetPayload(payLoadModific.GetFinalContent(webSocketMessage.PayloadAsBytes()));
                    }
                    catch (Exception ex)
                    {
                        ShowError(string.Format("error in GetFinalContent in HexReplace with [{0}]", ex.Message));
                    }
                }
                else
                {
                    string sourcePayload = webSocketMessage.PayloadAsString();
                    if (payLoadModific.ModificMode == ContentModificMode.ReCode)
                    {
                        try
                        {
                            webSocketMessage.SetPayload(payLoadModific.GetRecodeContent(sourcePayload));
                        }
                        catch (Exception ex)
                        {
                            ShowError(string.Format("error in GetRecodeContent in ReCode with [{0}]", ex.Message));
                        }
                    }
                    else
                    {
                        webSocketMessage.SetPayload(payLoadModific.GetFinalContent(sourcePayload));
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///  Modific the websocket message with your rule
        /// </summary>
        /// <param name="oSession"></param>
        /// <param name="webSocketMessage"></param>
        /// <param name="nowFiddlerRequsetChange"></param>
        /// <param name="ShowError"></param>
        /// <param name="ShowMes"></param>
        public static void ModificWebSocketMessage(Session oSession, WebSocketMessage webSocketMessage, IFiddlerHttpTamper nowFiddlerChange, bool isRequest, Action <string> ShowError, Action <string> ShowMes)
        {
            if (nowFiddlerChange.ParameterPickList != null)
            {
                PickSessionParameter(oSession, nowFiddlerChange, ShowError, ShowMes, webSocketMessage.IsOutbound, webSocketMessage);
            }
            ParameterContentModific payLoadModific = null;

            if (isRequest)
            {
                FiddlerRequestChange nowFiddlerRequsetChange = (FiddlerRequestChange)nowFiddlerChange;
                payLoadModific = nowFiddlerRequsetChange.BodyModific;
            }
            else
            {
                FiddlerResponseChange nowFiddlerResponseChange = (FiddlerResponseChange)nowFiddlerChange;
                payLoadModific = nowFiddlerResponseChange.BodyModific;
            }
            //Modific body
            if (payLoadModific != null && payLoadModific.ModificMode != ContentModificMode.NoChange)
            {
                if (payLoadModific.ModificMode == ContentModificMode.HexReplace)
                {
                    try
                    {
                        webSocketMessage.SetPayload(payLoadModific.GetFinalContent(webSocketMessage.PayloadAsBytes()));
                    }
                    catch (Exception ex)
                    {
                        ShowError(string.Format("error in GetFinalContent in HexReplace with [{0}]", ex.Message));
                    }
                }
                else
                {
                    if (webSocketMessage.FrameType == WebSocketFrameTypes.Binary)
                    {
                        ShowError("error in GetFinalContent that WebSocketFrameTypes is Binary ,just use <hex> mode");
                    }
                    else if (webSocketMessage.FrameType == WebSocketFrameTypes.Ping || webSocketMessage.FrameType == WebSocketFrameTypes.Pong || webSocketMessage.FrameType == WebSocketFrameTypes.Close)
                    {
                        // do nothing
                    }
                    else
                    {
                        string sourcePayload = webSocketMessage.PayloadAsString();
                        if (payLoadModific.ModificMode == ContentModificMode.ReCode)
                        {
                            try
                            {
                                webSocketMessage.SetPayload(payLoadModific.GetRecodeContent(sourcePayload));
                            }
                            catch (Exception ex)
                            {
                                ShowError(string.Format("error in GetRecodeContent in ReCode with [{0}]", ex.Message));
                            }
                        }
                        else
                        {
                            string errMes;
                            NameValueCollection nameValueCollection = new NameValueCollection();

                            //webSocketMessage.SetPayload(payLoadModific.GetFinalContent(sourcePayload));
                            string tempPayload = payLoadModific.GetFinalContent(sourcePayload, nameValueCollection, out errMes);
                            if (errMes != null)
                            {
                                ShowError(string.Format("error in GetFinalContent in PayLoadModific that [{0}]", errMes));
                            }
                            if (tempPayload != sourcePayload) //非标准协议的实现,或没有实现的压缩会导致PayloadAsString()使数据不可逆
                            {
                                webSocketMessage.SetPayload(tempPayload);
                            }

                            if (nameValueCollection != null && nameValueCollection.Count > 0)
                            {
                                ShowMes(string.Format("[ParameterizationContent]:{0}", nameValueCollection.MyToFormatString()));
                            }
                        }
                    }
                }
            }
        }