fiddler 插件開發二

本篇主要講解Fildder插件開發中的涉及到的主要接口與類。

1.IFiddlerExtension 接口

若是要開發的自定義插件有UI界面,則須要實現IFiddlerExtension 接口。你程序集中的實現了IFiddlerExtension接口的公有類(public class)將會在Fiddler啓動時加載。緩存

public interface IFiddlerExtension
    {
      // Called when Fiddler User Interface is fully available
      void OnLoad();

      // Called when Fiddler is shutting down
      void OnBeforeUnload();
    }
  • OnLoad 方法將會在Fiddler加載完成而且她的UI徹底可用時調用,在這個方法中,你能夠安全地添加菜單項,選項卡頁或者其餘UI元素到Fiddler UI。
  • OnBeforeUnload 方法將會在Fiddler 關閉和卸載全部插件時執行。

2.IAutoTamper 接口

IAutoTamper 接口繼承了IFiddlerExtension接口,全部實現了IAutoTamper 接口的插件將會在每個http/https 請求或響應時被調用,因此能夠用來劫持或修改http/https 請求響應數據。安全

注意:這個接口的方法是在後臺被調用,非UI線程,若是想要更新UI,能夠使用Invoke 或者 BeginInvoke 方法來更新UI。IAutoTamper 的全部方法可能會在OnLoad事件以前就執行。less

public interface IAutoTamper : IFiddlerExtension
{
  // Called before the user can edit a request using the Fiddler Inspectors
  void AutoTamperRequestBefore(Session oSession);


  // Called after the user has had the chance to edit the request using the Fiddler Inspectors, but before the request is sent
  void AutoTamperRequestAfter(Session oSession);


  // Called before the user can edit a response using the Fiddler Inspectors, unless streaming.
  void AutoTamperResponseBefore(Session oSession);


  // Called after the user edited a response using the Fiddler Inspectors.  Not called when streaming.
  void AutoTamperResponseAfter(Session oSession);


  // Called Fiddler returns a self-generated HTTP error (for instance DNS lookup failed, etc)
  void OnBeforeReturningError(Session oSession);
}

3.IAutoTamper2 接口

全部實現了IAutoTamper2 接口(繼承自IAutoTamper接口)的擴展將會在響應頭(Response Headers)可用時被調用。ui

/// <summary>
/// Interface for AutoTamper extensions that want to "peek" at response headers
/// </summary>
public interface IAutoTamper2 : IAutoTamper
{
     /// <summary>
     /// Called when the response headers become available
     /// </summary>
     /// <param name="oSession">The Session object for which the response headers are available</param>
    void OnPeekAtResponseHeaders(Session oSession);
}

4.IAutoTamper3 接口

全部實現了IAutoTamper3接口(繼承自IAutoTamper2接口)的擴展將會在請求頭(Request Headers)可用時被調用。spa

/// <summary>
/// Interface for AutoTamper extensions that want to "peek" at request headers
/// </summary>
public interface IAutoTamper3 : IAutoTamper2
{
    /// <summary>
    /// Called when the request headers become available
    /// </summary>
    /// <param name="oSession">The Session object for which the request headers are available</param>
    void OnPeekAtRequestHeaders(Session oSession);
}

5.IHandleExecAction接口

全部實現了IHandleExecAction接口的擴展將在用戶執行QuickExec命令時被調用。OnExecAction方法中返回 true 表示命令執行成功,不用再處理其餘Action。插件

public interface IHandleExecAction
{
  // return TRUE if handled. 
  bool OnExecAction(string sCommand); 
}

例如:線程

public bool OnExecAction(string sCommand)
{
    if (sCommand == "clearcache")
    {
        //檢測到用戶在quickexec中輸入的命令是clearcache時,調用Fiddler的清緩存方法
        FiddlerApplication.UI.actClearWinINETCache();
        return true;  //表示命令處理成功,不用繼續其餘的處理
    }
    return false;  //表示命令沒有被處理,容許其餘 ExecAction handlers繼續處理
}

6.參考資料

http://www.fiddlerbook.com/Fiddler/dev/IFiddlerExtension.aspcode

相關文章
相關標籤/搜索