You should think about getting your children into counselling to better deal with their feelings, and to hopefully gain an understanding of your wife’s behavior.
The best solution for this is to sit those boys down and talk to them. Tell them that the separation and divorce are not their concern or business. Let them know that you are the adult and you will get things worked out. They need to be focused on their schoolwork and other appropriate things…I don’t want to sound harsh but though this affects them, it is not their problem.
Their knowledge of what is going on in this should be limited but if your ex is anything like my husband’s ex, they will know every dirty detail plus whatever she can make up. Your best bet is to not discuss it at all with them except to answer questions about your time with them, how this is affecting them and what you can do to make things easier. If they answer with the “fire your attorney” then your response should be, “that will not help you through this”. Let them know that if they want to know your side that you will discuss it with them when they are older, but that for the moment this is not what they need to be concerned about.
Unfortunately there is nothing you can do to make her stop badmouthing you. A judge may be able to warn her about alienating the children’s affection from you but that will be up to your attorney to bring up in court, if it goes that far. You can ask her to stop discussing it with them and document this. For the time being, when you are with them, do not discuss anything to do with the separation or divorce, custody or ED. If they bring it up with questions, let them know that you love them but you are not going to discuss this with them and try to steer the conversation in another direction. This is a difficult situation but your children knowing all the details is not going to help them cope with it.