Skip to content

Instantly share code, notes, and snippets.

@starcraft66
Last active July 2, 2020 20:56
Show Gist options
  • Save starcraft66/6c89344bce73fdf4db2744b71880296f to your computer and use it in GitHub Desktop.
Save starcraft66/6c89344bce73fdf4db2744b71880296f to your computer and use it in GitHub Desktop.
Extract files from the Firefox for Android cache using html dumps of "Cache entry information" pages on devices where extracting the Firefox cache is not possible (non-rooted Android devices). Currently hardcoded to write files with the webp extension.
import re
import glob
from bs4 import BeautifulSoup
inputs = glob.glob("input/*.html")
for input in inputs:
ba = bytearray()
with open(input, 'r') as file:
soup = BeautifulSoup(file, 'html.parser')
data = soup.find_all('pre')[0].contents[0]
foundbytes = re.findall("[0-9a-f]{8}:((\ \ [0-9a-f]{2}){1,16})", data)
for byteline in foundbytes:
cleanbyteline = re.sub(' ', '', byteline[0])
thebytes = bytes.fromhex(cleanbyteline)
for b in thebytes:
ba.append(b)
with open(f"output/{input[6:-5]}.webp", "wb") as out:
out.write(ba)
out.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment