Created
December 4, 2020 05:15
-
-
Save zxcmehran/4e31405606495bc9324b5cc88d906116 to your computer and use it in GitHub Desktop.
Chrome/Firefox cache file extractor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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
Copied from https://gist.github.com/zxcmehran-old/b4cab69b70166187f5cb due to account migration.