A game (Sims 3 to be specific) is poorly coded, and one of the ways to get it to stop randomly crashing is to add it to your DEP exception list. I don't really want to do that if I don't have to, so I was wondering if there was a way to use SetProcessDEPPolicy on an external process to disable DEP on it? I'm not a brilliant programmer by any means, so the more information you can give, the better.
Asked
Active
Viewed 1,119 times
1 Answers
0
It is possible to do so by injecting a thread into the remote process:
HMODULE hKernel32 = GetModuleHandle("kernel32");
// Procedures in kernel32.dll are loaded at the same address in all processes
// so find the address in our own process, then use it in the target process
FARPROC pSetProcessDEPPolicy = GetProcAddress(hKernel32, "SetProcessDEPPolicy");
HANDLE hThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pSetProcessDEPPolicy, 0 /* disable DEP */, 0, NULL);
if (hThread == NULL) {
// handle/report error
}
WaitForSingleObject(hThread);
CloseHandle(hThread);
However this is generally a bad idea; there's a time window between when the process starts and when you perform the thread injection during which DEP is enabled, and anti-cheat or DRM functionality might see the thread injection as an attempt to hack the program. It's far more reliable to simply set the DEP exception list, and has the same effect.

bdonlan
- 224,562
- 31
- 268
- 324
-
So then would it be best if my program started the other application, instead of say, listening for it's launch? (Note that I don't know how to start an application in c++, I've only dabbled in c# and ahk, but I'll probably figure it out) – Dragonshadow Aug 22 '11 at 17:34
-
@Dragonshadow, starting the application doesn't make this any easier (there are ways to synchronize with the start of the app and inject the thread then, but they're quite complex). Why are you so insistent on not setting a DEP blacklist for the offending app? – bdonlan Aug 22 '11 at 17:51
-
The computer in question this would be run on has hardware issues that I can't take of right now, so restarting is a gamble whether it will come back up. Setting the DEP blacklist requires restarting the computer. – Dragonshadow Aug 22 '11 at 18:05
-
Perhaps these hardware issues are causing your crashes? – bdonlan Aug 22 '11 at 18:21
-
Nah, it's a power supply issue. Sim3 is just a broken game half the time. – Dragonshadow Aug 22 '11 at 19:01
-
Power supply issues can cause memory corruption by placing noise on the power rails. Anyway, if you insist on making a launcher, look into the debugging APIs, and place a breakpoint on the EXE's entry point address. – bdonlan Aug 22 '11 at 19:03