Пример #1
0
		private void FiddlerApplication_AfterSessionComplete( Fiddler.Session oSession ) {

			//保存
			{
				Utility.Configuration.ConfigurationData.ConfigConnection c = Utility.Configuration.Config.Connection;

				if ( c.SaveReceivedData ) {

					try {

						if ( !Directory.Exists( c.SaveDataPath ) )
							Directory.CreateDirectory( c.SaveDataPath );


						if ( c.SaveResponse && oSession.fullUrl.Contains( "/kcsapi/" ) ) {

							// 非同期で書き出し処理するので取っておく
							// stringはイミュータブルなのでOK
							string url = oSession.fullUrl;
							string body = oSession.GetResponseBodyAsString();

							Task.Run( (Action)( () => {
								SaveResponse( url, body );
							} ) );

						} else if ( oSession.fullUrl.Contains( "/kcs/" ) &&
							( ( c.SaveSWF && oSession.oResponse.MIMEType == "application/x-shockwave-flash" ) || c.SaveOtherFile ) ) {

							string saveDataPath = c.SaveDataPath; // スレッド間の競合を避けるため取っておく
							string tpath = string.Format( "{0}\\{1}", saveDataPath, oSession.fullUrl.Substring( oSession.fullUrl.IndexOf( "/kcs/" ) + 5 ).Replace( "/", "\\" ) );
							{
								int index = tpath.IndexOf( "?" );
								if ( index != -1 ) {
									if ( Utility.Configuration.Config.Connection.ApplyVersion ) {
										string over = tpath.Substring( index + 1 );
										int vindex = over.LastIndexOf( "VERSION=", StringComparison.CurrentCultureIgnoreCase );
										if ( vindex != -1 ) {
											string version = over.Substring( vindex + 8 ).Replace( '.', '_' );
											tpath = tpath.Insert( tpath.LastIndexOf( '.', index ), "_v" + version );
											index += version.Length + 2;
										}

									}

									tpath = tpath.Remove( index );
								}
							}

							// 非同期で書き出し処理するので取っておく
							byte[] responseCopy = new byte[oSession.ResponseBody.Length];
							Array.Copy( oSession.ResponseBody, responseCopy, oSession.ResponseBody.Length );

							Task.Run( (Action)( () => {
								try {
									lock ( this ) {
										// 同時に書き込みが走るとアレなのでロックしておく

										Directory.CreateDirectory( Path.GetDirectoryName( tpath ) );

										//System.Diagnostics.Debug.WriteLine( oSession.fullUrl + " => " + tpath );
										using ( var sw = new System.IO.BinaryWriter( System.IO.File.OpenWrite( tpath ) ) ) {
											sw.Write( responseCopy );
										}
									}

									Utility.Logger.Add( 1, string.Format( "通信からファイル {0} を保存しました。", tpath.Remove( 0, saveDataPath.Length + 1 ) ) );

								} catch ( IOException ex ) {	//ファイルがロックされている; 頻繁に出るのでエラーレポートを残さない

									Utility.Logger.Add( 3, "通信内容の保存に失敗しました。 " + ex.Message );
								}
							} ) );

						}

					} catch ( Exception ex ) {

						Utility.ErrorReporter.SendErrorReport( ex, "通信内容の保存に失敗しました。" );
					}

				}

			}


			if ( oSession.fullUrl.Contains( "/kcsapi/" ) && oSession.oResponse.MIMEType == "text/plain" ) {

				// 非同期でGUIスレッドに渡すので取っておく
				// stringはイミュータブルなのでOK
				string url = oSession.fullUrl;
				string body = oSession.GetResponseBodyAsString();
				UIControl.BeginInvoke( (Action)( () => { LoadResponse( url, body ); } ) );

				// kancolle-db.netに送信する
				if ( Utility.Configuration.Config.Connection.SendDataToKancolleDB ) {
					Task.Run( (Action)( () => DBSender.ExecuteSession( oSession ) ) );
				}

			}



			if ( ServerAddress == null ) {
				string url = oSession.fullUrl;

				int idxb = url.IndexOf( "/kcsapi/" );

				if ( idxb != -1 ) {
					int idxa = url.LastIndexOf( "/", idxb - 1 );

					ServerAddress = url.Substring( idxa + 1, idxb - idxa - 1 );
				}
			}

		}
Пример #2
0
		private void FiddlerApplication_BeforeResponse( Fiddler.Session oSession ) {

			//flash 品質設定
			if ( oSession.bBufferResponse && oSession.fullUrl.Contains( "/gadget/js/kcs_flash.js" ) ) {

				string js = oSession.GetResponseBodyAsString();
				bool flag = false;

				var wmode = _wmodeRegex.Match( js );
				if ( wmode.Success ) {
					js = js.Replace( wmode.Value, string.Format( @"""wmode"":""{0}""", Utility.Configuration.Config.FormBrowser.FlashWMode ) );
					flag = true;
				}

				var quality = _qualityRegex.Match( js );
				if ( quality.Success ) {
					js = js.Replace( quality.Value, string.Format( @"""quality"":""{0}""", Utility.Configuration.Config.FormBrowser.FlashQuality ) );
					flag = true;
				}

				if ( flag ) {
					oSession.utilSetResponseBody( js );

					Utility.Logger.Add( 1, "flashの品質設定を行いました。" );
				}
			}
		}
