Override a function which is not in class and whitelisted

Hello Everyone, need to override a function that is not whitelisted and not within a class. Could you please guide me on how to achieve this?

@NCP Sir need your suggestions here!

Possible using monkey patch.

Reference:

@NCP Thank You sir.