https://github.com/frida/frida
With Frida, you write JavaScript programs and then inject them into arbitrary processes, to hook and modify and call whatever you please.
It gets a lot of use in the reverse engineering and vulnerability research communities, but has broader scope too.
For instance, I used it recently to automate the UI of a video production program on Windows, by sending window messages to the main message loop from an injected thread, and hooking into various system dialog functions to override them.