If your phone gets hacked, you can try to do hard reset, if that doesn't work for you, then you can install new rom, but before that, do full wipe. Check https://www.xda-developers.com/ for guides and for more info.
how do you install the new rom
That is the reason i posted xda forum. You need to install custom recovery, then download rom and put it on sd card. Next step is to boot into custom recovery and wipe system,data,dalvik cache and cache, and then go to install, find rom on sd card, select it and thats it. But find proper rom for your phone and follow instructions.
Feya Andev has the right idea... It can be difficult to trace malicious activity on a phone and what exactly is infected, which is why a full wipe might be the best decision based on the situation!
Best steps are to fully protect your phone to the best of your ability to avoid getting compromised in the first place :P