Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Chrome/Firefox cache file extractor
<?php
/*
* Chrome/Firefox cache file extractor
* Just open cache entry page and copy/paste file data hex section
* into "cachefile.txt" file in script working directory and run me.
* You can run me through CLI or Webserver.
*
* Change $is_gzip to false if data is not gzip encoded.
*
* Chrome: chrome://cache
* Firefox: about:cache
*
* @author Mehran Ahadi
* @link http://mehran.ahadi.me/
* @link https://medium.com/@zxcmehran/recover-the-past-4b721d73badd
*/
// change to false if it's not gzipped.
$is_gzip = true;
//input file
$cachehexfile = 'cachefile.txt';
// output file, undecompressed
$hexout = 'cachefile.bin';
// output file, decompressed
$gzout = 'cachefile-extracted.txt';
define('LINE_LIMIT', 16);
define('TIME_PERIOD', 3);
$stime = $time = time();
$counter = 0;
$if = fopen($cachehexfile, 'r');
$of = fopen($hexout, 'wb');
while($l = fgets($if)){
$matches = array();
preg_match_all('/([0-9a-f]{2}) /', $l, $matches);
$limit = 0;
foreach ($matches[1] as $match) {
if($limit == LINE_LIMIT){
break;
}
fwrite($of, pack('H*', $match));
$limit++;
}
$counter += LINE_LIMIT;
if(time()>=$time+TIME_PERIOD){
$time = time();
printf("%0.2f KBytes in %d secs <br>\n", $counter/1024, $time - $stime);
flush();
}
}
fclose($if);
fclose($of);
printf("Hex converted in %d secs: %s (%0.2f KBytes) <br>\n", $time-$stime, htmlspecialchars($hexout), $counter/1024);
flush();
// now extract the gzipped file
if($is_gzip){
echo "Started extracting Gzip data.<br>\n";
flush();
$sfp = gzopen($hexout, 'rb');
$fp = fopen($gzout, 'w');
$stime = $time = time();
$counter = 0;
while (!gzeof($sfp)) {
$string = gzread($sfp, 4096);
fwrite($fp, $string, strlen($string));
$counter += strlen($string);
if(time()>=$time+TIME_PERIOD){
$time = time();
printf("%0.2f KBytes in %d secs <br>\n", $counter/1024, $time - $stime);
flush();
}
}
gzclose($sfp);
fclose($fp);
printf("Decompressed in %d secs: %s (%0.2f KBytes) <br>\n", $time-$stime, htmlspecialchars($gzout), $counter/1024);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.