Great! The good news is that lz4 is successfully installed in your virtual environment (~/myenv). That part of the problem is solved.
The new error, FileNotFoundError: [Errno 2] No such file or directory: 'sessionstore.jsonlz4', means your Python script (decompress_mozilla_lz4.py) is trying to open a file named sessionstore.jsonlz4 (and recovered_session.json later) but it cannot find it in the location it's looking.
This is a common issue and usually comes down to one of these:
- The file
sessionstore.jsonlz4 actually doesn't exist on your system.
- The file exists, but your script is looking in the wrong place. When you specify a file by just its name (like
'sessionstore.jsonlz4'), Python looks for it in the current working directory where you execute the script.
Let's troubleshoot this:
Troubleshooting Steps:
1. Locate the sessionstore.jsonlz4 file:
- Do you know where this file is supposed to be? This file is typically found in your Firefox (or Waterfox) profile directory.
2. Check your current working directory:
- Before running your Python script, run the
pwd command in your terminal:
pwd
This will show you the directory you are currently in.
- Your script (
decompress_mozilla_lz4.py) is located at /home/kali/waterfox/. If you are running the script from that directory, it expects sessionstore.jsonlz4 to be inside /home/kali/waterfox/ as well.
Solutions:
Once you've located sessionstore.jsonlz4, choose one of the following approaches:
Option 1: Move sessionstore.jsonlz4 into the script's directory (Simplest for one-off)
Option 2: Specify the full path to sessionstore.jsonlz4 when running the script (Most robust)
This is the best practice. You modify your script slightly to accept the input file path as an argument.
First, modify your decompress_mozilla_lz4.py script:
Change your script to accept the input file and output file paths as command-line arguments. This makes it much more flexible.
import lz4.frame
import json
import sys
import os # Import os module for path manipulation
# Check if correct number of arguments are provided
if len(sys.argv) < 3:
print("Usage: python3 decompress_mozilla_lz4.py <input_file.jsonlz4> <output_file.json>")
sys.exit(1)
input_file = sys.argv[1] # First argument after script name
output_file = sys.argv[2] # Second argument
try:
print(f"Attempting to open input file: {input_file}")
with open(input_file, "rb") as f:
compressed_data = f.read()
# The first 8 bytes (magic number "mozLz40\0") are not part of the actual LZ4 data
# and should be skipped before decompression.
# From Mozilla's source, it's 8 bytes: 'mozLz40\0'
decompressed_data = lz4.frame.decompress(compressed_data[8:])
# Decode as UTF-8 (Firefox session data is typically JSON)
json_data = decompressed_data.decode('utf-8')
session_data = json.loads(json_data)
print(f"Attempting to write output file: {output_file}")
with open(output_file, "w", encoding='utf-8') as f:
json.dump(session_data, f, indent=4) # Pretty print JSON
print(f"Successfully decompressed '{input_file}' to '{output_file}'")
except FileNotFoundError:
print(f"Error: Input file '{input_file}' or output directory for '{output_file}' not found.")
except lz4.frame.LZ4FrameError as e:
print(f"Error during LZ4 decompression: {e}. The file might not be a valid mozLz40 file or is corrupted.")
except json.JSONDecodeError as e:
print(f"Error decoding JSON: {e}. The decompressed data might not be valid JSON.")
except Exception as e:
print(f"An unexpected error occurred: {e}")
Then, run the modified script from any directory:
Once you know the full path to sessionstore.jsonlz4 (e.g., /home/kali/.waterfox/profile/some_profile_id/sessionstore.jsonlz4), run your script like this:
cd /home/kali/waterfox/ # Go to your script's directory
source ~/myenv/bin/activate
python3 decompress_mozilla_lz4.py /home/kali/.waterfox/profile/some_profile_id/sessionstore.jsonlz4 recovered_session.json
Replace /home/kali/.waterfox/profile/some_profile_id/sessionstore.jsonlz4 with the actual full path to your sessionstore.jsonlz4 file. The recovered_session.json will be created in the /home/kali/waterfox/ directory.
Summary:
The key is to tell your script exactly where to find the sessionstore.jsonlz4 file. The FileNotFoundError is not an lz4 library issue, but rather an issue with the script's ability to locate its input.