I know how to inject a DLL into a running process and also how to utilize functions used internally by the process e.g.

```
void__stdcall remoteMethod(unsigned short id)
{
typedef void (__stdcall *pFunctionAddress)(unsigned short);
pFunctionAddress pMyFunction = (pFunctionAddress)(0xCAFEBABE);
pMyFunction(id);
}

```

Now i want to add a sleep() into an existing method in the running process - this is the main loop of the program and doesnt stop for a sec and uses up all processing power.

I know that with frameworks like detours i could make a trampoline function which calls my function and then the original one - however my problem is that the while(1) loop is somewhere within the function of the external process. So i know the offset where the loop starts - and after that i would like to first call sleep() and then continue with the normal route of the loop.

The only alternative i saw so far is binary editing the program but this is not a good solution.

Any suggestion? Thanks