Decompress Mozilla Firefox jsonlz4 bookmark backup files



Published: 2019-03-20 11:51:20 +0000
Categories: Python,

Language

Python

Description

Sometimes you need to extract something from Firefox without actually running it (as an example, I sometimes need to access stuff in firefox on a remote machine, whilst I can run firefox over a SSH tunnel with --no-remote, there's currently no way to prevent Firefox from restoring whatever tabs were previously open, other than turning it off in about:config, which is crap for day to day usage).

Firefox currently uses files of type mozlz4 (Basically a non-standard variation of lz4)

This snippet will decompress those files and print the output to stdout, so that the JSON can then be passed into something else (or grepped, etc)

Based On

Snippet

#!/usr/bin/env python
import sys

def mozlz4_to_text(filepath):
    # Given the path to a "mozlz4", "jsonlz4", "baklz4" etc. file, 
    # return the uncompressed text.

    try:
        import lz4.block as lz4
    except:
        import lz4

    bytestream = open(filepath, "rb")
    bytestream.read(8)  # skip past the b"mozLz40\0" header
    valid_bytes = bytestream.read()
    text = lz4.decompress(valid_bytes)
    return text

print mozlz4_to_text(sys.argv[1])

Usage Example

# Dump Bookmarks out
python mozlz4.py ~/.mozilla/firefox/glg1hlff.default/bookmarkbackups/bookmarks-2019-03-20_36_bKyosvOB911kdTFoAg9zeQ\=\=.jsonlz4

# Pretty print the JSON
python mozlz4.py ~/.mozilla/firefox/glg1hlff.default/bookmarkbackups/bookmarks-2019-03-20_36_bKyosvOB911kdTFoAg9zeQ\=\=.jsonlz4 | python -m "json.tool" | less

# Dump out information about the last session
python /tmp/mozlz4.py ~/.mozilla/firefox/glg1hlff.default/sessionstore-backups/previous.jsonlz4 | python -m "json.tool" | less

# Dump out session recovery info
python /tmp/mozlz4.py ~/.mozilla/firefox/glg1hlff.default/sessionstore-backups/recovery.jsonlz4 | python -m "json.tool" | less

Requires

  • python-lz4

Keywords

lz4, mozlz4, decompress, firefox, bookmarks,

Latest Posts


Copyright © 2022 Ben Tasker | Sitemap | Privacy Policy
Available at snippets.bentasker.co.uk, http://phecoopwm6x7azx26ctuqcp6673bbqkrqfeoiz2wwk36sady5tqbdpqd.onion and http://snippets.bentasker.i2p
hit counter