Is it safe and legal to replace an extension cord plug end?
Replacement cord ends are not illegal for home use in the USA. They are, however, disallowed by some jobsite governing organizations (OSHA, for example) in certain situations. 

Just make sure you're familiar with the fundamentals of electricity and know how to make good electrical and mechanical connections. (The cable jacket should usually extend into the plug and be retained by its clamp.)