syn*_*ack 7 python firefox indexeddb
我需要使用python读取firefox的indexeddb.
我用slite3
package来检索indexeddb的内容:
with sqlite3.connect(indexeddb_file) as conn:
c = conn.cursor()
c.execute('select * from object_data;')
rows = c.fetchall()
for row in rows:
print row[2]
Run Code Online (Sandbox Code Playgroud)
但是,虽然我知道数据库中的内容是字符串,但它们存储为sqlite 二进制blob.有没有办法从python中读取存储为blob的字符串?
我试过了:
UPDATE
下面是@paa在这个问题的一个注释中指出的firefox 源代码执行indexeddb 的编码方案,我在python中实现了数据库键的FF编码方法的一部分.所以,到目前为止,我只为字符串实现了它,但是为其他类型实现它会更容易:
BYTE_LENGTH = 8
def hex_to_bin(hex_str):
"""Return binary representation of hexadecimal string."""
return str(trim_bin(int(hex_str, 16)).zfill(len(hex_str) * 4))
def byte_to_unicode(bin_byte):
"""Return unicode encoding for binary byte."""
return chr(int(str(bin_byte), 2))
def trim_bin(int_n):
"""Return int num converted to trimmed bin representation."""
return bin(int_n)[2:]
def decode(key):
"""Return decoded idb key."""
decoded = key
m = re.search("[1-9]", key) # change for non-zero
if m:
i = m.start()
typeoffset = int(key[i])
else:
# error
pass
data = key[i + 1:]
if typeoffset is 1:
# decode number
pass
elif typeoffset is 2:
# decode date
pass
elif typeoffset is 3:
# decode string
bin_repr = hex_to_bin(data)
decoded = ""
for i in xrange(0, len(bin_repr), BYTE_LENGTH):
byte = bin_repr[i:i + BYTE_LENGTH]
if byte[0] is '0':
byte_1 = int(byte, 2) - 1
decoded += byte_to_unicode(trim_bin(byte_1))
else:
byte = byte[2:]
if byte[1] is '0':
byte_127 = int(byte, 2) + 127
decoded += byte_to_unicode(trim_bin(byte_127))
i += BYTE_LENGTH
decoded += byte_to_unicode(bin_repr[i:i + BYTE_LENGTH])
elif byte[1] is '1':
decoded += byte_to_unicode(byte)
i += BYTE_LENGTH
decoded += byte_to_unicode(bin_repr[i:i + BYTE_LENGTH])
i += BYTE_LENGTH
decoded += byte_to_unicode(bin_repr[i:i + 2])
return decoded
elif typeoffset is 4:
# decode array
pass
else:
# error
pass
return decoded
Run Code Online (Sandbox Code Playgroud)
但是,我仍然无法解码indexeddb的数据字段.在我看来,他们没有使用任何复杂的方案,如键,因为我可以读取实际值的一些部分,当我用UTF-16编码它们.
小智 1
(因为我还不能发表评论所以在这里打字......)
对于数据本身,我一直在尝试对数据 blob 做同样的事情。对于我的问题,我正在尝试抓取 JSON 字符串。如果我查看我试图筛选的数据库,大多数时候我确实会看到 UTF-16 编码的字符。但在一些奇怪的情况下,我有这样的情况:
“there we go”编码为 7400 6800 6500 7200 6500 2000 77 [05060C] 6700 6F00。[05060C] 据称编码“e”。
https://mxr.mozilla.org/mozilla-release/source/dom/indexedDB/IDBObjectStore.cpp
我正在尝试调查此事,看看是否有任何线索。目录中应该有很多其他可以提供帮助的源文件。