int
test_exec(sqlite3
*
Db,char
*
sql)
{
/
/
提一句什么这么玩,因为根据文档解释,sqlite3_key出错的话,不会立即报错,
/
/
只有执行一条sql语句后才知道sqlite3_key()执行成功与否。
if
(sqlite3_exec(Db, sql, NULL, NULL, NULL)
=
=
SQLITE_OK) {
printf(
"key is correct\r\n"
);
}
else
{
printf(
"key is incorrect\r\n"
);
}
}
int
main()
{
const char
*
filename
=
"C:\\Users\\xxx\\Desktop\\ChatMsg.db"
;
/
/
加密数据库路径
const char pkey[
0x20
]
=
{} ;
/
/
自己下断点或者hook获取key
sqlite3
*
Db;
if
(sqlite3_open(filename, &Db))
{
printf(
"sqlite3_open error"
);
return
0
;
}
sqlite3_key(Db, pkey,
0x20
);
test_exec(Db,
"PRAGMA cipher_compatibility = 3"
);
test_exec(Db,
"PRAGMA cipher_page_size = 4096"
);
test_exec(Db,
"PRAGMA synchronous=NORMAL"
);
test_exec(Db,
"Select * from sqlite_master"
);
/
/
test_exec(Db,
"PRAGMA rekey = 'testkey'"
);
/
/
修改密码
test_exec(Db,
"PRAGMA count_changes=OFF"
);
/
/
复制一个未加密的数据库
test_exec(Db,
"ATTACH DATABASE 'plaintext1.db' AS plaintext1 KEY '';"
);
test_exec(Db,
"SELECT sqlcipher_export('plaintext1');"
);
test_exec(Db,
"DETACH DATABASE plaintext1"
);
/
/
继续流程
test_exec(Db,
"PRAGMA auto_vacuum=0"
);
test_exec(Db,
"PRAGMA journal_mode = WAL"
);
if
(SQLITE_OK !
=
sqlite3_close(Db))
{
printf(
"sqlite3_close error"
);
}
return
0
;
}