I think JCL has some utils for this kind of stuff... I haven't used it myself but had a quick look and following items look promising:
jclSysUtils.WriteProtectedMemory()
jclPeImage.TJclPeMapImgHooks.ReplaceImport()
I think the jclHookExcept.JclHookExceptions() demonstrates how to use them.