Is it possible to change the get_posts() or wp_query() function to alter the results that are returned?

do you mean something like this?

https://developer.wordpress.org/reference/hooks/pre_get_posts/

Here you can alter the query before it is actually run.