Unless the Hacker has had direct and physical contact with this computer..
They some how been able to guess your Strong Computer Password ( alpa, numeric case sensitivity password )
Then, planted their backdoor Hacks on the computer
It is not likely the computer was Hacked
Adware and Malware can affect computers and are often downloaded from “shady” websites or developers who inject them into downloads.
A good sources of this type of softwares are by installing Hacked Version of Third Party Software or via Torrent downloads
Source: User tip from @Kurt Lang
What is malware? - Apple Community
Even so, the macOS operating system resides in a sealed and read-only volume that can’t be opened by users or third-party applications
If you believe the computer has been compromised
Start Over from Scratch
Heavy Handed ? - Yes
Effective ? - Yes
For Apple Silicon computer >> Use Disk Utility to erase a Mac with Apple silicon.