I am currently working with a VMProtect'ed game on windows where the pseudo handle returned from "GetCurrentProcess()" seems to have restricted access rights. For example, calls to VirtualProtectEx/VirtualProtect on this handle to set RWX permissions will fail. It is possible to bypass this protection by opening a new handle with the required access flags (PROCESS_VM_OPERATION) and then pass is to the -Ex functions.
However, using the LM_WriteMemoryEx- and LM_HookCodeEx-functions doesn't work because libmem's open_process implementation for windows simply returns the restricted handle from "GetCurrentProcess()", if it determines that the call comes from the current process:
|
open_process(DWORD pid, DWORD access) |
|
{ |
|
if (pid == GetCurrentProcessId()) |
|
return GetCurrentProcess(); |
|
|
|
return OpenProcess(access, FALSE, pid); |
|
} |
Solution
Since the open_process implementation seems to only be called inside libmem's -Ex functions, it should probably be fine to remove the if statement. If someone calls an -Ex function explicitly, they probably have an intention in doing so.
I am currently working with a VMProtect'ed game on windows where the pseudo handle returned from "GetCurrentProcess()" seems to have restricted access rights. For example, calls to
VirtualProtectEx/VirtualProtecton this handle to set RWX permissions will fail. It is possible to bypass this protection by opening a new handle with the required access flags (PROCESS_VM_OPERATION) and then pass is to the -Ex functions.However, using the
LM_WriteMemoryEx- andLM_HookCodeEx-functions doesn't work because libmem'sopen_processimplementation for windows simply returns the restricted handle from "GetCurrentProcess()", if it determines that the call comes from the current process:libmem/internal/winutils/winutils.c
Lines 90 to 96 in a6136d6
Solution
Since the
open_processimplementation seems to only be called inside libmem's -Ex functions, it should probably be fine to remove the if statement. If someone calls an -Ex function explicitly, they probably have an intention in doing so.