Handle file requests
Yes hook_file_download() is the one you want to implement, assuming you're using the private file system. The docs have examples of how to use that hook.

There's no built-in way to do this (at least no way that involves Drupal) for public files, as those are served directly at the web server level without the application ever getting involved. 

You'll be able to implement a solution for public files based on modifying the .htaccess file to not pass those files straight through, and implement your own path system similar to the core private files one; the particular functionality will obviously depend on your exact requirements, if you decide to go this route I'd recommend spending some time looking at the core system and file modules to see how the mechanism is implemented. 

Unfortunately it's not a few-lines-of-code job so I can't provide an example, it's something you'll have to put together yourself.