Skip to content

Missing access rights when running -Ex functions on current process #303

Description

@lnx00

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions