{"id":645,"date":"2011-05-14T11:58:51","date_gmt":"2011-05-14T10:58:51","guid":{"rendered":"http:\/\/www.frozax.com\/blog\/?p=645"},"modified":"2015-04-04T21:46:20","modified_gmt":"2015-04-04T21:46:20","slug":"recover-file-google-chrome-cache-gzipped","status":"publish","type":"post","link":"https:\/\/www.frozax.com\/blog\/2011\/05\/recover-file-google-chrome-cache-gzipped\/","title":{"rendered":"How to recover a file in Google Chrome cache (gzipped or not)"},"content":{"rendered":"<p>Exceptionally, this article is slightly off-topic and will not be related to game development.<\/p>\n<p>I wished I could find an article like this one a few hours earlier, therefore I&#8217;m writing it myself, hoping to help people fixing the same problem I had.<\/p>\n<h3>The context<\/h3>\n<p>Earlier today, I was logging onto my ftp to download the latest log of <a href=\"http:\/\/www.frozax.com\/games\/spring-up-harmony\">Spring Up Harmony<\/a> hiscores history in order to gather up-to-date piracy statistics. As the log files can grow quite large, I regularly download it locally and remove the server copy. Then, I use all my local copies to generate new stats, similar to the one shown in my <a href=\"http:\/\/www.frozax.com\/blog\/2011\/03\/piracy-stats-spring-up-harmony-pc-game\/\">96% Piracy blog article<\/a>.<\/p>\n<h3>The mistake<\/h3>\n<p>I was probably not really focused, but instead of\u00a0transferring\u00a0from my site to my local computer, I transfered the other way round and lost all my logs of the last 4 days! Argh! I&#8217;m sure the next time I will examine the &#8220;Are you sure you want to overwrite this file?&#8221; popup carefully.<\/p>\n<h3>The failed strategies<\/h3>\n<p>Here is a list of actions I made trying to recover data:<\/p>\n<ul>\n<li>As I looked at my stats log online a few hours earlier, I hoped that I kept a tab open in my browser but I didn&#8217;t.<\/li>\n<li>I checked the automatic backup of my hosting provider, but the daily backup was made 20 hours ago. That&#8217;s already a few days recovered, but I hoped to recover more of it.<\/li>\n<li>I looked into Chrome cache folder, only to find 285 Mb of strangely-named binary files. That will not get me anywhere.<\/li>\n<li>I looked for a free app to access chrome cache but the only one I found only told me which binary file contained my log file (<a href=\"http:\/\/www.nirsoft.net\/utils\/chrome_cache_view.html\">ChromeCacheView<\/a>).<\/li>\n<\/ul>\n<p>However, this last app gave me hope because it displayed information about the name and date of the file I was looking for. Only 3 hours from the mistake.\u00a0Losing 3 hours of log would be acceptable.<\/p>\n<h3>The Solution<\/h3>\n<p>Looking on google, I found that Chrome has an interesting integrated cache viewer that could have helped me from the beginning. By typing <em>about:cache<\/em> in the\u00a0address\u00a0bar, you access a list of cached files. You can also type a direct url if you know the file in the following form: <em>chrome:\/\/view-http-cache\/http:\/\/example.com\/file.htm<\/em>. I thought I found the solution and quickly accessed my log file. However, Chrome does not simply give you a way to get the cached file but instead displays raw data with <a href=\"http:\/\/en.wikipedia.org\/wiki\/List_of_HTTP_header_fields\">HTTP headers<\/a> and data received from the server. For my file, it gave me something like that (<em>click for full size<\/em>):<\/p>\n<p><a href=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/05\/chrome_cache.png\"><img decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-647 alignnone\" title=\"chrome_cache\" src=\"http:\/\/www.frozax.com\/blog\/wp-content\/uploads\/2011\/05\/chrome_cache-300x236.png\" alt=\"chrome_cache\" width=\"300\" height=\"236\" \/><\/a><\/p>\n<p>As you can see in the red circle, it&#8217;s pretty obvious that the binary data displayed below is\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Gzip\">gzip<\/a> data, and not plain text sadly. However, the presentation in Chrome is not really handy to get the real binary data because it contains on the left the addresses and on the right the binary form. The useful part is the hexadecimal version on the middle.<\/p>\n<p>An article on <a href=\"http:\/\/www.alexkorn.com\/blog\/2010\/05\/how-to-recover-deleted-javascript-files-using-the-cache-in-chrome-or-firefo\/\">Alex Korn site<\/a> gives a php script he used to extract the file content section of Chrome cache into a text file. It won&#8217;t be that simple in my case because my content is binary but it&#8217;s a good start. Alex Korn had his text file directly visible. The first time I ran this php script, I had errors extracting the gzip file (corrupted data). After a closer look it&#8217;s because of the reg exp used in the <em>preg_match_all<\/em>. Some data on the right side (binary) could match the reg exp and inject invalid bytes. I replaced the reg exp by using spaces (s) instead of whitespaces (b) and added code to directly decode the gzip data. This is the full script I used:<\/p>\n<blockquote>\n<pre>\/\/ cache.log is a copy of chrome cache page with only the file content section\r\n$cacheString = file_get_contents(\"cache.log\");\r\n$matches = array();\r\npreg_match_all('\/s[0-9a-f]{2}s\/', $cacheString, $matches);\r\n$f = fopen(\"t.bin\",\"wb\");\r\nforeach ($matches[0] as $match)\r\n{\r\n  fwrite($f,chr(hexdec($match)));\r\n}\r\nfclose($f);\r\n\r\nob_start();\r\nreadgzfile(\"t.bin\");\r\n$decoded_data=ob_get_clean();\r\necho $decoded_data;<\/pre>\n<\/blockquote>\n<p>And that did it, I finally recovered my file!<\/p>\n<h3>Conclusion<\/h3>\n<p>I know this article is really specific but as I said in the beggining, I really hope people looking for this information will find it here instead of spending as much time as I did figuring it out.<\/p>\n<p>You can follow me on <a href=\"http:\/\/twitter.com\/Frozax\">twitter<\/a> or <a href=\"http:\/\/www.facebook.com\/pages\/Frozax-Games\/93984111894\">facebook<\/a>, and feel free to comment this article here.<\/p>\n<div class=\"addtoany_share_save_container addtoany_content_bottom\"><div class=\"a2a_kit a2a_kit_size_32 addtoany_list a2a_target\" id=\"wpa2a_1\"><a class=\"a2a_button_twitter\" href=\"http:\/\/www.addtoany.com\/add_to\/twitter?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F05%2Frecover-file-google-chrome-cache-gzipped%2F&amp;linkname=How%20to%20recover%20a%20file%20in%20Google%20Chrome%20cache%20%28gzipped%20or%20not%29\" title=\"Twitter\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_facebook\" href=\"http:\/\/www.addtoany.com\/add_to\/facebook?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F05%2Frecover-file-google-chrome-cache-gzipped%2F&amp;linkname=How%20to%20recover%20a%20file%20in%20Google%20Chrome%20cache%20%28gzipped%20or%20not%29\" title=\"Facebook\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_google_plus\" href=\"http:\/\/www.addtoany.com\/add_to\/google_plus?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F05%2Frecover-file-google-chrome-cache-gzipped%2F&amp;linkname=How%20to%20recover%20a%20file%20in%20Google%20Chrome%20cache%20%28gzipped%20or%20not%29\" title=\"Google+\" rel=\"nofollow\" target=\"_blank\"><\/a><a class=\"a2a_button_reddit\" href=\"http:\/\/www.addtoany.com\/add_to\/reddit?linkurl=https%3A%2F%2Fwww.frozax.com%2Fblog%2F2011%2F05%2Frecover-file-google-chrome-cache-gzipped%2F&amp;linkname=How%20to%20recover%20a%20file%20in%20Google%20Chrome%20cache%20%28gzipped%20or%20not%29\" title=\"Reddit\" rel=\"nofollow\" target=\"_blank\"><\/a>\n<script type=\"text\/javascript\"><!--\nwpa2a.script_load();\n\/\/--><\/script>\n<\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>Exceptionally, this article is slightly off-topic and will not be related to game development. I wished I could find an article like this one a few hours earlier, therefore I&#8217;m writing it myself, hoping to help people fixing the same problem I had. The context Earlier today, I was logging onto my ftp to download&hellip; <a class=\"more-link\" href=\"https:\/\/www.frozax.com\/blog\/2011\/05\/recover-file-google-chrome-cache-gzipped\/\">Continue reading <span class=\"screen-reader-text\">How to recover a file in Google Chrome cache (gzipped or not)<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[12],"tags":[62,64,84,105],"_links":{"self":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/645"}],"collection":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/comments?post=645"}],"version-history":[{"count":2,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/645\/revisions"}],"predecessor-version":[{"id":1695,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/posts\/645\/revisions\/1695"}],"wp:attachment":[{"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/media?parent=645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/categories?post=645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.frozax.com\/blog\/wp-json\/wp\/v2\/tags?post=645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}