Viewing blob data as a hexdump with ASCII in the sqlite3 console

老子叫甜甜 提交于 2019-12-03 16:07:52
CL.

The sqlite3 shell cannot display ASCII values in a binary data dump.

You have to pipe its output into a separate tool:

sqlite3 test.db "SELECT MyBlob FROM MyTable WHERE ID = 42;" | hexdump -C
sqlite3 test.db "SELECT MyBlob FROM MyTable WHERE ID = 42;" | xxd -g1

However, sqlite3 converts the blob into a string to display it, so this will not work if the blob contains zero bytes.

You have to output the blob as hex, then convert it back into binary, so that you can then display it in the format you want:

sqlite3 test.db "SELECT quote(MyBlob) FROM MyTable WHERE id = 42;"  \
| cut -d\' -f2                                                      \
| xxd -r -p                                                         \
| xxd -g1

You can run the below script in the command.

sqlite3 test.db "select hex(obj) from data where rowid=1" >> hexdump

:) I'm not sure if it's what you need.

Here a sample of the query to see and use hex in where statement:

Query blob data as HEX:

> qlite3 your_db_file.db -separator ','  "SELECT _id, timestamp, length(hex(blob_data)), hex(blob_data) FROM your_table;"
11190,1562991418211,8,0020C618
11190,1562991418231,8,5A0E1003

Query blob data as HEX in WHERE:

> qlite3 your_db_file.db -separator ','  "SELECT _id, timestamp, length(hex(blob_data)), hex(blob_data) FROM your_table WHERE hex(blob_data)='0020C618';"
11190,1562991418211,8,0020C618
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!