Insert a simulated Ken Thompson virus into a program A Ken Thompson virus is a virus that infects your compiler and other programs. Since it infects all your tools, you can not detect it without using tools from before the virus was introduced.

Your will create a prototype for inserting the Ken Thompson virus into code. The goal of this virus will be to allow you to (fake) destroy any computer running a program infected with it.

Inserting a Ken Thompson virus is defined as follows. Start with an input program P. Your program will output a modified program Q that works as follows:


If the input to Q is aNouIQ5xKvUfdZVzo0Xs, it will output BOOM (in a real Ken Thompson virus, this would actually do something bad, but since it this is a fake virus, outputing BOOM is done instead).
For any other input to Q, run program P with that input


If the output of P is valid source code in the language you are using, insert the Ken Thompson virus into it and then Q will output the resulting infected program.
Otherwise, the output of Q is just the output of P.



You will write a program that takes P's code as input and produces Q's code as output.

You can use either a currently (at the time of this post) existing programming language, or a subset of one, for this challenge. (The idea is that language you are using would be the target language of some self-compiling compiler, but this is not required.) Since you want to be as subtle as possible, the shortest code (in bytes) wins!
For some other languages, determining If the output of P is valid source code in the language you are using is almost impossible, unless you use/rewrite a compiler. For some other languages you can eval a string and catch for error, if any. However, for Mathematica, it is just check for if the head of the result is a function - Mathematica doesn't allow output invalid function, like 1!-!&amp;.
So,
Mathematica, 209 bytes
(obviously can be golfed more, for example by assign long names to global variables)
With[{p=#,c=With[{p=#,c=6},If[#===&quot;aNouIQ5xKvUfdZVzo0Xs&quot;,&quot;BOOM&quot;,With[{r=p@#},If[Head@r===Head@p,(c/.3!-&gt;c)[r],r]]]&amp;]&amp;},If[#===&quot;aNouIQ5xKvUfdZVzo0Xs&quot;,&quot;BOOM&quot;,With[{r=p@#},If[Head@r===Head@p,(c/.3!-&gt;c)[r],r]]]&amp;]&amp;

The function takes a function as input, and output a function according to the specification.
Note that the input must be a pure function, not something like f[x_] := .... So all Mathematica built-in functions fail the criteria.
Although Mathematica have #0 parameter, I explicitly disallow that in my answer because a quine is not allowed to read the code of itself.
(I thought that question is trivial until I read the third rule)