开发者

Calling SetProcessDEPPolicy on another process?

开发者 https://www.devze.com 2023-03-30 09:48 出处:网络
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

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号