gpt4 book ai didi

python - 如何使用 Python 访问 Firefox 的内部 indexedDB 文件?

转载 作者:太空狗 更新时间:2023-10-30 00:17:27 24 4
gpt4 key购买 nike

我需要使用 python 读取 firefox 的 indexeddb。

我使用 slite3 包来检索 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]

然而,虽然我知道数据库中的内容是字符串,但它们存储为 sqlite binary blobs .有没有办法从 python 中读取存储为 blob 的字符串?

我试过:

更新

遵循 firefox 中的编码方案 source code关于@paa 在这个问题的评论之一中指出的 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

但是,我仍然无法解码 indexeddb 的数据字段。在我看来,他们没有使用任何复杂的方案,例如 key 方案,因为当我以 UTF-16 编码时,我可以读取实际值的某些部分。

最佳答案

(在这里打字,因为我还不能发表评论...)

对于数据本身,我一直在尝试对数据 blob 做同样的事情。对于我的问题,我正在尝试获取 JSON 字符串。如果我查看要筛选的数据库,大多数时候我确实会看到 UTF-16 编码的字符。但在某些奇怪的情况下,我有这个:

“我们开始”被编码为 7400 6800 6500 7200 6500 2000 77 [05060C] 6700 6F00。 [05060C] 应该编码为“e”。

https://mxr.mozilla.org/mozilla-release/source/dom/indexedDB/IDBObjectStore.cpp

我正在努力调查,看看是否有任何线索。目录中应该有很多其他源文件可以提供帮助。

关于python - 如何使用 Python 访问 Firefox 的内部 indexedDB 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22917139/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com