If you really need to ask those questions you should stay far, FAR away from coding for exploits.
Don't get me wrong, I don't want to be mean, but letting code run in an "exploited environment" is not as easy as just running an executable.
There is quite some restrictions and many, many other problems you have to deal with in that situation, you WILL get crashs you can't explain (due to missing experience), likely caused by stack oddities or other threads interfering with your code or your code with them.
Can you handle that, or even find those things as cause for the malfunction?
(If "yes", then go ahead, if no.... well....

)
You will not get happy with this, trust me.
// EDIT
One more thing that came into mind while re-reading the above:
You also can't just call functions like you are used to do, as you have no imports that get resolved upon your codes execution.
You have to manually find/know the funtion pointers and make them into function calls before you can use them.
Also there is only a limited list of functions you could call at all, only the ones already imported by the environment you exploited....
Well....