Пример #3
0
        void FiddlerApplication_AfterSessionComplete(Fiddler.Session oSession)
        {
            //ignoreフラグが立っていればリターン
            if (oSession.isFlagSet(Fiddler.SessionFlags.Ignored))
                return;

            string url = oSession.fullUrl;
            try
            {

                Invoke(new UpdateUI(() =>
                   {
                       if (checkBox1.Checked)
                       {
                           if (url.IndexOf("/kcs/") > 0)
                           {
                               listBox1.Items.Add(url);
                               listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;
                           }

                           if (url.IndexOf("/kcsapi/") > 0)
                           {
                               if (checkBox2.Checked)
                                   sw5.Start();

                               listBox1.Items.Add(url);
                               listBox1.TopIndex = listBox1.Items.Count - listBox1.Height / listBox1.ItemHeight;

                               if (checkBox4.Checked)
                               {
                                   string str = oSession.GetResponseBodyAsString();
                                   str = str.Substring(str.IndexOf("=") + 1);
                                   var json = DynamicJson.Parse(str);
                                   string filepath = @"result.txt";
                                   string text = url + Environment.NewLine + str + Environment.NewLine + json + Environment.NewLine + Environment.NewLine;
                                   File.AppendAllText(filepath, text);
                               }

                               if (checkBox3.Checked)
                               {
                                   string str = oSession.GetResponseBodyAsString();
                                   str = str.Substring(str.IndexOf("=") + 1);
                                   var json = DynamicJson.Parse(str);
                                   textBox1.AppendText(url + Environment.NewLine + str + Environment.NewLine + Environment.NewLine);
                                   textBox2.AppendText(url + Environment.NewLine + json + Environment.NewLine + Environment.NewLine);
                               }
                           }

                       }

                   }));
                if (url.IndexOf("/kcsapi/") > 0)
                {

                    string str = oSession.GetResponseBodyAsString();
                    str = str.Substring(str.IndexOf("=") + 1);
                    var json = DynamicJson.Parse(str);
                    var Member = new Edit_Ship { Ships = Member_Ship };

                    if (url.IndexOf("/api_get_member/basic") > 0)
                        MakeBasic(json);

                    if (url.IndexOf("/api_get_member/deck_port") > 0)
                        ParseMission(json);

                    if (url.IndexOf("/api_get_member/ndock") > 0)
                        ParseDock(json);

                    if (url.IndexOf("/api_get_member/material") > 0)
                        MakeMaterial(json);

                    if (url.IndexOf("api_get_member/deck") > 0 && url.IndexOf("api_get_member/deck_port") < 0)
                    {
                        var json_deck = json.api_data;
                        ParseMission(json);
                        Invoke(new UpdateUI_JSON(UpdateDeck), json_deck);
                    }

                    if (url.IndexOf("/api_get_member/ship2") > 0)
                    {

                        var deck_data = json.api_data_deck;
                        var ship_data = json.api_data;
                        var loop = ((member_ship[])ship_data).Count();

                        KanmusuCurrent.Invoke(new UpdateUI(() =>
                        {
                            KanmusuCurrent.Text = loop.ToString();
                        }));

                        Member.Make_Member_ShipTable(ship_data);
                       // Make_Member_ShipTable(ship_data);
                        Invoke(new UpdateUI_JSON(UpdateDeck), deck_data);
                    }

                    if (url.IndexOf("/api_get_member/ship3") > 0)
                    {
                        var deck_data = json.api_data.api_deck_data;
                        var ship_data = json.api_data.api_ship_data;
                        var loop = ((member_ship[])ship_data).Count();

                        KanmusuCurrent.Invoke(new UpdateUI(() =>
                        {
                            KanmusuCurrent.Text = loop.ToString();
                        }));
                        Member.Make_Member_ShipTable(ship_data);
                       // Make_Member_ShipTable(ship_data);
                        Invoke(new UpdateUI_JSON(UpdateDeck), deck_data);
                    }

                    sw5.Stop();
                    if (checkBox2.Checked)
                    {
                        textBox3.Invoke(new UpdateUI(() =>
                        {
                            textBox3.AppendText("\"" + url + "\"" + Environment.NewLine + "Session Complete = " + sw5.Elapsed + Environment.NewLine);
                        }));
                    }
                    sw5.Reset();
                }
            }
            catch
            {
                textBox3.Invoke(new UpdateUI(() =>
                {
                    textBox3.AppendText(url + "にて例外エラー" + Environment.NewLine);
                }));
            }
        }