diff options
Diffstat (limited to 'sandbox/src/win_utils.cc')
-rw-r--r-- | sandbox/src/win_utils.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/sandbox/src/win_utils.cc b/sandbox/src/win_utils.cc index bf4936b..8be9ce4 100644 --- a/sandbox/src/win_utils.cc +++ b/sandbox/src/win_utils.cc @@ -265,6 +265,26 @@ bool GetPathFromHandle(HANDLE handle, std::wstring* path) { return true; } +bool WriteProtectedChildMemory(HANDLE child_process, void* address, + const void* buffer, size_t length) { + // First, remove the protections. + DWORD old_protection; + if (!::VirtualProtectEx(child_process, address, length, + PAGE_WRITECOPY, &old_protection)) + return false; + + SIZE_T written; + bool ok = ::WriteProcessMemory(child_process, address, buffer, length, + &written) && (length == written); + + // Always attempt to restore the original protection. + if (!::VirtualProtectEx(child_process, address, length, + old_protection, &old_protection)) + return false; + + return ok; +} + }; // namespace sandbox // TODO(cpu): This is not the final code we want here but we are yet |