gpt4 book ai didi

c# - 如何使用c#向chrome cookies文件中插入一条新记录

转载 作者:太空狗 更新时间:2023-10-30 01:03:58 25 4
gpt4 key购买 nike

我找到了 chrome cookie 文件的位置,我使用 sqliteBrowser 打开它并找到 cookies 表的结构。

而且我也成功地从这个文件中读取了cookies,虽然cookies的值是加密的,但我还是找到了一些方法来解密它。

我还注意到 cookies 表的 creation_utc 字段使用的是自 1601.01.01 以来的时间计数。

我想说的是我已经做了一些工作并且已经知道 chrome cookies 文件的结构。

但问题是,当我想使用 C# 的 System.data.sqlite 向该文件插入一条新记录时,我的程序无法插入该记录并进入死锁状态,我注意到这种情况是由通过该 executeNoQuery 方法不返回!!!

相同的 sql 语法在我的测试 sqlite 文件中工作正常,所以我猜这个问题是由 chrome cookies 文件本身引起的。

谁能帮帮我?谢谢!

以下是我尝试设置 cookie 的代码:

        private static bool SetCookie_Chrome(string strHost, string strField, string value,DateTime expiresDate)
{
bool fRtn = false;
string strPath, strDb;


strPath = GetChromeCookiePath();
//strPath= GetTestCookiePath();
if (string.Empty == strPath) // Nope, perhaps another browser
return false;

try
{
strDb = "Data Source=" + strPath + ";pooling=false";

SQLiteConnection conn = new SQLiteConnection(strDb);

SQLiteCommand cmd = conn.CreateCommand();

Byte[] encryptedValue=getEncryptedValue(value);

cmd.CommandText = "INSERT INTO `cookies`(`creation_utc`,`host_key`,`name`,`value`,`path`,`expires_utc`,`secure`,`httponly`,`last_access_utc`,`has_expires`,`persistent`,`priority`,`encrypted_value`) "+
"VALUES ("+TimeUtil.get_creation_utc()+",'"+strHost+"','"+strField+"','','/',"+
TimeUtil.get_specific_utc(expiresDate.Year,expiresDate.Month,expiresDate.Day,expiresDate.Hour,expiresDate.Minute,expiresDate.Second)+
",0,0," + TimeUtil.get_creation_utc() + ",1,1,1,@evalue);";
cmd.Parameters.Add("@evalue", System.Data.DbType.Binary).Value = encryptedValue;
conn.Open();
int rtV=cmd.ExecuteNonQuery();
conn.Close();
fRtn = true;
}


catch (Exception e)
{
fRtn = false;
}
return fRtn;
}

最佳答案

如果有人想修改chrome cookie文件,你可以引用我上面贴的代码。其实代码是对的,我遇到问题的原因引用了上面的评论:

The reason why this situation happens is because I have another connection to the same sql file active, so like what the file lock works, it just lock the file in case you read some dirty value.

希望这个问题可以帮助到其他人。

关于c# - 如何使用c#向chrome cookies文件中插入一条新记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25417551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com