What are these boxes built into the tails of some fighters?
You're right. It's the ECM/EW antenna/equipment (fairing) in all the aircrafts except Typhoon. 

This photo shows the details of EW/ECM suite in Gripen.



Source: www.w54.biz

In Typhoon, it is the engine bleed air heat exchanger. The part is in detail here.



Source: b-domke.de