Skip to content

sqlite3 文件结构逆向分析

初始化数据结构,并插入数据

bash
sqlite3 a.db

sqlite> .databases
main: /Users/ydl/a.db
sqlite> .table
test   test1
sqlite> .tables test
test
sqlite> .schema test
CREATE TABLE test (`id` int);
sqlite> .schema test1
CREATE TABLE test1 (`test` varchar(30));
sqlite> select *from test;
1
1234567
sqlite> select * from test1;
hello world

dump 文件结构

bash
hexdump -C a.db
bash
00000000  53 51 4c 69 74 65 20 66  6f 72 6d 61 74 20 33 00  |SQLite format 3.|
00000010  10 00 01 01 00 40 20 20  00 00 00 05 00 00 00 03  |.....@  ........|
00000020  00 00 00 00 00 00 00 00  00 00 00 03 00 00 00 04  |................|
00000030  00 00 00 00 00 00 00 00  00 00 00 01 00 00 00 00  |................|
00000040  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
00000050  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 05  |................|
00000060  00 2e 24 80 0d 00 00 00  02 0f 8f 00 0f ce 0f 8f  |..$.............|
00000070  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00000f80  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 3d  |...............=|
00000f90  02 06 17 17 17 01 5b 74  61 62 6c 65 74 65 73 74  |......[tabletest|
00000fa0  31 74 65 73 74 31 03 43  52 45 41 54 45 20 54 41  |1test1.CREATE TA|
00000fb0  42 4c 45 20 74 65 73 74  31 20 28 60 74 65 73 74  |BLE test1 (`test|
00000fc0  60 20 76 61 72 63 68 61  72 28 33 30 29 29 30 01  |` varchar(30))0.|
00000fd0  06 17 15 15 01 45 74 61  62 6c 65 74 65 73 74 74  |.....Etabletestt|
00000fe0  65 73 74 02 43 52 45 41  54 45 20 54 41 42 4c 45  |est.CREATE TABLE|
00000ff0  20 74 65 73 74 20 28 60  69 64 60 20 69 6e 74 29  | test (`id` int)|
00001000  0d 00 00 00 02 0f f5 00  0f fc 0f f5 00 00 00 00  |................|
00001010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00001ff0  00 00 00 00 00 05 02 02  03 12 d6 87 02 01 02 09  |................|
00002000  0d 00 00 00 01 0f f1 00  0f f1 00 00 00 00 00 00  |................|
00002010  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|
*
00002ff0  00 0d 01 02 23 68 65 6c  6c 6f 20 77 6f 72 6c 64  |....#hello world|
00003000

参考资料

  1. Sqlite3 Database File Format