I'm writing a DLL for a program that needs to run in an infinite loop (with delays, of course). For example:
while (true) {
std::cout << "I am running.\n";
Sleep(1000);
}
I'm not sure how but no matter how I do this, the target program closes itself after a couple minutes. I know that it is not the DLL's presence because if I don't have an infinite loop and it "completes" (but stays in memory) it doesn't detect anything.
I am using Cheat Engine to inject the DLL. It is detected both when I inject it normally and when I have the loop in a separate function and create a thread for it.
If there aren't a few easy and easy to patch ways to detect things like this, what are alternatives? I'm writing it as a DLL because I need to call functions within the process (CreateRemoteThread-ing the bases wouldn't be easy because most of them have many more than one argument).