我找到了chrome cookie文件的位置,我使用sqlitebrowser打开它并找到cookie表的结构.
我也成功读取了这个文件中的cookie,虽然cookie的值是加密的,但我仍然找到一些方法来解密它.
我还注意到,cookie表的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.
希望这个问题可以帮助别人.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。