Guest User

flog projtect ref with this

a guest
Oct 16th, 2018
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 28.19 KB | None | 0 0
  1. /*
  2. * This demo program shows how to use the FiddlerCore library.
  3. *
  4. * Before compiling, ensure that the project's REFERENCES list points to the
  5. * copy of FiddlerCore4.dll included in this package.
  6. *
  7. * SESSION ARCHIVE (SAZ) SUPPORT
  8. * ===========
  9. * By default, the project is compiled without support for the SAZ File format.
  10. * If you want to add SAZ support, define the token SAZ_SUPPORT in the list of
  11. * Conditional Compilation symbols on the project's BUILD tab. You will also
  12. * need to add Ionic.Zip.Reduced.dll to your project's references, add the included
  13. * SAZ-DotNetZip.cs file to your code, and set
  14. *
  15. * FiddlerApplication.oSAZProvider = new DNZSAZProvider();
  16. *
  17. * in your startup code, as shown below.
  18. */
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27. using System;
  28. using System.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Threading;
  32. using Fiddler;
  33. using System.Threading.Tasks;
  34.  
  35. namespace Demo
  36. {
  37. public class Program
  38. {
  39. public static bool filewtittebtodisk;
  40.  
  41. public static bool insidetheprogram = true;
  42.  
  43.  
  44.  
  45. public static int count = 0;
  46. public static Proxy oSecureEndpoint;
  47. public static string sSecureEndpointHostname = "localhost";
  48. public static int iSecureEndpointPort = 7777;
  49.  
  50. public static List<Fiddler.Session> oAllSessions;
  51. public static void WriteCommandResponse(string s)
  52. {
  53. //ConsoleColor oldColor = Console.ForegroundColor;
  54. //Console.ForegroundColor = ConsoleColor.Yellow;
  55. //Console.WriteLine(s);
  56. //Console.ForegroundColor = oldColor;
  57. }
  58. public static string logpath;
  59.  
  60. public static void DoQuit()
  61. {
  62.  
  63. if (null != oSecureEndpoint) oSecureEndpoint.Dispose();
  64.  
  65. Fiddler.FiddlerApplication.Shutdown();
  66.  
  67. }
  68. public static string Ellipsize(string s, int iLen)
  69. {
  70. if (s.Length <= iLen) return s;
  71. return s.Substring(0, iLen - 3) + "...";
  72. }
  73.  
  74. public Program()
  75. {
  76. logpath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\PerformanceMonitorUtility";
  77. }
  78.  
  79. //private void T_Tick(object sender, EventArgs e)
  80. //{
  81. // //if (count == 1)
  82. // //{
  83. // // string[] s = { "l" };
  84. // // Main(s);
  85. // // count = count + 1;
  86. // //}
  87. //}
  88.  
  89. #if SAZ_SUPPORT
  90. public static void ReadSessions(List<Fiddler.Session> oAllSessions)
  91. {
  92. Session[] oLoaded = Utilities.ReadSessionArchive(Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
  93. + Path.DirectorySeparatorChar + "ToLoad.saz", false);
  94.  
  95. if ((oLoaded != null) && (oLoaded.Length > 0))
  96. {
  97. oAllSessions.AddRange(oLoaded);
  98. WriteCommandResponse("Loaded: " + oLoaded.Length + " sessions.");
  99. }
  100. }
  101.  
  102. public static void SaveSessionsToDesktop(List<Fiddler.Session> oAllSessions)
  103. {
  104. bool bSuccess = false;
  105.  
  106. if (!Directory.Exists(logpath + "\\Log\\NetworkLog"))
  107. {
  108. Directory.CreateDirectory(logpath + "\\Log\\NetworkLog");
  109. }
  110.  
  111.  
  112. string sFilename = logpath + "\\Log\\NetworkLog\\" + DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + ".saz";
  113.  
  114.  
  115. try
  116. {
  117. try
  118. {
  119. Monitor.Enter(oAllSessions);
  120.  
  121. string sPassword = "ECWTECH";
  122.  
  123.  
  124. bSuccess = Utilities.WriteSessionArchive(sFilename, oAllSessions.ToArray(), sPassword, false);
  125. }
  126. finally
  127. {
  128. Monitor.Exit(oAllSessions);
  129. }
  130.  
  131. //WriteCommandResponse(bSuccess ? ("Wrote: " + sFilename) : ("Failed to save: " + sFilename));
  132. }
  133. #pragma warning disable
  134. catch (Exception eX)
  135. {
  136. //Console.WriteLine("Save failed: " + eX.Message);
  137. }
  138. }
  139. #endif
  140.  
  141. public static void WriteSessionList(List<Fiddler.Session> oAllSessions)
  142. {
  143. //ConsoleColor oldColor = Console.ForegroundColor;
  144. //Console.ForegroundColor = ConsoleColor.White;
  145. //Console.WriteLine("Session list contains...");
  146. try
  147. {
  148. Monitor.Enter(oAllSessions);
  149. //foreach (Session oS in oAllSessions)
  150. //{
  151. // //Console.Write(String.Format("{0} {1} {2}\n{3} {4}\n\n", oS.id, oS.oRequest.headers.HTTPMethod, Ellipsize(oS.fullUrl, 60), oS.responseCode, oS.oResponse.MIMEType));
  152. // File.AppendAllText(drv[0] + "//PerformanceUtility//flog.txt", oS.id + " " + oS.oRequest.headers.HTTPMethod + " " + Ellipsize(oS.fullUrl, 60) + " " + oS.responseCode + " " + oS.oResponse.MIMEType);
  153. //}
  154. }
  155. finally
  156. {
  157. Monitor.Exit(oAllSessions);
  158. //todo : max memory usage check and fix ---- added to check if memory can be reclaimed jaymin mod to check
  159. //oAllSessions.Clear();
  160.  
  161. }
  162. //Console.WriteLine();
  163. //Console.ForegroundColor = oldColor;
  164. return;
  165. }
  166.  
  167. public static void Main(string[] args)
  168. {
  169.  
  170.  
  171.  
  172. oAllSessions = new List<Fiddler.Session>();
  173.  
  174. // <-- Personalize for your Application, 64 chars or fewer
  175. //Fiddler.FiddlerApplication.SetAppDisplayName("FiddlerCoreDemoApp");
  176.  
  177. #region AttachEventListeners
  178. //
  179. // It is important to understand that FiddlerCore calls event handlers on session-handling
  180. // background threads. If you need to properly synchronize to the UI-thread (say, because
  181. // you're adding the sessions to a list view) you must call .Invoke on a delegate on the
  182. // window handle.
  183. //
  184. // If you are writing to a non-threadsafe data structure (e.g. List<t>) you must
  185. // use a Monitor or other mechanism to ensure safety.
  186. //
  187.  
  188. // Simply echo notifications to the console. Because Fiddler.CONFIG.QuietMode=true
  189. // by default, we must handle notifying the user ourselves.
  190. Fiddler.FiddlerApplication.OnNotification += delegate (object sender, NotificationEventArgs oNEA) { Console.WriteLine("** NotifyUser: " + oNEA.NotifyString); };
  191. Fiddler.FiddlerApplication.Log.OnLogString += delegate (object sender, LogEventArgs oLEA) { Console.WriteLine("** LogString: " + oLEA.LogString); };
  192.  
  193. Fiddler.FiddlerApplication.BeforeRequest += delegate (Fiddler.Session oS)
  194. {
  195. // Console.WriteLine("Before request for:\t" + oS.fullUrl);
  196. // In order to enable response tampering, buffering mode MUST
  197. // be enabled; this allows FiddlerCore to permit modification of
  198. // the response in the BeforeResponse handler rather than streaming
  199. // the response to the client as the response comes in.
  200. oS.bBufferResponse = false;
  201. Monitor.Enter(oAllSessions);
  202. oAllSessions.Add(oS);
  203. Monitor.Exit(oAllSessions);
  204.  
  205. // Set this property if you want FiddlerCore to automatically authenticate by
  206. // answering Digest/Negotiate/NTLM/Kerberos challenges itself
  207. // oS["X-AutoAuth"] = "(default)";
  208.  
  209. /* If the request is going to our secure endpoint, we'll echo back the response.
  210.  
  211. Note: This BeforeRequest is getting called for both our main proxy tunnel AND our secure endpoint,
  212. so we have to look at which Fiddler port the client connected to (pipeClient.LocalPort) to determine whether this request
  213. was sent to secure endpoint, or was merely sent to the main proxy tunnel (e.g. a CONNECT) in order to *reach* the secure endpoint.
  214.  
  215. As a result of this, if you run the demo and visit https://localhost:7777 in your browser, you'll see
  216.  
  217. Session list contains...
  218.  
  219. 1 CONNECT http://localhost:7777
  220. 200 <-- CONNECT tunnel sent to the main proxy tunnel, port 8877
  221.  
  222. 2 GET https://localhost:7777/
  223. 200 text/html <-- GET request decrypted on the main proxy tunnel, port 8877
  224.  
  225. 3 GET https://localhost:7777/
  226. 200 text/html <-- GET request received by the secure endpoint, port 7777
  227. */
  228.  
  229. if ((oS.oRequest.pipeClient.LocalPort == iSecureEndpointPort) && (oS.hostname == sSecureEndpointHostname))
  230. {
  231. oS.utilCreateResponseAndBypassServer();
  232. oS.oResponse.headers.SetStatus(200, "Ok");
  233. oS.oResponse["Content-Type"] = "text/html; charset=UTF-8";
  234. oS.oResponse["Cache-Control"] = "private, max-age=0";
  235. oS.utilSetResponseBody("<html><body>Request for httpS://" + sSecureEndpointHostname + ":" + iSecureEndpointPort.ToString() + " received. Your request was:<br /><plaintext>" + oS.oRequest.headers.ToString());
  236. }
  237. };
  238.  
  239. /*
  240. // The following event allows you to examine every response buffer read by Fiddler. Note that this isn't useful for the vast majority of
  241. // applications because the raw buffer is nearly useless; it's not decompressed, it includes both headers and body bytes, etc.
  242. //
  243. // This event is only useful for a handful of applications which need access to a raw, unprocessed byte-stream
  244. Fiddler.FiddlerApplication.OnReadResponseBuffer += new EventHandler<RawReadEventArgs>(FiddlerApplication_OnReadResponseBuffer);
  245. */
  246.  
  247. /*
  248. Fiddler.FiddlerApplication.BeforeResponse += delegate(Fiddler.Session oS) {
  249. // Console.WriteLine("{0}:HTTP {1} for {2}", oS.id, oS.responseCode, oS.fullUrl);
  250.  
  251. // Uncomment the following two statements to decompress/unchunk the
  252. // HTTP response and subsequently modify any HTTP responses to replace
  253. // instances of the word "Microsoft" with "Bayden". You MUST also
  254. // set bBufferResponse = true inside the beforeREQUEST method above.
  255. //
  256. //oS.utilDecodeResponse(); oS.utilReplaceInResponse("Microsoft", "Bayden");
  257. };*/
  258.  
  259. Fiddler.FiddlerApplication.AfterSessionComplete += delegate (Fiddler.Session oS)
  260. {
  261. //Console.WriteLine("Finished session:\t" + oS.fullUrl);
  262. //Console.Title = ("Session list contains: " + oAllSessions.Count.ToString() + " sessions");
  263. };
  264.  
  265. // Tell the system console to handle CTRL+C by calling our method that
  266. // gracefully shuts down the FiddlerCore.
  267. //
  268. // Note, this doesn't handle the case where the user closes the window with the close button.
  269. // See http://geekswithblogs.net/mrnat/archive/2004/09/23/11594.aspx for info on that...
  270. //
  271. Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);
  272. #endregion AttachEventListeners
  273.  
  274. string sSAZInfo = "NoSAZ";
  275. #if SAZ_SUPPORT
  276. sSAZInfo = Assembly.GetAssembly(typeof(Ionic.Zip.ZipFile)).FullName;
  277.  
  278. // You can load Transcoders from any different assembly if you'd like, using the ImportTranscoders(string AssemblyPath)
  279. // overload.
  280. //
  281. //if (!FiddlerApplication.oTranscoders.ImportTranscoders(Assembly.GetExecutingAssembly()))
  282. //{
  283. // Console.WriteLine("This assembly was not compiled with a SAZ-exporter");
  284. //}
  285.  
  286. DNZSAZProvider.fnObtainPwd = () =>
  287. {
  288. //Console.WriteLine("Enter the password (or just hit Enter to cancel):");
  289. string sResult = Console.ReadLine();
  290. //Console.WriteLine();
  291. return sResult;
  292. };
  293.  
  294. FiddlerApplication.oSAZProvider = new DNZSAZProvider();
  295.  
  296. //DNZSAZWriter dz = new DNZSAZWriter("abc.saz");
  297. //StreamWriter s = new StreamWriter("abc.saz");
  298. //SAZWriterDelegate sw =null;
  299. //sw += filetowrite;
  300. //dz.AddFile("abc.saz", sw);
  301. //dz.CompleteArchive();
  302.  
  303. #endif
  304.  
  305. //Console.WriteLine(String.Format("Starting {0} ({1})...", Fiddler.FiddlerApplication.GetVersionString(), sSAZInfo));
  306.  
  307. // For the purposes of this demo, we'll forbid connections to HTTPS
  308. // sites that use invalid certificates. Change this from the default only
  309. // if you know EXACTLY what that implies.
  310. Fiddler.CONFIG.IgnoreServerCertErrors = false;
  311.  
  312. // ... but you can allow a specific (even invalid) certificate by implementing and assigning a callback...
  313. // FiddlerApplication.OnValidateServerCertificate += new System.EventHandler<ValidateServerCertificateEventArgs>(CheckCert);
  314.  
  315. FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.abortifclientaborts", true);
  316.  
  317. // NOTE: In the next line, you can pass 0 for the port (instead of 8877) to have FiddlerCore auto-select an available port
  318. ushort iPort = 8877;
  319.  
  320. FiddlerCoreStartupSettings startupSettings =
  321. new FiddlerCoreStartupSettingsBuilder()
  322. .ListenOnPort(iPort)
  323. .RegisterAsSystemProxy()
  324. .DecryptSSL()
  325. //.AllowRemoteClients()
  326. //.ChainToUpstreamGateway()
  327. .MonitorAllConnections()
  328. //.HookUsingPACFile()
  329. //.CaptureLocalhostTraffic()
  330. //.CaptureFTP()
  331. .OptimizeThreadPool()
  332. //.SetUpstreamGatewayTo("http=CorpProxy:80;https=SecureProxy:443;ftp=ftpGW:20")
  333. .Build();
  334.  
  335. //FiddlerApplication.oSAZProvider = new DNZSAZProvider();
  336.  
  337. // *******************************
  338. // Important HTTPS Decryption Info
  339. // *******************************
  340. // When FiddlerCoreStartupSettingsBuilder.DecryptSSL() is called, you must include either
  341. //
  342. // MakeCert.exe
  343. //
  344. // *or*
  345. //
  346. // CertMaker.dll
  347. // BCMakeCert.dll
  348. //
  349. // ... in the folder where your executable and FiddlerCore.dll live. These files
  350. // are needed to generate the self-signed certificates used to man-in-the-middle
  351. // secure traffic. MakeCert.exe uses Windows APIs to generate certificates which
  352. // are stored in the user's \Personal\ Certificates store. These certificates are
  353. // NOT compatible with iOS devices which require specific fields in the certificate
  354. // which are not set by MakeCert.exe.
  355. //
  356. // In contrast, CertMaker.dll uses the BouncyCastle C# library (BCMakeCert.dll) to
  357. // generate new certificates from scratch. These certificates are stored in memory
  358. // only, and are compatible with iOS devices.
  359.  
  360. Fiddler.FiddlerApplication.Startup(startupSettings);
  361.  
  362. FiddlerApplication.Log.LogFormat("Created endpoint listening on port {0}", iPort);
  363.  
  364. FiddlerApplication.Log.LogFormat("Gateway: {0}", CONFIG.UpstreamGateway.ToString());
  365.  
  366. //Console.WriteLine("Hit CTRL+C to end session.");
  367.  
  368. // We'll also create a HTTPS listener, useful for when FiddlerCore is masquerading as a HTTPS server
  369. // instead of acting as a normal CERN-style proxy server.
  370. oSecureEndpoint = FiddlerApplication.CreateProxyEndpoint(iSecureEndpointPort, true, sSecureEndpointHostname);
  371. if (null != oSecureEndpoint)
  372. {
  373. FiddlerApplication.Log.LogFormat("Created secure endpoint listening on port {0}, using a HTTPS certificate for '{1}'", iSecureEndpointPort, sSecureEndpointHostname);
  374. }
  375.  
  376. // bool bDone = false;
  377. // do
  378. // {
  379. // Console.WriteLine("\nEnter a command [C=Clear; L=List; G=Collect Garbage; W=write SAZ; R=read SAZ;\n\tS=Toggle Forgetful Streaming; T=Trust Root Certificate; Q=Quit]:");
  380. // Console.Write(">");
  381. // //ConsoleKeyInfo cki = Console.ReadKey();
  382. // //Console.WriteLine();
  383. // switch (Char.ToLower(Convert.ToChar(args[0])))
  384. // {
  385. // case 'c':
  386. // Monitor.Enter(oAllSessions);
  387. // oAllSessions.Clear();
  388. // Monitor.Exit(oAllSessions);
  389. // WriteCommandResponse("Clear...");
  390. // FiddlerApplication.Log.LogString("Cleared session list.");
  391. // break;
  392.  
  393. // case 'd':
  394. // FiddlerApplication.Log.LogString("FiddlerApplication::Shutdown.");
  395. // FiddlerApplication.Shutdown();
  396. // break;
  397.  
  398. // case 'l':
  399. // WriteSessionList(oAllSessions);
  400. // bDone = true;
  401. // break;
  402.  
  403. // case 'g':
  404. // Console.WriteLine("Working Set:\t" + Environment.WorkingSet.ToString("n0"));
  405. // Console.WriteLine("Begin GC...");
  406. // GC.Collect();
  407. // Console.WriteLine("GC Done.\nWorking Set:\t" + Environment.WorkingSet.ToString("n0"));
  408. // break;
  409.  
  410. // case 'q':
  411. // bDone = true;
  412. // DoQuit();
  413. // break;
  414.  
  415. // case 'r':
  416. //#if SAZ_SUPPORT
  417. // ReadSessions(oAllSessions);
  418. //#else
  419. // WriteCommandResponse("This demo was compiled without SAZ_SUPPORT defined");
  420. //#endif
  421. // break;
  422.  
  423. // case 'w':
  424. //#if SAZ_SUPPORT
  425. // if (oAllSessions.Count > 0)
  426. // {
  427. // SaveSessionsToDesktop(oAllSessions);
  428. // }
  429. // else
  430. // {
  431. // WriteCommandResponse("No sessions have been captured");
  432. // }
  433. //#else
  434. // WriteCommandResponse("This demo was compiled without SAZ_SUPPORT defined");
  435. //#endif
  436. // break;
  437.  
  438. // case 't':
  439. // try
  440. // {
  441. // WriteCommandResponse("Result: " + Fiddler.CertMaker.trustRootCert().ToString());
  442. // }
  443. // catch (Exception eX)
  444. // {
  445. // WriteCommandResponse("Failed: " + eX.ToString());
  446. // }
  447. // break;
  448.  
  449. // // Forgetful streaming
  450. // case 's':
  451. // bool bForgetful = !FiddlerApplication.Prefs.GetBoolPref("fiddler.network.streaming.ForgetStreamedData", false);
  452. // FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.ForgetStreamedData", bForgetful);
  453. // Console.WriteLine(bForgetful ? "FiddlerCore will immediately dump streaming response data." : "FiddlerCore will keep a copy of streamed response data.");
  454. // break;
  455.  
  456. // }
  457. // } while (!bDone);
  458. }
  459.  
  460. public void GetInput(char c)
  461. {
  462. bool bDone = false;
  463. do
  464. {
  465. //Console.WriteLine("\nEnter a command [C=Clear; L=List; G=Collect Garbage; W=write SAZ; R=read SAZ;\n\tS=Toggle Forgetful Streaming; T=Trust Root Certificate; Q=Quit]:");
  466. //Console.Write(">");
  467. //ConsoleKeyInfo cki = Console.ReadKey();
  468. //Console.WriteLine();
  469. switch (c)
  470. {
  471. case 'c':
  472. //Monitor.Enter(oAllSessions);
  473. //oAllSessions.Clear();
  474. //Monitor.Exit(oAllSessions);
  475. //WriteCommandResponse("Clear...");
  476. //FiddlerApplication.Log.LogString("Cleared session list.");
  477. break;
  478.  
  479. case 'd':
  480. //FiddlerApplication.Log.LogString("FiddlerApplication::Shutdown.");
  481. //FiddlerApplication.Shutdown();
  482. break;
  483.  
  484. case 'l':
  485. try
  486. {
  487. var gettrustcertval = Fiddler.CertMaker.trustRootCert();
  488. if (gettrustcertval == false)
  489. {
  490. Fiddler.CertMaker.trustRootCert();
  491. }
  492. }
  493. catch (Exception ex)
  494. {
  495.  
  496. //MessageBox.Show(ex.ToString());
  497.  
  498. }
  499.  
  500.  
  501. WriteSessionList(oAllSessions);
  502. return;
  503.  
  504. case 'g':
  505. //Console.WriteLine("Working Set:\t" + Environment.WorkingSet.ToString("n0"));
  506. //Console.WriteLine("Begin GC...");
  507. //GC.Collect();
  508. //Console.WriteLine("GC Done.\nWorking Set:\t" + Environment.WorkingSet.ToString("n0"));
  509. break;
  510.  
  511. case 'q':
  512. bDone = true;
  513. DoQuit();
  514. break;
  515.  
  516. case 'r':
  517. #if SAZ_SUPPORT
  518. ReadSessions(oAllSessions);
  519. #else
  520.  
  521. #endif
  522. break;
  523.  
  524. case 'w':
  525. #if SAZ_SUPPORT
  526. if (oAllSessions.Count > 0)
  527. {
  528. //SaveSessionsToDesktop(oAllSessions);
  529. //Task t = new Task(() => SaveSessionsToDesktop(oAllSessions));
  530. //Task t = new Task(() => SaveSessionsToDesktop(oAllSessions));
  531. Task.Factory.StartNew(() => SaveSessionsToDesktop(oAllSessions)).ContinueWith(tsk => filewtittebtodisk = true);
  532. //ContinueWith(u=> insidetheprogram=false).ContinueWith(x => DoQuit());
  533. //t.Start();
  534.  
  535. }
  536. else
  537. {
  538. //todo while updating the app check once if you can update the app with 0 status of count
  539. //filewtittebtodisk = true
  540. WriteCommandResponse("No sessions have been captured");
  541. }
  542. #else
  543. WriteCommandResponse("This demo was compiled without SAZ_SUPPORT defined");
  544. #endif
  545.  
  546. return;
  547.  
  548. case 't':
  549. try
  550. {
  551. WriteCommandResponse("Result: " + Fiddler.CertMaker.trustRootCert().ToString());
  552. }
  553. catch (Exception eX)
  554. {
  555. WriteCommandResponse("Failed: " + eX.ToString());
  556. }
  557. break;
  558.  
  559. // Forgetful streaming
  560. case 's':
  561. bool bForgetful = !FiddlerApplication.Prefs.GetBoolPref("fiddler.network.streaming.ForgetStreamedData", false);
  562. FiddlerApplication.Prefs.SetBoolPref("fiddler.network.streaming.ForgetStreamedData", bForgetful);
  563. Console.WriteLine(bForgetful ? "FiddlerCore will immediately dump streaming response data." : "FiddlerCore will keep a copy of streamed response data.");
  564. break;
  565.  
  566. }
  567. } while (!bDone);
  568. }
  569.  
  570.  
  571. /*
  572. /// <summary>
  573. /// This callback allows your code to evaluate the certificate for a site and optionally override default validation behavior for that certificate.
  574. /// You should not implement this method unless you understand why it is a security risk.
  575. /// </summary>
  576. static void CheckCert(object sender, ValidateServerCertificateEventArgs e)
  577. {
  578. if (null != e.ServerCertificate)
  579. {
  580. Console.WriteLine("Certificate for " + e.ExpectedCN + " was for site " + e.ServerCertificate.Subject + " and errors were " + e.CertificatePolicyErrors.ToString());
  581.  
  582. if (e.ServerCertificate.Subject.Contains("fiddler2.com"))
  583. {
  584. Console.WriteLine("Got a certificate for fiddler2.com. We'll say this is also good for any other site, like https://fiddlertool.com.");
  585. e.ValidityState = CertificateValidity.ForceValid;
  586. }
  587. }
  588. }
  589. */
  590.  
  591. //public static void filetowrite(Stream s)
  592. //{
  593. // byte[] b = null;
  594. // s.Write(b, 0, 0);
  595. //}
  596. /*
  597. // This event handler is called on every socket read for the HTTP Response. You almost certainly don't want
  598. // to add a handler for this event, but the code below shows how you can use it to mess up your HTTP traffic.
  599. static void FiddlerApplication_OnReadResponseBuffer(object sender, RawReadEventArgs e)
  600. {
  601. // NOTE: arrDataBuffer is a fixed-size array. Only bytes 0 to iCountOfBytes should be read/manipulated.
  602. //
  603. // Just for kicks, lowercase every byte. Note that this will obviously break any binary content.
  604. for (int i = 0; i < e.iCountOfBytes; i++)
  605. {
  606. if ((e.arrDataBuffer[i] > 0x40) && (e.arrDataBuffer[i] < 0x5b))
  607. {
  608. e.arrDataBuffer[i] = (byte)(e.arrDataBuffer[i] + (byte)0x20);
  609. }
  610. }
  611. Console.WriteLine(String.Format("Read {0} response bytes for session {1}", e.iCountOfBytes, e.sessionOwner.id));
  612. }
  613. */
  614.  
  615. /// <summary>
  616. /// When the user hits CTRL+C, this event fires. We use this to shut down and unregister our FiddlerCore.
  617. /// </summary>
  618. /// <param name="sender"></param>
  619. /// <param name="e"></param>
  620. public static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e)
  621. {
  622. DoQuit();
  623. }
  624. }
  625. }
Add Comment
Please, Sign In to add comment