How to modify and rewrite the activation output of a layer before applying the output to next layer?

You could use forward hooks as described here and manipulate the output inplace in the hook.