I want to alter the stack of a newly created remote thread, but upon invoking CreateRemoteThread to create a thread in a suspended state, the stack has not been allocated.
I’m using GetThreadContext to get the address of ESP after creating the suspended thread, though if I look at this address in my disassembly window in the VS debugger, it has not been allocated. Also, writing to this address using WriteProcessMemory fails every time.
How can I edit the stack of a newly created but suspended remote thread?
When you get thread handle, its stack is allocated, (as well as TIB structure).
MSVS debugger may show wrong information, so don’t rely on it.
I’m not sure if thread context has correct values, maybe it’s set later.
You should use
TIBstructure to get stack addresses, if it’s really what you need.If you just want to call function remotely before thread function invocation, you can use
QueueUserAPCorRtlRemoteCall, both works when thread is created withCREATE_SUSPENDEDflag.