While dark matter (DM) is the key ingredient for a successful theory of structure formation, its microscopic nature remains elusive. Indirect detection may provide a powerful test for some strongly motivated DM particle models. Nevertheless, astrophysical backgrounds are usually expected with amplitudes and spectral features similar to the chased signals. On galactic scales, these backgrounds arise from interactions of cosmic rays (CRs) with the interstellar gas, both being difficult to infer and model in detail from observations. Moreover, the associated predictions unavoidably come with theoretical errors, which are known to be significant. We show that a trustworthy guide for such challenging searches can be obtained by exploiting the full information contained in cosmological simulations of galaxies, which now include baryonic gas dynamics and star formation. We further insert CR production and transport from the identified supernova events and fully calculate the CR distribution in a simulated galaxy. We focus on diffuse gamma rays, and self-consistently calculate both the astrophysical galactic emission and the DM signal. We notably show that adiabatic contraction does not necessarily induce large signal-to-noise ratios in galactic centers, and could anyway be traced from the astrophysical background itself. We finally discuss how all this may be used as a generic diagnostic tool for galaxy formation.