Is there a way to alter the implementation of a hook given by a third-party module, or a core module?
You can use hook_module_implements_alter() to alter the list of modules which implement a given hook. So just implement the hook in your module too and then remove the one from the module you want to replace.

Note that this hook should be used very carefully, you can do really weird stuff with it which will make it very hard to maintain and understand, among other things.