在路上
本文是转载来的,感谢原作者
本篇主要讲解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元素到FiddlerUI。
- OnBeforeUnload 方法将会在Fiddler 关闭和卸载所有插件时执行。
2.IAutoTamper 接口
IAutoTamper 接口继承了IFiddlerExtension接口,所有实现了IAutoTamper 接口的插件将会在每一个http/https 请求或响应时被调用,所以可以用来劫持或修改http/https 请求响应数据。
注意:这个接口的方法是在后台被调用,非UI线程,如果想要更新UI,可以使用Invoke 或者 BeginInvoke 方法来更新UI。IAutoTamper 的所有方法可能会在OnLoad事件之前就执行。
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)可用时被调用。
/// <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)可用时被调用。
/// <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.参考资料
Fiddler插件开发原文档: http://www.fiddlerbook.com/Fiddler/dev/IFiddlerExtension.asp