private void myFreeHttpWindow_OnGetSessionSeekHead(object sender, FreeHttpWindow.GetSessionSeekHeadEventArgs e) { Session tempSession = Fiddler.FiddlerObject.UI.GetFirstSelectedSession(); if (tempSession == null) { FreeHttpWindow.MarkWarnControl(Fiddler.FiddlerApplication.UI.lvSessions); } else { if (e != null && e.ResquestHead.Key != null) { //HTTPHeaderItem nowHTTPHeaderItem = tempSession.RequestHeaders.First(hTTPHeaderItem => hTTPHeaderItem.Name == e.ResquestHead.Key); HTTPHeaderItem nowHTTPHeaderItem = tempSession.RequestHeaders.FirstOrDefault(hTTPHeaderItem => hTTPHeaderItem.Name == e.ResquestHead.Key); if (nowHTTPHeaderItem != null) { e.ResquestHead = new KeyValuePair <string, string>(nowHTTPHeaderItem.Name, nowHTTPHeaderItem.Value); e.SeekUri = tempSession.fullUrl; } } if (e != null && e.ResponseHead.Key != null) { HTTPHeaderItem nowHTTPHeaderItem = tempSession.ResponseHeaders.FirstOrDefault(hTTPHeaderItem => hTTPHeaderItem.Name == e.ResponseHead.Key); if (nowHTTPHeaderItem != null) { e.ResponseHead = new KeyValuePair <string, string>(nowHTTPHeaderItem.Name, nowHTTPHeaderItem.Value); e.SeekUri = tempSession.fullUrl; } } } }
private void myFreeHttpWindow_OnGetSessionRawData(object sender, FreeHttpWindow.GetSessionRawDataEventArgs e) { Session tempSession = Fiddler.FiddlerObject.UI.GetFirstSelectedSession(); if (tempSession == null) { Fiddler.FiddlerObject.UI.ShowAlert(new frmAlert("STOP", "please select a session", "OK")); FreeHttpWindow.MarkWarnControl(Fiddler.FiddlerApplication.UI.lvSessions); return; } switch (e.SessionAction) { case FreeHttpWindow.GetSessionAction.ShowShowResponse: string tempStr = FiddlerSessionTamper.GetSessionRawData(tempSession, true); ShowMes(tempStr == null ? "error session" : string.Format("Get Raw Data\r\n{0}", tempStr)); myFreeHttpWindow.ShowOwnerWindow(tempSession.fullUrl, tempStr); break; case FreeHttpWindow.GetSessionAction.SetCookies: myFreeHttpWindow.SetClientAddCookies(tempSession.RequestHeaders["Cookie"]); break; case FreeHttpWindow.GetSessionAction.DeleteCookies: myFreeHttpWindow.SetClientDelCookies(tempSession.RequestHeaders["Cookie"]); break; default: Fiddler.FiddlerObject.UI.ShowAlert(new frmAlert("STOP", "Not supported this SessionAction", "OK")); break; } }
public void OnLoad() { AddFiddlerObjectLog("OnLoad"); //string workPath = string.Format("{0}\\FreeHttp", System.Windows.Forms.Application.StartupPath); //System.Threading.Tasks.Task.Run(OnLoad); string workPath = string.Format("{0}\\FreeHttp", Directory.GetCurrentDirectory()); if (!isOnLoad) { tabPage = new TabPage(); tabPage.Text = "Free Http"; if (FiddlerApplication.UI.tabsViews.ImageList != null) { myIco = FreeHttp.Resources.MyResource.freehttp; FiddlerApplication.UI.tabsViews.ImageList.Images.Add(myIco); tabPage.ImageIndex = FiddlerApplication.UI.tabsViews.ImageList.Images.Count - 1; } try { if (!Directory.Exists(workPath)) { AddFiddlerObjectLog(string.Format("Create working directory {0}", workPath)); Directory.CreateDirectory(workPath); } AddFiddlerObjectLog(string.Format("load configuration")); myFreeHttpWindow = new FreeHttpWindow(SerializableHelper.DeserializeRuleList(), SerializableHelper.DeserializeData <FiddlerModificSettingInfo>("FreeHttp\\FreeHttpSetting.xml"), SerializableHelper.DeserializeContractData <FreeHttp.AutoTest.RunTimeStaticData.ActuatorStaticDataCollection>("FreeHttp\\FreeHttpStaticDataCollection.xml")); } catch (Exception ex) { AddFiddlerObjectLog(string.Format("load configuration fial ,{0}", ex.Message)); } finally { if (myFreeHttpWindow == null) { myFreeHttpWindow = new FreeHttpWindow(null, null, null); } } myFreeHttpWindow.OnUpdataFromSession += myFreeHttpWindow_OnUpdataFromSession; myFreeHttpWindow.OnGetSessionRawData += myFreeHttpWindow_OnGetSessionRawData; myFreeHttpWindow.OnGetSessionEventArgs += MyFreeHttpWindow_OnGetSessionEventArgs; myFreeHttpWindow.OnGetSessionSeekHead += myFreeHttpWindow_OnGetSessionSeekHead; myFreeHttpWindow.OnShowInIndependentWindow += MyFreeHttpWindow_OnShowInIndependentWindow; myFreeHttpWindow.Dock = DockStyle.Fill; myFreeHttpWindow.Enter += myFreeHttpWindow_Enter; tabPage.Controls.Add(myFreeHttpWindow); FiddlerApplication.UI.tabsViews.TabPages.Add(tabPage); Fiddler.FiddlerApplication.UI.Deactivate += UI_Deactivate; FiddlerApplication.UI.tabsViews.SelectedIndexChanged += tabsViews_SelectedIndexChanged; FiddlerApplication.OnWebSocketMessage += FiddlerApplication_OnWebSocketMessage; FiddlerApplication.UI.tabsViews.ParentChanged += TabsViews_ParentChanged; upgradeService = new UpgradeService(); upgradeService.GetUpgradeMes += upgradeService_GetUpgradeMes; operationReportService = new OperationReportService(); isOnLoad = true; } }
private void myFreeHttpWindow_OnUpdataFromSession(object sender, EventArgs e) { Session tempSession = Fiddler.FiddlerObject.UI.GetFirstSelectedSession(); if (tempSession != null) { ShowMes(string.Format("Get http session in {0}", tempSession.fullUrl)); ((FreeHttpWindow)sender).SetModificSession(tempSession); } else { Fiddler.FiddlerObject.UI.ShowAlert(new frmAlert("STOP", "please select a session", "OK")); //((FreeHttpWindow)sender).MarkWarnControl(Fiddler.FiddlerApplication.UI.Controls[0]); FreeHttpWindow.MarkWarnControl(Fiddler.FiddlerApplication.UI.lvSessions); } }
public ParameterPick GetParameterPickInfo() { Action <Control, string> MyThrowException = (myControl, errorMes) => { FreeHttpWindow.MarkWarnControl(myControl); this.errorProvider_addParameter.SetIconAlignment(myControl, ErrorIconAlignment.MiddleRight); this.errorProvider_addParameter.SetIconPadding(myControl, -20); this.errorProvider_addParameter.SetError(myControl, errorMes); myControl.Select(); myControl.Focus(); throw new Exception(errorMes); }; this.errorProvider_addParameter.Clear(); ParameterPick returnParameterPick = new ParameterPick(); ParameterPickType tempParameterPickType; if (string.IsNullOrEmpty(tb_ParameterName.Text)) { MyThrowException(tb_ParameterName, "your ParameterName is empty"); } returnParameterPick.ParameterName = tb_ParameterName.Text; returnParameterPick.PickRange = (ParameterPickRange)Enum.Parse(typeof(ParameterPickRange), cb_pickRange.Text); if (!Enum.TryParse <ParameterPickType>(cb_ParameterType.Text, out tempParameterPickType)) { MyThrowException(cb_ParameterType, "ParameterPickType Error"); } returnParameterPick.PickType = tempParameterPickType; returnParameterPick.PickTypeAdditional = cb_ParameterTypeAddition.Text; returnParameterPick.PickTypeExpression = tb_ParameterExpression.Text; string tempError = ParameterPickHelper.CheckParameterPickExpression(returnParameterPick); if (tempError != null) { if (tempError.Contains("PickTypeAdditional")) { MyThrowException(cb_ParameterTypeAddition, tempError); } else { MyThrowException(tb_ParameterExpression, tempError); } } return(returnParameterPick); }
public void AutoTamperResponseAfter(Session oSession) { if (!isOnLoad) { return; } if (myFreeHttpWindow.IsResponseRuleEnable) { if (isSkipUiHide && oSession["ui-hide"] == "true") { return; } if (myFreeHttpWindow.ModificSettingInfo.IsSkipConnectTunnels && oSession.RequestMethod == "CONNECT") { return; } List <IFiddlerHttpTamper> matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.FiddlerResponseChangeList, false); if (matchItems != null && matchItems.Count > 0) { foreach (var matchItem in matchItems) { FiddlerResponseChange nowFiddlerResponseChange = ((FiddlerResponseChange)matchItem); ListViewItem tempListViewItem = myFreeHttpWindow.FindListViewItemFromRule(matchItem); if (!(nowFiddlerResponseChange.IsRawReplace && nowFiddlerResponseChange.IsIsDirectRespons)) { FreeHttpWindow.MarkMatchRule(tempListViewItem); MarkSession(oSession); ShowMes(string.Format("macth the [reponse rule {0}] with {1}", tempListViewItem.SubItems[0].Text, oSession.fullUrl)); FiddlerSessionTamper.ModificSessionResponse(oSession, nowFiddlerResponseChange, ShowError, ShowMes); } if (nowFiddlerResponseChange.LesponseLatency > 0) { ShowMes(string.Format("[reponse rule {0}] is modified , now delay {1} ms", tempListViewItem.SubItems[0].Text, nowFiddlerResponseChange.LesponseLatency)); System.Threading.Thread.Sleep(nowFiddlerResponseChange.LesponseLatency); } if (myFreeHttpWindow.ModificSettingInfo.IsOnlyMatchFistTamperRule) { break; } } } } }
void myFreeHttpWindow_OnGetSessionRawData(object sender, FreeHttpWindow.GetSessionRawDataEventArgs e) { Session tempSession = Fiddler.FiddlerObject.UI.GetFirstSelectedSession(); if (tempSession != null) { if (e.IsGetCookies) { myFreeHttpWindow.SetClientCookies(tempSession.RequestHeaders["Cookie"]); } else { string tempStr = FiddlerSessionTamper.GetSessionRawData(tempSession, e.IsShowResponse); ShowMes(tempStr == null ? "error session" : string.Format("Get Raw Data\r\n{0}", tempStr)); myFreeHttpWindow.ShowOwnerWindow(tempSession.fullUrl, tempStr); } } else { Fiddler.FiddlerObject.UI.ShowAlert(new frmAlert("STOP", "please select a session", "OK")); //((FreeHttpWindow)sender).MarkWarnControl(Fiddler.FiddlerApplication.UI.lvSessions); FreeHttpWindow.MarkWarnControl(Fiddler.FiddlerApplication.UI.lvSessions); } }
public void AutoTamperRequestBefore(Session oSession) { //if (oSession.HTTPMethodIs("CONNECT") && oSession.HostnameIs("api.map.baidu.com")) //{ // oSession["x-OverrideSslProtocols"] = "ssl3.0"; //} //oSession.oRequest["AddOrigin"] = "from lijie PC"; if (!isOnLoad) { return; } if (myFreeHttpWindow.IsRequestRuleEnable) { //IsRequestRuleEnable is more efficient then string comparison (so if not IsRequestRuleEnable the string comparison will not execute) if (isSkipUiHide && oSession["ui-hide"] == "true") { return; } if (myFreeHttpWindow.ModificSettingInfo.IsSkipConnectTunnels && oSession.RequestMethod == "CONNECT") { return; } List <IFiddlerHttpTamper> matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.FiddlerRequestChangeList, true); if (matchItems != null && matchItems.Count > 0) { foreach (var matchItem in matchItems) { FiddlerRequestChange nowFiddlerRequsetChange = ((FiddlerRequestChange)matchItem); ListViewItem tempListViewItem = myFreeHttpWindow.FindListViewItemFromRule(matchItem); FreeHttpWindow.MarkMatchRule(tempListViewItem); MarkSession(oSession); ShowMes(string.Format("macth the [requst rule {0}] with {1}", tempListViewItem.SubItems[0].Text, oSession.fullUrl)); FiddlerSessionTamper.ModificSessionRequest(oSession, nowFiddlerRequsetChange, ShowError, ShowMes); if (myFreeHttpWindow.ModificSettingInfo.IsOnlyMatchFistTamperRule) { break; } } } } if (myFreeHttpWindow.IsResponseRuleEnable) { if (myFreeHttpWindow.ModificSettingInfo.IsSkipConnectTunnels && oSession.RequestMethod == "CONNECT") { return; } List <IFiddlerHttpTamper> matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.FiddlerResponseChangeList, false); if (matchItems != null && matchItems.Count > 0) { oSession.bBufferResponse = true;// if any response rule may match the Session, we should set bBufferResponse true (When streaming is enabled for a response, each block of data read from the server is immediately passed to the client application. ) foreach (var matchItem in matchItems) { FiddlerResponseChange nowFiddlerResponseChange = ((FiddlerResponseChange)matchItem); ListViewItem tempListViewItem = myFreeHttpWindow.FindListViewItemFromRule(matchItem); if (nowFiddlerResponseChange.IsIsDirectRespons) { FreeHttpWindow.MarkMatchRule(tempListViewItem); MarkSession(oSession); ShowMes(string.Format("macth the [reponse rule {0}] with {1}", tempListViewItem.SubItems[0].Text, oSession.fullUrl)); FiddlerSessionTamper.ReplaceSessionResponse(oSession, nowFiddlerResponseChange, ShowError, ShowMes); //oSession.state = SessionStates.Done; if (myFreeHttpWindow.ModificSettingInfo.IsOnlyMatchFistTamperRule) { break; } } } } } }
private void FiddlerApplication_OnWebSocketMessage(object sender, WebSocketMessageEventArgs e) { //((Bitmap)((Fiddler.Session)sender).ViewItem.ImageList.Images[34]).Save(@"D:\A1.ico", System.Drawing.Imaging.ImageFormat.Icon); Session oSession = (Session)sender; WebSocketMessage webSocketMessage = e.oWSM; if (!isOnLoad) { return; } if (webSocketMessage == null) { AddFiddlerObjectLog("get null WebSocketMessage"); return; } if (webSocketMessage.FrameType == WebSocketFrameTypes.Close || webSocketMessage.FrameType == WebSocketFrameTypes.Ping || webSocketMessage.FrameType == WebSocketFrameTypes.Pong || webSocketMessage.FrameType == WebSocketFrameTypes.Reservedx3 || webSocketMessage.FrameType == WebSocketFrameTypes.Reservedx4 || webSocketMessage.FrameType == WebSocketFrameTypes.Reservedx5 || webSocketMessage.FrameType == WebSocketFrameTypes.Reservedx6 || webSocketMessage.FrameType == WebSocketFrameTypes.Reservedx7 || webSocketMessage.FrameType == WebSocketFrameTypes.ReservedxB || webSocketMessage.FrameType == WebSocketFrameTypes.ReservedxC || webSocketMessage.FrameType == WebSocketFrameTypes.ReservedxD || webSocketMessage.FrameType == WebSocketFrameTypes.ReservedxE || webSocketMessage.FrameType == WebSocketFrameTypes.ReservedxF) { return; } if ((myFreeHttpWindow.IsRequestRuleEnable && webSocketMessage.IsOutbound) || (myFreeHttpWindow.IsResponseRuleEnable && !webSocketMessage.IsOutbound)) { if (isSkipUiHide && oSession["ui-hide"] == "true") { return; } if (myFreeHttpWindow.ModificSettingInfo.IsSkipConnectTunnels && oSession.RequestMethod == "CONNECT") { return; } bool isRequest = webSocketMessage.IsOutbound; List <IFiddlerHttpTamper> matchItems = null; if (isRequest) { matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.FiddlerRequestChangeList, isRequest, webSocketMessage); } else { //oSession.WriteResponseToStream(new MemoryStream(new Byte[] { 0x81,0x81,0x01,0x41 }), false); //WebSocket ws = oSession.__oTunnel as WebSocket; //ws.listMessages.Add(webSocketMessage); matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.FiddlerResponseChangeList, isRequest, webSocketMessage); } if (matchItems != null && matchItems.Count > 0) { foreach (var matchItem in matchItems) { ListViewItem tempListViewItem = myFreeHttpWindow.FindListViewItemFromRule(matchItem); FreeHttpWindow.MarkMatchRule(tempListViewItem); MarkSession(oSession); ShowMes(string.Format("macth the [requst rule {0}] with {1}", tempListViewItem.SubItems[0].Text, oSession.fullUrl)); FiddlerSessionTamper.ModificWebSocketMessage(oSession, webSocketMessage, matchItem, isRequest, ShowError, ShowMes); if (!isRequest) { FiddlerResponseChange nowFiddlerResponseChange = ((FiddlerResponseChange)matchItem); if (nowFiddlerResponseChange.LesponseLatency > 0) { ShowMes(string.Format("[reponse rule {0}] is modified , now delay {1} ms", tempListViewItem.SubItems[0].Text, nowFiddlerResponseChange.LesponseLatency)); System.Threading.Thread.Sleep(nowFiddlerResponseChange.LesponseLatency); } if (myFreeHttpWindow.ModificSettingInfo.IsOnlyMatchFistTamperRule) { break; } } } } } }
public void AutoTamperRequestBefore(Session oSession) { //if (oSession.HTTPMethodIs("CONNECT") && oSession.HostnameIs("api.map.baidu.com")) //{ // oSession["x-OverrideSslProtocols"] = "ssl3.0"; //} //oSession.oRequest["AddOrigin"] = "from lijie PC"; if (!isOnLoad) { return; } if (myFreeHttpWindow.IsRequestRuleEnable) { //IsRequestRuleEnable is more efficient then string comparison (so if not IsRequestRuleEnable the string comparison will not execute) if (isSkipUiHide && oSession["ui-hide"] == "true") { return; } if (myFreeHttpWindow.ModificSettingInfo.IsSkipTlsHandshake && oSession.RequestMethod == "CONNECT") { return; } List <ListViewItem> matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.RequestRuleListView, true); if (matchItems != null && matchItems.Count > 0) { foreach (var matchItem in matchItems) { FiddlerRequsetChange nowFiddlerRequsetChange = ((FiddlerRequsetChange)matchItem.Tag); FreeHttpWindow.MarkMatchRule(matchItem); MarkSession(oSession); ShowMes(string.Format("macth the [requst rule {0}] with {1}", matchItem.SubItems[0].Text, oSession.fullUrl)); FiddlerSessionTamper.ModificSessionRequest(oSession, nowFiddlerRequsetChange, ShowError, ShowMes); if (myFreeHttpWindow.ModificSettingInfo.IsOnlyMatchFistTamperRule) { break; } } } } if (myFreeHttpWindow.IsResponseRuleEnable) { if (myFreeHttpWindow.ModificSettingInfo.IsSkipTlsHandshake && oSession.RequestMethod == "CONNECT") { return; } List <ListViewItem> matchItems = FiddlerSessionHelper.FindMatchTanperRule(oSession, myFreeHttpWindow.ResponseRuleListView, false); if (matchItems != null && matchItems.Count > 0) { foreach (var matchItem in matchItems) { FiddlerResponseChange nowFiddlerResponseChange = ((FiddlerResponseChange)matchItem.Tag); if (nowFiddlerResponseChange.IsIsDirectRespons) { FreeHttpWindow.MarkMatchRule(matchItem); MarkSession(oSession); ShowMes(string.Format("macth the [reponse rule {0}] with {1}", matchItem.SubItems[0].Text, oSession.fullUrl)); FiddlerSessionTamper.ReplaceSessionResponse(oSession, nowFiddlerResponseChange, ShowError, ShowMes); //oSession.state = SessionStates.Done; if (myFreeHttpWindow.ModificSettingInfo.IsOnlyMatchFistTamperRule) { break; } } } } } }