home *** CD-ROM | disk | FTP | other *** search
- import System;
- import System.Windows.Forms;
- import Fiddler;
-
- // GLOBALIZATION NOTE:
- // Be sure to save this file with UTF-8 Encoding if using any non-ASCII characters
- // in strings, etc.
- //
- // JScript Reference
- // http://msdn.microsoft.com/library/en-us/jscript7/html/jsoriProgrammingWithJScriptNET.asp
- //
- // FiddlerScript Reference
- // http://www.fiddlertool.com/fiddler/dev/scriptsamples.asp
- //
- // FiddlerScript Editor:
- // http://www.fiddlertool.com/dl/fsesetup.exe
-
- class Handlers
- {
- public static RulesOption("Hide all 200s")
- var m_Hide200s: boolean = false;
-
- public static RulesOption("Simple &ad removal")
- var m_NoAD: boolean = false;
-
- public static RulesOption("Netscape &3", "&User-Agents", true)
- var m_NS3: boolean = false;
-
- public static RulesOption("&Firefox 1.5", "&User-Agents", true)
- var m_FFox: boolean = false;
-
- public static RulesOption("IE &6 (XPSP2)", "&User-Agents", true)
- var m_IE6: boolean = false;
-
- public static RulesOption("IE &7 (Vista)", "&User-Agents", true)
- var m_IE7: boolean = false;
-
- public static RulesOption("IE &8 (Win2k3)", "&User-Agents", true, true)
- var m_IE8: boolean = false;
-
- public static RulesOption("&Disabled", "&User-Agents", true)
- var m_UANONE: boolean = true;
-
- public static RulesOption("Request &Japanese Content")
- var m_Japanese: boolean = false;
-
- public static RulesOption("Simulate &Modem speeds")
- var m_SimulateModem: boolean = false;
-
- // Force a manual reload of the script file. Resets all
- // RulesOption variables to their defaults.
- public static ToolsAction("Reset Script")
- function DoManualReload(){
- FiddlerObject.ReloadScript();
- }
-
- public static ToolsAction("Enumerate Selected Sessions")
- function DoRunSessions(oSessions: Fiddler.Session[]){
- if (null != oSessions){
- MessageBox.Show("Number of selected sessions: " + oSessions.Length);
- }
-
- for (var x = 0; x < oSessions.Length; x++){
- MessageBox.Show("Result: " + oSessions[x].responseCode);
- Clipboard.SetDataObject(oSessions[x].responseCode.ToString());
- }
- }
-
- public static ContextAction("Reissue Selected Requests")
- function ReRunSessions(oSessions: Fiddler.Session[]){
- if (null == oSessions){
- MessageBox.Show("Please select sessions to reissue.", "Nothing to Do");
- return;
- }
-
- for (var x = 0; x < oSessions.Length; x++){
- FiddlerObject.utilIssueRequest(oSessions[x].oRequest.headers.ToString(true, true) +
- System.Text.Encoding.UTF8.GetString(oSessions[x].requestBodyBytes));
- }
- }
-
- static function OnBoot(){
- // MessageBox.Show("Fiddler has finished booting");
- // System.Diagnostics.Process.Start("iexplore.exe");
-
- // FiddlerObject.UI.miManipulateIgnoreImages.Checked = false;
-
- // FiddlerObject.UI.ActivateRequestInspector("HEADERS");
- // FiddlerObject.UI.ActivateResponseInspector("HEADERS");
- }
-
- static function OnShutdown(){
- // MessageBox.Show("Fiddler has shutdown");
- }
-
- static function OnAttach(){
- // MessageBox.Show("Fiddler is now the system proxy");
- // System.Diagnostics.Process.Start("proxycfg.exe", "-u"); // Notify WinHTTP of proxy change
- }
-
- static function OnDetach(){
- // MessageBox.Show("Fiddler is no longer the system proxy");
- // System.Diagnostics.Process.Start("proxycfg.exe", "-u"); // Notify WinHTTP of proxy change
- }
-
- static function OnBeforeRequest(oSession:Fiddler.Session)
- {
- if ((null != gs_ReplaceToken) && (oSession.url.indexOf(gs_ReplaceToken)>-1)){
- oSession.url = oSession.url.Replace(gs_ReplaceToken, gs_ReplaceTokenWith);
- }
-
- if ((null!=bpRequestURI) && (oSession.url.indexOf(bpRequestURI)>-1)){
- oSession["x-breakrequest"]="uri";
- }
-
- if ((null!=bpMethod) && (oSession.oRequest.headers.HTTPMethod == bpMethod)){
- oSession["x-breakrequest"]="method";
- }
-
- if (m_SimulateModem){
- // Delay sends by 300ms per KB uploaded.
- oSession["request-trickle-delay"] = "300";
- }
-
- if (m_NoAD &&
- (oSession.host.indexOf("ad.")>-1 ||
- oSession.host.indexOf("ad2")>-1 ||
- oSession.url.indexOf("/ad")>-1)){
- oSession.oRequest.FailSession(403, "Advertisement", "This looks like an ad");
- }
-
- // User-Agent Overrides
- if (m_NS3){
- oSession.oRequest["User-Agent"] = "Mozilla/3.0 (Win95; I)";
- }
- else
- if (m_FFox){
- oSession.oRequest["User-Agent"] = "Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.8.0.5) Gecko/20060719 Firefox/1.5.0.5)";
- }
- else
- if (m_IE6){
- oSession.oRequest["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
- }
- else
- if (m_IE7){
- oSession.oRequest["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1)";
- }
- else
- if (m_IE8){
- oSession.oRequest["User-Agent"] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.2; WOW64)";
- }
-
-
- if (m_Japanese){
- oSession.oRequest["Accept-Language"] = "ja";
- }
-
- //if (oSession.url.toLowerCase().indexOf("/sandbox/")>-1){
- // oSession.oFlags["x-breakrequest"] = "yup"; // The very existence of this Flag triggers breakpoint; value is unimportant.
- //}
-
- }
-
- static function OnBeforeResponse(oSession:Fiddler.Session)
- {
- if (m_SimulateModem){
- // Delay receives by 150ms per KB downloaded.
- oSession["response-trickle-delay"] = "150";
- }
-
- if (m_Hide200s && oSession.responseCode == 200){
- oSession["ui-hide"] = "true";
- }
-
- if ((bpStatus>0) && (oSession.responseCode == bpStatus)){
- oSession["x-breakresponse"]="status";
- }
-
- // Uncomment to reduce incidence of "unexpected socket closure" exceptions in .NET code.
- // Note that you really should also fix your .NET code to gracefully handle unexpected connection closure.
- //
- // if ((oSession.responseCode != 401) && (oSession.responseCode != 407)){
- // oSession.oResponse["Connection"] = "close";
- // }
-
- }
-
- static function Main()
- {
- var today: Date = new Date();
- FiddlerObject.StatusText = " CustomRules.js was loaded at: " + today;
- }
-
-
- // These static variables are used for simple breakpointing
- static var bpRequestURI:String = null;
- static var bpStatus:int = -1;
- static var bpMethod: String = null;
- static var gs_ReplaceToken: String = null;
- static var gs_ReplaceTokenWith: String = null;
-
- // The ExecAction function is called by either the QuickExec box in the Fiddler window,
- // or by the ExecAction.exe command line utility.
- static function OnExecAction(sParams: String[]){
- FiddlerObject.StatusText = "ExecAction: " + sParams[0];
-
- var sAction = sParams[0].toLowerCase();
- switch (sAction){
-
- case "bp":
- FiddlerObject.alert("bpu = breakpoint request uri\nbpm = breakpoint request method\nbps=breakpoint response status");
- break;
- case "bps":
- if (sParams.Length<2) {bpStatus=-1; FiddlerObject.StatusText="Response Status breakpoint cleared"; return;}
- bpStatus = parseInt(sParams[1]); FiddlerObject.StatusText="Response status breakpoint for "+sParams[1];
- break;
- case "bpv":
- case "bpm":
- if (sParams.Length<2) {bpMethod=null; FiddlerObject.StatusText="Request Method breakpoint cleared"; return;}
- bpMethod = sParams[1].toUpperCase(); FiddlerObject.StatusText="Request Method breakpoint for "+sParams[1].toUpperCase();
- break;
- case "bpu":
- if (sParams.Length<2) {bpRequestURI=null; FiddlerObject.StatusText="RequestURI breakpoint cleared"; return;}
- if (sParams[1].toLowerCase().StartsWith("http://")){sParams[1] = sParams[1].Substring(7);}
- bpRequestURI = sParams[1];
- FiddlerObject.StatusText="RequestURI breakpoint for "+sParams[1];
- break;
- case "urlreplace":
- if (sParams.Length<3) {gs_ReplaceToken=null; FiddlerObject.StatusText="URL Replacement cleared"; return;}
- gs_ReplaceToken = sParams[1];
- gs_ReplaceTokenWith = sParams[2].Replace(" ", "%20"); // Simple helper
- FiddlerObject.StatusText="Replacing [" + sParams[1] + "] in URIs with [" + sParams[2] + "]";
- break;
- case "select":
- if (sParams.Length<2) { FiddlerObject.StatusText="Please specify Content-Type to select."; return;}
- FiddlerObject.UI.actSelectSessionsWithResponseHeaderValue("Content-Type", sParams[1]);
- FiddlerObject.StatusText="Searching for Content-Type: " + sParams[1];
- break;
- case "allbut":
- if (sParams.Length<2) { FiddlerObject.StatusText="Please specify Content-Type to retain during wipe."; return;}
- FiddlerObject.UI.actSelectSessionsWithResponseHeaderValue("Content-Type", sParams[1]);
- FiddlerObject.UI.actRemoveUnselectedSessions();
- FiddlerObject.UI.lvSessions.SelectedItems.Clear();
- FiddlerObject.StatusText="Removed all but Content-Type: " + sParams[1];
- break;
- case "stop":
- FiddlerObject.UI.actDetachProxy();
- break;
- case "start":
- FiddlerObject.UI.actAttachProxy();
- break;
- case "cls":
- case "clear":
- FiddlerObject.UI.actRemoveAllSessions();
- break;
- case "g":
- case "go":
- FiddlerObject.UI.actResumeAllSessions();
- break;
- case "help":
- System.Diagnostics.Process.Start("http://www.fiddlertool.com/fiddler/help/quickexec.asp");
- break;
- case "hide":
- FiddlerObject.UI.actMinimizeToTray();
- break;
- case "show":
- FiddlerObject.UI.actRestoreWindow();
- break;
- case "quit":
- FiddlerObject.UI.actExit();
- break;
- case "dump":
- FiddlerObject.UI.actSelectAll();
- FiddlerObject.UI.actSaveSessionsToZip("C:\\dump.zip");
- FiddlerObject.UI.actRemoveAllSessions();
- break;
-
- default:
- if (sAction.StartsWith("http") || sAction.StartsWith("www")){
- System.Diagnostics.Process.Start(sAction);
- }
- else
- FiddlerObject.StatusText = "Requested action: " + sAction + " not found.";
- }
- }
- }