-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
61 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#include <base/hook/patch.h> | ||
#include <base/hook/detail/memory_protect.h> | ||
#include <Windows.h> | ||
|
||
namespace base { namespace hook { | ||
|
||
bool patch(uintptr_t address, const char* value, size_t value_size) | ||
{ | ||
detail::memory_protect protect_(address, value_size); | ||
if (protect_.success()) | ||
{ | ||
DWORD written; | ||
if (::WriteProcessMemory(::GetCurrentProcess(), (LPVOID)address, value, value_size, &written)) | ||
{ | ||
::FlushInstructionCache(::GetCurrentProcess(), (LPVOID)address, value_size); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <base/config.h> | ||
#include <cassert> | ||
#include <cstdint> | ||
|
||
namespace base { namespace hook { | ||
_BASE_API bool patch(uintptr_t address, const char* value, size_t value_size); | ||
|
||
|
||
template <size_t n> | ||
bool patch(uintptr_t address, const char(&value)[n]) | ||
{ | ||
assert(n > 1); | ||
return patch(address, value, n - 1); | ||
} | ||
|
||
template <size_t n> | ||
bool patch(uintptr_t address, char(&value)[n]) | ||
{ | ||
return patch(address, value, std::string::traits_type::length(value)); | ||
} | ||
}} |