c# winform 火狐浏览器 查看cookie
2015-08-29 00:46
609 查看
c# winform 火狐浏览器 查看cookie
Firefox的Cookie数据位于:%APPDATA%\Mozilla\Firefox\Profiles\ 目录中的xxx.default目录,名为cookies.sqlite的文件。
如:C:\Users\jay\AppData\Roaming\Mozilla\Firefox\Profiles\ji4grfex.default\cookies.sqlite
在Firefox中查看cookie, 可以选择”工具 > 选项 >” “隐私 > 显示cookie”。
1、先获取cookies.sqlite文件路径
2、SQLite数据库需要引用System.Data.SQLite
下载地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
得到System.Data.SQLite.dll添加到工程引用;
*可以使用SQLite Database Browser来查看数据:
下载地址:http://sourceforge.net/projects/sqlitebrowser/
3、SQLite.Interop.dll文件要复制到输出目录中
4、通过name和host字段查询返回value值,value带有中文要转译
HttpUtility.UrlDecode需要引用System.Web
好吧,SQLite确实也很强大,只不过在这里并不是很爽,原因是需要以上2个dll文件才可以正常使用。
那下面就用另一种办法实现下,虽然效率没有上面的高,但已足够用了。
首先使用记事本打开cookies.sqlite文件观察
得到格式:
站点(域名)+Cookie名称+内容+域+路径
实现通过指定名称+域,取中间的部分就是cookie值。
使用正则表达式:
(?<=jd.com_pst)(?'value'[\w%]+)(?=.jd.com)
![](http://images2015.cnblogs.com/blog/447901/201508/447901-20150829004359719-119430606.png)
下载地址:
http://download.csdn.net/detail/h_gxi/9059561
Firefox的Cookie数据位于:%APPDATA%\Mozilla\Firefox\Profiles\ 目录中的xxx.default目录,名为cookies.sqlite的文件。
如:C:\Users\jay\AppData\Roaming\Mozilla\Firefox\Profiles\ji4grfex.default\cookies.sqlite
在Firefox中查看cookie, 可以选择”工具 > 选项 >” “隐私 > 显示cookie”。
1、先获取cookies.sqlite文件路径
2、SQLite数据库需要引用System.Data.SQLite
下载地址:http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
得到System.Data.SQLite.dll添加到工程引用;
*可以使用SQLite Database Browser来查看数据:
下载地址:http://sourceforge.net/projects/sqlitebrowser/
3、SQLite.Interop.dll文件要复制到输出目录中
4、通过name和host字段查询返回value值,value带有中文要转译
HttpUtility.UrlDecode需要引用System.Web
好吧,SQLite确实也很强大,只不过在这里并不是很爽,原因是需要以上2个dll文件才可以正常使用。
那下面就用另一种办法实现下,虽然效率没有上面的高,但已足够用了。
首先使用记事本打开cookies.sqlite文件观察
得到格式:
站点(域名)+Cookie名称+内容+域+路径
实现通过指定名称+域,取中间的部分就是cookie值。
使用正则表达式:
(?<=jd.com_pst)(?'value'[\w%]+)(?=.jd.com)
![](http://images2015.cnblogs.com/blog/447901/201508/447901-20150829004359719-119430606.png)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SQLite; using System.Drawing; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Forms; namespace FirefoxCookie { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private string dbPath = string.Empty; //cookies.sqlite文件路径 private void Form1_Load(object sender, EventArgs e) { DirectoryInfo di = new DirectoryInfo(System.Environment.GetEnvironmentVariable("AppData") + @"\Mozilla\Firefox\Profiles\"); DirectoryInfo[] dirs = di.GetDirectories();//获取子文件夹列表 if (dirs != null) { dbPath = dirs[0].FullName + "\\cookies.sqlite"; } //所有cookie this.dataGridView1.DataSource = GetTable("select * from moz_cookies"); //所有站点 this.comboBox1.DataSource = GetTable("select Distinct baseDomain from moz_cookies"); this.comboBox1.DisplayMember = "baseDomain"; //注册事件 属性值更改时触发 comboBox1.SelectedIndexChanged += new System.EventHandler(this.SelectedIndexChanged); } //通过指定站点查找 private void SelectedIndexChanged(object sender, EventArgs e) { string txt = ((ComboBox)sender).Text; this.dataGridView1.DataSource = GetTable("select * from moz_cookies where baseDomain=@baseDomain", new SQLiteParameter("baseDomain", txt)); } private void button1_Click(object sender, EventArgs e) { string name = this.txtName.Text.Trim(); string host = this.txtHost.Text.Trim(); string value = string.Empty; if (File.Exists(dbPath)) { string sqlStr = "select value from moz_cookies where name=@name and host=@host"; SQLiteParameter[] pms = new SQLiteParameter[]{ new SQLiteParameter("name", name), new SQLiteParameter("host", host) }; value = (string)ExecuteScalar(sqlStr, pms) ?? "未找到!"; } value = System.Web.HttpUtility.UrlDecode(value); //中文需要转码 this.txtValue.Text = value; } private object ExecuteScalar(string sql, params SQLiteParameter[] pms) { using (SQLiteConnection conn = new SQLiteConnection("Data Source =" + dbPath)) { using (SQLiteCommand com = new SQLiteCommand(sql, conn)) { if (pms != null) { com.Parameters.AddRange(pms); } conn.Open(); return com.ExecuteScalar(); } } } private DataTable GetTable(string sql, params SQLiteParameter[] pms) { using (SQLiteConnection conn = new SQLiteConnection("Data Source =" + dbPath)) { using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(sql, conn)) { DataTable dt = new DataTable(); if (pms != null) { adapter.SelectCommand.Parameters.AddRange(pms); } conn.Open(); adapter.Fill(dt); return dt; } } } private void button2_Click(object sender, EventArgs e) { string str = string.Empty; using (FileStream fs = new FileStream(dbPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (StreamReader sr = new StreamReader(fs, System.Text.Encoding.Default)) { str = sr.ReadToEnd(); } } string pattern = string.Format(@"(?<={0})(?'value'[\w%]+)(?={1})", this.txtName.Text.Trim(), this.txtHost.Text.Trim()); Match match = Regex.Match(str, pattern); if (match.Success) { string value = match.Groups["value"].Value; value = System.Web.HttpUtility.UrlDecode(value); //中文需要转码 this.txtValue.Text = value; } } } }
下载地址:
http://download.csdn.net/detail/h_gxi/9059561
相关文章推荐
- c# JD快速搜索工具,2015分析JD搜索报文,模拟请求搜索数据,快速定位宝贝排行位置。
- c#异步socket
- C# List<T>中Select List Distinct()去重复
- EF性能优化(C# 版 潘鹏)
- C# ListView用法详解
- C# 统计代码时间
- c# AE 闪烁和定位
- C#读取Excel2007的文件
- C#操作Excel总结
- C# PC端读取INI文件处理
- C#如何通过反射获取属性值
- c# 多线程编程
- flex与C# Socket通信
- 零基础学习.NET平台和Csharp编程开发
- C#IISRESET服务
- c#线程同步
- C#调用微软自带的计算器、记事本等软件
- C#调用微软自带的计算器、记事本等软件
- c#模拟请求获取与设置cookies
- C#线程篇---Task(任务)和线程池不得不说的秘密(5)