I'm trying to decode the jsonlz4
file that contains my saved tabs from Firefox (saved in %appdata%\Mozilla\Firefox\Profiles\xxxxxx.default-release\sessionstore-backups\recovery.jsonlz4
, in the hope of eventually being able to parse the json and extract the URLs in my tabs and maybe other data from my session.
I was hoping that the lz4-pure-java
library could decompress it to json.
I'm trying to use Method 2 Example from the lz4-java github, and a comment here says that the file should be standard lz4 if we skip the 12-byte header.
Here's my code:
package com.jsonparser;
import net.jpountz.lz4.LZ4Factory;
import net.jpountz.lz4.LZ4SafeDecompressor;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
public class jsonLZ4 {
public static void main(String[] args) throws IOException {
String infile = "C:\\Users\\username\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\xxxxxx.default-release\\sessionstore-backups\\recovery.jsonlz4";
byte[] datain = Files.readAllBytes(Paths.get(infile));
// need to skip the first 12 bytes for Firefox format
byte[] data = Arrays.copyOfRange(datain,12,datain.length);
LZ4Factory factory = LZ4Factory.fastestInstance();
byte[] compressed = data;
int compressedLength = compressed.length;
byte[] restored = new byte[compressed.length*2]; // not sure how to set length properly without knowing decompressed size
// - method 2: when the compressed length is known (a little slower)
// the destination buffer needs to be over-sized
LZ4SafeDecompressor decompressor2 = factory.safeDecompressor();
int decompressedLength2 = decompressor2.decompress(compressed, 0, compressedLength, restored, 0);
String s = new String(restored, StandardCharsets.UTF_8);
System.out.println("decompressed data is: " + s);
}
}
Unfortunately I'm getting a decompression error:
Exception in thread "main" net.jpountz.lz4.LZ4Exception: Malformed input at 1803197
at net.jpountz.lz4.LZ4JavaUnsafeSafeDecompressor.decompress(LZ4JavaUnsafeSafeDecompressor.java:62)
at net.jpountz.lz4.LZ4SafeDecompressor.decompress(LZ4SafeDecompressor.java:77)
at com.jsonparser.jsonLZ4.main(jsonLZ4.java:31)
Process finished with exit code 1
Does anyone know how I can successfully decompress this file, preferably using only java?
Thanks.