I don't see how all aftermarket exhausts could be illegal. Afterall, I'm sure somebody has had to replace part of, or a complete exhausts system on their vehicle at one point in a cars life due to mechanical failure.
I'd assume that the aftermarket exhaust would have to pass emissions and not exceed factory or a set state noise level. Reading the code section, as long as you don't have a "whistle-tip", a bypass, cutoff, straight-pipe, and don't exceed 95 dbA you can have the citation dismissed in court if you have your certificate of compliance for sections 27150-51.
If you feel you have a case, take it to court. Otherwise, just pay the fine.
"You're abrasive, an idiot, a liar, a liberal and fool. I'd call that fairly accurate. Wait a minute. I think I could have just called you a Liberal and that would have included all the others ..." ro56 @ realpolice, 2006.
RIP Sergeant Reeves and Officer Gilner