Have I been hacked? Mysterious code at the top of theme files [closed]

Yes ! This is a malicious code – if you don’t have any backup. I will suggest you to remove this code from top of every file manually. There is no “Genire” plugin/script which can safely remove it from your every file.
If you are good with PHP, you can write your own script.

Follow these steps to make all secure :

  1. Remove All Malicious Code From Every File
  2. Change file permissions.
  3. Install this plugin and run a scan for more info : https://wordpress.org/plugins/gotmls/