简体   繁体   English

解码伯克利数据库字符串

[英]Decode berkeley db strings

Having trouble decoding data from berkeley db.无法从 berkeley db 解码数据。 I've dumped data with db4.8_dump or db4.8_dump -p and decoding using python.decode()我已经使用db4.8_dumpdb4.8_dump -p转储数据并使用python.decode()解码

So, here's what the data looks like after db4.8_dump in hex coding所以,这是 db4.8_dump 十六进制编码后的数据

036b65794104053ca761cf8062cfff09a2ec355a2694da4eed0677b510cf0c43a0d8486694e9966f2133302c5aa51664e9003b04cfa3847ce20de92040844b9b05aa15b5ab58

and same data with -p switch db4.8_dump -p :-p开关db4.8_dump -p相同的数据:

\03keyA\04\05<\a7a\cf\80b\cf\ff\09\a2\ec5Z&\94\daN\ed\06w\b5\10\cf\0cC\a0\d8Hf\94\e9\96o!30,Z\a5\16d\e9\00;\04\cf\a3\84|\e2\0d\e9 @\84K\9b\05\aa\15\b5\abX

I can decode it like his, but still unreadable :我可以像他一样解码它,但仍然无法读取:

mbstr = b'036b65794104053ca761cf8062cfff09a2ec355a2694da4eed0677b510cf0c43a0d8486694e9966f2133302c5aa51664e9003b04cfa3847ce20de92040844b9b05aa15b5ab58'

mbstr.decode('hex')
'\x03keyA\x04\x05<\xa7a\xcf\x80b\xcf\xff\t\xa2\xec5Z&\x94\xdaN\xed\x06w\xb5\x10\xcf\x0cC\xa0\xd8Hf\x94\xe9\x96o!30,Z\xa5\x16d\xe9\x00;\x04\xcf\xa3\x84|\xe2\r\xe9 @\x84K\x9b\x05\xaa\x15\xb5\xabX'

Per documentation https://docs.oracle.com/cd/E17275_01/html/programmer_reference/dumpload_format.html每个文档https://docs.oracle.com/cd/E17275_01/html/programmer_reference/dumpload_format.html

If the backslash character precedes any other character, the next two characters must be interpreted as hexadecimal specification of a single character;如果反斜杠字符在任何其他字符之前,则接下来的两个字符必须解释为单个字符的十六进制规范; for example, \\0a is a newline character in the ASCII character set.例如,\\0a 是 ASCII 字符集中的换行符。 but this doesn't work for me.但这对我不起作用。 ie IE

>>> mbstr.decode('hex')
'\x03keyA\x04\x05<\xa7a\xcf\x80b\xcf\xff\t\xa2\xec5Z&\x94\xdaN\xed\x06w\xb5\x10\xcf\x0cC\xa0\xd8Hf\x94\xe9\x96o!30,Z\xa5\x16d\xe9\x00;\x04\xcf\xa3\x84|\xe2\r\xe9 @\x84K\x9b\x05\xaa\x15\xb5\xabX'
>>> mbstr.decode('hex').decode('ascii')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xa7 in position 8: ordinal not in range(128)

How can I convert data into readable string format?如何将数据转换为可读的字符串格式? Thank you谢谢

Berkeley DB keys and data are frequently not strings. Berkeley DB 键和数据通常不是字符串。 Actually, I can't recall a time when I've ever used strings for the keys.实际上,我不记得我曾经使用字符串作为键的时间。 Data, sure.数据,当然。 Sometimes.有时。 But the key comparison function is so performance critical, it nearly always makes sense to represent keys in binary, like it would sit in a packed C struct.但是键比较函数对性能非常关键,用二进制表示键几乎总是有意义的,就像它位于压缩的 C 结构中一样。

To make sense of the data stored in Berkeley DB, you need the source code for the application that populated it.要理解存储在 Berkeley DB 中的数据,您需要填充它的应用程序的源代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM