在sqlite3控制台中使用ASCII将十六进制转储数据查看为十六进制转储 [英] Viewing blob data as a hexdump with ASCII in the sqlite3 console
问题描述
我在SQLite表中有一列数据存储为Blob.具体来说,它是一个序列化的POJO(java对象).
I have a column of data in a SQLite table being stored as a blob. Specifically, it is a serialized POJO (java object).
无论哪种方式,我都想在SQLite控制台中以十六进制转储的形式查看它,就像这样:
Either way, I'd like to view it in the SQLite console as a hex dump, sort of like this:
0000000000 |The correction f|
0000000016 |or the aberratio|
0000000032 |n of light is sa|
0000000048 |id,.on high auth|
0000000064 |ority, not to be|
0000000080 | perfect even in|
0000000096 | that most perfe|
0000000112 |ct organ, the.ey|
0000000128 |e..|
我知道语句SELECT HEX(obj) FROM data WHERE rowid = 1
将获取的数据仅为十六进制,但现在我想将其通过管道传递给可以提供十六进制转储视图的对象.
I know the statement SELECT HEX(obj) FROM data WHERE rowid = 1
will get the data as just hex, but now I want to pipe it to something that will give me a hexdump view.
PS-我知道我要查看的数据是二进制的(序列化的POJO),但我想看看其中的内容是什么.因此,即使最终结果还是个谜,也请让我知道!
PS - I know the data I am trying to view is binary (a serialized POJO) but I would like to see what is inside as an experiment. So, even if the end result is cryptic anyway, please let me know!
更新: 我尝试了一些建议,但发现sqlite3没有输出完整的十六进制.我预计大约有500个字节,但是却变成了10个字节:
Update: I tried some of the suggestions but found that sqlite3 isn't outputing the full hex. I am expecting around 500 bytes but instead getting like 10:
root@ubuntu:~# sqlite3 IceCream.db "select hex(obj) from Customers where rowid=1;"
ACED00057372002D6564752E6761746563682E7365636C6173732E70726F6A656374322E637573746F6D65722E437573746F6D6572000000000000000102000B4C0007616464726573737400124C6A6176612F6C616E672F537472696E673B4C0012617661696C61626C65467265654974656D737400134C6A6176612F6C616E672F496E74656765723B4C00096269727468446174657400104C6A6176612F7574696C2F446174653B4C000C646973636F756E745261746571007E00024C000966697273744E616D6571007E00014C000A676F6C645374617475737400134C6A6176612F6C616E672F426F6F6C65616E3B4C00086C6173744E616D6571007E00014C000D6D6F6E74686C79506F696E747371007E00024C0013706F696E74734561726E656450657254696D657400134C6A6176612F7574696C2F486173684D61703B4C000B746F74616C506F696E747371007E00024C000876697053696E636571007E0003787200386564752E6761746563682E7365636C6173732E70726F6A656374322E73797374656D732E446174616261736553657269616C4F626A65637400000000000000010200024C000269647400104C6A6176612F6C616E672F4C6F6E673B4C00166C61737454696D654F626A6563744D6F64696669656471007E000778707372000E6A6176612E6C616E672E4C6F6E673B8BE490CC8F23DF0200014A000576616C7565787200106A6176612E6C616E672E4E756D62657286AC951D0B94E08B020000787000000000000000017371007E0009000001497757AAFB740006436172736F6E737200116A6176612E6C616E672E496E746567657212E2A0A4F781873802000149000576616C75657871007E000A000000007372000E6A6176612E7574696C2E44617465686A81014B59741903000078707708000001349BB816607871007E000F74000442696C6C737200116A6176612E6C616E672E426F6F6C65616ECD207280D59CFAEE0200015A000576616C7565787000740005313233205471007E000F737200116A6176612E7574696C2E486173684D61700507DAC1C31660D103000146000A6C6F6164466163746F7278703F400000770800000010000000007871007E000F70
root@ubuntu:~# sqlite3 IceCream.db "select obj from Customers where rowid=1;" | hexdump -C
00000000 ac ed 0a |...|
00000003
推荐答案
sqlite3
shell无法在二进制数据转储中显示ASCII值.
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
但是,sqlite3
将blob转换为字符串以显示它,因此,如果blob包含零字节,则此操作将无效.
However, sqlite3
converts the blob into a string to display it, so this will not work if the blob contains zero bytes.
您必须将blob输出为十六进制,然后将其转换回二进制,以便可以按所需格式显示它:
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
这篇关于在sqlite3控制台中使用ASCII将十六进制转储数据查看为十六进制转储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!